Merge remote-tracking branch 'qatar/master'
authorMichael Niedermayer <michaelni@gmx.at>
Wed, 28 Sep 2011 23:03:02 +0000 (01:03 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Wed, 28 Sep 2011 23:11:01 +0000 (01:11 +0200)
* qatar/master: (23 commits)
  avconv: Reformat s16 volume adjustment.
  ARM: NEON optimised vector_fmac_scalar()
  dca: use vector_fmac_scalar from dsputil
  dsputil: add vector_fmac_scalar()
  latmenc: Fix private options
  vf_unsharp: store hsub/vsub in the filter context
  vf_unsharp: adopt a more natural order of params in apply_unsharp()
  vf_unsharp: rename method "unsharpen" to "apply_unsharp"
  vf_scale: apply the same transform to the aspect during init that is applied per frame
  vf_pad: fix "vsub" variable value computation
  vf_scale: add a "sar" variable
  lavfi: fix realloc size computation in avfilter_add_format()
  vsrc_color: use internal timebase
  lavfi: fix signature for avfilter_graph_parse() and avfilter_graph_config()
  graphparser: prefer void * over AVClass * for log contexts
  avfiltergraph: use meaningful error codes
  avconv: Initialize return value for codec copy path.
  fate: use 'run' helper for seek-test
  fate: remove seek-mpeg2reuse test
  Fix memory (re)allocation in matroskadec.c, related to MSVR-11-0080.
  ...

Conflicts:
doc/filters.texi
libavfilter/avfilter.h
libavfilter/avfiltergraph.c
libavfilter/avfiltergraph.h
libavfilter/graphparser.c
libavfilter/vf_scale.c
libavfilter/vsrc_color.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
13 files changed:
1  2 
avconv.c
doc/filters.texi
ffmpeg.c
libavcodec/arm/dsputil_init_neon.c
libavcodec/arm/dsputil_neon.S
libavcodec/dca.c
libavcodec/dsputil.c
libavcodec/dsputil.h
libavfilter/avfilter.h
libavfilter/avfiltergraph.h
libavformat/latmenc.c
libavformat/matroskadec.c
tests/fate-run.sh

diff --cc avconv.c
Simple merge
@@@ -1678,15 -1013,12 +1678,18 @@@ the output (cropped) width and heigt
  @item ow, oh
  same as @var{out_w} and @var{out_h}
  
 -@item dar, a
 -input display aspect ratio, same as @var{iw} / @var{ih}
 +@item a
 +same as @var{iw} / @var{ih}
 +
 +@item sar
 +input sample aspect ratio
 +
 +@item dar
 +input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar}
  
+ @item sar
+ input sample aspect ratio
  @item hsub, vsub
  horizontal and vertical chroma subsample values. For example for the
  pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
diff --cc ffmpeg.c
+++ b/ffmpeg.c
@@@ -160,8 -230,11 +160,8 @@@ static uint8_t *audio_buf
  static uint8_t *audio_out;
  static unsigned int allocated_audio_out_size, allocated_audio_buf_size;
  
--static short *samples;
 -
 -static AVBitStreamFilterContext *video_bitstream_filters=NULL;
 -static AVBitStreamFilterContext *audio_bitstream_filters=NULL;
 -static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL;
++static void *samples;
 +static uint8_t *input_tmp= NULL;
  
  #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass"
  
