Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Thu, 26 May 2011 01:00:37 +0000 (03:00 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 26 May 2011 01:28:22 +0000 (03:28 +0200)
* qatar/master: (32 commits)
  doc: create separate section for audio encoders
  swscale: Remove orphaned, commented-out function declaration.
  swscale: Eliminate rgb24toyv12_c() duplication.
  Remove h263_msmpeg4 from MpegEncContext.
  APIchanges: Fill in git hash for fps_probe_size (30315a8)
  avformat: Add fpsprobesize as an AVOption.
  avoptions: Return explicitly NAN or {0,0} if the option isn't found
  rtmp: Reindent
  rtmp: Don't try to do av_malloc(0)
  tty: replace AVFormatParameters.sample_rate abuse with a private option.
  Fix end time of last chapter in compute_chapters_end
  ffmpeg: get rid of useless AVInputStream.nb_streams.
  ffmpeg: simplify managing input files and streams
  ffmpeg: purge redundant AVInputStream.index.
  lavf: deprecate AVFormatParameters.channel.
  libdc1394: add a private option for channel.
  dv1394: add a private option for channel.
  v4l2: reindent.
  v4l2: add a private option for channel.
  lavf: deprecate AVFormatParameters.standard.
  ...

Conflicts:
doc/APIchanges
doc/encoders.texi
ffmpeg.c
libavdevice/alsa-audio.h
libavformat/version.h
libavutil/opt.c
libswscale/rgb2rgb.h
libswscale/rgb2rgb_template.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
31 files changed:
1  2 
doc/APIchanges
doc/encoders.texi
ffmpeg.c
libavcodec/h263dec.c
libavcodec/mpegvideo.c
libavcodec/mpegvideo.h
libavcodec/mpegvideo_enc.c
libavdevice/alsa-audio-dec.c
libavdevice/alsa-audio.h
libavdevice/bktr.c
libavdevice/dv1394.c
libavdevice/libdc1394.c
libavdevice/oss_audio.c
libavdevice/sndio_common.h
libavdevice/sndio_dec.c
libavdevice/v4l.c
libavdevice/v4l2.c
libavformat/avformat.h
libavformat/mpegts.c
libavformat/options.c
libavformat/pcmdec.c
libavformat/rawdec.c
libavformat/rawdec.h
libavformat/rtmppkt.c
libavformat/rtmpproto.c
libavformat/tty.c
libavformat/utils.c
libavformat/version.h
libavutil/opt.c
libswscale/rgb2rgb.h
libswscale/rgb2rgb_template.c

diff --cc doc/APIchanges
@@@ -13,19 -13,9 +13,22 @@@ libavutil:   2011-04-1
  
  API changes, most recent first:
  
 +2011-05-22 - xxxxxx - lavf 53.2.0 - avformat.h
 +  Introduce avformat_alloc_output_context2() and deprecate
 +  avformat_alloc_output_context().
 +
 +2011-05-22 - xxxxxx - lavfi 2.10.0 - vsrc_buffer.h
 +  Make libavfilter/vsrc_buffer.h public.
 +
 +2011-05-XX - XXXXXX - lavfi 2.8.0 - avcodec.h
 +  Add av_vsrc_buffer_add_frame() to libavfilter/avcodec.h.
 +
 +2011-05-XX - XXXXXX - lavfi 2.6.0 - avcodec.h
 +  Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h.
 +
+ 2011-05-25 - 30315a8 - lavf 53.1.0 - avformat.h
+   Add fps_probe_size to AVFormatContext.
  2011-05-18 - 64150ff - lavc 53.4.0 - AVCodecContext.request_sample_fmt
    Add request_sample_fmt field to AVCodecContext.
  
Simple merge
diff --cc ffmpeg.c
+++ b/ffmpeg.c
@@@ -113,8 -102,9 +113,7 @@@ static const OptionDef options[]
  #define MAX_FILES 100
  #define MAX_STREAMS 1024    /* arbitrary sanity check value */
  
 -#define FFM_PACKET_SIZE 4096 //XXX a duplicate of the line in ffm.h
 -
  static const char *last_asked_format = NULL;
- static AVFormatContext *input_files[MAX_FILES];
  static int64_t input_files_ts_offset[MAX_FILES];
  static double *input_files_ts_scale[MAX_FILES] = {NULL};
  static AVCodec **input_codecs = NULL;
@@@ -342,15 -329,13 +340,19 @@@ typedef struct AVInputFile 
      int eof_reached;      /* true if eof reached */
      int ist_index;        /* index of first stream in ist_table */
      int buffer_size;      /* current total buffer size */
-     int nb_streams;       /* nb streams we are aware of */
  } AVInputFile;
  
 +#if HAVE_TERMIOS_H
 +
 +/* init terminal so that we can grab keys */
 +static struct termios oldtty;
 +#endif
 +
