[soc]: r4625 - in concat: ffmpeg.c.diff libavformat/Makefile.diff libavformat/allformats.c.diff libavformat/concatgen.c libavformat/datanode.c libavformat/m3u.c libavformat/playlist.c libavformat/p...
Author: gkovacs Date: Mon Jul 6 09:20:22 2009 New Revision: 4625 Log: * added xspf demuxer * removed flist from PlaylistContext * now allocating all PlayElem at startup * using AV_TIME_BASE_Q macro Modified: concat/ffmpeg.c.diff concat/libavformat/Makefile.diff concat/libavformat/allformats.c.diff concat/libavformat/concatgen.c concat/libavformat/datanode.c concat/libavformat/m3u.c concat/libavformat/playlist.c concat/libavformat/playlist.h concat/libavformat/pls.c concat/libavformat/xspf.c Modified: concat/ffmpeg.c.diff ============================================================================== --- concat/ffmpeg.c.diff Mon Jul 6 02:00:49 2009 (r4624) +++ concat/ffmpeg.c.diff Mon Jul 6 09:20:22 2009 (r4625) @@ -1,5 +1,5 @@ diff --git a/ffmpeg.c b/ffmpeg.c -index 22bfed8..dbef707 100644 +index 22bfed8..5790959 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -70,6 +70,8 @@ @@ -91,7 +91,7 @@ index 22bfed8..dbef707 100644 AVFormatContext *ic; AVFormatParameters params, *ap = ¶ms; int err, i, ret, rfps, rfps_base; -@@ -2859,6 +2884,43 @@ static void opt_input_file(const char *filename) +@@ -2859,6 +2884,45 @@ static void opt_input_file(const char *filename) using_stdin |= !strncmp(filename, "pipe:", 5) || !strcmp(filename, "/dev/stdin"); @@ -106,9 +106,10 @@ index 22bfed8..dbef707 100644 + playlist_ctx->pelist_size = 1; + playlist_ctx->pelist = av_malloc(playlist_ctx->pelist_size * sizeof(*(playlist_ctx->pelist))); + memset(playlist_ctx->pelist, 0, playlist_ctx->pelist_size * sizeof(*(playlist_ctx->pelist))); -+ playlist_ctx->flist = av_malloc(playlist_ctx->pelist_size * sizeof(*(playlist_ctx->flist))); -+ playlist_ctx->flist[0] = av_malloc(sizeof(char) * (filenamelen+1)); -+ av_strlcpy(playlist_ctx->flist[0], filename, filenamelen+1); ++ playlist_ctx->pelist[playlist_ctx->pelist_size-1] = av_malloc(sizeof(*(playlist_ctx->pelist[playlist_ctx->pelist_size-1]))); ++ memset(playlist_ctx->pelist[playlist_ctx->pelist_size-1], 0, sizeof(*(playlist_ctx->pelist[playlist_ctx->pelist_size-1]))); ++ playlist_ctx->pelist[playlist_ctx->pelist_size-1]->filename = av_malloc(sizeof(char) * (filenamelen+1)); ++ av_strlcpy(playlist_ctx->pelist[playlist_ctx->pelist_size-1]->filename, filename, filenamelen+1); + av_strlcpy(ic->filename, filename, sizeof(ic->filename)); + ic->nb_streams = 2; + ic->iformat = concat_make_demuxer(); @@ -124,9 +125,10 @@ index 22bfed8..dbef707 100644 + printf("adding new file to playlist\n"); + ++playlist_ctx->pelist_size; + playlist_ctx->pelist = av_realloc(playlist_ctx->pelist, playlist_ctx->pelist_size * sizeof(*(playlist_ctx->pelist))); -+ playlist_ctx->flist = av_realloc(playlist_ctx->flist, playlist_ctx->pelist_size); -+ playlist_ctx->flist[playlist_ctx->pelist_size-1] = av_malloc(sizeof(char) * (filenamelen+1)); -+ av_strlcpy(playlist_ctx->flist[playlist_ctx->pelist_size-1], filename, filenamelen+1); ++ playlist_ctx->pelist[playlist_ctx->pelist_size-1] = av_malloc(sizeof(*(playlist_ctx->pelist[playlist_ctx->pelist_size-1]))); ++ memset(playlist_ctx->pelist[playlist_ctx->pelist_size-1], 0, sizeof(*(playlist_ctx->pelist[playlist_ctx->pelist_size-1]))); ++ playlist_ctx->pelist[playlist_ctx->pelist_size-1]->filename = av_realloc(playlist_ctx->pelist[playlist_ctx->pelist_size-1]->filename, sizeof(char) * (filenamelen+1)); ++ av_strlcpy(playlist_ctx->pelist[playlist_ctx->pelist_size-1]->filename, filename, filenamelen+1); + } + return; + } @@ -135,7 +137,7 @@ index 22bfed8..dbef707 100644 /* get default parameters from command line */ ic = avformat_alloc_context(); -@@ -2925,6 +2987,8 @@ static void opt_input_file(const char *filename) +@@ -2925,6 +2989,8 @@ static void opt_input_file(const char *filename) start_time = 0; } @@ -144,7 +146,7 @@ index 22bfed8..dbef707 100644 /* update the current parameters so that they match the one of the input stream */ for(i=0;i<ic->nb_streams;i++) { AVCodecContext *enc = ic->streams[i]->codec; -@@ -3000,6 +3064,8 @@ static void opt_input_file(const char *filename) +@@ -3000,6 +3066,8 @@ static void opt_input_file(const char *filename) dump_format(ic, nb_input_files, filename, 0); nb_input_files++; @@ -153,7 +155,7 @@ index 22bfed8..dbef707 100644 file_iformat = NULL; file_oformat = NULL; -@@ -3874,6 +3940,7 @@ static const OptionDef options[] = { +@@ -3874,6 +3942,7 @@ static const OptionDef options[] = { { "programid", HAS_ARG | OPT_INT | OPT_EXPERT, {(void*)&opt_programid}, "desired program number", "" }, { "xerror", OPT_BOOL, {(void*)&exit_on_error}, "exit on error", "error" }, { "copyinkf", OPT_BOOL | OPT_EXPERT, {(void*)©_initial_nonkeyframes}, "copy initial non-keyframes" }, Modified: concat/libavformat/Makefile.diff ============================================================================== --- concat/libavformat/Makefile.diff Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/Makefile.diff Mon Jul 6 09:20:22 2009 (r4625) @@ -1,12 +1,12 @@ diff --git a/libavformat/Makefile b/libavformat/Makefile -index 8e8a869..d2aaf47 100644 +index 8e8a869..625225d 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -34,6 +34,7 @@ OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += raw.o -+OBJS-$(CONFIG_CONCAT_DEMUXER) += m3u.o pls.o playlist.o concat.o concatgen.o datanode.o ++OBJS-$(CONFIG_CONCAT_DEMUXER) += m3u.o pls.o xspf.o playlist.o concat.o concatgen.o datanode.o OBJS-$(CONFIG_CRC_MUXER) += crcenc.o OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o OBJS-$(CONFIG_DAUD_MUXER) += daud.o Modified: concat/libavformat/allformats.c.diff ============================================================================== --- concat/libavformat/allformats.c.diff Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/allformats.c.diff Mon Jul 6 09:20:22 2009 (r4625) @@ -1,5 +1,5 @@ diff --git a/libavformat/allformats.c b/libavformat/allformats.c -index ad47631..83d7d21 100644 +index ad47631..ef642c4 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -66,6 +66,7 @@ void av_register_all(void) @@ -26,3 +26,11 @@ index ad47631..83d7d21 100644 REGISTER_MUXER (PSP, psp); REGISTER_DEMUXER (PVA, pva); REGISTER_DEMUXER (QCP, qcp); +@@ -199,6 +202,7 @@ void av_register_all(void) + REGISTER_DEMUXER (WSVQA, wsvqa); + REGISTER_DEMUXER (WV, wv); + REGISTER_DEMUXER (XA, xa); ++ REGISTER_DEMUXER (XSPF, xspf); + REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe); + + /* external libraries */ Modified: concat/libavformat/concatgen.c ============================================================================== --- concat/libavformat/concatgen.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/concatgen.c Mon Jul 6 09:20:22 2009 (r4625) @@ -41,8 +41,7 @@ int ff_concatgen_read_packet(AVFormatCon if (ret >= 0) { if (pkt) { int64_t time_offset; - AVRational avbasetime = {1, AV_TIME_BASE}; - time_offset = av_rescale_q(ctx->time_offsets[pkt->stream_index], avbasetime, ic->streams[stream_index]->time_base); + time_offset = av_rescale_q(ctx->time_offsets[pkt->stream_index], AV_TIME_BASE_Q, ic->streams[stream_index]->time_base); printf("%s conv stream time from %ld to %ld/%ld is %ld\n", ic->iformat->name, ctx->time_offsets[pkt->stream_index], ic->streams[stream_index]->time_base.num, ic->streams[stream_index]->time_base.den, time_offset); // TODO changing either dts or pts leads to timing issues on h264 pkt->dts += time_offset; Modified: concat/libavformat/datanode.c ============================================================================== --- concat/libavformat/datanode.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/datanode.c Mon Jul 6 09:20:22 2009 (r4625) @@ -151,6 +151,8 @@ DataNode *ff_datanode_tree_from_xml(Byte quo = 1; goto writeoutput; } + if (c == '\n' || c == ' ' || c == '\t') + continue; if (tag == 0) { // awaiting opening tag if (c == '<') { // opening tag tag = 1; @@ -260,12 +262,6 @@ DataNode *ff_datanode_tree_from_xml(Byte return o; } -DataNode *ff_datanode_tree_from_xml(ByteIOContext *p) -{ - // TODO - return NULL; -} - DataNode *ff_datanode_getlognext(DataNode *d) { if (d->child) @@ -292,7 +288,7 @@ void ff_datanode_filter_values_by_name(D { if (!d) return; - if (d->value && !strncmp(n, d->name, strlen(n))) + if (d->name && d->value && !strncmp(n, d->name, strlen(n))) ff_stringlist_append(l, d->value); ff_datanode_filter_values_by_name(ff_datanode_getlognext(d), l, n); } Modified: concat/libavformat/m3u.c ============================================================================== --- concat/libavformat/m3u.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/m3u.c Mon Jul 6 09:20:22 2009 (r4625) @@ -40,32 +40,38 @@ static int m3u_probe(AVProbeData *p) return 0; } -static int m3u_list_files(ByteIOContext *s, - char ***flist_ptr, - unsigned int *lfx_ptr, - char *workingdir) +static int m3u_list_files(ByteIOContext *s, PlaylistContext *ctx) +// char ***flist_ptr, +// unsigned int *lfx_ptr, +// char *workingdir) { - char **ofl; - int i; + char **flist; + int i, j; int bufsize = 16; i = 0; - ofl = av_malloc(sizeof(char*) * bufsize); + flist = av_malloc(sizeof(char*) * bufsize); while (1) { char *c = ff_buf_getline(s); if (c == NULL) // EOF break; if (*c == 0) // hashed out continue; - ofl[i] = c; + flist[i] = c; if (++i == bufsize) { bufsize += 16; - ofl = av_realloc(ofl, sizeof(char*) * bufsize); + flist = av_realloc(flist, sizeof(char*) * bufsize); } } - *flist_ptr = ofl; - *lfx_ptr = i; - ofl[i] = 0; - ff_playlist_relative_paths(ofl, workingdir); + ctx->pelist_size = i; + flist[i] = 0; + ff_playlist_relative_paths(flist, ctx->workingdir); + ctx->pelist = av_malloc(ctx->pelist_size * sizeof(*(ctx->pelist))); + memset(ctx->pelist, 0, ctx->pelist_size * sizeof(*(ctx->pelist))); + for (i = 0; i < ctx->pelist_size; ++i) { + ctx->pelist[i] = av_malloc(sizeof(*(ctx->pelist[i]))); + ctx->pelist[i]->filename = flist[i]; + } + av_free(flist); return 0; } @@ -74,12 +80,7 @@ static int m3u_read_header(AVFormatConte { int i; PlaylistContext *ctx = ff_playlist_make_context(s->filename); - m3u_list_files(s->pb, - &(ctx->flist), - &(ctx->pelist_size), - ctx->workingdir); - ctx->pelist = av_malloc(ctx->pelist_size * sizeof(*(ctx->pelist))); - memset(ctx->pelist, 0, ctx->pelist_size * sizeof(*(ctx->pelist))); + m3u_list_files(s->pb, ctx); s->priv_data = ctx; for (i = 0; i < ctx->pe_curidxs_size; ++i) { ff_playlist_populate_context(ctx, s, i); Modified: concat/libavformat/playlist.c ============================================================================== --- concat/libavformat/playlist.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/playlist.c Mon Jul 6 09:20:22 2009 (r4625) @@ -25,8 +25,7 @@ #include <time.h> // based on decode_thread() in ffplay.c -int ff_alloc_playelem(unsigned char *filename, - PlayElem *pe) +int ff_playlist_setup_playelem(PlayElem *pe) { AVFormatContext *ic; AVFormatParameters *ap; @@ -38,18 +37,17 @@ int ff_alloc_playelem(unsigned char *fil ap->time_base = (AVRational){1, 25}; ap->pix_fmt = 0; pe->ic = ic; - pe->filename = filename; pe->fmt = 0; pe->buf_size = 0; pe->ap = ap; return 0; } -PlayElem* ff_playlist_make_playelem(char *filename) +void ff_playlist_make_playelem(PlayElem *pe) { int err; - PlayElem *pe = av_malloc(sizeof(*pe)); - err = ff_alloc_playelem(filename, pe); +// PlayElem *pe = av_malloc(sizeof(*pe)); + err = ff_playlist_setup_playelem(pe); if (err < 0) print_error("during-av_alloc_playelem", err); err = av_open_input_file(&(pe->ic), pe->filename, pe->fmt, pe->buf_size, pe->ap); @@ -180,7 +178,8 @@ int ff_playlist_populate_context(Playlis AVFormatContext *ic; AVFormatParameters *nap; printf("playlist_populate_context called\n"); - ctx->pelist[ctx->pe_curidxs[stream_index]] = ff_playlist_make_playelem(ctx->flist[ctx->pe_curidxs[stream_index]]); +// ctx->pelist[ctx->pe_curidxs[stream_index]] = av_malloc(sizeof(*(ctx->pelist[ctx->pe_curidxs[stream_index]]))); + ff_playlist_make_playelem(ctx->pelist[ctx->pe_curidxs[stream_index]]); ic = ctx->pelist[ctx->pe_curidxs[stream_index]]->ic; nap = ctx->pelist[ctx->pe_curidxs[stream_index]]->ap; ic->iformat->read_header(ic, 0); @@ -251,8 +250,7 @@ int64_t ff_playlist_get_duration(AVForma int64_t durn; // durn = ic->duration; - AVRational avbasetime = {1, AV_TIME_BASE}; - durn = av_rescale_q(ic->streams[stream_index]->duration, ic->streams[stream_index]->time_base, avbasetime); + durn = av_rescale_q(ic->streams[stream_index]->duration, ic->streams[stream_index]->time_base, AV_TIME_BASE_Q); // durn = ic->streams[stream_index]->duration; // ogg gives wrong value printf("duration is %ld\n", durn); Modified: concat/libavformat/playlist.h ============================================================================== --- concat/libavformat/playlist.h Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/playlist.h Mon Jul 6 09:20:22 2009 (r4625) @@ -36,13 +36,10 @@ typedef struct PlayElem { } PlayElem; typedef struct PlaylistContext { - char **flist; -// int flist_len; PlayElem **pelist; int pelist_size; int *pe_curidxs; int pe_curidxs_size; -// int pe_curidx; AVChapter **chlist; int chlist_size; int ch_curidx; @@ -52,7 +49,9 @@ typedef struct PlaylistContext { int time_offsets_size; } PlaylistContext; -PlayElem* ff_playlist_make_playelem(char *filename); +void ff_playlist_make_playelem(PlayElem* pe); + +int ff_playlist_setup_playelem(PlayElem *pe); PlaylistContext* ff_playlist_make_context(char *filename); Modified: concat/libavformat/pls.c ============================================================================== --- concat/libavformat/pls.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/pls.c Mon Jul 6 09:20:22 2009 (r4625) @@ -41,11 +41,10 @@ static int pls_probe(AVProbeData *p) return 0; } -static int pls_list_files(ByteIOContext *s, - char ***flist_ptr, - unsigned int *lfx_ptr, - char *workingdir) +static int pls_list_files(ByteIOContext *s, PlaylistContext *ctx) { + int i; + char **flist; StringList *l; DataNode *d; l = ff_stringlist_alloc(); @@ -53,8 +52,15 @@ static int pls_list_files(ByteIOContext ff_datanode_visualize(d); ff_datanode_filter_values_by_name(d, l, "File"); ff_stringlist_print(l); - ff_stringlist_export(l, flist_ptr, lfx_ptr); - ff_playlist_relative_paths(*flist_ptr, workingdir); + ff_stringlist_export(l, &flist, &(ctx->pelist_size)); + ff_playlist_relative_paths(flist, ctx->workingdir); + ctx->pelist = av_malloc(ctx->pelist_size * sizeof(*(ctx->pelist))); + memset(ctx->pelist, 0, ctx->pelist_size * sizeof(*(ctx->pelist))); + for (i = 0; i < ctx->pelist_size; ++i) { + ctx->pelist[i] = av_malloc(sizeof(*(ctx->pelist[i]))); + ctx->pelist[i]->filename = flist[i]; + } + av_free(flist); return 0; } @@ -63,12 +69,7 @@ static int pls_read_header(AVFormatConte { int i; PlaylistContext *ctx = ff_playlist_make_context(s->filename); - pls_list_files(s->pb, - &(ctx->flist), - &(ctx->pelist_size), - ctx->workingdir); - ctx->pelist = av_malloc(ctx->pelist_size * sizeof(*(ctx->pelist))); - memset(ctx->pelist, 0, ctx->pelist_size * sizeof(*(ctx->pelist))); + pls_list_files(s->pb, ctx); s->priv_data = ctx; for (i = 0; i < ctx->pe_curidxs_size; ++i) { ff_playlist_populate_context(ctx, s, i); Modified: concat/libavformat/xspf.c ============================================================================== --- concat/libavformat/xspf.c Mon Jul 6 02:00:49 2009 (r4624) +++ concat/libavformat/xspf.c Mon Jul 6 09:20:22 2009 (r4625) @@ -1,2 +1,101 @@ +/* + * XSPF muxer and demuxer + * Copyright (c) 2009 Geza Kovacs + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "concatgen.h" +#include "datanode.h" + +/* The ffmpeg codecs we support, and the IDs they have in the file */ +static const AVCodecTag codec_xspf_tags[] = { + { 0, 0 }, +}; +static int xspf_probe(AVProbeData *p) +{ + if (p->buf != 0) { + if (!strncmp(p->buf, "<?xml", 5)) + return AVPROBE_SCORE_MAX; + else + return 0; + } + if (match_ext(p->filename, "xspf")) + return AVPROBE_SCORE_MAX/2; + else + return 0; +} +static int xspf_list_files(ByteIOContext *s, PlaylistContext *ctx) +{ + int i; + char **flist; + StringList *l; + DataNode *d; + l = ff_stringlist_alloc(); + d = ff_datanode_tree_from_xml(s); + ff_datanode_visualize(d); + ff_datanode_filter_values_by_name(d, l, "location"); + ff_stringlist_print(l); + ff_stringlist_export(l, &flist, &(ctx->pelist_size)); + ff_playlist_relative_paths(flist, ctx->workingdir); + ctx->pelist = av_malloc(ctx->pelist_size * sizeof(*(ctx->pelist))); + memset(ctx->pelist, 0, ctx->pelist_size * sizeof(*(ctx->pelist))); + for (i = 0; i < ctx->pelist_size; ++i) { + ctx->pelist[i] = av_malloc(sizeof(*(ctx->pelist[i]))); + ctx->pelist[i]->filename = flist[i]; + } + av_free(flist); + return 0; +} + +static int xspf_read_header(AVFormatContext *s, + AVFormatParameters *ap) +{ + int i; + PlaylistContext *ctx = ff_playlist_make_context(s->filename); + xspf_list_files(s->pb, ctx); + s->priv_data = ctx; + for (i = 0; i < ctx->pe_curidxs_size; ++i) { + ff_playlist_populate_context(ctx, s, i); + } + return 0; +} + +#if CONFIG_XSPF_DEMUXER +AVInputFormat xspf_demuxer = { + "xspf", + NULL_IF_CONFIG_SMALL("XSPF format"), + sizeof(PlaylistContext), + xspf_probe, + xspf_read_header, + ff_concatgen_read_packet, + ff_concatgen_read_close, + ff_concatgen_read_seek, + ff_concatgen_read_timestamp, + NULL, //flags + NULL, //extensions + NULL, //value + ff_concatgen_read_play, + ff_concatgen_read_pause, + (const AVCodecTag* const []){codec_xspf_tags, 0}, + ff_concatgen_read_seek, //m3u_read_seek2 + NULL, //metadata_conv + NULL, //next +}; +#endif
participants (1)
-
gkovacs