[FFmpeg-soc] [soc]: r4664 - in concat: ffmpeg.c.diff libavformat/concatgen.c libavformat/m3u.c libavformat/playlist.c libavformat/pls.c libavformat/xspf.c

gkovacs subversion at mplayerhq.hu
Sun Jul 12 09:02:19 CEST 2009


Author: gkovacs
Date: Sun Jul 12 09:02:18 2009
New Revision: 4664

Log:
identifier for concat demuxers, open codec in init_playelem

Modified:
   concat/ffmpeg.c.diff
   concat/libavformat/concatgen.c
   concat/libavformat/m3u.c
   concat/libavformat/playlist.c
   concat/libavformat/pls.c
   concat/libavformat/xspf.c

Modified: concat/ffmpeg.c.diff
==============================================================================
--- concat/ffmpeg.c.diff	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/ffmpeg.c.diff	Sun Jul 12 09:02:18 2009	(r4664)
@@ -1,5 +1,5 @@
 diff --git a/ffmpeg.c b/ffmpeg.c
-index 22bfed8..a8db150 100644
+index 22bfed8..3ed3f4d 100644
 --- a/ffmpeg.c
 +++ b/ffmpeg.c
 @@ -70,6 +70,8 @@
@@ -32,31 +32,16 @@ index 22bfed8..a8db150 100644
  {
      AVFormatContext *os;
      AVOutputStream *ost;
-@@ -1250,6 +1257,23 @@ static int output_packet(AVInputStream *ist, int ist_index,
+@@ -1250,6 +1257,8 @@ static int output_packet(AVInputStream *ist, int ist_index,
      AVSubtitle subtitle, *subtitle_to_free;
      int got_subtitle;
      AVPacket avpkt;
-+    if (ist && is && pkt && is->nb_streams > pkt->stream_index && is->streams && is->streams[pkt->stream_index] && is->streams[pkt->stream_index]->codec) {
-+        fprintf(stdout, "stream index modified to %d\n", pkt->stream_index);
++    if (ist && is && pkt && is->nb_streams > pkt->stream_index && is->streams && is->streams[pkt->stream_index] && is->streams[pkt->stream_index]->codec)
 +        ist->st = is->streams[pkt->stream_index];
-+        if (!ist->st->codec->codec) {
-+            AVCodec *codec = avcodec_find_decoder(ist->st->codec->codec_id);
-+            if (!codec) {
-+                fprintf(stderr, "output_packet: 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) {
-+                fprintf(stderr, "output_packet: Error while opening decoder for input stream #%d.%d\n",
-+                        ist->file_index, ist->index);
-+                return AVERROR(EINVAL);
-+            }
-+        }
-+    }
  
      if(ist->next_pts == AV_NOPTS_VALUE)
          ist->next_pts= ist->pts;
-@@ -1644,6 +1668,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -1644,6 +1653,7 @@ static int av_encode(AVFormatContext **output_files,
      uint8_t no_packet[MAX_FILES]={0};
      int no_packet_count=0;
  
@@ -64,7 +49,7 @@ index 22bfed8..a8db150 100644
      file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
      if (!file_table)
          goto fail;
-@@ -2278,8 +2303,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -2278,8 +2288,7 @@ static int av_encode(AVFormatContext **output_files,
          }
  
          //fprintf(stderr,"read #%d.%d size=%d\n", ist->file_index, ist->index, pkt.size);
@@ -74,7 +59,7 @@ index 22bfed8..a8db150 100644
              if (verbose >= 0)
                  fprintf(stderr, "Error while decoding stream #%d.%d\n",
                          ist->file_index, ist->index);
-@@ -2300,7 +2324,7 @@ static int av_encode(AVFormatContext **output_files,
+@@ -2300,7 +2309,7 @@ static int av_encode(AVFormatContext **output_files,
      for(i=0;i<nb_istreams;i++) {
          ist = ist_table[i];
          if (ist->decoding_needed) {
@@ -83,7 +68,7 @@ index 22bfed8..a8db150 100644
          }
      }
  
-@@ -2848,6 +2872,7 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
+@@ -2848,6 +2857,7 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder)
  
  static void opt_input_file(const char *filename)
  {
@@ -91,7 +76,7 @@ index 22bfed8..a8db150 100644
      AVFormatContext *ic;
      AVFormatParameters params, *ap = &params;
      int err, i, ret, rfps, rfps_base;
-@@ -2859,6 +2884,45 @@ static void opt_input_file(const char *filename)
+@@ -2859,6 +2869,45 @@ static void opt_input_file(const char *filename)
      using_stdin |= !strncmp(filename, "pipe:", 5) ||
                      !strcmp(filename, "/dev/stdin");
  
@@ -137,7 +122,7 @@ index 22bfed8..a8db150 100644
      /* get default parameters from command line */
      ic = avformat_alloc_context();
  
-@@ -2925,6 +2989,8 @@ static void opt_input_file(const char *filename)
+@@ -2925,6 +2974,8 @@ static void opt_input_file(const char *filename)
          start_time = 0;
      }
  
@@ -146,7 +131,7 @@ index 22bfed8..a8db150 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 +3066,8 @@ static void opt_input_file(const char *filename)
+@@ -3000,6 +3051,8 @@ static void opt_input_file(const char *filename)
          dump_format(ic, nb_input_files, filename, 0);
  
      nb_input_files++;
@@ -155,7 +140,7 @@ index 22bfed8..a8db150 100644
      file_iformat = NULL;
      file_oformat = NULL;
  
-@@ -3874,6 +3942,7 @@ static const OptionDef options[] = {
+@@ -3874,6 +3927,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*)&copy_initial_nonkeyframes}, "copy initial non-keyframes" },

Modified: concat/libavformat/concatgen.c
==============================================================================
--- concat/libavformat/concatgen.c	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/libavformat/concatgen.c	Sun Jul 12 09:02:18 2009	(r4664)
@@ -29,6 +29,7 @@ int ff_concatgen_read_packet(AVFormatCon
     int stream_index;
     PlaylistContext *ctx;
     AVFormatContext *ic;
+    char have_switched_streams = 0;
     ctx = s->priv_data;
     stream_index = 0;
     retr:
@@ -37,41 +38,31 @@ int ff_concatgen_read_packet(AVFormatCon
     if (pkt) {
         stream_index = pkt->stream_index;
         ic = ctx->pelist[ctx->pe_curidxs[stream_index]]->ic;
+        pkt->stream = ic->streams[pkt->stream_index];
     }
     if (ret >= 0) {
         if (pkt) {
             int64_t time_offset;
             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 %d/%d 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);
+            fprintf(stderr, "%s conv stream time from %ld to %d/%d 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;
             if (!ic->streams[pkt->stream_index]->codec->has_b_frames)
                 pkt->pts = pkt->dts + 1;
         }
-    }
+    } else if (ret < 0 && !have_switched_streams && ctx->pe_curidxs[stream_index] < ctx->pelist_size - 1) {
     // TODO switch from AVERROR_EOF to AVERROR_EOS
     // -32 AVERROR_EOF for avi, -51 for ogg
-    else if (ret < 0 && ctx->pe_curidxs[stream_index] < ctx->pelist_size - 1) {
-        // TODO account for out-of-sync audio/video by using per-stream offsets
-        // using streams[]->duration slightly overestimates offset
-//        playld->dts_offset += ic->streams[0]->duration;
-        // using streams[]->cur_dts slightly overestimates offset
-//        playld->dts_offset += ic->streams[0]->cur_dts;
-//        playld->dts_offset += playld->dts_prevpacket;
         printf("switching streams\n");
         for (i = 0; i < ic->nb_streams && i < ctx->pe_curidxs_size; ++i) {
             ctx->time_offsets[i] += ff_playlist_get_duration(ic, i);
         }
         ++ctx->pe_curidxs[stream_index];
-//        pkt->destruct(pkt);
-        pkt = av_malloc(sizeof(AVPacket));
-//        for (i = 0; i < playld->pe_curidxs_size; ++i) {
-            ff_playlist_populate_context(ctx, s, stream_index);
-//        }
+        ff_playlist_populate_context(ctx, s, stream_index);
+        have_switched_streams = 1;
         goto retr;
-    }
-    else {
-        printf("avpacket ret is %d\n", ret);
+    } else {
+        fprintf(stderr, "avpacket ret is %d\n", ret);
     }
     return ret;
 }

Modified: concat/libavformat/m3u.c
==============================================================================
--- concat/libavformat/m3u.c	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/libavformat/m3u.c	Sun Jul 12 09:02:18 2009	(r4664)
@@ -92,7 +92,7 @@ static int m3u_read_header(AVFormatConte
 #if CONFIG_M3U_DEMUXER
 AVInputFormat m3u_demuxer = {
     "m3u",
-    NULL_IF_CONFIG_SMALL("M3U format"),
+    NULL_IF_CONFIG_SMALL("CONCAT M3U format"),
     sizeof(PlaylistContext),
     m3u_probe,
     m3u_read_header,

Modified: concat/libavformat/playlist.c
==============================================================================
--- concat/libavformat/playlist.c	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/libavformat/playlist.c	Sun Jul 12 09:02:18 2009	(r4664)
@@ -25,6 +25,7 @@
 
 void ff_playlist_init_playelem(PlayElem *pe)
 {
+    int i;
     int err;
     pe->ic = av_malloc(sizeof(*(pe->ic)));
     pe->ap = av_malloc(sizeof(*(pe->ap)));
@@ -54,6 +55,20 @@ void ff_playlist_init_playelem(PlayElem 
     if(!pe->fmt) {
         av_log(NULL, AV_LOG_ERROR, "failed pe ic fmt not set\n");
     }
+    for (i = 0; i < pe->ic->nb_streams; ++i) {
+        AVCodec *codec = avcodec_find_decoder(pe->ic->streams[i]->codec->codec_id);
+        if (!codec) {
+            fprintf(stderr, "output_packet: Decoder (codec id %d) not found for input stream #%d\n",
+                    pe->ic->streams[i]->codec->codec_id, i);
+            return AVERROR(EINVAL);
+        }
+        if (avcodec_open(pe->ic->streams[i]->codec, codec) < 0) {
+            fprintf(stderr, "output_packet: Error while opening decoder for input stream #%d\n",
+                    i);
+            return AVERROR(EINVAL);
+        }
+    }
+
 }
 
 PlaylistContext* ff_playlist_alloc_context(const char *filename)
@@ -104,7 +119,7 @@ int ff_playlist_populate_context(Playlis
     int i;
     AVFormatContext *ic;
     AVFormatParameters *nap;
-    printf("playlist_populate_context called\n");
+    fprintf(stderr, "playlist_populate_context called\n");
 //    ctx->pelist[ctx->pe_curidxs[stream_index]] = av_malloc(sizeof(*(ctx->pelist[ctx->pe_curidxs[stream_index]])));
     ff_playlist_init_playelem(ctx->pelist[ctx->pe_curidxs[stream_index]]);
     ic = ctx->pelist[ctx->pe_curidxs[stream_index]]->ic;

Modified: concat/libavformat/pls.c
==============================================================================
--- concat/libavformat/pls.c	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/libavformat/pls.c	Sun Jul 12 09:02:18 2009	(r4664)
@@ -118,7 +118,7 @@ static int pls_read_header(AVFormatConte
 #if CONFIG_PLS_DEMUXER
 AVInputFormat pls_demuxer = {
     "pls",
-    NULL_IF_CONFIG_SMALL("PLS format"),
+    NULL_IF_CONFIG_SMALL("CONCAT PLS format"),
     sizeof(PlaylistContext),
     pls_probe,
     pls_read_header,

Modified: concat/libavformat/xspf.c
==============================================================================
--- concat/libavformat/xspf.c	Sat Jul 11 19:31:39 2009	(r4663)
+++ concat/libavformat/xspf.c	Sun Jul 12 09:02:18 2009	(r4664)
@@ -119,7 +119,7 @@ static int xspf_read_header(AVFormatCont
 #if CONFIG_XSPF_DEMUXER
 AVInputFormat xspf_demuxer = {
     "xspf",
-    NULL_IF_CONFIG_SMALL("XSPF format"),
+    NULL_IF_CONFIG_SMALL("CONCAT XSPF format"),
     sizeof(PlaylistContext),
     xspf_probe,
     xspf_read_header,


More information about the FFmpeg-soc mailing list