+static bo_t *GetDamrTag( mp4_stream_t *p_stream )
+{
+ bo_t *damr;
+
+ damr = box_new( "damr" );
+
+ bo_add_fourcc( damr, "REFC" );
+ bo_add_8( damr, 0 );
+
+ if( p_stream->fmt.i_codec == VLC_FOURCC( 's', 'a', 'm', 'r' ) )
+ bo_add_16be( damr, 0x81ff ); /* Mode set (all modes for AMR_NB) */
+ else
+ bo_add_16be( damr, 0x83ff ); /* Mode set (all modes for AMR_WB) */
+ bo_add_16be( damr, 0x1 ); /* Mode change period (no restriction) */
+
+ box_fix( damr );
+
+ return damr;
+}
+
+static bo_t *GetD263Tag( mp4_stream_t *p_stream )
+{
+ bo_t *d263;
+
+ d263 = box_new( "d263" );
+
+ bo_add_fourcc( d263, "VLC " );
+ bo_add_16be( d263, 0xa );
+ bo_add_8( d263, 0 );
+
+ box_fix( d263 );
+
+ return d263;
+}
+
+static bo_t *GetAvcCTag( mp4_stream_t *p_stream )
+{
+ bo_t *avcC = NULL;
+ uint8_t *p_sps = NULL;
+ uint8_t *p_pps = NULL;
+ int i_sps_size = 0;
+ int i_pps_size = 0;
+
+ if( p_stream->fmt.i_extra > 0 )
+ {
+ /* FIXME: take into account multiple sps/pps */
+ uint8_t *p_buffer = p_stream->fmt.p_extra;
+ int i_buffer = p_stream->fmt.i_extra;
+
+ while( i_buffer > 4 &&
+ p_buffer[0] == 0 && p_buffer[1] == 0 &&
+ p_buffer[2] == 0 && p_buffer[3] == 1 )
+ {
+ const int i_nal_type = p_buffer[4]&0x1f;
+ int i_offset = 1;
+ int i_size = 0;
+ int i_startcode = 0;
+
+ //msg_Dbg( p_stream, "we found a startcode for NAL with TYPE:%d", i_nal_type );
+
+ for( i_offset = 1; i_offset+3 < i_buffer ; i_offset++)
+ {
+ if( p_buffer[i_offset] == 0 && p_buffer[i_offset+1] == 0 &&
+ p_buffer[i_offset+2] == 0 && p_buffer[i_offset+3] == 1 )
+ {
+ /* we found another startcode */
+ i_startcode = i_offset;
+ break;
+ }
+ }
+ i_size = i_startcode ? i_startcode : i_buffer;
+ if( i_nal_type == 7 )
+ {
+ p_sps = &p_buffer[4];
+ i_sps_size = i_size - 4;
+ }
+ if( i_nal_type == 8 )
+ {
+ p_pps = &p_buffer[4];
+ i_pps_size = i_size - 4;
+ }
+ i_buffer -= i_size;
+ p_buffer += i_size;
+ }
+ }
+
+ /* FIXME use better value */
+ avcC = box_new( "avcC" );
+ bo_add_8( avcC, 1 ); /* configuration version */
+ bo_add_8( avcC, i_sps_size ? p_sps[1] : 77 );
+ bo_add_8( avcC, i_sps_size ? p_sps[2] : 64 );
+ bo_add_8( avcC, i_sps_size ? p_sps[3] : 30 ); /* level, 5.1 */
+ bo_add_8( avcC, 0xff ); /* 0b11111100 | lengthsize = 0x11 */
+
+ bo_add_8( avcC, 0xe0 | (i_sps_size > 0 ? 1 : 0) ); /* 0b11100000 | sps_count */
+ if( i_sps_size > 0 )
+ {
+ bo_add_16be( avcC, i_sps_size );
+ bo_add_mem( avcC, i_sps_size, p_sps );
+ }
+
+ bo_add_8( avcC, (i_pps_size > 0 ? 1 : 0) ); /* pps_count */
+ if( i_pps_size > 0 )
+ {
+ bo_add_16be( avcC, i_pps_size );
+ bo_add_mem( avcC, i_pps_size, p_pps );
+ }
+ box_fix( avcC );
+
+ return avcC;
+}
+