+ static AVInputStream *input_streams = NULL;
+ static int         nb_input_streams = 0;
+ static AVInputFile   *input_files   = NULL;
+ static int         nb_input_files   = 0;
  #if CONFIG_AVFILTER
  
  static int configure_video_filters(AVInputStream *ist, AVOutputStream *ost)
@@@ -1202,35 -1170,27 +1207,35 @@@ static void do_video_out(AVFormatContex
      if (resample_changed) {
          av_log(NULL, AV_LOG_INFO,
                 "Input stream #%d.%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n",
-                ist->file_index, ist->index,
+                ist->file_index, ist->st->index,
                 ost->resample_width, ost->resample_height, avcodec_get_pix_fmt_name(ost->resample_pix_fmt),
                 dec->width         , dec->height         , avcodec_get_pix_fmt_name(dec->pix_fmt));
 -        if(!ost->video_resample)
 -            ffmpeg_exit(1);
 +        ost->resample_width   = dec->width;
 +        ost->resample_height  = dec->height;
 +        ost->resample_pix_fmt = dec->pix_fmt;
      }
  
 -#if !CONFIG_AVFILTER
 +    ost->video_resample = dec->width   != enc->width  ||
 +                          dec->height  != enc->height ||
 +                          dec->pix_fmt != enc->pix_fmt;
 +
      if (ost->video_resample) {
 -        final_picture = &ost->pict_tmp;
 -        if (resample_changed) {
 +        final_picture = &ost->resample_frame;
 +        if (!ost->img_resample_ctx || resample_changed) {
 +            /* initialize the destination picture */
 +            if (!ost->resample_frame.data[0]) {
 +                avcodec_get_frame_defaults(&ost->resample_frame);
 +                if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt,
 +                                    enc->width, enc->height)) {
 +                    fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n");
 +                    ffmpeg_exit(1);
 +                }
 +            }
              /* initialize a new scaler context */
              sws_freeContext(ost->img_resample_ctx);
 -            ost->img_resample_ctx = sws_getContext(
 -                ist->st->codec->width,
 -                ist->st->codec->height,
 -                ist->st->codec->pix_fmt,
 -                ost->st->codec->width,
 -                ost->st->codec->height,
 -                ost->st->codec->pix_fmt,
 -                ost->sws_flags, NULL, NULL, NULL);
 +            ost->img_resample_ctx = sws_getContext(dec->width, dec->height, dec->pix_fmt,
 +                                                   enc->width, enc->height, enc->pix_fmt,
 +                                                   ost->sws_flags, NULL, NULL, NULL);
              if (ost->img_resample_ctx == NULL) {
                  fprintf(stderr, "Cannot get resampling context\n");
                  ffmpeg_exit(1);
@@@ -1973,60 -1937,19 +1978,23 @@@ static int transcode(AVFormatContext **
                       int nb_input_files,
                       AVStreamMap *stream_maps, int nb_stream_maps)
  {
-     int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0, step;
 -    int ret = 0, i, j, k, n, nb_ostreams = 0;
++    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0,step;
++
      AVFormatContext *is, *os;
      AVCodecContext *codec, *icodec;
      AVOutputStream *ost, **ost_table = NULL;
-     AVInputStream *ist, **ist_table = NULL;
-     AVInputFile *file_table;
+     AVInputStream *ist;
      char error[1024];
 +    int key;
      int want_sdp = 1;
      uint8_t no_packet[MAX_FILES]={0};
      int no_packet_count=0;
 +    int nb_frame_threshold[AVMEDIA_TYPE_NB]={0};
 +    int nb_streams[AVMEDIA_TYPE_NB]={0};
  
-     file_table= av_mallocz(nb_input_files * sizeof(AVInputFile));
-     if (!file_table)
-         goto fail;
-     /* input stream init */
-     j = 0;
-     for(i=0;i<nb_input_files;i++) {
-         is = input_files[i];
-         file_table[i].ist_index = j;
-         file_table[i].nb_streams = is->nb_streams;
-         j += is->nb_streams;
-     }
-     nb_istreams = j;
-     ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *));
-     if (!ist_table)
-         goto fail;
-     for(i=0;i<nb_istreams;i++) {
-         ist = av_mallocz(sizeof(AVInputStream));
-         if (!ist)
-             goto fail;
-         ist_table[i] = ist;
-     }
-     j = 0;
-     for(i=0;i<nb_input_files;i++) {
-         is = input_files[i];
-         for(k=0;k<is->nb_streams;k++) {
-             ist = ist_table[j++];
-             ist->st = is->streams[k];
-             ist->file_index = i;
-             ist->index = k;
-             ist->discard = 1; /* the stream is discarded by default
-                                  (changed later) */
-             if (rate_emu) {
-                 ist->start = av_gettime();
-             }
-         }
-     }
+     if (rate_emu)
+         for (i = 0; i < nb_input_streams; i++)
+             input_streams[i].start = av_gettime();
  
      /* output stream init */
      nb_ostreams = 0;
      ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams);
      if (!ost_table)
          goto fail;
-         for(j=0; j<nb_istreams; j++) {
 +
 +    for(k=0;k<nb_output_files;k++) {
 +        os = output_files[k];
 +        for(i=0;i<os->nb_streams;i++,n++) {
 +            nb_streams[os->streams[i]->codec->codec_type]++;
 +        }
 +    }
 +    for(step=1<<30; step; step>>=1){
 +        int found_streams[AVMEDIA_TYPE_NB]={0};
 +        for(j=0; j<AVMEDIA_TYPE_NB; j++)
 +            nb_frame_threshold[j] += step;
 +
-             ist = ist_table[j];
++        for(j=0; j<nb_input_streams; j++) {
 +            int skip=0;
-                 AVFormatContext *f= input_files[ ist->file_index ];
++            ist = &input_streams[j];
 +            if(opt_programid){
 +                int pi,si;
++                AVFormatContext *f= input_files[ ist->file_index ].ctx;
 +                skip=1;
 +                for(pi=0; pi<f->nb_programs; pi++){
 +                    AVProgram *p= f->programs[pi];
 +                    if(p->id == opt_programid)
 +                        for(si=0; si<p->nb_stream_indexes; si++){
 +                            if(f->streams[ p->stream_index[si] ] == ist->st)
 +                                skip=0;
 +                        }
 +                }
 +            }
 +            if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip
 +                && nb_frame_threshold[ist->st->codec->codec_type] <= ist->st->codec_info_nb_frames){
 +                found_streams[ist->st->codec->codec_type]++;
 +            }
 +        }
 +        for(j=0; j<AVMEDIA_TYPE_NB; j++)
 +            if(found_streams[j] < nb_streams[j])
 +                nb_frame_threshold[j] -= step;
 +    }
      n = 0;
      for(k=0;k<nb_output_files;k++) {
          os = output_files[k];
                  }
  
              } else {
 -                int best_nb_frames=-1;
                  /* get corresponding input stream index : we select the first one with the right type */
                  found = 0;
-                 for(j=0;j<nb_istreams;j++) {
+                 for (j = 0; j < nb_input_streams; j++) {
                      int skip=0;
-                     ist = ist_table[j];
+                     ist = &input_streams[j];
                      if(opt_programid){
                          int pi,si;
-                         AVFormatContext *f= input_files[ ist->file_index ];
+                         AVFormatContext *f = input_files[ist->file_index].ctx;
                          skip=1;
                          for(pi=0; pi<f->nb_programs; pi++){
                              AVProgram *p= f->programs[pi];
                  ret = AVERROR(EINVAL);
                  goto dump_format;
              }
 -
 -            /* update requested sample format for the decoder based on the
 -               corresponding encoder sample format */
 -            for (j = 0; j < nb_ostreams; j++) {
 -                ost = ost_table[j];
 -                if (ost->source_index == i) {
 -                    update_sample_fmt(ist->st->codec, codec, ost->st->codec);
 -                    break;
 -                }
 -            }
 -
              if (avcodec_open(ist->st->codec, codec) < 0) {
                  snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d",
-                         ist->file_index, ist->index);
+                         ist->file_index, ist->st->index);
                  ret = AVERROR(EINVAL);
                  goto dump_format;
              }
      redo:
          ipts_min= 1e100;
          opts_min= 1e100;
-                     ist = ist_table[0];
-                     debug = ist->st->codec->debug<<1;
 +        /* if 'q' pressed, exits */
 +        if (!using_stdin) {
 +            if (q_pressed)
 +                break;
 +            /* read_key() returns 0 on EOF */
 +            key = read_key();
 +            if (key == 'q')
 +                break;
 +            if (key == '+') verbose++;
 +            if (key == '-') verbose--;
 +            if (key == 's') qp_hist     ^= 1;
 +            if (key == 'h'){
 +                if (do_hex_dump){
 +                    do_hex_dump = do_pkt_dump = 0;
 +                } else if(do_pkt_dump){
 +                    do_hex_dump = 1;
 +                } else
 +                    do_pkt_dump = 1;
 +                av_log_set_level(AV_LOG_DEBUG);
 +            }
 +            if (key == 'd' || key == 'D'){
 +                int debug=0;
 +                if(key == 'D') {
-                 for(i=0;i<nb_istreams;i++) {
-                     ist = ist_table[i];
-                     ist->st->codec->debug = debug;
++                    debug = input_streams[0].st->codec->debug<<1;
 +                    if(!debug) debug = 1;
 +                    while(debug & (FF_DEBUG_DCT_COEFF|FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) //unsupported, would just crash
 +                        debug += debug;
 +                }else
 +                    scanf("%d", &debug);
++                for(i=0;i<nb_input_streams;i++) {
++                    input_streams[i].st->codec->debug = debug;
 +                }
 +                for(i=0;i<nb_ostreams;i++) {
 +                    ost = ost_table[i];
 +                    ost->st->codec->debug = debug;
 +                }
 +                if(debug) av_log_set_level(AV_LOG_DEBUG);
 +                fprintf(stderr,"debug=%d\n", debug);
 +            }
 +            if (key == '?'){
 +                fprintf(stderr, "key    function\n"
 +                                "?      show this help\n"
 +                                "+      increase verbosity\n"
 +                                "-      decrease verbosity\n"
 +                                "D      cycle through available debug modes\n"
 +                                "h      dump packets/hex press to cycle through the 3 states\n"
 +                                "q      quit\n"
 +                                "s      Show QP histogram\n"
 +                );
 +            }
 +        }
  
          /* select the stream that we must read now by looking at the
             smallest output pts */
@@@ -3455,10 -3318,11 +3421,12 @@@ static void opt_input_file(const char *
      if (verbose >= 0)
          av_dump_format(ic, nb_input_files, filename, 0);
  
-     nb_input_files++;
+     input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1);
+     input_files[nb_input_files - 1].ctx        = ic;
+     input_files[nb_input_files - 1].ist_index  = nb_input_streams - ic->nb_streams;
  
      video_channel = 0;
 +    top_field_first = -1;
  
      av_freep(&video_codec_name);
      av_freep(&audio_codec_name);
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
          other formats */
  #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)
  
 +typedef void (*ff_reorder_func)(const void *, void *, int);
 +
  typedef struct {
+     AVClass *class;
      snd_pcm_t *h;
      int frame_size;  ///< preferred size for reads and writes
      int period_size; ///< bytes per sample * channels
 +    ff_reorder_func reorder_func;
 +    void *reorder_buf;
 +    int reorder_buf_size; ///< in frames
+     int sample_rate; ///< sample rate set by user
+     int channels;    ///< number of channels set by user
  } AlsaData;
  
  /**
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
  #ifndef FF_API_SDP_CREATE
  #define FF_API_SDP_CREATE              (LIBAVFORMAT_VERSION_MAJOR < 54)
  #endif
 +#ifndef FF_API_ALLOC_OUTPUT_CONTEXT
 +#define FF_API_ALLOC_OUTPUT_CONTEXT    (LIBAVFORMAT_VERSION_MAJOR < 54)
 +#endif
+ #ifndef FF_API_FORMAT_PARAMETERS
+ #define FF_API_FORMAT_PARAMETERS       (LIBAVFORMAT_VERSION_MAJOR < 54)
+ #endif
  
  #endif /* AVFORMAT_VERSION_H */
diff --cc libavutil/opt.c
Simple merge
@@@ -68,30 -68,9 +68,20 @@@ void shuffle_bytes_1230(const uint8_t *
  void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size);
  void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size);
  
- void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst,
-                    uint8_t *udst, uint8_t *vdst,
-                    long width, long height,
-                    long lumStride, long chromStride,
-                    long srcStride);
 +#if LIBSWSCALE_VERSION_MAJOR < 1
 +/* deprecated, use the public versions in swscale.h */
 +attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +
 +/* totally deprecated, please fix code that uses this */
 +attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette);
 +#endif
 +
- /**
-  * Height should be a multiple of 2 and width should be a multiple of 16.
-  * (If this is a problem for anyone then tell me, and I will fix it.)
-  * Chrominance data is only taken from every second line, others are ignored.
-  * FIXME: Write high quality version.
-  */
- //void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst,
++
+ void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
+                    uint8_t *vdst, long width, long height, long lumStride,
+                    long chromStride, long srcStride);
  
  /**
   * Height should be a multiple of 2 and width should be a multiple of 16.
Simple merge