@@@ -1504,123 -1448,39 +1504,123 @@@ static void generate_silence(uint8_t *b
      memset(buf, fill_char, size);
  }
  
 -/* pkt = NULL means EOF (needed to flush decoder buffers) */
 -static int output_packet(InputStream *ist, int ist_index,
 -                         OutputStream **ost_table, int nb_ostreams,
 -                         const AVPacket *pkt)
 +static void flush_encoders(OutputStream *ost_table, int nb_ostreams)
  {
 -    AVFormatContext *os;
 -    OutputStream *ost;
 -    int ret, i;
 -    int got_output;
 -    AVFrame picture;
 -    void *buffer_to_free = NULL;
 -    static unsigned int samples_size= 0;
 -    AVSubtitle subtitle, *subtitle_to_free;
 -    int64_t pkt_pts = AV_NOPTS_VALUE;
 -#if CONFIG_AVFILTER
 -    int frame_available;
 -#endif
 -    float quality;
 +    int i, ret;
  
 -    AVPacket avpkt;
 -    int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
 +    for (i = 0; i < nb_ostreams; i++) {
 +        OutputStream   *ost = &ost_table[i];
 +        AVCodecContext *enc = ost->st->codec;
 +        AVFormatContext *os = output_files[ost->file_index].ctx;
  
 -    if(ist->next_pts == AV_NOPTS_VALUE)
 -        ist->next_pts= ist->pts;
 +        if (!ost->encoding_needed)
 +            continue;
  
 -    if (pkt == NULL) {
 -        /* EOF handling */
 -        av_init_packet(&avpkt);
 -        avpkt.data = NULL;
 -        avpkt.size = 0;
 -        goto handle_eof;
 -    } else {
 -        avpkt = *pkt;
 +        if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1)
 +            continue;
 +        if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE))
 +            continue;
 +
 +        for(;;) {
 +            AVPacket pkt;
 +            int fifo_bytes;
 +            av_init_packet(&pkt);
 +            pkt.stream_index= ost->index;
 +
 +            switch (ost->st->codec->codec_type) {
 +            case AVMEDIA_TYPE_AUDIO:
 +                fifo_bytes = av_fifo_size(ost->fifo);
 +                ret = 0;
 +                /* encode any samples remaining in fifo */
 +                if (fifo_bytes > 0) {
 +                    int osize = av_get_bytes_per_sample(enc->sample_fmt);
 +                    int fs_tmp = enc->frame_size;
 +
 +                    av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL);
 +                    if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
 +                        enc->frame_size = fifo_bytes / (osize * enc->channels);
 +                    } else { /* pad */
 +                        int frame_bytes = enc->frame_size*osize*enc->channels;
 +                        if (allocated_audio_buf_size < frame_bytes)
 +                            exit_program(1);
 +                        generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes);
 +                    }
 +
 +                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf);
 +                    pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den,
 +                                              ost->st->time_base.num, enc->sample_rate);
 +                    enc->frame_size = fs_tmp;
 +                }
 +                if (ret <= 0) {
 +                    ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL);
 +                }
 +                if (ret < 0) {
 +                    av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n");
 +                    exit_program(1);
 +                }
 +                audio_size += ret;
 +                pkt.flags |= AV_PKT_FLAG_KEY;
 +                break;
 +            case AVMEDIA_TYPE_VIDEO:
 +                ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL);
 +                if (ret < 0) {
 +                    av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n");
 +                    exit_program(1);
 +                }
 +                video_size += ret;
 +                if(enc->coded_frame && enc->coded_frame->key_frame)
 +                    pkt.flags |= AV_PKT_FLAG_KEY;
 +                if (ost->logfile && enc->stats_out) {
 +                    fprintf(ost->logfile, "%s", enc->stats_out);
 +                }
 +                break;
 +            default:
 +                ret=-1;
 +            }
 +
 +            if (ret <= 0)
 +                break;
 +            pkt.data = bit_buffer;
 +            pkt.size = ret;
 +            if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE)
 +                pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base);
 +            write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters);
 +        }
 +    }
 +}
 +
 +/* pkt = NULL means EOF (needed to flush decoder buffers) */
 +static int output_packet(InputStream *ist, int ist_index,
 +                         OutputStream *ost_table, int nb_ostreams,
 +                         const AVPacket *pkt)
 +{
 +    AVFormatContext *os;
 +    OutputStream *ost;
-     int ret, i;
++    int ret = 0, i;
 +    int got_output;
 +    void *buffer_to_free = NULL;
 +    static unsigned int samples_size= 0;
 +    AVSubtitle subtitle, *subtitle_to_free;
 +    int64_t pkt_pts = AV_NOPTS_VALUE;
 +#if CONFIG_AVFILTER
 +    int frame_available;
 +#endif
 +    float quality;
 +
 +    AVPacket avpkt;
 +    int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt);
 +
 +    if(ist->next_pts == AV_NOPTS_VALUE)
 +        ist->next_pts= ist->pts;
 +
 +    if (pkt == NULL) {
 +        /* EOF handling */
 +        av_init_packet(&avpkt);
 +        avpkt.data = NULL;
 +        avpkt.size = 0;
 +        goto handle_eof;
 +    } else {
 +        avpkt = *pkt;
      }
  
      if(pkt->dts != AV_NOPTS_VALUE)
          if (ist->decoding_needed) {
              switch(ist->st->codec->codec_type) {
              case AVMEDIA_TYPE_AUDIO:{
--                if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
--                    samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE);
++                if(pkt && samples_size < FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE)) {
++                    samples_size = FFMAX(pkt->size * bps, AVCODEC_MAX_AUDIO_FRAME_SIZE);
                      av_free(samples);
                      samples= av_malloc(samples_size);
                  }
          // preprocess audio (volume)
          if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
              if (audio_volume != 256) {
--                short *volp;
--                volp = samples;
--                for(i=0;i<(decoded_data_size / sizeof(short));i++) {
--                    int v = ((*volp) * audio_volume + 128) >> 8;
-                     *volp++ = av_clip_int16(v);
 -                    if (v < -32768) v = -32768;
 -                    if (v >  32767) v = 32767;
 -                    *volp++ = v;
++                switch (ist->st->codec->sample_fmt) {
++                case AV_SAMPLE_FMT_U8:
++                {
++                    uint8_t *volp = samples;
++                    for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
++                        int v = (((*volp - 128) * audio_volume + 128) >> 8) + 128;
++                        *volp++ = av_clip_uint8(v);
++                    }
++                    break;
++                }
++                case AV_SAMPLE_FMT_S16:
++                {
++                    int16_t *volp = samples;
++                    for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
++                        int v = ((*volp) * audio_volume + 128) >> 8;
++                        *volp++ = av_clip_int16(v);
++                    }
++                    break;
++                }
++                case AV_SAMPLE_FMT_S32:
++                {
++                    int32_t *volp = samples;
++                    for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
++                        int64_t v = (((int64_t)*volp * audio_volume + 128) >> 8);
++                        *volp++ = av_clipl_int32(v);
++                    }
++                    break;
++                }
++                case AV_SAMPLE_FMT_FLT:
++                {
++                    float *volp = samples;
++                    float scale = audio_volume / 256.f;
++                    for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
++                        *volp++ *= scale;
++                    }
++                    break;
++                }
++                case AV_SAMPLE_FMT_DBL:
++                {
++                    double *volp = samples;
++                    double scale = audio_volume / 256.;
++                    for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) {
++                        *volp++ *= scale;
++                    }
++                    break;
++                }
++                default:
++                    av_log(NULL, AV_LOG_FATAL,
++                           "Audio volume adjustment on sample format %s is not supported.\n",
++                           av_get_sample_fmt_name(ist->st->codec->sample_fmt));
++                    exit_program(1);
                  }
              }
          }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
