[FFmpeg-soc] [soc]: r5032 - in concat: ffmpeg.c.diff libavcodec/avcodec.h.diff libavformat/concatgen.c libavformat/playlist.c libavformat/playlist.h libavformat/utils.c.diff
gkovacs
subversion at mplayerhq.hu
Tue Aug 11 11:51:07 CEST 2009
Author: gkovacs
Date: Tue Aug 11 11:51:07 2009
New Revision: 5032
Log:
switched from in-place swapping of streams to appending new streams onto streams list
Modified:
concat/ffmpeg.c.diff
concat/libavcodec/avcodec.h.diff
concat/libavformat/concatgen.c
concat/libavformat/playlist.c
concat/libavformat/playlist.h
concat/libavformat/utils.c.diff
Modified: concat/ffmpeg.c.diff
==============================================================================
--- concat/ffmpeg.c.diff Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/ffmpeg.c.diff Tue Aug 11 11:51:07 2009 (r5032)
@@ -1,5 +1,5 @@
diff --git a/ffmpeg.c b/ffmpeg.c
-index e899180..b241d48 100644
+index e899180..aacf4c0 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1237,7 +1237,8 @@ static void print_report(AVFormatContext **output_files,
@@ -7,12 +7,12 @@ index e899180..b241d48 100644
static int output_packet(AVInputStream *ist, int ist_index,
AVOutputStream **ost_table, int nb_ostreams,
- const AVPacket *pkt)
-+ const AVPacket *pkt,
++ AVPacket *pkt,
+ AVFormatContext *is)
{
AVFormatContext *os;
AVOutputStream *ost;
-@@ -1250,7 +1251,24 @@ static int output_packet(AVInputStream *ist, int ist_index,
+@@ -1250,7 +1251,25 @@ static int output_packet(AVInputStream *ist, int ist_index,
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
AVPacket avpkt;
@@ -35,10 +35,41 @@ index e899180..b241d48 100644
+ }
+ }
+ }
++
if(ist->next_pts == AV_NOPTS_VALUE)
ist->next_pts= ist->pts;
-@@ -2278,8 +2296,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -2241,11 +2260,28 @@ static int av_encode(AVFormatContext **output_files,
+ if (do_pkt_dump) {
+ av_pkt_dump_log(NULL, AV_LOG_DEBUG, &pkt, do_hex_dump);
+ }
++
++ if (pkt.stream_index >= nb_istreams && pkt.stream_index < is->nb_streams && is->streams[pkt.stream_index]) {
++ ist_table = av_realloc(ist_table, sizeof(*ist_table) * (pkt.stream_index + 1));
++ for (i = nb_istreams; i < pkt.stream_index + 1; ++i) {
++ ist = ist_table[i] = av_mallocz(sizeof(AVInputStream));
++ ist->st = is->streams[pkt.stream_index];
++ ist->file_index = file_index;
++ ist->decoding_needed = 1;
++ ist->is_start = 1;
++ ist->discard = 0;
++ ist->index = file_table[file_index].ist_index + pkt.stream_index;
++ ist->pts = 0;
++ ist->next_pts = AV_NOPTS_VALUE;
++ }
++ file_table[file_index].nb_streams = pkt.stream_index + 1;
++// nb_istreams = pkt.stream_index + 1;
++ }
+ /* the following test is needed in case new streams appear
+ dynamically in stream : we ignore them */
+ if (pkt.stream_index >= file_table[file_index].nb_streams)
+ goto discard_packet;
+- ist_index = file_table[file_index].ist_index + pkt.stream_index;
++ ist_index = file_table[file_index].ist_index + pkt.stream_index - pkt.index_offset;
+ ist = ist_table[ist_index];
+ if (ist->discard)
+ goto discard_packet;
+@@ -2278,8 +2314,7 @@ static int av_encode(AVFormatContext **output_files,
}
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
@@ -48,7 +79,7 @@ index e899180..b241d48 100644
if (verbose >= 0)
fprintf(stderr, "Error while decoding stream #%d.%d\n",
ist->file_index, ist->index);
-@@ -2300,7 +2317,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -2300,7 +2335,7 @@ static int av_encode(AVFormatContext **output_files,
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
Modified: concat/libavcodec/avcodec.h.diff
==============================================================================
--- concat/libavcodec/avcodec.h.diff Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/libavcodec/avcodec.h.diff Tue Aug 11 11:51:07 2009 (r5032)
@@ -1,16 +1,17 @@
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
-index 8eb7c3c..bc76988 100644
+index 8eb7c3c..a929a7f 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
-@@ -951,6 +951,7 @@ typedef struct AVPacket {
+@@ -951,6 +951,8 @@ typedef struct AVPacket {
* subtitles are correctly displayed after seeking.
*/
int64_t convergence_duration;
+ struct AVStream *stream; /**< stream that packet was read from */
++ int index_offset;
} AVPacket;
#define AV_PKT_FLAG_KEY 0x0001
#if LIBAVCODEC_VERSION_MAJOR < 53
-@@ -3714,6 +3715,7 @@ int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
+@@ -3714,6 +3716,7 @@ int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
#define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */
#define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */
#define AVERROR_EOF AVERROR(EPIPE) /**< End of file. */
Modified: concat/libavformat/concatgen.c
==============================================================================
--- concat/libavformat/concatgen.c Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/libavformat/concatgen.c Tue Aug 11 11:51:07 2009 (r5032)
@@ -40,15 +40,21 @@ int ff_concatgen_read_packet(AVFormatCon
char have_switched_streams = 0;
ctx = s->priv_data;
stream_index = 0;
+// pkt = NULL;
for (;;) {
ic = ctx->icl[ctx->pe_curidx];
+// ff_playlist_set_streams(s);
ret = ic->iformat->read_packet(ic, pkt);
- if (pkt) {
- stream_index = pkt->stream_index;
- }
+// ff_playlist_set_streams(s);
+ s->cur_st = ic->cur_st;
if (ret >= 0) {
if (pkt) {
- if (!ic->streams[pkt->stream_index]->codec->has_b_frames) {
+ pkt->stream = ic->streams[pkt->stream_index];
+ stream_index = pkt->stream_index;
+ pkt->index_offset = ff_playlist_streams_offset_from_playidx(ctx, ctx->pe_curidx);
+ pkt->stream_index += pkt->index_offset;
+// ff_playlist_set_streams(s);
+ if (!ic->streams[stream_index]->codec->has_b_frames) {
pkt->dts += av_rescale_q(ff_playlist_time_offset(ctx->durations, ctx->pe_curidx),
AV_TIME_BASE_Q,
ic->streams[stream_index]->time_base);
Modified: concat/libavformat/playlist.c
==============================================================================
--- concat/libavformat/playlist.c Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/libavformat/playlist.c Tue Aug 11 11:51:07 2009 (r5032)
@@ -52,20 +52,40 @@ void ff_playlist_populate_context(Playli
ctx->icl = av_realloc(ctx->icl, sizeof(*(ctx->icl)) * (pe_curidx+2));
ctx->icl[pe_curidx+1] = NULL;
ctx->icl[pe_curidx] = ff_playlist_alloc_formatcontext(ctx->flist[pe_curidx]);
+ ctx->nb_streams_list[pe_curidx] = ctx->icl[pe_curidx]->nb_streams;
}
void ff_playlist_set_streams(AVFormatContext *s)
{
int i;
+ int offset;
AVFormatContext *ic;
PlaylistContext *ctx = s->priv_data;
ic = ctx->icl[ctx->pe_curidx];
- s->nb_streams = ic->nb_streams;
- for (i = 0; i < ic->nb_streams; ++i)
- s->streams[i] = ic->streams[i];
+ offset = ff_playlist_streams_offset_from_playidx(ctx, ctx->pe_curidx);
+ for (i = 0; i < ic->nb_streams; ++i) {
+ s->streams[offset + i] = ic->streams[i];
+// ic->streams[i]->index += offset;
+ if (!ic->streams[i]->codec->codec) {
+ AVCodec *codec = avcodec_find_decoder(ic->streams[i]->codec->codec_id);
+ if (!codec) {
+ av_log(ic->streams[i]->codec, AV_LOG_ERROR, "Decoder (codec id %d) not found for input stream #%d\n",
+ ic->streams[i]->codec->codec_id, ic->streams[i]->index);
+ return AVERROR(EINVAL);
+ }
+ if (avcodec_open(ic->streams[i]->codec, codec) < 0) {
+ av_log(ic->streams[i]->codec, AV_LOG_ERROR, "Error while opening decoder for input stream #%d\n",
+ ic->streams[i]->index);
+ return AVERROR(EINVAL);
+ }
+ }
+ }
+ s->nb_streams = ic->nb_streams + offset;
s->cur_st = ic->cur_st;
- s->packet_buffer = ic->packet_buffer;
- s->packet_buffer_end = ic->packet_buffer_end;
+ if (ic->packet_buffer && ic->packet_buffer->pkt.data && ic->packet_buffer->pkt.stream_index >= offset && ic->packet_buffer->pkt.stream_index < ic->nb_streams + offset)
+ s->packet_buffer = ic->packet_buffer;
+ if (ic->packet_buffer_end && ic->packet_buffer_end->pkt.data && ic->packet_buffer_end->pkt.stream_index >= offset && ic->packet_buffer_end->pkt.stream_index < ic->nb_streams + offset);
+ s->packet_buffer_end = ic->packet_buffer_end;
}
PlaylistContext *ff_playlist_get_context(AVFormatContext *ic)
@@ -139,6 +159,9 @@ void ff_playlist_add_path(PlaylistContex
ctx->durations = av_realloc(ctx->durations,
sizeof(*(ctx->durations)) * (ctx->pelist_size+1));
ctx->durations[ctx->pelist_size] = 0;
+ ctx->nb_streams_list = av_realloc(ctx->nb_streams_list,
+ sizeof(*(ctx->nb_streams_list)) * (ctx->pelist_size+1));
+ ctx->nb_streams_list[ctx->pelist_size] = 0;
}
void ff_playlist_relative_paths(char **flist,
@@ -186,3 +209,32 @@ int ff_playlist_stream_index_from_time(P
*localpts = pts-(total-ctx->durations[i-1]);
return i;
}
+
+int ff_playlist_playidx_from_streamidx(PlaylistContext *ctx, int stream_index)
+{
+ int i, total;
+ i = total = 0;
+ while (stream_index >= total)
+ total += ctx->nb_streams_list[i++];
+ return i-1;
+}
+
+int ff_playlist_localstidx_from_streamidx(PlaylistContext *ctx, int stream_index)
+{
+ int i, total;
+ i = total = 0;
+ while (stream_index >= total) {
+ total += ctx->nb_streams_list[i++];
+ }
+ return stream_index - (total - ctx->nb_streams_list[i-1]);
+}
+
+int ff_playlist_streams_offset_from_playidx(PlaylistContext *ctx, int playidx)
+{
+// return 0;
+ int i, total;
+ i = total = 0;
+ while (playidx > i)
+ total += ctx->nb_streams_list[i++];
+ return total;
+}
Modified: concat/libavformat/playlist.h
==============================================================================
--- concat/libavformat/playlist.h Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/libavformat/playlist.h Tue Aug 11 11:51:07 2009 (r5032)
@@ -47,6 +47,7 @@ typedef struct PlaylistContext {
int pelist_size; /**< Number of playlist elements stored in icl */
int pe_curidx; /**< Index of the AVFormatContext in icl that packets are being read from */
int64_t *durations; /**< Durations, in AV_TIME_BASE units, for each playlist item */
+ int *nb_streams_list; /**< List of the number of streams in each playlist item*/
} PlaylistContext;
/** @fn AVFormatContext *ff_playlist_alloc_formatcontext(char *filename)
@@ -139,4 +140,10 @@ int ff_playlist_stream_index_from_time(P
int64_t pts,
int64_t *localpts);
+int ff_playlist_playidx_from_streamidx(PlaylistContext *ctx, int stream_index);
+
+int ff_playlist_localstidx_from_streamidx(PlaylistContext *ctx, int stream_index);
+
+int ff_playlist_streams_offset_from_playidx(PlaylistContext *ctx, int playidx);
+
#endif /* AVFORMAT_PLAYLIST_H */
Modified: concat/libavformat/utils.c.diff
==============================================================================
--- concat/libavformat/utils.c.diff Mon Aug 10 22:31:18 2009 (r5031)
+++ concat/libavformat/utils.c.diff Tue Aug 11 11:51:07 2009 (r5032)
@@ -1,5 +1,5 @@
diff --git a/libavformat/utils.c b/libavformat/utils.c
-index 0c1a50d..ca69238 100644
+index 0c1a50d..d2f0f96 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -27,6 +27,7 @@
@@ -46,41 +46,48 @@ index 0c1a50d..ca69238 100644
/* Do not open file if the format does not need it. XXX: specific
hack needed to handle RTSP/TCP */
if (!fmt || !(fmt->flags & AVFMT_NOFILE)) {
-@@ -910,6 +933,10 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+@@ -909,7 +932,12 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st,
+ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
{
AVStream *st;
- int len, ret, i;
+- int len, ret, i;
++ int len, ret, i, offset;
+ int stream_index;
+ AVStream *stream;
+ stream_index = 0;
+ stream = 0;
++ offset = 0;
av_init_packet(pkt);
-@@ -943,8 +970,14 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+@@ -943,8 +971,10 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
/* return packet if any */
if (pkt->size) {
got_packet:
-+ if (stream && stream->codec && stream->codec->codec) {
-+ pkt->stream = stream;
-+ pkt->stream_index = stream_index;
-+ } else {
-+ pkt->stream = st;
-+ pkt->stream_index = st->index;
-+ }
++ pkt->stream = st;
++ pkt->stream_index = stream_index;
++ pkt->index_offset = offset;
pkt->duration = 0;
- pkt->stream_index = st->index;
pkt->pts = st->parser->pts;
pkt->dts = st->parser->dts;
pkt->pos = st->parser->pos;
-@@ -980,8 +1013,11 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+@@ -968,6 +998,9 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
+ AVPacket cur_pkt;
+ /* read next packet */
+ ret = av_read_packet(s, &cur_pkt);
++ offset = cur_pkt.index_offset;
++ stream_index = cur_pkt.stream_index;
++ stream = cur_pkt.stream;
+ if (ret < 0) {
+ if (ret == AVERROR(EAGAIN))
+ return ret;
+@@ -980,8 +1013,9 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt)
NULL, 0,
AV_NOPTS_VALUE, AV_NOPTS_VALUE,
AV_NOPTS_VALUE);
- if (pkt->size)
+ if (pkt->size) {
-+ stream_index = cur_pkt.stream_index;
-+ stream = cur_pkt.stream;
goto got_packet;
+ }
}
More information about the FFmpeg-soc
mailing list