Commit d5d904b9 authored by Rafaël Carré's avatar Rafaël Carré

mp4 mux: use block_t

parent 0edad062
...@@ -136,10 +136,8 @@ struct sout_mux_sys_t ...@@ -136,10 +136,8 @@ struct sout_mux_sys_t
typedef struct bo_t typedef struct bo_t
{ {
int i_buffer_size; block_t *b;
int i_buffer; size_t len;
uint8_t *p_buffer;
} bo_t; } bo_t;
static void bo_init ( bo_t * ); static void bo_init ( bo_t * );
...@@ -149,7 +147,6 @@ static void bo_add_24be ( bo_t *, uint32_t ); ...@@ -149,7 +147,6 @@ static void bo_add_24be ( bo_t *, uint32_t );
static void bo_add_32be ( bo_t *, uint32_t ); static void bo_add_32be ( bo_t *, uint32_t );
static void bo_add_64be ( bo_t *, uint64_t ); static void bo_add_64be ( bo_t *, uint64_t );
static void bo_add_fourcc(bo_t *, const char * ); static void bo_add_fourcc(bo_t *, const char * );
static void bo_add_bo ( bo_t *, bo_t * );
static void bo_add_mem ( bo_t *, int , uint8_t * ); static void bo_add_mem ( bo_t *, int , uint8_t * );
static void bo_add_descr( bo_t *, uint8_t , uint32_t ); static void bo_add_descr( bo_t *, uint8_t , uint32_t );
...@@ -158,13 +155,10 @@ static void bo_fix_32be ( bo_t *, int , uint32_t ); ...@@ -158,13 +155,10 @@ static void bo_fix_32be ( bo_t *, int , uint32_t );
static bo_t *box_new ( const char *fcc ); static bo_t *box_new ( const char *fcc );
static bo_t *box_full_new( const char *fcc, uint8_t v, uint32_t f ); static bo_t *box_full_new( const char *fcc, uint8_t v, uint32_t f );
static void box_fix ( bo_t *box ); static void box_fix ( bo_t *box );
static void box_free ( bo_t *box );
static void box_gather ( bo_t *box, bo_t *box2 ); static void box_gather ( bo_t *box, bo_t *box2 );
static void box_send( sout_mux_t *p_mux, bo_t *box ); static void box_send( sout_mux_t *p_mux, bo_t *box );
static block_t *bo_to_sout( bo_t *box );
static bo_t *GetMoovBox( sout_mux_t *p_mux ); static bo_t *GetMoovBox( sout_mux_t *p_mux );
static block_t *ConvertSUBT( block_t *); static block_t *ConvertSUBT( block_t *);
...@@ -211,7 +205,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -211,7 +205,7 @@ static int Open( vlc_object_t *p_this )
bo_add_fourcc( box, "qt " ); bo_add_fourcc( box, "qt " );
box_fix( box ); box_fix( box );
p_sys->i_pos += box->i_buffer; p_sys->i_pos += box->len;
p_sys->i_mdat_pos = p_sys->i_pos; p_sys->i_mdat_pos = p_sys->i_pos;
box_send( p_mux, box ); box_send( p_mux, box );
...@@ -225,7 +219,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -225,7 +219,7 @@ static int Open( vlc_object_t *p_this )
box = box_new( "mdat" ); box = box_new( "mdat" );
bo_add_64be ( box, 0 ); // enough to store an extended size bo_add_64be ( box, 0 ); // enough to store an extended size
p_sys->i_pos += box->i_buffer; p_sys->i_pos += box->len;
box_send( p_mux, box ); box_send( p_mux, box );
...@@ -264,8 +258,8 @@ static void Close( vlc_object_t * p_this ) ...@@ -264,8 +258,8 @@ static void Close( vlc_object_t * p_this )
bo_add_32be ( &bo, p_sys->i_pos - p_sys->i_mdat_pos - 8 ); bo_add_32be ( &bo, p_sys->i_pos - p_sys->i_mdat_pos - 8 );
bo_add_fourcc( &bo, "mdat" ); bo_add_fourcc( &bo, "mdat" );
} }
p_hdr = bo_to_sout( &bo ); p_hdr = bo.b;
free( bo.p_buffer ); p_hdr->i_buffer = bo.len;
sout_AccessOutSeek( p_mux->p_access, p_sys->i_mdat_pos ); sout_AccessOutSeek( p_mux->p_access, p_sys->i_mdat_pos );
sout_AccessOutWrite( p_mux->p_access, p_hdr ); sout_AccessOutWrite( p_mux->p_access, p_hdr );
...@@ -283,7 +277,7 @@ static void Close( vlc_object_t * p_this ) ...@@ -283,7 +277,7 @@ static void Close( vlc_object_t * p_this )
* at the start */ * at the start */
block_t *p_buf; block_t *p_buf;
int64_t i_chunk, i_size = p_sys->i_pos - p_sys->i_mdat_pos; int64_t i_chunk, i_size = p_sys->i_pos - p_sys->i_mdat_pos;
int i_moov_size = moov->i_buffer; int i_moov_size = moov->len;
while( i_size > 0 ) while( i_size > 0 )
{ {
...@@ -314,7 +308,7 @@ static void Close( vlc_object_t * p_this ) ...@@ -314,7 +308,7 @@ static void Close( vlc_object_t * p_this )
unsigned int i; unsigned int i;
int i_chunk; int i_chunk;
moov->i_buffer = p_stream->i_stco_pos; moov->len = p_stream->i_stco_pos;
for( i_chunk = 0, i = 0; i < p_stream->i_entry_count; i_chunk++ ) for( i_chunk = 0, i = 0; i < p_stream->i_entry_count; i_chunk++ )
{ {
if( p_stream->b_stco64 ) if( p_stream->b_stco64 )
...@@ -337,7 +331,7 @@ static void Close( vlc_object_t * p_this ) ...@@ -337,7 +331,7 @@ static void Close( vlc_object_t * p_this )
} }
} }
moov->i_buffer = i_moov_size; moov->len = i_moov_size;
i_moov_pos = p_sys->i_mdat_pos; i_moov_pos = p_sys->i_mdat_pos;
p_sys->b_fast_start = false; p_sys->b_fast_start = false;
} }
...@@ -1468,7 +1462,7 @@ static bo_t *GetStblBox( sout_mux_t *p_mux, mp4_stream_t *p_stream ) ...@@ -1468,7 +1462,7 @@ static bo_t *GetStblBox( sout_mux_t *p_mux, mp4_stream_t *p_stream )
} }
box_gather( stbl, stsc ); box_gather( stbl, stsc );
box_gather( stbl, stsz ); box_gather( stbl, stsz );
p_stream->i_stco_pos = stbl->i_buffer + 16; p_stream->i_stco_pos = stbl->len + 16;
box_gather( stbl, stco ); box_gather( stbl, stco );
/* finish stbl */ /* finish stbl */
...@@ -1861,22 +1855,22 @@ static bo_t *GetMoovBox( sout_mux_t *p_mux ) ...@@ -1861,22 +1855,22 @@ static bo_t *GetMoovBox( sout_mux_t *p_mux )
stbl = GetStblBox( p_mux, p_stream ); stbl = GetStblBox( p_mux, p_stream );
/* append stbl to minf */ /* append stbl to minf */
p_stream->i_stco_pos += minf->i_buffer; p_stream->i_stco_pos += minf->len;
box_gather( minf, stbl ); box_gather( minf, stbl );
/* append minf to mdia */ /* append minf to mdia */
box_fix( minf ); box_fix( minf );
p_stream->i_stco_pos += mdia->i_buffer; p_stream->i_stco_pos += mdia->len;
box_gather( mdia, minf ); box_gather( mdia, minf );
/* append mdia to trak */ /* append mdia to trak */
box_fix( mdia ); box_fix( mdia );
p_stream->i_stco_pos += trak->i_buffer; p_stream->i_stco_pos += trak->len;
box_gather( trak, mdia ); box_gather( trak, mdia );
/* append trak to moov */ /* append trak to moov */
box_fix( trak ); box_fix( trak );
p_stream->i_stco_pos += moov->i_buffer; p_stream->i_stco_pos += moov->len;
box_gather( moov, trak ); box_gather( moov, trak );
} }
...@@ -1891,25 +1885,16 @@ static bo_t *GetMoovBox( sout_mux_t *p_mux ) ...@@ -1891,25 +1885,16 @@ static bo_t *GetMoovBox( sout_mux_t *p_mux )
static void bo_init( bo_t *p_bo ) static void bo_init( bo_t *p_bo )
{ {
p_bo->i_buffer_size = 1024; p_bo->len = 0;
p_bo->p_buffer = xmalloc( p_bo->i_buffer_size ); p_bo->b = block_Alloc( 1024 );
p_bo->i_buffer = 0;
} }
static void bo_add_8( bo_t *p_bo, uint8_t i ) static void bo_add_8( bo_t *p_bo, uint8_t i )
{ {
if( p_bo->i_buffer < p_bo->i_buffer_size ) if( p_bo->len >= p_bo->b->i_buffer)
{ p_bo->b = block_Realloc(p_bo->b, 0, p_bo->b->i_buffer + 1024);
p_bo->p_buffer[p_bo->i_buffer] = i;
}
else
{
p_bo->i_buffer_size += 1024;
p_bo->p_buffer = xrealloc( p_bo->p_buffer, p_bo->i_buffer_size );
p_bo->p_buffer[p_bo->i_buffer] = i;
}
p_bo->i_buffer++; p_bo->b->p_buffer[p_bo->len++] = i;
} }
static void bo_add_16be( bo_t *p_bo, uint16_t i ) static void bo_add_16be( bo_t *p_bo, uint16_t i )
...@@ -1932,10 +1917,10 @@ static void bo_add_32be( bo_t *p_bo, uint32_t i ) ...@@ -1932,10 +1917,10 @@ static void bo_add_32be( bo_t *p_bo, uint32_t i )
static void bo_fix_32be ( bo_t *p_bo, int i_pos, uint32_t i) static void bo_fix_32be ( bo_t *p_bo, int i_pos, uint32_t i)
{ {
p_bo->p_buffer[i_pos ] = ( i >> 24 )&0xff; p_bo->b->p_buffer[i_pos ] = ( i >> 24 )&0xff;
p_bo->p_buffer[i_pos + 1] = ( i >> 16 )&0xff; p_bo->b->p_buffer[i_pos + 1] = ( i >> 16 )&0xff;
p_bo->p_buffer[i_pos + 2] = ( i >> 8 )&0xff; p_bo->b->p_buffer[i_pos + 2] = ( i >> 8 )&0xff;
p_bo->p_buffer[i_pos + 3] = ( i )&0xff; p_bo->b->p_buffer[i_pos + 3] = ( i )&0xff;
} }
static void bo_add_64be( bo_t *p_bo, uint64_t i ) static void bo_add_64be( bo_t *p_bo, uint64_t i )
...@@ -1966,12 +1951,6 @@ static void bo_add_descr( bo_t *p_bo, uint8_t tag, uint32_t size ) ...@@ -1966,12 +1951,6 @@ static void bo_add_descr( bo_t *p_bo, uint8_t tag, uint32_t size )
bo_add_8(p_bo, size & 0x7F); bo_add_8(p_bo, size & 0x7F);
} }
static void bo_add_bo( bo_t *p_bo, bo_t *p_bo2 )
{
for( int i = 0; i < p_bo2->i_buffer; i++ )
bo_add_8( p_bo, p_bo2->p_buffer[i] );
}
static bo_t * box_new( const char *fcc ) static bo_t * box_new( const char *fcc )
{ {
bo_t *box; bo_t *box;
...@@ -2006,47 +1985,26 @@ static bo_t * box_full_new( const char *fcc, uint8_t v, uint32_t f ) ...@@ -2006,47 +1985,26 @@ static bo_t * box_full_new( const char *fcc, uint8_t v, uint32_t f )
static void box_fix( bo_t *box ) static void box_fix( bo_t *box )
{ {
bo_t box_tmp; box->b->p_buffer[0] = box->len >> 24;
box->b->p_buffer[1] = box->len >> 16;
memcpy( &box_tmp, box, sizeof( bo_t ) ); box->b->p_buffer[2] = box->len >> 8;
box->b->p_buffer[3] = box->len;
box_tmp.i_buffer = 0;
bo_add_32be( &box_tmp, box->i_buffer );
}
static void box_free( bo_t *box )
{
free( box->p_buffer );
free( box );
} }
static void box_gather ( bo_t *box, bo_t *box2 ) static void box_gather ( bo_t *box, bo_t *box2 )
{ {
bo_add_bo( box, box2 ); box->b = block_Realloc(box->b, 0, box->len + box2->len);
box_free( box2 ); memcpy(&box->b->p_buffer[box->len], box2->b->p_buffer, box2->len);
} box->len += box2->len;
block_Release(box2->b);
static block_t * bo_to_sout( bo_t *box ) free( box2 );
{
block_t *p_buf;
p_buf = block_Alloc( box->i_buffer );
if( box->i_buffer > 0 )
{
memcpy( p_buf->p_buffer, box->p_buffer, box->i_buffer );
}
return p_buf;
} }
static void box_send( sout_mux_t *p_mux, bo_t *box ) static void box_send( sout_mux_t *p_mux, bo_t *box )
{ {
block_t *p_buf; box->b->i_buffer = box->len;
sout_AccessOutWrite( p_mux->p_access, box->b );
p_buf = bo_to_sout( box ); free(box);
box_free( box );
sout_AccessOutWrite( p_mux->p_access, p_buf );
} }
static int64_t get_timestamp(void) static int64_t get_timestamp(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment