[FFmpeg-soc] [soc]: r5070 - concat/ffmpeg.c.diff
gkovacs
subversion at mplayerhq.hu
Thu Aug 13 12:20:42 CEST 2009
Author: gkovacs
Date: Thu Aug 13 12:20:42 2009
New Revision: 5070
Log:
allow introduction of new streams by resizing ist_table
Modified:
concat/ffmpeg.c.diff
Modified: concat/ffmpeg.c.diff
==============================================================================
--- concat/ffmpeg.c.diff Thu Aug 13 11:28:22 2009 (r5069)
+++ concat/ffmpeg.c.diff Thu Aug 13 12:20:42 2009 (r5070)
@@ -1,5 +1,5 @@
diff --git a/ffmpeg.c b/ffmpeg.c
-index e899180..aacf4c0 100644
+index e899180..1d63190 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1237,7 +1237,8 @@ static void print_report(AVFormatContext **output_files,
@@ -12,64 +12,97 @@ index e899180..aacf4c0 100644
{
AVFormatContext *os;
AVOutputStream *ost;
-@@ -1250,7 +1251,25 @@ static int output_packet(AVInputStream *ist, int ist_index,
+@@ -1249,8 +1250,14 @@ static int output_packet(AVInputStream *ist, int ist_index,
+ static unsigned int samples_size= 0;
AVSubtitle subtitle, *subtitle_to_free;
int got_subtitle;
++ int offset = 0;
AVPacket avpkt;
--
-+ if (ist && is && pkt && is->iformat && is->iformat->long_name &&
-+ !strncmp(is->iformat->long_name, "CONCAT", 6) && is->nb_streams > pkt->stream_index &&
-+ is->streams && is->streams[pkt->stream_index] && is->streams[pkt->stream_index]->codec) {
+
++ if (pkt) {
+ ist->st = is->streams[pkt->stream_index];
-+ if (!ist->st->codec->codec) {
-+ AVCodec *codec = avcodec_find_decoder(ist->st->codec->codec_id);
-+ if (!codec) {
-+ av_log(ist->st->codec, AV_LOG_ERROR, "Decoder (codec id %d) not found for input stream #%d.%d\n",
-+ ist->st->codec->codec_id, ist->file_index, ist->index);
-+ return AVERROR(EINVAL);
-+ }
-+ if (avcodec_open(ist->st->codec, codec) < 0) {
-+ av_log(ist->st->codec, AV_LOG_ERROR, "Error while opening decoder for input stream #%d.%d\n",
-+ ist->file_index, ist->index);
-+ return AVERROR(EINVAL);
-+ }
-+ }
++ offset = pkt->index_offset;
+ }
+
if(ist->next_pts == AV_NOPTS_VALUE)
ist->next_pts= ist->pts;
-@@ -2241,11 +2260,28 @@ static int av_encode(AVFormatContext **output_files,
+@@ -1292,6 +1299,15 @@ static int output_packet(AVInputStream *ist, int ist_index,
+ endianness as CPU */
+ ret = avcodec_decode_audio3(ist->st->codec, samples, &data_size,
+ &avpkt);
++
++
++ ist->st = is->streams[avpkt.stream_index];
++
++ while (ret < 0)
++ ret = ist->st->codec->codec->decode(ist->st->codec, samples, &data_size,
++ &avpkt);
++
++
+ if (ret < 0)
+ goto fail_decode;
+ avpkt.data += ret;
+@@ -1314,6 +1330,12 @@ static int output_packet(AVInputStream *ist, int ist_index,
+ ret = avcodec_decode_video2(ist->st->codec,
+ &picture, &got_picture, &avpkt);
+ ist->st->quality= picture.quality;
++
++ ist->st = is->streams[avpkt.stream_index];
++
++ while (ret < 0)
++ ret = ist->st->codec->codec->decode(ist->st->codec,
++ &picture, &got_picture, &avpkt);
+ if (ret < 0)
+ goto fail_decode;
+ if (!got_picture) {
+@@ -1398,7 +1420,7 @@ static int output_packet(AVInputStream *ist, int ist_index,
+ int frame_size;
+
+ ost = ost_table[i];
+- if (ost->source_index == ist_index) {
++ if (ost->source_index == ist_index - offset) {
+ os = output_files[ost->file_index];
+
+ #if 0
+@@ -2241,12 +2263,35 @@ 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]) {
++ if (pkt.stream_index >= nb_istreams && pkt.stream_index < is->nb_streams && pkt.stream_index > 0 && 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;
++ for (i = nb_istreams; i < pkt.stream_index + 1; ++i)
++ ist_table[i] = NULL;
++ file_table[file_index].nb_streams = file_table[file_index].ist_index + pkt.stream_index + 1;
++ nb_istreams = file_table[file_index].ist_index + pkt.stream_index + 1;
++ }
++
++ if (!ist_table[pkt.stream_index]) {
++ ist = ist_table[pkt.stream_index] = 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->sample_index = 0;
++ ist->index = file_table[file_index].ist_index + pkt.stream_index;
++ ist->pts = 0;
++ ist->next_pts = AV_NOPTS_VALUE;
+ }
++
/* 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];
++
+ ist_index = file_table[file_index].ist_index + pkt.stream_index;
+- ist = ist_table[ist_index];
++ ist = ist_table[ist_index - pkt.index_offset];
if (ist->discard)
goto discard_packet;
-@@ -2278,8 +2314,7 @@ static int av_encode(AVFormatContext **output_files,
+
+@@ -2278,8 +2323,7 @@ static int av_encode(AVFormatContext **output_files,
}
//fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
@@ -79,7 +112,7 @@ index e899180..aacf4c0 100644
if (verbose >= 0)
fprintf(stderr, "Error while decoding stream #%d.%d\n",
ist->file_index, ist->index);
-@@ -2300,7 +2335,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -2300,7 +2344,7 @@ static int av_encode(AVFormatContext **output_files,
for(i=0;i<nb_istreams;i++) {
ist = ist_table[i];
if (ist->decoding_needed) {
More information about the FFmpeg-soc
mailing list