[vlc-commits] flac encoders: use the long format extradata
Rafaël Carré
git at videolan.org
Tue Aug 20 23:57:14 CEST 2013
vlc | branch: master | Rafaël Carré <funman at videolan.org> | Tue Aug 20 23:56:03 2013 +0200| [6d40f995b0f65c68fad7e2aea68d3337df1ea708] | committer: Rafaël Carré
flac encoders: use the long format extradata
fLaC marker is helpful for file format detection
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6d40f995b0f65c68fad7e2aea68d3337df1ea708
---
modules/codec/avcodec/encoder.c | 37 +++++++++++++++++++++++++++++++------
modules/codec/flac.c | 9 ++++++---
2 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index f14d898..0ceb4fe 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -822,16 +822,41 @@ int OpenEncoder( vlc_object_t *p_this )
av_dict_free(&options);
- p_enc->fmt_out.i_extra = p_context->extradata_size;
- if( p_enc->fmt_out.i_extra )
+ if( i_codec_id == AV_CODEC_ID_FLAC )
{
+ p_enc->fmt_out.i_extra = 4 + 1 + 3 + p_context->extradata_size;
p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
- if ( p_enc->fmt_out.p_extra == NULL )
+ if( p_enc->fmt_out.p_extra )
{
- goto error;
+ uint8_t *p = p_enc->fmt_out.p_extra;
+ p[0] = 0x66; /* f */
+ p[1] = 0x4C; /* L */
+ p[2] = 0x61; /* a */
+ p[3] = 0x43; /* C */
+ p[4] = 0x80; /* streaminfo block, last block before audio */
+ p[5] = ( p_context->extradata_size >> 16 ) & 0xff;
+ p[6] = ( p_context->extradata_size >> 8 ) & 0xff;
+ p[7] = ( p_context->extradata_size ) & 0xff;
+ memcpy( &p[8], p_context->extradata, p_context->extradata_size );
+ }
+ else
+ {
+ p_enc->fmt_out.i_extra = 0;
+ }
+ }
+ else
+ {
+ p_enc->fmt_out.i_extra = p_context->extradata_size;
+ if( p_enc->fmt_out.i_extra )
+ {
+ p_enc->fmt_out.p_extra = malloc( p_enc->fmt_out.i_extra );
+ if ( p_enc->fmt_out.p_extra == NULL )
+ {
+ goto error;
+ }
+ memcpy( p_enc->fmt_out.p_extra, p_context->extradata,
+ p_enc->fmt_out.i_extra );
}
- memcpy( p_enc->fmt_out.p_extra, p_context->extradata,
- p_enc->fmt_out.i_extra );
}
p_context->flags &= ~CODEC_FLAG_GLOBAL_HEADER;
diff --git a/modules/codec/flac.c b/modules/codec/flac.c
index b57c3a4..72a12bc 100644
--- a/modules/codec/flac.c
+++ b/modules/codec/flac.c
@@ -584,9 +584,12 @@ EncoderWriteCallback( const FLAC__StreamEncoder *encoder,
msg_Dbg( p_enc, "Writing STREAMINFO: %zu", bytes );
/* Backup the STREAMINFO metadata block */
- p_enc->fmt_out.i_extra = STREAMINFO_SIZE;
- p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE );
- memcpy(p_enc->fmt_out.p_extra, buffer + 4, STREAMINFO_SIZE );
+ p_enc->fmt_out.i_extra = STREAMINFO_SIZE + 8;
+ p_enc->fmt_out.p_extra = xmalloc( STREAMINFO_SIZE + 8);
+ memcpy(p_enc->fmt_out.p_extra, "fLaC", 4);
+ memcpy(p_enc->fmt_out.p_extra + 4, buffer, STREAMINFO_SIZE );
+ /* Fake this as the last metadata block */
+ ((uint8_t*)p_enc->fmt_out.p_extra)[4] |= 0x80;
}
p_sys->i_headers++;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
More information about the vlc-commits
mailing list