@@@ -29,8 -29,8 +29,8 @@@
  #include "libavutil/rational.h"
  
  #define LIBAVFILTER_VERSION_MAJOR  2
 -#define LIBAVFILTER_VERSION_MINOR  7
 -#define LIBAVFILTER_VERSION_MICRO  2
 +#define LIBAVFILTER_VERSION_MINOR 43
- #define LIBAVFILTER_VERSION_MICRO  5
++#define LIBAVFILTER_VERSION_MICRO  6
  
  #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
                                                 LIBAVFILTER_VERSION_MINOR, \
@@@ -133,42 -117,7 +133,43 @@@ void avfilter_inout_free(AVFilterInOut 
   * @return zero on success, a negative AVERROR code on error
   */
  int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
 -                         AVFilterInOut *inputs, AVFilterInOut *outputs,
 +                         AVFilterInOut **inputs, AVFilterInOut **outputs,
                           void *log_ctx);
  
 +/**
 + * Send a command to one or more filter instances.
 + *
 + * @param graph  the filter graph
 + * @param target the filter(s) to which the command should be sent
 + *               "all" sends to all filters
 + *               otherwise it can be a filter or filter instance name
 + *               which will send the command to all matching filters.
 + * @param cmd    the command to sent, for handling simplicity all commands must be alphanumeric only
 + * @param arg    the argument for the command
 + * @param res    a buffer with size res_size where the filter(s) can return a response.
 + *
 + * @returns >=0 on success otherwise an error code.
 + *              AVERROR(ENOSYS) on unsupported commands
 + */
 +int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags);
 +
 +/**
 + * Queue a command for one or more filter instances.
 + *
 + * @param graph  the filter graph
 + * @param target the filter(s) to which the command should be sent
 + *               "all" sends to all filters
 + *               otherwise it can be a filter or filter instance name
 + *               which will send the command to all matching filters.
 + * @param cmd    the command to sent, for handling simplicity all commands must be alphanummeric only
 + * @param arg    the argument for the command
 + * @param ts     time at which the command should be sent to the filter
 + *
 + * @note As this executes commands after this function returns, no return code
 + *       from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported.
 + */
 +int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts);
 +
 +
