Mercurial > libavformat.hg
changeset 3120:ea5623a8efde libavformat
Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
of matroska and nut.
author | eugeni |
---|---|
date | Fri, 07 Mar 2008 19:25:09 +0000 |
parents | b1caac2f77ad |
children | 753a52a0869e |
files | avformat.h matroskadec.c matroskaenc.c nut.c nut.h nutdec.c nutenc.c |
diffstat | 7 files changed, 100 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/avformat.h Thu Mar 06 20:44:44 2008 +0000 +++ b/avformat.h Fri Mar 07 19:25:09 2008 +0000 @@ -22,7 +22,7 @@ #define FFMPEG_AVFORMAT_H #define LIBAVFORMAT_VERSION_MAJOR 52 -#define LIBAVFORMAT_VERSION_MINOR 7 +#define LIBAVFORMAT_VERSION_MINOR 8 #define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ @@ -278,6 +278,13 @@ int min_distance; /**< min distance between this and the previous keyframe, used to avoid unneeded searching */ } AVIndexEntry; +#define AV_DISPOSITION_DEFAULT 0x0001 +#define AV_DISPOSITION_DUB 0x0002 +#define AV_DISPOSITION_ORIGINAL 0x0004 +#define AV_DISPOSITION_COMMENT 0x0008 +#define AV_DISPOSITION_LYRICS 0x0010 +#define AV_DISPOSITION_KARAOKE 0x0020 + /** * Stream structure. * New fields can be added to the end with minor version bumps. @@ -357,6 +364,8 @@ int64_t pts_buffer[MAX_REORDER_DELAY+1]; char *filename; /**< source filename of the stream */ + + int disposition; /**< AV_DISPOSITION_* bitfield */ } AVStream; #define AV_PROGRAM_RUNNING 1
--- a/matroskadec.c Thu Mar 06 20:44:44 2008 +0000 +++ b/matroskadec.c Fri Mar 07 19:25:09 2008 +0000 @@ -2298,6 +2298,9 @@ if (strcmp(track->language, "und")) strcpy(st->language, track->language); + if (track->flags & MATROSKA_TRACK_DEFAULT) + st->disposition |= AV_DISPOSITION_DEFAULT; + if (track->default_duration) av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, track->default_duration, 1000000000, 30000);
--- a/matroskaenc.c Thu Mar 06 20:44:44 2008 +0000 +++ b/matroskaenc.c Fri Mar 07 19:25:09 2008 +0000 @@ -550,6 +550,8 @@ else put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, "und"); + put_ebml_uint(pb, MATROSKA_ID_TRACKFLAGDEFAULT, !!(st->disposition & AV_DISPOSITION_DEFAULT)); + // look for a codec ID string specific to mkv to use, // if none are found, use AVI codes for (j = 0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++) {
--- a/nut.c Thu Mar 06 20:44:44 2008 +0000 +++ b/nut.c Fri Mar 07 19:25:09 2008 +0000 @@ -68,3 +68,14 @@ av_free(node); } } + +const Dispositions ff_nut_dispositions[] = { + {"default" , AV_DISPOSITION_DEFAULT}, + {"dub" , AV_DISPOSITION_DUB}, + {"original" , AV_DISPOSITION_ORIGINAL}, + {"comment" , AV_DISPOSITION_COMMENT}, + {"lyrics" , AV_DISPOSITION_LYRICS}, + {"karaoke" , AV_DISPOSITION_KARAOKE}, + {"" , 0} +}; +
--- a/nut.h Thu Mar 06 20:44:44 2008 +0000 +++ b/nut.h Fri Mar 07 19:25:09 2008 +0000 @@ -99,10 +99,17 @@ extern const AVCodecTag ff_nut_subtitle_tags[]; +typedef struct { + char str[9]; + int flag; +} Dispositions; + void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val); int64_t ff_lsb2full(StreamContext *stream, int64_t lsb); int ff_nut_sp_pos_cmp(syncpoint_t *a, syncpoint_t *b); int ff_nut_sp_pts_cmp(syncpoint_t *a, syncpoint_t *b); void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts); +extern const Dispositions ff_nut_dispositions[]; + #endif /* FFMPEG_NUT_H */
--- a/nutdec.c Thu Mar 06 20:44:44 2008 +0000 +++ b/nutdec.c Fri Mar 07 19:25:09 2008 +0000 @@ -371,6 +371,19 @@ return 0; } +static void set_disposition_bits(AVFormatContext* avf, char* value, int stream_id){ + int flag = 0, i; + for (i=0; ff_nut_dispositions[i].flag; ++i) { + if (!strcmp(ff_nut_dispositions[i].str, value)) + flag = ff_nut_dispositions[i].flag; + } + if (!flag) + av_log(avf, AV_LOG_INFO, "unknown disposition type '%s'\n", value); + for (i = 0; i < avf->nb_streams; ++i) + if (stream_id == i || stream_id == -1) + avf->streams[i]->disposition |= flag; +} + static int decode_info_header(NUTContext *nut){ AVFormatContext *s= nut->avf; ByteIOContext *bc = s->pb; @@ -412,6 +425,11 @@ type= "v"; } + if (stream_id_plus1 < 0 || stream_id_plus1 > s->nb_streams) { + av_log(s, AV_LOG_ERROR, "invalid stream id for info packet\n"); + continue; + } + if(chapter_id==0 && !strcmp(type, "UTF-8")){ if (!strcmp(name, "Author")) av_strlcpy(s->author , str_value, sizeof(s->author)); @@ -421,6 +439,8 @@ av_strlcpy(s->copyright, str_value, sizeof(s->copyright)); else if(!strcmp(name, "Description")) av_strlcpy(s->comment , str_value, sizeof(s->comment)); + else if(!strcmp(name, "Disposition")) + set_disposition_bits(s, str_value, stream_id_plus1 - 1); } }
--- a/nutenc.c Thu Mar 06 20:44:44 2008 +0000 +++ b/nutenc.c Fri Mar 07 19:25:09 2008 +0000 @@ -472,6 +472,37 @@ return 0; } +static int write_streaminfo(NUTContext *nut, ByteIOContext *bc, int stream_id){ + AVFormatContext *s= nut->avf; + AVStream* st = s->streams[stream_id]; + ByteIOContext *dyn_bc; + uint8_t *dyn_buf=NULL; + int count=0, dyn_size, i; + int ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + + for (i=0; ff_nut_dispositions[i].flag; ++i) { + if (st->disposition & ff_nut_dispositions[i].flag) + count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str); + } + dyn_size = url_close_dyn_buf(dyn_bc, &dyn_buf); + + if (count) { + put_v(bc, stream_id + 1); //stream_id_plus1 + put_v(bc, 0); //chapter_id + put_v(bc, 0); //timestamp_start + put_v(bc, 0); //length + + put_v(bc, count); + + put_buffer(bc, dyn_buf, dyn_size); + } + + av_free(dyn_buf); + return count; +} + static int write_headers(NUTContext *nut, ByteIOContext *bc){ ByteIOContext *dyn_bc; int i, ret; @@ -498,6 +529,22 @@ write_globalinfo(nut, dyn_bc); put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); + for (i = 0; i < nut->avf->nb_streams; i++) { + ret = url_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + ret = write_streaminfo(nut, dyn_bc, i); + if (ret < 0) + return ret; + if (ret > 0) + put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); + else { + uint8_t* buf; + url_close_dyn_buf(dyn_bc, &buf); + av_free(buf); + } + } + nut->last_syncpoint_pos= INT_MIN; nut->header_count++; return 0;