Mercurial > libavformat.hg
changeset 2509:5abcad2566b3 libavformat
Move writing codec private element to its own function
author | conrad |
---|---|
date | Wed, 05 Sep 2007 00:25:49 +0000 |
parents | 9b96804b67c1 |
children | 4ba8d5f648a4 |
files | matroskaenc.c |
diffstat | 1 files changed, 43 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/matroskaenc.c Wed Sep 05 00:25:46 2007 +0000 +++ b/matroskaenc.c Wed Sep 05 00:25:49 2007 +0000 @@ -470,6 +470,46 @@ } } +static int mkv_write_codecprivate(ByteIOContext *pb, AVCodecContext *codec, int native_id) +{ + int ret; + + if (native_id) { + if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA) { + ret = put_xiph_codecpriv(pb, codec); + if (ret < 0) return ret; + } else if (codec->codec_id == CODEC_ID_FLAC) { + ret = put_flac_codecpriv(pb, codec); + if (ret < 0) return ret; + } else if (codec->extradata_size) { + put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codec->extradata, codec->extradata_size); + } + } else if (codec->codec_type == CODEC_TYPE_VIDEO) { + ebml_master bmp_header; + + if (!codec->codec_tag) + codec->codec_tag = codec_get_tag(codec_bmp_tags, codec->codec_id); + + bmp_header = start_ebml_master(pb, MATROSKA_ID_CODECPRIVATE, 0); + put_bmp_header(pb, codec, codec_bmp_tags, 0); + end_ebml_master(pb, bmp_header); + + } else if (codec->codec_type == CODEC_TYPE_AUDIO) { + ebml_master wav_header; + + codec->codec_tag = codec_get_tag(codec_wav_tags, codec->codec_id); + if (!codec->codec_tag) { + av_log(codec, AV_LOG_ERROR, "no wav codec id found"); + return -1; + } + + wav_header = start_ebml_master(pb, MATROSKA_ID_CODECPRIVATE, 0); + put_wav_header(pb, codec); + end_ebml_master(pb, wav_header); + } + return 0; +} + static int mkv_write_tracks(AVFormatContext *s) { MatroskaMuxContext *mkv = s->priv_data; @@ -516,32 +556,13 @@ } } - if (native_id) { - if (codec->codec_id == CODEC_ID_VORBIS || codec->codec_id == CODEC_ID_THEORA) { - ret = put_xiph_codecpriv(pb, codec); - if (ret < 0) return ret; - } else if (codec->codec_id == CODEC_ID_FLAC) { - ret = put_flac_codecpriv(pb, codec); - if (ret < 0) return ret; - } else if (codec->extradata_size) { - put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codec->extradata, codec->extradata_size); - } - } - switch (codec->codec_type) { case CODEC_TYPE_VIDEO: put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); if (!native_id) { - ebml_master bmp_header; // if there is no mkv-specific codec id, use VFW mode - if (!codec->codec_tag) - codec->codec_tag = codec_get_tag(codec_bmp_tags, codec->codec_id); - put_ebml_string(pb, MATROSKA_ID_CODECID, MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC); - bmp_header = start_ebml_master(pb, MATROSKA_ID_CODECPRIVATE, 0); - put_bmp_header(pb, codec, codec_bmp_tags, 0); - end_ebml_master(pb, bmp_header); } subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKVIDEO, 0); // XXX: interlace flag? @@ -560,18 +581,8 @@ put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_AUDIO); if (!native_id) { - ebml_master wav_header; // no mkv-specific ID, use ACM mode - codec->codec_tag = codec_get_tag(codec_wav_tags, codec->codec_id); - if (!codec->codec_tag) { - av_log(s, AV_LOG_ERROR, "no codec id found for stream %d", i); - return -1; - } - put_ebml_string(pb, MATROSKA_ID_CODECID, MATROSKA_CODEC_ID_AUDIO_ACM); - wav_header = start_ebml_master(pb, MATROSKA_ID_CODECPRIVATE, 0); - put_wav_header(pb, codec); - end_ebml_master(pb, wav_header); } subinfo = start_ebml_master(pb, MATROSKA_ID_TRACKAUDIO, 0); put_ebml_uint (pb, MATROSKA_ID_AUDIOCHANNELS , codec->channels); @@ -590,6 +601,9 @@ av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska."); break; } + ret = mkv_write_codecprivate(pb, codec, native_id); + if (ret < 0) return ret; + end_ebml_master(pb, track); // ms precision is the de-facto standard timescale for mkv files