++
  #endif /* AVFILTER_AVFILTERGRAPH_H */
  #include "libavcodec/mpeg4audio.h"
  #include "libavutil/opt.h"
  #include "avformat.h"
 +#include "rawenc.h"
  
  typedef struct {
+     AVClass *av_class;
      int off;
      int channel_conf;
      int object_type;
@@@ -996,13 -969,15 +997,18 @@@ static int matroska_decode_buffer(uint8
          zstream.avail_in = isize;
          do {
              pkt_size *= 3;
-             pkt_data = av_realloc(pkt_data, pkt_size);
+             newpktdata = av_realloc(pkt_data, pkt_size);
+             if (!newpktdata) {
+                 inflateEnd(&zstream);
+                 goto failed;
+             }
+             pkt_data = newpktdata;
              zstream.avail_out = pkt_size - zstream.total_out;
              zstream.next_out = pkt_data + zstream.total_out;
 -            result = inflate(&zstream, Z_NO_FLUSH);
 +            if (pkt_data) {
 +                result = inflate(&zstream, Z_NO_FLUSH);
 +            } else
 +                result = Z_MEM_ERROR;
          } while (result==Z_OK && pkt_size<10000000);
          pkt_size = zstream.total_out;
          inflateEnd(&zstream);
          bzstream.avail_in = isize;
          do {
              pkt_size *= 3;
-             pkt_data = av_realloc(pkt_data, pkt_size);
+             newpktdata = av_realloc(pkt_data, pkt_size);
+             if (!newpktdata) {
+                 BZ2_bzDecompressEnd(&bzstream);
+                 goto failed;
+             }
+             pkt_data = newpktdata;
              bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
              bzstream.next_out = pkt_data + bzstream.total_out_lo32;
 -            result = BZ2_bzDecompress(&bzstream);
 +            if (pkt_data) {
 +                result = BZ2_bzDecompress(&bzstream);
 +            } else
 +                result = BZ_MEM_ERROR;
          } while (result==BZ_OK && pkt_size<10000000);
          pkt_size = bzstream.total_out_lo32;
          BZ2_bzDecompressEnd(&bzstream);
Simple merge