Merge remote-tracking branch 'dwbuiten/master'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 22 Jul 2012 21:59:57 +0000 (23:59 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 22 Jul 2012 22:00:03 +0000 (00:00 +0200)
* dwbuiten/master:
  wav: Add check for 'fmt' tag in SMV code

Merged-by: Michael Niedermayer <michaelni@gmx.at>
83 files changed:
common.mak
configure
libavcodec/ac3enc_fixed.c
libavcodec/ac3enc_opts_template.c
libavcodec/adpcmenc.c
libavcodec/eac3enc.c
libavcodec/g723_1.c
libavcodec/g723_1_data.h
libavcodec/libopenjpegdec.c
libavcodec/libopenjpegenc.c
libavcodec/version.h
libavfilter/af_aformat.c
libavfilter/af_anull.c
libavfilter/af_channelmap.c
libavfilter/af_join.c
libavfilter/asrc_anullsrc.c
libavfilter/avfilter.h
libavfilter/buffersink.c
libavfilter/buffersrc.c
libavfilter/f_settb.c
libavfilter/fifo.c
libavfilter/internal.h
libavfilter/sink_buffer.c
libavfilter/split.c
libavfilter/src_movie.c
libavfilter/vf_alphaextract.c
libavfilter/vf_alphamerge.c
libavfilter/vf_aspect.c
libavfilter/vf_ass.c
libavfilter/vf_bbox.c
libavfilter/vf_blackdetect.c
libavfilter/vf_blackframe.c
libavfilter/vf_boxblur.c
libavfilter/vf_colormatrix.c
libavfilter/vf_copy.c
libavfilter/vf_crop.c
libavfilter/vf_cropdetect.c
libavfilter/vf_delogo.c
libavfilter/vf_deshake.c
libavfilter/vf_drawbox.c
libavfilter/vf_drawtext.c
libavfilter/vf_fade.c
libavfilter/vf_fieldorder.c
libavfilter/vf_format.c
libavfilter/vf_fps.c
libavfilter/vf_frei0r.c
libavfilter/vf_gradfun.c
libavfilter/vf_hflip.c
libavfilter/vf_hqdn3d.c
libavfilter/vf_idet.c
libavfilter/vf_libopencv.c
libavfilter/vf_lut.c
libavfilter/vf_mp.c
libavfilter/vf_null.c
libavfilter/vf_overlay.c
libavfilter/vf_pad.c
libavfilter/vf_pixdesctest.c
libavfilter/vf_removelogo.c
libavfilter/vf_scale.c
libavfilter/vf_select.c
libavfilter/vf_setfield.c
libavfilter/vf_setpts.c
libavfilter/vf_showinfo.c
libavfilter/vf_slicify.c
libavfilter/vf_super2xsai.c
libavfilter/vf_swapuv.c
libavfilter/vf_thumbnail.c
libavfilter/vf_tile.c
libavfilter/vf_tinterlace.c
libavfilter/vf_transpose.c
libavfilter/vf_unsharp.c
libavfilter/vf_vflip.c
libavfilter/vf_yadif.c
libavfilter/video.c
libavfilter/video.h
libavfilter/vsink_nullsink.c
libavfilter/vsrc_color.c
libavfilter/vsrc_testsrc.c
libavformat/g723_1.c
libavformat/matroskadec.c
libavformat/version.h
tests/Makefile
tests/fate/filter.mak [new file with mode: 0644]

index e306cef..5e43c7d 100644 (file)
@@ -54,7 +54,7 @@ COMPILE_S = $(call COMPILE,AS)
        $(COMPILE_S)
 
 %.ho: %.h
-       $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $<
+       $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ -x c $<
 
 %.ver: %.v
        $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@
index 31c13d1..2932988 100755 (executable)
--- a/configure
+++ b/configure
@@ -1810,6 +1810,20 @@ ffserver_extralibs='$ldl'
 doc_deps_any="texi2html makeinfo pod2man"
 
 # tests
+colormatrix1_test_deps="colormatrix_filter"
+colormatrix2_test_deps="colormatrix_filter"
+flashsv2_test_deps="zlib"
+mpg_test_deps="mpeg1system_muxer mpegps_demuxer"
+mpng_test_deps="zlib"
+pp_test_deps="mp_filter"
+pp2_test_deps="mp_filter"
+pp3_test_deps="mp_filter"
+pp4_test_deps="mp_filter"
+pp5_test_deps="mp_filter"
+pp6_test_deps="mp_filter"
+seek_lavf_mxf_d10_test_deps="mxf_d10_test"
+zlib_test_deps="zlib"
+zmbv_test_deps="zlib"
 
 test_deps(){
     suf1=$1
@@ -1824,8 +1838,6 @@ test_deps(){
     done
 }
 
-seek_lavf_mxf_d10_test_deps="mxf_d10_test"
-
 test_deps _muxer _demuxer                                               \
     aiff                                                                \
     pcm_alaw=alaw                                                       \
@@ -1851,20 +1863,6 @@ test_deps _muxer _demuxer                                               \
     wav                                                                 \
     yuv4mpegpipe=yuv4mpeg                                               \
 
-colormatrix1_test_deps="colormatrix_filter"
-colormatrix2_test_deps="colormatrix_filter"
-flashsv2_test_deps="zlib"
-mpg_test_deps="mpeg1system_muxer mpegps_demuxer"
-mpng_test_deps="zlib"
-pp_test_deps="mp_filter"
-pp2_test_deps="mp_filter"
-pp3_test_deps="mp_filter"
-pp4_test_deps="mp_filter"
-pp5_test_deps="mp_filter"
-pp6_test_deps="mp_filter"
-zlib_test_deps="zlib"
-zmbv_test_deps="zlib"
-
 # default parameters
 
 logfile="config.log"
@@ -2238,6 +2236,78 @@ EOF
     die "Sanity test failed."
 fi
 
+pgi_flags(){
+    for flag; do
+        case $flag in
+            -fomit-frame-pointer) echo -Mnoframe ;;
+            -g)                   echo -gopt ;;
+            *)                    echo $flag ;;
+        esac
+    done
+}
+
+suncc_flags(){
+    for flag; do
+        case $flag in
+            -march=*|-mcpu=*)
+                case "${flag#*=}" in
+                    native)                   echo -xtarget=native       ;;
+                    v9|niagara)               echo -xarch=sparc          ;;
+                    ultrasparc)               echo -xarch=sparcvis       ;;
+                    ultrasparc3|niagara2)     echo -xarch=sparcvis2      ;;
+                    i586|pentium)             echo -xchip=pentium        ;;
+                    i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
+                    pentium3*|c3-2)           echo -xtarget=pentium3     ;;
+                    pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
+                    pentium4*)          echo -xtarget=pentium4           ;;
+                    prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
+                    *-sse3)             echo -xarch=sse3                 ;;
+                    core2)              echo -xarch=ssse3 -xchip=core2   ;;
+                    amdfam10|barcelona)       echo -xarch=sse4_1         ;;
+                    athlon-4|athlon-[mx]p)    echo -xarch=ssea           ;;
+                    k8|opteron|athlon64|athlon-fx)
+                                              echo -xarch=sse2a          ;;
+                    athlon*)                  echo -xarch=pentium_proa   ;;
+                esac
+                ;;
+            -std=c99)             echo -xc99              ;;
+            -fomit-frame-pointer) echo -xregs=frameptr    ;;
+            -fPIC)                echo -KPIC -xcode=pic32 ;;
+            -W*,*)                echo $flag              ;;
+            -f*-*|-W*)                                    ;;
+            *)                    echo $flag              ;;
+        esac
+    done
+}
+
+tms470_flags(){
+    for flag; do
+        case $flag in
+            -march=*|-mcpu=*)
+                case "${flag#*=}" in
+                    armv7-a|cortex-a*)      echo -mv=7a8 ;;
+                    armv7-r|cortex-r*)      echo -mv=7r4 ;;
+                    armv7-m|cortex-m*)      echo -mv=7m3 ;;
+                    armv6*|arm11*)          echo -mv=6   ;;
+                    armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
+                                            echo -mv=5e  ;;
+                    armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
+                esac
+                ;;
+            -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
+            -mfpu=vfp)      echo --float_support=vfpv2        ;;
+            -mfpu=vfpv3)    echo --float_support=vfpv3        ;;
+            -msoft-float)   echo --float_support=vfplib       ;;
+            -O[0-3]|-mf=*)  echo $flag                        ;;
+            -g)             echo -g -mn                       ;;
+            -pds=*)         echo $flag                        ;;
+            -D*|-I*)        echo $flag                        ;;
+            --gcc|--abi=*)  echo $flag                        ;;
+            -me)            echo $flag                        ;;
+        esac
+    done
+}
+
 if   $cc -v 2>&1 | grep -q '^gcc.*LLVM'; then
     cc_type=llvm_gcc
     gcc_extra_ver=$(expr "$($cc --version | head -n1)" : '.*\((.*)\)')
@@ -2313,30 +2383,6 @@ elif $cc -version 2>/dev/null | grep -q TMS470; then
     cflags_speed='-O3 -mf=5'
     cflags_size='-O3 -mf=2'
     cflags_filter=tms470_flags
-    tms470_flags(){
-        for flag; do
-            case $flag in
-                -march=*|-mcpu=*)
-                    case "${flag#*=}" in
-                        armv7-a|cortex-a*)      echo -mv=7a8 ;;
-                        armv7-r|cortex-r*)      echo -mv=7r4 ;;
-                        armv7-m|cortex-m*)      echo -mv=7m3 ;;
-                        armv6*|arm11*)          echo -mv=6   ;;
-                        armv5*e|arm[79]*e*|arm9[24]6*|arm96*|arm102[26])
-                                                echo -mv=5e  ;;
-                        armv4*|arm7*|arm9[24]*) echo -mv=4   ;;
-                    esac
-                    ;;
-                -mfpu=neon)     echo --float_support=vfpv3 --neon ;;
-                -mfpu=vfp)      echo --float_support=vfpv2        ;;
-                -mfpu=vfpv3)    echo --float_support=vfpv3        ;;
-                -msoft-float)   echo --float_support=vfplib       ;;
-                -O[0-3]|-mf=*)  echo $flag                        ;;
-                -g)             echo -g -mn                       ;;
-                -pds=*)         echo $flag                        ;;
-            esac
-        done
-    }
 elif $cc -v 2>&1 | grep -q clang; then
     cc_type=clang
     cc_ident=$($cc --version | head -n1)
@@ -2353,39 +2399,6 @@ elif $cc -V 2>&1 | grep -q Sun; then
     cflags_speed='-O5'
     cflags_size='-O5 -xspace'
     cflags_filter=suncc_flags
-    suncc_flags(){
-        for flag; do
-            case $flag in
-                -march=*|-mcpu=*)
-                    case "${flag#*=}" in
-                        native)                   echo -xtarget=native       ;;
-                        v9|niagara)               echo -xarch=sparc          ;;
-                        ultrasparc)               echo -xarch=sparcvis       ;;
-                        ultrasparc3|niagara2)     echo -xarch=sparcvis2      ;;
-                        i586|pentium)             echo -xchip=pentium        ;;
-                        i686|pentiumpro|pentium2) echo -xtarget=pentium_pro  ;;
-                        pentium3*|c3-2)           echo -xtarget=pentium3     ;;
-                        pentium-m)          echo -xarch=sse2 -xchip=pentium3 ;;
-                        pentium4*)          echo -xtarget=pentium4           ;;
-                        prescott|nocona)    echo -xarch=sse3 -xchip=pentium4 ;;
-                        *-sse3)             echo -xarch=sse3                 ;;
-                        core2)              echo -xarch=ssse3 -xchip=core2   ;;
-                        amdfam10|barcelona)       echo -xarch=sse4_1         ;;
-                        athlon-4|athlon-[mx]p)    echo -xarch=ssea           ;;
-                        k8|opteron|athlon64|athlon-fx)
-                                                  echo -xarch=sse2a          ;;
-                        athlon*)                  echo -xarch=pentium_proa   ;;
-                    esac
-                    ;;
-                -std=c99)             echo -xc99              ;;
-                -fomit-frame-pointer) echo -xregs=frameptr    ;;
-                -fPIC)                echo -KPIC -xcode=pic32 ;;
-                -W*,*)                echo $flag              ;;
-                -f*-*|-W*)                                    ;;
-                *)                    echo $flag              ;;
-            esac
-        done
-    }
 elif $cc -v 2>&1 | grep -q 'PathScale\|Path64'; then
     cc_type=pathscale
     cc_ident=$($cc -v 2>&1 | head -n1 | tr -d :)
@@ -2410,15 +2423,6 @@ elif $cc -V 2>&1 | grep -q Portland; then
     cflags_size="-O2 -Munroll=c:1 $opt_common"
     cflags_noopt="-O1"
     cflags_filter=pgi_flags
-    pgi_flags(){
-        for flag; do
-            case $flag in
-                -fomit-frame-pointer) echo -Mnoframe ;;
-                -g)                   echo -gopt ;;
-                *)                    echo $flag ;;
-            esac
-        done
-    }
 fi
 
 test -n "$cc_type" && enable $cc_type ||
index 399b238..8293ecd 100644 (file)
@@ -38,7 +38,7 @@
 static const AVClass ac3enc_class = {
     .class_name = "Fixed-Point AC-3 Encoder",
     .item_name  = av_default_item_name,
-    .option     = ac3fixed_options,
+    .option     = ac3_options,
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
index fa89844..1c67aa4 100644 (file)
 #include "internal.h"
 #include "ac3.h"
 
-#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED
-static const AVOption ac3fixed_options[] = {
-#elif AC3ENC_TYPE == AC3ENC_TYPE_AC3
 static const AVOption ac3_options[] = {
-#else /* AC3ENC_TYPE_EAC3 */
-static const AVOption eac3_options[] = {
-#endif
 /* Metadata Options */
 {"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM},
 #if AC3ENC_TYPE != AC3ENC_TYPE_EAC3
index 6dde9e7..4a00232 100644 (file)
@@ -717,6 +717,9 @@ error:
     return AVERROR(ENOMEM);
 }
 
+static const enum AVSampleFormat sample_fmts[] = {
+    AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE
+};
 
 #define ADPCM_ENCODER(id_, name_, long_name_)               \
 AVCodec ff_ ## name_ ## _encoder = {                        \
@@ -727,8 +730,7 @@ AVCodec ff_ ## name_ ## _encoder = {                        \
     .init           = adpcm_encode_init,                    \
     .encode2        = adpcm_encode_frame,                   \
     .close          = adpcm_encode_close,                   \
-    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16,    \
-                                                      AV_SAMPLE_FMT_NONE }, \
+    .sample_fmts    = sample_fmts,                          \
     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
 }
 
index 9f4a6a7..e11b29c 100644 (file)
@@ -36,7 +36,7 @@
 static const AVClass eac3enc_class = {
     .class_name = "E-AC-3 Encoder",
     .item_name  = av_default_item_name,
-    .option     = eac3_options,
+    .option     = ac3_options,
     .version    = LIBAVUTIL_VERSION_INT,
 };
 
index ce3793d..8c5407e 100644 (file)
  * G.723.1 compatible decoder
  */
 
-#include "avcodec.h"
 #define BITSTREAM_READER_LE
+#include "libavutil/audioconvert.h"
+#include "libavutil/lzo.h"
+#include "libavutil/opt.h"
+#include "avcodec.h"
 #include "internal.h"
 #include "get_bits.h"
 #include "acelp_vectors.h"
 #include "celp_filters.h"
 #include "celp_math.h"
 #include "lsp.h"
-#include "libavutil/lzo.h"
 #include "g723_1_data.h"
 
 typedef struct g723_1_context {
+    AVClass *class;
     AVFrame frame;
+
     G723_1_Subframe subframe[4];
-    FrameType cur_frame_type;
-    FrameType past_frame_type;
-    Rate cur_rate;
+    enum FrameType cur_frame_type;
+    enum FrameType past_frame_type;
+    enum Rate cur_rate;
     uint8_t lsp_index[LSP_BANDS];
     int pitch_lag[2];
     int erased_frames;
@@ -62,6 +66,7 @@ typedef struct g723_1_context {
     int pf_gain;                 ///< formant postfilter
                                  ///< gain scaling unit memory
 
+    int postfilter;
     int16_t prev_data[HALF_FRAME_LEN];
     int16_t prev_weight_sig[PITCH_MAX];
 
@@ -80,11 +85,12 @@ static av_cold int g723_1_decode_init(AVCodecContext *avctx)
 
     avctx->sample_fmt  = AV_SAMPLE_FMT_S16;
     p->pf_gain         = 1 << 12;
-    memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t));
 
     avcodec_get_frame_defaults(&p->frame);
     avctx->coded_frame = &p->frame;
 
+    memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
+
     return 0;
 }
 
@@ -108,7 +114,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
     info_bits = get_bits(&gb, 2);
 
     if (info_bits == 3) {
-        p->cur_frame_type = UntransmittedFrame;
+        p->cur_frame_type = UNTRANSMITTED_FRAME;
         return 0;
     }
 
@@ -118,14 +124,14 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
     p->lsp_index[0] = get_bits(&gb, 8);
 
     if (info_bits == 2) {
-        p->cur_frame_type = SIDFrame;
+        p->cur_frame_type = SID_FRAME;
         p->subframe[0].amp_index = get_bits(&gb, 6);
         return 0;
     }
 
     /* Extract the info common to both rates */
-    p->cur_rate       = info_bits ? Rate5k3 : Rate6k3;
-    p->cur_frame_type = ActiveFrame;
+    p->cur_rate       = info_bits ? RATE_5300 : RATE_6300;
+    p->cur_frame_type = ACTIVE_FRAME;
 
     p->pitch_lag[0] = get_bits(&gb, 7);
     if (p->pitch_lag[0] > 123)       /* test if forbidden code */
@@ -146,9 +152,9 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
         temp = get_bits(&gb, 12);
         ad_cb_len = 170;
         p->subframe[i].dirac_train = 0;
-        if (p->cur_rate == Rate6k3 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) {
+        if (p->cur_rate == RATE_6300 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) {
             p->subframe[i].dirac_train = temp >> 11;
-            temp &= 0x7ff;
+            temp &= 0x7FF;
             ad_cb_len = 85;
         }
         p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS);
@@ -165,7 +171,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
     p->subframe[2].grid_index = get_bits1(&gb);
     p->subframe[3].grid_index = get_bits1(&gb);
 
-    if (p->cur_rate == Rate6k3) {
+    if (p->cur_rate == RATE_6300) {
         skip_bits1(&gb);  /* skip reserved bit */
 
         /* Compute pulse_pos index using the 13-bit combined position index */
@@ -192,7 +198,7 @@ static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf,
         p->subframe[1].pulse_sign = get_bits(&gb, 5);
         p->subframe[2].pulse_sign = get_bits(&gb, 6);
         p->subframe[3].pulse_sign = get_bits(&gb, 5);
-    } else { /* Rate5k3 */
+    } else { /* 5300 bps */
         p->subframe[0].pulse_pos  = get_bits(&gb, 12);
         p->subframe[1].pulse_pos  = get_bits(&gb, 12);
         p->subframe[2].pulse_pos  = get_bits(&gb, 12);
@@ -333,7 +339,7 @@ static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp,
             break;
     }
     if (!stable)
-        memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(int16_t));
+        memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(*cur_lsp));
 }
 
 /**
@@ -432,7 +438,7 @@ static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp)
                                  8192, 8192, 1 << 13, 14, LPC_ORDER);
     ff_acelp_weighted_vector_sum(lpc + 2 * LPC_ORDER, cur_lsp, prev_lsp,
                                  12288, 4096, 1 << 13, 14, LPC_ORDER);
-    memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(int16_t));
+    memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(*lpc));
 
     for (i = 0; i < SUBFRAMES; i++) {
         lsp2lpc(lpc_ptr);
@@ -448,7 +454,7 @@ static void gen_dirac_train(int16_t *buf, int pitch_lag)
     int16_t vector[SUBFRAME_LEN];
     int i, j;
 
-    memcpy(vector, buf, SUBFRAME_LEN * sizeof(int16_t));
+    memcpy(vector, buf, SUBFRAME_LEN * sizeof(*vector));
     for (i = pitch_lag; i < SUBFRAME_LEN; i += pitch_lag) {
         for (j = 0; j < SUBFRAME_LEN - i; j++)
             buf[i + j] += vector[j];
@@ -465,13 +471,13 @@ static void gen_dirac_train(int16_t *buf, int pitch_lag)
  * @param index     current subframe index
  */
 static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm,
-                               Rate cur_rate, int pitch_lag, int index)
+                               enum Rate cur_rate, int pitch_lag, int index)
 {
     int temp, i, j;
 
-    memset(vector, 0, SUBFRAME_LEN * sizeof(int16_t));
+    memset(vector, 0, SUBFRAME_LEN * sizeof(*vector));
 
-    if (cur_rate == Rate6k3) {
+    if (cur_rate == RATE_6300) {
         if (subfrm.pulse_pos >= max_pos[index])
             return;
 
@@ -495,7 +501,7 @@ static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm,
         }
         if (subfrm.dirac_train == 1)
             gen_dirac_train(vector, pitch_lag);
-    } else { /* Rate5k3 */
+    } else { /* 5300 bps */
         int cb_gain  = fixed_cb_gain[subfrm.amp_index];
         int cb_shift = subfrm.grid_index;
         int cb_sign  = subfrm.pulse_sign;
@@ -554,7 +560,7 @@ static void gen_acb_excitation(int16_t *vector, int16_t *prev_excitation,
     get_residual(residual, prev_excitation, lag);
 
     /* Select quantization table */
-    if (cur_rate == Rate6k3 && pitch_lag < SUBFRAME_LEN - 2) {
+    if (cur_rate == RATE_6300 && pitch_lag < SUBFRAME_LEN - 2) {
         cb_ptr = adaptive_cb_gain85;
     } else
         cb_ptr = adaptive_cb_gain170;
@@ -608,7 +614,7 @@ static int autocorr_max(G723_1_Context *p, int offset, int *ccr_max,
  * @param ccr      cross-correlation
  * @param res_eng  residual energy
  */
-static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate,
+static void comp_ppf_gains(int lag, PPFParam *ppf, enum Rate cur_rate,
                            int tgt_eng, int ccr, int res_eng)
 {
     int pf_residual;     /* square of postfiltered residual */
@@ -657,7 +663,7 @@ static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate,
  * @param cur_rate  current bitrate
  */
 static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag,
-                           PPFParam *ppf, Rate cur_rate)
+                           PPFParam *ppf, enum Rate cur_rate)
 {
 
     int16_t scale;
@@ -795,15 +801,15 @@ static void residual_interp(int16_t *buf, int16_t *out, int lag,
         /* Attenuate */
         for (i = 0; i < lag; i++)
             vector_ptr[i - lag] = vector_ptr[i - lag] * 3 >> 2;
-        av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(int16_t),
-                          FRAME_LEN * sizeof(int16_t));
-        memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t));
+        av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(*vector_ptr),
+                          FRAME_LEN * sizeof(*vector_ptr));
+        memcpy(out, vector_ptr, FRAME_LEN * sizeof(*vector_ptr));
     } else {  /* Unvoiced */
         for (i = 0; i < FRAME_LEN; i++) {
             *rseed = *rseed * 521 + 259;
             out[i] = gain * *rseed >> 15;
         }
-        memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(int16_t));
+        memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(*buf));
     }
 }
 
@@ -889,8 +895,8 @@ static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf)
     int filter_signal[LPC_ORDER + FRAME_LEN], *signal_ptr;
     int i, j, k;
 
-    memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(int16_t));
-    memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(int));
+    memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(*buf));
+    memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(*filter_signal));
 
     for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) {
         for (k = 0; k < LPC_ORDER; k++) {
@@ -977,8 +983,8 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
 
     if (unpack_bitstream(p, buf, buf_size) < 0) {
         bad_frame         = 1;
-        p->cur_frame_type = p->past_frame_type == ActiveFrame ?
-                            ActiveFrame : UntransmittedFrame;
+        p->cur_frame_type = p->past_frame_type == ACTIVE_FRAME ?
+                            ACTIVE_FRAME : UNTRANSMITTED_FRAME;
     }
 
     p->frame.nb_samples = FRAME_LEN + LPC_ORDER;
@@ -989,20 +995,21 @@ static int g723_1_decode_frame(AVCodecContext *avctx, void *data,
     out= (int16_t*)p->frame.data[0];
 
 
-    if(p->cur_frame_type == ActiveFrame) {
-        if (!bad_frame) {
+    if(p->cur_frame_type == ACTIVE_FRAME) {
+        if (!bad_frame)
             p->erased_frames = 0;
-        else if(p->erased_frames != 3)
+        else if(p->erased_frames != 3)
             p->erased_frames++;
 
         inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame);
         lsp_interpolate(lpc, cur_lsp, p->prev_lsp);
 
         /* Save the lsp_vector for the next frame */
-        memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(int16_t));
+        memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(*p->prev_lsp));
 
         /* Generate the excitation for the frame */
-        memcpy(p->excitation, p->prev_excitation, PITCH_MAX * sizeof(int16_t));
+        memcpy(p->excitation, p->prev_excitation,
+               PITCH_MAX * sizeof(*p->excitation));
         vector_ptr = p->excitation + PITCH_MAX;
         if (!p->erased_frames) {
             /* Update interpolation gain memory */
@@ -1118,7 +1125,7 @@ static av_cold int g723_1_encode_init(AVCodecContext *avctx)
     }
 
     if (avctx->bit_rate == 6300) {
-        p->cur_rate = Rate6k3;
+        p->cur_rate = RATE_6300;
     } else if (avctx->bit_rate == 5300) {
         av_log(avctx, AV_LOG_ERROR, "Bitrate not supported yet, use 6.3k\n");
         return AVERROR_PATCHWELCOME;
@@ -2041,7 +2048,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size)
 
     init_put_bits(&pb, frame, size);
 
-    if (p->cur_rate == Rate6k3) {
+    if (p->cur_rate == RATE_6300) {
         info_bits = 0;
         put_bits(&pb, 2, info_bits);
     }
@@ -2059,7 +2066,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size)
     for (i = 0; i < SUBFRAMES; i++) {
         temp = p->subframe[i].ad_cb_gain * GAIN_LEVELS +
                p->subframe[i].amp_index;
-        if (p->cur_rate ==  Rate6k3)
+        if (p->cur_rate ==  RATE_6300)
             temp += p->subframe[i].dirac_train << 11;
         put_bits(&pb, 12, temp);
     }
@@ -2069,7 +2076,7 @@ static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size)
     put_bits(&pb, 1, p->subframe[2].grid_index);
     put_bits(&pb, 1, p->subframe[3].grid_index);
 
-    if (p->cur_rate == Rate6k3) {
+    if (p->cur_rate == RATE_6300) {
         skip_put_bits(&pb, 1); /* reserved bit */
 
         /* Write 13 bit combined position index */
@@ -2192,7 +2199,7 @@ static int g723_1_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
 
         /* Reconstruct the excitation */
         gen_acb_excitation(impulse_resp, p->prev_excitation, p->pitch_lag[i >> 1],
-                           p->subframe[i], Rate6k3);
+                           p->subframe[i], RATE_6300);
 
         memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN,
                sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN));
index 34221e3..66a0324 100644 (file)
@@ -25,8 +25,8 @@
  * G723.1 compatible decoder data tables
  */
 
-#ifndef AVCODEC_G729_DATA_H
-#define AVCODEC_G729_DATA_H
+#ifndef AVCODEC_G729_1_DATA_H
+#define AVCODEC_G729_1_DATA_H
 
 #include <stdint.h>
 
 /**
  * G723.1 frame types
  */
-typedef enum {
-    ActiveFrame,        ///< Active speech
-    SIDFrame,           ///< Silence Insertion Descriptor frame
-    UntransmittedFrame
+typedef enum FrameType {
+    ACTIVE_FRAME,        ///< Active speech
+    SID_FRAME,           ///< Silence Insertion Descriptor frame
+    UNTRANSMITTED_FRAME
 } FrameType;
 
 static const uint8_t frame_size[4] = {24, 20, 4, 1};
 
-typedef enum {
-    Rate6k3,
-    Rate5k3
+typedef enum Rate {
+    RATE_6300,
+    RATE_5300
 } Rate;
 
 /**
  * G723.1 unpacked data subframe
  */
-typedef struct {
+typedef struct G723_1_Subframe {
     int ad_cb_lag;     ///< adaptive codebook lag
     int ad_cb_gain;
     int dirac_train;
@@ -1319,4 +1319,4 @@ static const int16_t percept_flt_tbl[2][LPC_ORDER] = {
     {16384,  8192,  4096,  2048,  1024,   512,   256,   128,    64,    32}
 };
 
-#endif /* AVCODEC_G729_DATA_H */
+#endif /* AVCODEC_G729_1_DATA_H */
index e7a7d8d..333955f 100644 (file)
  */
 
 /**
-* @file
-* JPEG 2000 decoder using libopenjpeg
-*/
+ * @file
+ * JPEG 2000 decoder using libopenjpeg
+ */
+
+#define  OPJ_STATIC
+#include <openjpeg.h>
 
-#include "libavutil/opt.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/pixfmt.h"
-#include "avcodec.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+#include "avcodec.h"
 #include "thread.h"
-#define  OPJ_STATIC
-#include <openjpeg.h>
 
 #define JP2_SIG_TYPE    0x6A502020
 #define JP2_SIG_VALUE   0x0D0A870A
@@ -61,7 +62,8 @@ typedef struct {
     int lowqual;
 } LibOpenJPEGContext;
 
-static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum PixelFormat pix_fmt){
+static inline int libopenjpeg_matches_pix_fmt(const opj_image_t *image, enum PixelFormat pix_fmt)
+{
     AVPixFmtDescriptor descriptor = av_pix_fmt_descriptors[pix_fmt];
     int match = 1;
 
@@ -129,7 +131,7 @@ static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) {
         return 0;
 
     component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane;
-    for(i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) {
+    for (i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) {
         if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane)
             return 0;
     }
@@ -139,11 +141,11 @@ static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) {
 static inline void libopenjpeg_copy_to_packed8(AVFrame *picture, opj_image_t *image) {
     uint8_t *img_ptr;
     int index, x, y, c;
-    for(y = 0; y < picture->height; y++) {
+    for (y = 0; y < picture->height; y++) {
         index = y*picture->width;
         img_ptr = picture->data[0] + y*picture->linesize[0];
-        for(x = 0; x < picture->width; x++, index++) {
-            for(c = 0; c < image->numcomps; c++) {
+        for (x = 0; x < picture->width; x++, index++) {
+            for (c = 0; c < image->numcomps; c++) {
                 *img_ptr++ = image->comps[c].data[index];
             }
         }
@@ -154,9 +156,9 @@ static inline void libopenjpeg_copy_to_packed16(AVFrame *picture, opj_image_t *i
     uint16_t *img_ptr;
     int index, x, y, c;
     int adjust[4];
-    for (x = 0; x < image->numcomps; x++) {
+    for (x = 0; x < image->numcomps; x++)
         adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0);
-    }
+
     for (y = 0; y < picture->height; y++) {
         index = y*picture->width;
         img_ptr = (uint16_t*) (picture->data[0] + y*picture->linesize[0]);
@@ -173,11 +175,11 @@ static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) {
     uint8_t *img_ptr;
     int index, x, y;
 
-    for(index = 0; index < image->numcomps; index++) {
+    for (index = 0; index < image->numcomps; index++) {
         comp_data = image->comps[index].data;
-        for(y = 0; y < image->comps[index].h; y++) {
+        for (y = 0; y < image->comps[index].h; y++) {
             img_ptr = picture->data[index] + y * picture->linesize[index];
-            for(x = 0; x < image->comps[index].w; x++) {
+            for (x = 0; x < image->comps[index].w; x++) {
                 *img_ptr = (uint8_t) *comp_data;
                 img_ptr++;
                 comp_data++;
@@ -190,11 +192,11 @@ static inline void libopenjpeg_copyto16(AVFrame *picture, opj_image_t *image) {
     int *comp_data;
     uint16_t *img_ptr;
     int index, x, y;
-    for(index = 0; index < image->numcomps; index++) {
+    for (index = 0; index < image->numcomps; index++) {
         comp_data = image->comps[index].data;
-        for(y = 0; y < image->comps[index].h; y++) {
+        for (y = 0; y < image->comps[index].h; y++) {
             img_ptr = (uint16_t*) (picture->data[index] + y * picture->linesize[index]);
-            for(x = 0; x < image->comps[index].w; x++) {
+            for (x = 0; x < image->comps[index].w; x++) {
                 *img_ptr = *comp_data;
                 img_ptr++;
                 comp_data++;
@@ -240,49 +242,55 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
     *data_size = 0;
 
     // Check if input is a raw jpeg2k codestream or in jp2 wrapping
-    if((AV_RB32(buf) == 12) &&
-       (AV_RB32(buf + 4) == JP2_SIG_TYPE) &&
-       (AV_RB32(buf + 8) == JP2_SIG_VALUE)) {
+    if ((AV_RB32(buf)     == 12)           &&
+        (AV_RB32(buf + 4) == JP2_SIG_TYPE) &&
+        (AV_RB32(buf + 8) == JP2_SIG_VALUE)) {
         dec = opj_create_decompress(CODEC_JP2);
     } else {
-        // If the AVPacket contains a jp2c box, then skip to
-        // the starting byte of the codestream.
+        /* If the AVPacket contains a jp2c box, then skip to
+         * the starting byte of the codestream. */
         if (AV_RB32(buf + 4) == AV_RB32("jp2c"))
             buf += 8;
         dec = opj_create_decompress(CODEC_J2K);
     }
 
-    if(!dec) {
+    if (!dec) {
         av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n");
         return -1;
     }
     opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL);
     ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
-    ctx->dec_params.cp_layer  = ctx->lowqual;
+    ctx->dec_params.cp_layer          = ctx->lowqual;
     // Tie decoder with decoding parameters
     opj_setup_decoder(dec, &ctx->dec_params);
     stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
-    if(!stream) {
-        av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n");
+
+    if (!stream) {
+        av_log(avctx, AV_LOG_ERROR,
+               "Codestream could not be opened for reading.\n");
         opj_destroy_decompress(dec);
         return -1;
     }
 
-    // Decode the header only
+    // Decode the header only.
     image = opj_decode_with_info(dec, stream, NULL);
     opj_cio_close(stream);
-    if(!image) {
+
+    if (!image) {
         av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
         opj_destroy_decompress(dec);
         return -1;
     }
+
     width  = image->x1 - image->x0;
     height = image->y1 - image->y0;
 
-    if(av_image_check_size(width, height, 0, avctx) < 0) {
-        av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height);
+    if (av_image_check_size(width, height, 0, avctx) < 0) {
+        av_log(avctx, AV_LOG_ERROR,
+               "%dx%d dimension invalid.\n", width, height);
         goto done;
     }
+
     avcodec_set_dimensions(avctx, width, height);
 
     if (avctx->pix_fmt != PIX_FMT_NONE) {
@@ -303,29 +311,30 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         if (image->comps[i].prec > avctx->bits_per_raw_sample)
             avctx->bits_per_raw_sample = image->comps[i].prec;
 
-    if(picture->data[0])
+    if (picture->data[0])
         ff_thread_release_buffer(avctx, picture);
 
-    if(ff_thread_get_buffer(avctx, picture) < 0){
+    if (ff_thread_get_buffer(avctx, picture) < 0) {
         av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed\n");
         goto done;
     }
 
     ctx->dec_params.cp_limit_decoding = NO_LIMITATION;
     ctx->dec_params.cp_reduce = avctx->lowres;
-    // Tie decoder with decoding parameters
+    // Tie decoder with decoding parameters.
     opj_setup_decoder(dec, &ctx->dec_params);
     stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size);
-    if(!stream) {
-        av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n");
+    if (!stream) {
+        av_log(avctx, AV_LOG_ERROR,
+               "Codestream could not be opened for reading.\n");
         goto done;
     }
 
     opj_image_destroy(image);
-    // Decode the codestream
+    // Decode the codestream.
     image = opj_decode_with_info(dec, stream, NULL);
     opj_cio_close(stream);
-    if(!image) {
+    if (!image) {
         av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n");
         goto done;
     }
@@ -367,7 +376,7 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
 
     *output    = ctx->image;
     *data_size = sizeof(AVPicture);
-    ret = buf_size;
+    ret        = buf_size;
 
 done:
     opj_image_destroy(image);
@@ -379,16 +388,16 @@ static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx)
 {
     LibOpenJPEGContext *ctx = avctx->priv_data;
 
-    if(ctx->image.data[0])
+    if (ctx->image.data[0])
         ff_thread_release_buffer(avctx, &ctx->image);
-    return 0 ;
+    return 0;
 }
 
 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
 
 static const AVOption options[] = {
-    { "lowqual",       "Limit the number of layers used for decoding",         OFFSET(lowqual),        AV_OPT_TYPE_INT,   { 0 }, 0, INT_MAX, VD },
+    { "lowqual", "Limit the number of layers used for decoding",    OFFSET(lowqual), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, VD },
     { NULL },
 };
 
index bd741df..82d2866 100644 (file)
  */
 
 /**
-* @file
-* JPEG 2000 encoder using libopenjpeg
-*/
+ * @file
+ * JPEG 2000 encoder using libopenjpeg
+ */
 
 #define  OPJ_STATIC
 #include <openjpeg.h>
 
-#include "libavutil/opt.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/avassert.h"
-#include "avcodec.h"
+#include "libavutil/imgutils.h"
 #include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+#include "avcodec.h"
 #include "internal.h"
 
 typedef struct {
@@ -284,9 +284,8 @@ static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, const AVFrame *fram
         for (y = 0; y < height; ++y) {
             image_index = y * width;
             frame_index = y * frame->linesize[compno];
-            for (x = 0; x < width; ++x) {
+            for (x = 0; x < width; ++x)
                 image->comps[compno].data[image_index++] = frame->data[compno][frame_index++];
-            }
         }
     }
 
@@ -319,9 +318,8 @@ static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, const AVFrame *fra
         for (y = 0; y < height; ++y) {
             image_index = y * width;
             frame_index = y * (frame->linesize[compno] / 2);
-            for (x = 0; x < width; ++x) {
+            for (x = 0; x < width; ++x)
                 image->comps[compno].data[image_index++] = frame_ptr[frame_index++];
-            }
         }
     }
 
@@ -333,7 +331,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
 {
     LibOpenJPEGContext *ctx = avctx->priv_data;
     opj_cinfo_t *compress = ctx->compress;
-    opj_image_t *image = ctx->image;
+    opj_image_t *image    = ctx->image;
     opj_cio_t *stream;
     int cpyresult = 0;
     int ret, len;
@@ -342,7 +340,7 @@ static int libopenjpeg_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     // x1, y1 is the width, height of the reference grid
     image->x0 = 0;
     image->y0 = 0;
-    image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1;
+    image->x1 = (avctx->width  - 1) * ctx->enc_params.subsampling_dx + 1;
     image->y1 = (avctx->height - 1) * ctx->enc_params.subsampling_dy + 1;
 
     switch (avctx->pix_fmt) {
@@ -432,7 +430,7 @@ static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx)
     opj_destroy_compress(ctx->compress);
     opj_image_destroy(ctx->image);
     av_freep(&avctx->coded_frame);
-    return 0 ;
+    return 0;
 }
 
 #define OFFSET(x) offsetof(LibOpenJPEGContext, x)
@@ -456,11 +454,11 @@ static const AVOption options[] = {
     { "rpcl",          NULL,                0,                     AV_OPT_TYPE_CONST, { RPCL        }, 0,         0,           VE, "prog_order"  },
     { "pcrl",          NULL,                0,                     AV_OPT_TYPE_CONST, { PCRL        }, 0,         0,           VE, "prog_order"  },
     { "cprl",          NULL,                0,                     AV_OPT_TYPE_CONST, { CPRL        }, 0,         0,           VE, "prog_order"  },
-    { "numresolution", NULL,                OFFSET(numresolution), AV_OPT_TYPE_INT,   { 6           }, 1,         10,          VE                },
-    { "numlayers",     NULL,                OFFSET(numlayers),     AV_OPT_TYPE_INT,   { 1           }, 1,         10,          VE                },
-    { "disto_alloc",   NULL,                OFFSET(disto_alloc),   AV_OPT_TYPE_INT,   { 1           }, 0,         1,           VE                },
-    { "fixed_alloc",   NULL,                OFFSET(fixed_alloc),   AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE                },
-    { "fixed_quality", NULL,                OFFSET(fixed_quality), AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE                },
+    { "numresolution", NULL,                OFFSET(numresolution), AV_OPT_TYPE_INT,   { 6           }, 1,         10,          VE },
+    { "numlayers",     NULL,                OFFSET(numlayers),     AV_OPT_TYPE_INT,   { 1           }, 1,         10,          VE },
+    { "disto_alloc",   NULL,                OFFSET(disto_alloc),   AV_OPT_TYPE_INT,   { 1           }, 0,         1,           VE },
+    { "fixed_alloc",   NULL,                OFFSET(fixed_alloc),   AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE },
+    { "fixed_quality", NULL,                OFFSET(fixed_quality), AV_OPT_TYPE_INT,   { 0           }, 0,         1,           VE },
     { NULL },
 };
 
@@ -480,7 +478,7 @@ AVCodec ff_libopenjpeg_encoder = {
     .encode2        = libopenjpeg_encode_frame,
     .close          = libopenjpeg_encode_close,
     .capabilities   = 0,
-    .pix_fmts       = (const enum PixelFormat[]){
+    .pix_fmts       = (const enum PixelFormat[]) {
         PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_RGB48, PIX_FMT_RGBA64,
         PIX_FMT_GRAY8, PIX_FMT_GRAY8A, PIX_FMT_GRAY16,
         PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUVA420P,
index 47e6ff9..2e2d697 100644 (file)
@@ -27,7 +27,7 @@
  */
 
 #define LIBAVCODEC_VERSION_MAJOR 54
-#define LIBAVCODEC_VERSION_MINOR  43
+#define LIBAVCODEC_VERSION_MINOR  44
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
index 59e41c0..4e97942 100644 (file)
@@ -133,10 +133,10 @@ AVFilter avfilter_af_aformat = {
     .query_formats = query_formats,
     .priv_size     = sizeof(AFormatContext),
 
-    .inputs        = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO, },
-                                      { .name = NULL}},
-    .outputs       = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO},
-                                      { .name = NULL}},
+    .inputs        = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO, },
+                                            { .name = NULL}},
+    .outputs       = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO},
+                                            { .name = NULL}},
 };
index f52db1e..0bf846d 100644 (file)
@@ -32,12 +32,12 @@ AVFilter avfilter_af_anull = {
 
     .priv_size = 0,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO,
-                                    .get_audio_buffer = ff_null_get_audio_buffer, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO,
+                                          .get_audio_buffer = ff_null_get_audio_buffer, },
+                                        { .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO, },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO, },
+                                        { .name = NULL}},
 };
index 1c1837c..9e2509c 100644 (file)
@@ -392,12 +392,12 @@ AVFilter avfilter_af_channelmap = {
     .query_formats = channelmap_query_formats,
     .priv_size     = sizeof(ChannelMapContext),
 
-    .inputs        = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO,
-                                        .filter_samples  = channelmap_filter_samples,
-                                        .config_props    = channelmap_config_input },
-                                      { .name = NULL }},
-    .outputs       = (AVFilterPad[]) {{ .name            = "default",
-                                        .type            = AVMEDIA_TYPE_AUDIO },
-                                      { .name = NULL }},
+    .inputs        = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO,
+                                              .filter_samples  = channelmap_filter_samples,
+                                              .config_props    = channelmap_config_input },
+                                            { .name = NULL }},
+    .outputs       = (const AVFilterPad[]) {{ .name            = "default",
+                                              .type            = AVMEDIA_TYPE_AUDIO },
+                                            { .name = NULL }},
 };
index 9ed11a9..f25ec92 100644 (file)
@@ -248,7 +248,7 @@ static void join_uninit(AVFilterContext *ctx)
 
     for (i = 0; i < ctx->nb_inputs; i++) {
         av_freep(&ctx->input_pads[i].name);
-        avfilter_unref_buffer(s->input_frames[i]);
+        avfilter_unref_bufferp(&s->input_frames[i]);
     }
 
     av_freep(&s->channels);
@@ -402,7 +402,7 @@ static void join_free_buffer(AVFilterBuffer *buf)
         int i;
 
         for (i = 0; i < priv->nb_in_buffers; i++)
-            avfilter_unref_buffer(priv->in_buffers[i]);
+            avfilter_unref_bufferp(&priv->in_buffers[i]);
 
         av_freep(&priv->in_buffers);
         av_freep(&buf->priv);
index 6541a39..3df5429 100644 (file)
@@ -127,8 +127,8 @@ AVFilter avfilter_asrc_anullsrc = {
     .inputs      = (const AVFilterPad[]) {{ .name = NULL}},
 
     .outputs     = (const AVFilterPad[]) {{ .name = "default",
-                                      .type = AVMEDIA_TYPE_AUDIO,
-                                      .config_props = config_props,
-                                      .request_frame = request_frame, },
-                                    { .name = NULL}},
+                                            .type = AVMEDIA_TYPE_AUDIO,
+                                            .config_props = config_props,
+                                            .request_frame = request_frame, },
+                                          { .name = NULL}},
 };
index 4d3a7a8..229f78d 100644 (file)
@@ -261,8 +261,11 @@ struct AVFilterPad {
      * picture inside the link structure.
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error. picref will be
+     * unreferenced by the caller in case of error.
      */
-    void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
+    int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
 
     /**
      * Callback function to get a video buffer. If NULL, the filter system will
@@ -287,16 +290,20 @@ struct AVFilterPad {
      * in the link structure during start_frame().
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error.
      */
-    void (*end_frame)(AVFilterLink *link);
+    int (*end_frame)(AVFilterLink *link);
 
     /**
      * Slice drawing callback. This is where a filter receives video data
      * and should do its processing.
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error.
      */
-    void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
+    int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
 
     /**
      * Samples filtering callback. This is where a filter receives audio data
@@ -385,7 +392,7 @@ enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx);
 
 /** default handler for end_frame() for video inputs */
 attribute_deprecated
-void avfilter_default_end_frame(AVFilterLink *link);
+int  avfilter_default_end_frame(AVFilterLink *link);
 
 /**
  * Filter definition. This defines the pads a filter contains, and all the
index 9e908ad..e00af7c 100644 (file)
@@ -47,20 +47,16 @@ static av_cold void uninit(AVFilterContext *ctx)
         av_audio_fifo_free(sink->audio_fifo);
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
 {
     BufferSinkContext *s = link->dst->priv;
 
 //     av_assert0(!s->cur_buf);
     s->cur_buf    = buf;
     link->cur_buf = NULL;
-};
 
-static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
-{
-    start_frame(link, buf);
     return 0;
-}
+};
 
 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
 {
@@ -149,13 +145,13 @@ AVFilter avfilter_vsink_buffer = {
     .priv_size = sizeof(BufferSinkContext),
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name          = "default",
-                                    .type          = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame   = start_frame,
-                                    .min_perms     = AV_PERM_READ,
-                                    .needs_fifo    = 1 },
-                                  { .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
+    .inputs    = (const AVFilterPad[]) {{ .name          = "default",
+                                          .type          = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame   = start_frame,
+                                          .min_perms     = AV_PERM_READ,
+                                          .needs_fifo    = 1 },
+                                        { .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name = NULL }},
 };
 
 AVFilter avfilter_asink_abuffer = {
@@ -164,11 +160,11 @@ AVFilter avfilter_asink_abuffer = {
     .priv_size = sizeof(BufferSinkContext),
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name           = "default",
-                                    .type           = AVMEDIA_TYPE_AUDIO,
-                                    .filter_samples = filter_samples,
-                                    .min_perms      = AV_PERM_READ,
-                                    .needs_fifo     = 1 },
-                                  { .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name = NULL }},
+    .inputs    = (const AVFilterPad[]) {{ .name           = "default",
+                                          .type           = AVMEDIA_TYPE_AUDIO,
+                                          .filter_samples = start_frame,
+                                          .min_perms      = AV_PERM_READ,
+                                          .needs_fifo     = 1 },
+                                        { .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name = NULL }},
 };
index befefb8..5186b09 100644 (file)
@@ -382,19 +382,19 @@ static int request_frame(AVFilterLink *link)
 
     switch (link->type) {
     case AVMEDIA_TYPE_VIDEO:
-        ff_start_frame(link, avfilter_ref_buffer(buf, ~0));
-        ff_draw_slice(link, 0, link->h, 1);
-        ff_end_frame(link);
+        if ((ret = ff_start_frame(link, buf)) < 0 ||
+            (ret = ff_draw_slice(link, 0, link->h, 1)) < 0 ||
+            (ret = ff_end_frame(link)) < 0)
+            return ret;
         break;
     case AVMEDIA_TYPE_AUDIO:
-        ret = ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
+        ret = ff_filter_samples(link, buf);
         break;
     default:
+        avfilter_unref_bufferp(&buf);
         return AVERROR(EINVAL);
     }
 
-    avfilter_unref_buffer(buf);
-
     return ret;
 }
 
@@ -416,13 +416,13 @@ AVFilter avfilter_vsrc_buffer = {
     .init      = init_video,
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = request_frame,
-                                    .poll_frame      = poll_frame,
-                                    .config_props    = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = request_frame,
+                                          .poll_frame      = poll_frame,
+                                          .config_props    = config_props, },
+                                        { .name = NULL}},
 };
 
 AVFilter avfilter_asrc_abuffer = {
@@ -434,11 +434,11 @@ AVFilter avfilter_asrc_abuffer = {
     .init      = init_audio,
     .uninit    = uninit,
 
-    .inputs    = (AVFilterPad[]) {{ .name = NULL }},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_AUDIO,
-                                    .request_frame   = request_frame,
-                                    .poll_frame      = poll_frame,
-                                    .config_props    = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_AUDIO,
+                                          .request_frame   = request_frame,
+                                          .poll_frame      = poll_frame,
+                                          .config_props    = config_props, },
+                                        { .name = NULL}},
 };
index 9aed964..033e1f7 100644 (file)
@@ -99,7 +99,7 @@ static int config_output_props(AVFilterLink *outlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
@@ -113,7 +113,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
     }
     inlink->cur_buf = NULL;
 
-    ff_start_frame(outlink, picref);
+    return ff_start_frame(outlink, picref);
 }
 
 static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
index bb7f0fa..4e0e87f 100644 (file)
@@ -65,17 +65,18 @@ static av_cold void uninit(AVFilterContext *ctx)
 
     for (buf = fifo->root.next; buf; buf = tmp) {
         tmp = buf->next;
-        avfilter_unref_buffer(buf->buf);
+        avfilter_unref_bufferp(&buf->buf);
         av_free(buf);
     }
 
-    avfilter_unref_buffer(fifo->buf_out);
+    avfilter_unref_bufferp(&fifo->buf_out);
 }
 
 static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
 {
     FifoContext *fifo = inlink->dst->priv;
 
+    inlink->cur_buf = NULL;
     fifo->last->next = av_mallocz(sizeof(Buf));
     if (!fifo->last->next) {
         avfilter_unref_buffer(buf);
@@ -88,12 +89,6 @@ static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
-{
-    add_to_queue(inlink, buf);
-    inlink->cur_buf = NULL;
-}
-
 static void queue_pop(FifoContext *s)
 {
     Buf *tmp = s->root.next->next;
@@ -103,9 +98,15 @@ static void queue_pop(FifoContext *s)
     s->root.next = tmp;
 }
 
-static void end_frame(AVFilterLink *inlink) { }
+static int end_frame(AVFilterLink *inlink)
+{
+    return 0;
+}
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
 /**
  * Move data pointers and pts offset samples forward.
@@ -168,6 +169,9 @@ static int return_audio_frame(AVFilterContext *ctx)
             queue_pop(s);
         } else {
             buf_out = avfilter_ref_buffer(head, AV_PERM_READ);
+            if (!buf_out)
+                return AVERROR(ENOMEM);
+
             buf_out->audio->nb_samples = link->request_samples;
             buffer_offset(link, head, link->request_samples);
         }
@@ -240,9 +244,11 @@ static int request_frame(AVFilterLink *outlink)
      * so we don't have to worry about dereferencing it ourselves. */
     switch (outlink->type) {
     case AVMEDIA_TYPE_VIDEO:
-        ff_start_frame(outlink, fifo->root.next->buf);
-        ff_draw_slice (outlink, 0, outlink->h, 1);
-        ff_end_frame  (outlink);
+        if ((ret = ff_start_frame(outlink, fifo->root.next->buf)) < 0 ||
+            (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+            (ret = ff_end_frame(outlink)) < 0)
+            return ret;
+
         queue_pop(fifo);
         break;
     case AVMEDIA_TYPE_AUDIO:
@@ -269,18 +275,18 @@ AVFilter avfilter_vf_fifo = {
 
     .priv_size = sizeof(FifoContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= ff_null_get_video_buffer,
-                                    .start_frame     = start_frame,
-                                    .draw_slice      = draw_slice,
-                                    .end_frame       = end_frame,
-                                    .rej_perms       = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= ff_null_get_video_buffer,
+                                          .start_frame     = add_to_queue,
+                                          .draw_slice      = draw_slice,
+                                          .end_frame       = end_frame,
+                                          .rej_perms       = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = request_frame, },
+                                        { .name = NULL}},
 };
 
 AVFilter avfilter_af_afifo = {
@@ -292,14 +298,14 @@ AVFilter avfilter_af_afifo = {
 
     .priv_size = sizeof(FifoContext),
 
-    .inputs    = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO,
-                                    .get_audio_buffer = ff_null_get_audio_buffer,
-                                    .filter_samples   = add_to_queue,
-                                    .rej_perms        = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name             = "default",
-                                    .type             = AVMEDIA_TYPE_AUDIO,
-                                    .request_frame    = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO,
+                                          .get_audio_buffer = ff_null_get_audio_buffer,
+                                          .filter_samples   = add_to_queue,
+                                          .rej_perms        = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_AUDIO,
+                                          .request_frame    = request_frame, },
+                                        { .name = NULL}},
 };
index 5f0299c..c217883 100644 (file)
@@ -93,6 +93,9 @@ struct AVFilterPad {
      * picture inside the link structure.
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error. picref will be
+     * unreferenced by the caller in case of error.
      */
     void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
 
@@ -119,16 +122,20 @@ struct AVFilterPad {
      * in the link structure during start_frame().
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error.
      */
-    void (*end_frame)(AVFilterLink *link);
+    int (*end_frame)(AVFilterLink *link);
 
     /**
      * Slice drawing callback. This is where a filter receives video data
      * and should do its processing.
      *
      * Input video pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error.
      */
-    void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
+    int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
 
     /**
      * Samples filtering callback. This is where a filter receives audio data
index 31e0a98..f7b16db 100644 (file)
@@ -96,7 +96,7 @@ static av_cold void common_uninit(AVFilterContext *ctx)
     }
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     BufferSinkContext *buf = inlink->dst->priv;
@@ -108,7 +108,7 @@ static void end_frame(AVFilterLink *inlink)
             av_log(ctx, AV_LOG_ERROR,
                    "Cannot buffer more frames. Consume some available frames "
                    "before adding new ones.\n");
-            return;
+            return AVERROR(ENOMEM);
         }
     }
 
@@ -124,6 +124,7 @@ static void end_frame(AVFilterLink *inlink)
                (char *)av_x_if_null(ctx->name, ctx->filter->name));
         buf->warning_limit *= 10;
     }
+    return 0;
 }
 
 void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
index c42a8ab..85377c1 100644 (file)
@@ -63,32 +63,47 @@ static void split_uninit(AVFilterContext *ctx)
         av_freep(&ctx->output_pads[i].name);
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = inlink->dst;
-    int i;
+    int i, ret = 0;
 
-    for (i = 0; i < ctx->nb_outputs; i++)
-        ff_start_frame(ctx->outputs[i],
-                       avfilter_ref_buffer(picref, ~AV_PERM_WRITE));
+    for (i = 0; i < ctx->nb_outputs; i++) {
+        AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~AV_PERM_WRITE);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+
+        ret = ff_start_frame(ctx->outputs[i], buf_out);
+        if (ret < 0)
+            break;
+    }
+    return ret;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = inlink->dst;
-    int i;
+    int i, ret = 0;
 
-    for (i = 0; i < ctx->nb_outputs; i++)
-        ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
+    for (i = 0; i < ctx->nb_outputs; i++) {
+        ret = ff_draw_slice(ctx->outputs[i], y, h, slice_dir);
+        if (ret < 0)
+            break;
+    }
+    return ret;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
-    int i;
+    int i, ret = 0;
 
-    for (i = 0; i < ctx->nb_outputs; i++)
-        ff_end_frame(ctx->outputs[i]);
+    for (i = 0; i < ctx->nb_outputs; i++) {
+        ret = ff_end_frame(ctx->outputs[i]);
+        if (ret < 0)
+            break;
+    }
+    return ret;
 }
 
 AVFilter avfilter_vf_split = {
@@ -98,14 +113,14 @@ AVFilter avfilter_vf_split = {
     .init   = split_init,
     .uninit = split_uninit,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= ff_null_get_video_buffer,
-                                    .start_frame     = start_frame,
-                                    .draw_slice      = draw_slice,
-                                    .end_frame       = end_frame, },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= ff_null_get_video_buffer,
+                                          .start_frame     = start_frame,
+                                          .draw_slice      = draw_slice,
+                                          .end_frame       = end_frame, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name = NULL}},
 };
 
 static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
@@ -114,8 +129,14 @@ static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
     int i, ret = 0;
 
     for (i = 0; i < ctx->nb_outputs; i++) {
-        ret = ff_filter_samples(inlink->dst->outputs[i],
-                                avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
+        AVFilterBufferRef *buf_out = avfilter_ref_buffer(samplesref,
+                                                         ~AV_PERM_WRITE);
+        if (!buf_out) {
+            ret = AVERROR(ENOMEM);
+            break;
+        }
+
+        ret = ff_filter_samples(inlink->dst->outputs[i], buf_out);
         if (ret < 0)
             break;
     }
index b1d8fd3..cb65dd6 100644 (file)
@@ -326,13 +326,24 @@ static int movie_request_frame(AVFilterLink *outlink)
         return ret;
 
     outpicref = avfilter_ref_buffer(movie->picref, ~0);
-    ff_start_frame(outlink, outpicref);
-    ff_draw_slice(outlink, 0, outlink->h, 1);
-    ff_end_frame(outlink);
-    avfilter_unref_buffer(movie->picref);
-    movie->picref = NULL;
+    if (!outpicref) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
 
-    return 0;
+    ret = ff_start_frame(outlink, outpicref);
+    if (ret < 0)
+        goto fail;
+
+    ret = ff_draw_slice(outlink, 0, outlink->h, 1);
+    if (ret < 0)
+        goto fail;
+
+    ret = ff_end_frame(outlink);
+fail:
+    avfilter_unref_bufferp(&movie->picref);
+
+    return ret;
 }
 
 AVFilter avfilter_vsrc_movie = {
@@ -344,11 +355,11 @@ AVFilter avfilter_vsrc_movie = {
     .query_formats = movie_query_formats,
 
     .inputs    = (const AVFilterPad[]) {{ .name = NULL }},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = movie_request_frame,
-                                    .config_props    = movie_config_output_props, },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = movie_request_frame,
+                                          .config_props    = movie_config_output_props, },
+                                        { .name = NULL}},
 };
 
 #endif  /* CONFIG_MOVIE_FILTER */
index 06cbb71..f6ce1b3 100644 (file)
@@ -59,7 +59,7 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
 {
     AlphaExtractContext *extract = inlink->dst->priv;
     AVFilterBufferRef *cur_buf = inlink->cur_buf;
@@ -91,7 +91,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
                    linesize);
         }
     }
-    ff_draw_slice(inlink->dst->outputs[0], y0, h, slice_dir);
+    return ff_draw_slice(inlink->dst->outputs[0], y0, h, slice_dir);
 }
 
 AVFilter avfilter_vf_alphaextract = {
index 67422a1..278f9a3 100644 (file)
@@ -95,8 +95,8 @@ static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) {}
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) {}
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) {return 0;}
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) {return 0;}
 
 static void draw_frame(AVFilterContext *ctx,
                        AVFilterBufferRef *main_buf,
@@ -130,7 +130,7 @@ static void draw_frame(AVFilterContext *ctx,
     ff_draw_slice(ctx->outputs[0], 0, h, 1);
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     AlphaMergeContext *merge = ctx->priv;
@@ -157,6 +157,7 @@ static void end_frame(AVFilterLink *inlink)
         ff_end_frame(ctx->outputs[0]);
         avfilter_unref_buffer(alpha_buf);
     }
+    return 0;
 }
 
 static int request_frame(AVFilterLink *outlink)
index 6e639c1..e4ca5d5 100644 (file)
@@ -51,13 +51,13 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AspectContext *aspect = link->dst->priv;
 
     picref->video->sample_aspect_ratio = aspect->ratio;
     link->cur_buf = NULL;
-    ff_start_frame(link->dst->outputs[0], picref);
+    return ff_start_frame(link->dst->outputs[0], picref);
 }
 
 #if CONFIG_SETDAR_FILTER
@@ -86,17 +86,17 @@ AVFilter avfilter_vf_setdar = {
 
     .priv_size = sizeof(AspectContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = setdar_config_props,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .end_frame        = ff_null_end_frame },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = setdar_config_props,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .end_frame        = ff_null_end_frame },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
 #endif /* CONFIG_SETDAR_FILTER */
 
@@ -118,16 +118,16 @@ AVFilter avfilter_vf_setsar = {
 
     .priv_size = sizeof(AspectContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = setsar_config_props,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .end_frame        = ff_null_end_frame },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = setsar_config_props,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .end_frame        = ff_null_end_frame },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
 #endif /* CONFIG_SETSAR_FILTER */
index e7f2fe1..a40f93c 100644 (file)
@@ -157,7 +157,7 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 /* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */
 #define AR(c)  ( (c)>>24)
@@ -180,7 +180,7 @@ static void overlay_ass_image(AssContext *ass, AVFilterBufferRef *picref,
     }
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
@@ -197,7 +197,7 @@ static void end_frame(AVFilterLink *inlink)
     overlay_ass_image(ass, picref, image);
 
     ff_draw_slice(outlink, 0, picref->video->h, 1);
-    ff_end_frame(outlink);
+    return ff_end_frame(outlink);
 }
 
 AVFilter avfilter_vf_ass = {
index 47d4709..b59d1bc 100644 (file)
@@ -56,7 +56,7 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     BBoxContext *bbox = ctx->priv;
@@ -86,7 +86,7 @@ static void end_frame(AVFilterLink *inlink)
     av_log(ctx, AV_LOG_INFO, "\n");
 
     bbox->frame++;
-    ff_end_frame(inlink->dst->outputs[0]);
+    return ff_end_frame(inlink->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_bbox = {
index cd35297..dfd94ef 100644 (file)
@@ -146,7 +146,7 @@ static int request_frame(AVFilterLink *outlink)
     return ret;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = inlink->dst;
     BlackDetectContext *blackdetect = ctx->priv;
@@ -160,10 +160,10 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         p += picref->linesize[0];
     }
 
-    ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     BlackDetectContext *blackdetect = ctx->priv;
@@ -194,7 +194,7 @@ static void end_frame(AVFilterLink *inlink)
     blackdetect->last_picref_pts = picref->pts;
     blackdetect->frame_count++;
     blackdetect->nb_black_pixels = 0;
-    ff_end_frame(inlink->dst->outputs[0]);
+    return ff_end_frame(inlink->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_blackdetect = {
index 2c842de..dc33444 100644 (file)
@@ -77,7 +77,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = inlink->dst;
     BlackFrameContext *blackframe = ctx->priv;
@@ -91,10 +91,10 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         p += picref->linesize[0];
     }
 
-    ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(ctx->outputs[0], y, h, slice_dir);
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     BlackFrameContext *blackframe = ctx->priv;
@@ -114,7 +114,7 @@ static void end_frame(AVFilterLink *inlink)
 
     blackframe->frame++;
     blackframe->nblack = 0;
-    ff_end_frame(inlink->dst->outputs[0]);
+    return ff_end_frame(inlink->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_blackframe = {
@@ -126,13 +126,13 @@ AVFilter avfilter_vf_blackframe = {
 
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = draw_slice,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame_keep_ref,
-                                    .end_frame        = end_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = draw_slice,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame_keep_ref,
+                                          .end_frame        = end_frame, },
+                                        { .name = NULL}},
 
     .outputs   = (const AVFilterPad[]) {{ .name       = "default",
                                     .type             = AVMEDIA_TYPE_VIDEO },
index 6e6949e..e98e90a 100644 (file)
@@ -301,9 +301,9 @@ static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_li
                    h, radius, power, temp);
 }
 
-static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { return 0; }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     BoxBlurContext *boxblur = ctx->priv;
@@ -328,7 +328,7 @@ static void end_frame(AVFilterLink *inlink)
               boxblur->temp);
 
     ff_draw_slice(outlink, 0, inlink->h, 1);
-    avfilter_default_end_frame(inlink);
+    return avfilter_default_end_frame(inlink);
 }
 
 AVFilter avfilter_vf_boxblur = {
@@ -339,14 +339,14 @@ AVFilter avfilter_vf_boxblur = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_input,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_READ },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_input,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_READ },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index d6f6dbd..bb66bd3 100644 (file)
@@ -340,7 +340,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
     return picref;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = link->dst;
     ColorMatrixContext *color = ctx->priv;
@@ -348,10 +348,10 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 
     color->outpicref = outpicref;
 
-    ff_start_frame(link->dst->outputs[0], outpicref);
+    return ff_start_frame(link->dst->outputs[0], outpicref);
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     AVFilterContext *ctx = link->dst;
     ColorMatrixContext *color = ctx->priv;
@@ -365,10 +365,10 @@ static void end_frame(AVFilterLink *link)
         process_frame_uyvy422(color, out, link->cur_buf);
 
     ff_draw_slice(ctx->outputs[0], 0, link->dst->outputs[0]->h, 1);
-    ff_end_frame(ctx->outputs[0]);
+    return ff_end_frame(ctx->outputs[0]);
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 AVFilter avfilter_vf_colormatrix = {
     .name          = "colormatrix",
index 111d315..3992492 100644 (file)
@@ -29,14 +29,14 @@ AVFilter avfilter_vf_copy = {
     .name      = "copy",
     .description = NULL_IF_CONFIG_SMALL("Copy the input video unchanged to the output."),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .end_frame        = ff_null_end_frame,
-                                    .rej_perms        = ~0 },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .end_frame        = ff_null_end_frame,
+                                          .rej_perms        = ~0 },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 18ad88f..4d3a7f3 100644 (file)
@@ -259,7 +259,7 @@ static int config_output(AVFilterLink *link)
     return 0;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = link->dst;
     CropContext *crop = ctx->priv;
@@ -267,6 +267,9 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     int i;
 
     ref2 = avfilter_ref_buffer(picref, ~0);
+    if (!ref2)
+        return AVERROR(ENOMEM);
+
     ref2->video->w = crop->w;
     ref2->video->h = crop->h;
 
@@ -310,16 +313,16 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
         ref2->data[3] += crop->x * crop->max_step[3];
     }
 
-    ff_start_frame(link->dst->outputs[0], ref2);
+    return ff_start_frame(link->dst->outputs[0], ref2);
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = link->dst;
     CropContext *crop = ctx->priv;
 
     if (y >= crop->y + crop->h || y + h <= crop->y)
-        return;
+        return 0;
 
     if (y < crop->y) {
         h -= crop->y - y;
@@ -328,15 +331,15 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
     if (y + h > crop->y + crop->h)
         h = crop->y + crop->h - y;
 
-    ff_draw_slice(ctx->outputs[0], y - crop->y, h, slice_dir);
+    return ff_draw_slice(ctx->outputs[0], y - crop->y, h, slice_dir);
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     CropContext *crop = link->dst->priv;
 
     crop->var_values[VAR_N] += 1.0;
-    ff_end_frame(link->dst->outputs[0]);
+    return ff_end_frame(link->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_crop = {
@@ -349,16 +352,16 @@ AVFilter avfilter_vf_crop = {
     .init          = init,
     .uninit        = uninit,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .end_frame        = end_frame,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .config_props     = config_input, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_output, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .end_frame        = end_frame,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .config_props     = config_input, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_output, },
+                                        { .name = NULL}},
 };
index 8ffbe70..b245d6e 100644 (file)
@@ -114,7 +114,7 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     CropDetectContext *cd = ctx->priv;
@@ -191,7 +191,7 @@ static void end_frame(AVFilterLink *inlink)
                w, h, x, y);
     }
 
-    ff_end_frame(inlink->dst->outputs[0]);
+    return ff_end_frame(inlink->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_cropdetect = {
@@ -203,15 +203,15 @@ AVFilter avfilter_vf_cropdetect = {
 
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_input,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .end_frame        = end_frame, },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_input,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .end_frame        = end_frame, },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };
index 35ceb35..8b9f29d 100644 (file)
@@ -209,27 +209,48 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
+    AVFilterBufferRef *outpicref = NULL, *for_next_filter;
+    int ret = 0;
 
     if (inpicref->perms & AV_PERM_PRESERVE) {
         outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
                                         outlink->w, outlink->h);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
         outpicref->video->w = outlink->w;
         outpicref->video->h = outlink->h;
-    } else
+    } else {
         outpicref = avfilter_ref_buffer(inpicref, ~0);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+    }
+
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
+    if (ret < 0) {
+        avfilter_unref_bufferp(&outpicref);
+        return ret;
+    }
 
     outlink->out_buf = outpicref;
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     DelogoContext *delogo = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -239,6 +260,7 @@ static void end_frame(AVFilterLink *inlink)
     int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w;
     int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h;
     int plane;
+    int ret;
 
     for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) {
         int hsub = plane == 1 || plane == 2 ? hsub0 : 0;
@@ -253,8 +275,10 @@ static void end_frame(AVFilterLink *inlink)
                      delogo->show, direct);
     }
 
-    ff_draw_slice(outlink, 0, inlink->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_delogo = {
@@ -264,16 +288,16 @@ AVFilter avfilter_vf_delogo = {
     .init          = init,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
-                                    .rej_perms        = AV_PERM_PRESERVE },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
+                                          .rej_perms        = AV_PERM_PRESERVE },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 70d7fe9..0a1d865 100644 (file)
@@ -425,7 +425,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&deshake->avctx);
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     DeshakeContext *deshake = link->dst->priv;
     AVFilterBufferRef *in  = link->cur_buf;
@@ -529,11 +529,12 @@ static void end_frame(AVFilterLink *link)
 
     // Draw the transformed frame information
     ff_draw_slice(link->dst->outputs[0], 0, link->h, 1);
-    ff_end_frame(link->dst->outputs[0]);
+    return ff_end_frame(link->dst->outputs[0]);
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
+    return 0;
 }
 
 AVFilter avfilter_vf_deshake = {
index c823b14..8be8b14 100644 (file)
@@ -94,7 +94,7 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
 {
     DrawBoxContext *drawbox = inlink->dst->priv;
     int plane, x, y, xb = drawbox->x, yb = drawbox->y;
@@ -120,7 +120,7 @@ static void draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
         }
     }
 
-    ff_draw_slice(inlink->dst->outputs[0], y0, h, 1);
+    return ff_draw_slice(inlink->dst->outputs[0], y0, h, 1);
 }
 
 AVFilter avfilter_vf_drawbox = {
@@ -130,17 +130,17 @@ AVFilter avfilter_vf_drawbox = {
     .init      = init,
 
     .query_formats   = query_formats,
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_input,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .end_frame        = ff_null_end_frame,
-                                    .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
-                                    .rej_perms        = AV_PERM_PRESERVE },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_input,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .end_frame        = ff_null_end_frame,
+                                          .min_perms        = AV_PERM_WRITE | AV_PERM_READ,
+                                          .rej_perms        = AV_PERM_PRESERVE },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index dbdcd39..ac61942 100644 (file)
@@ -780,14 +780,18 @@ static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref,
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
     DrawTextContext *dtext = ctx->priv;
     AVFilterBufferRef *picref = inlink->cur_buf;
+    int ret;
 
     dtext->var_values[VAR_T] = picref->pts == AV_NOPTS_VALUE ?
         NAN : picref->pts * av_q2d(inlink->time_base);
@@ -801,8 +805,10 @@ static void end_frame(AVFilterLink *inlink)
 
     dtext->var_values[VAR_N] += 1.0;
 
-    ff_draw_slice(outlink, 0, picref->video->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, picref->video->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_drawtext = {
@@ -813,19 +819,19 @@ AVFilter avfilter_vf_drawtext = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .config_props     = config_input,
-                                    .min_perms        = AV_PERM_WRITE |
-                                                        AV_PERM_READ,
-                                    .rej_perms        = AV_PERM_PRESERVE },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .config_props     = config_input,
+                                          .min_perms        = AV_PERM_WRITE |
+                                                              AV_PERM_READ,
+                                          .rej_perms        = AV_PERM_PRESERVE },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
     .process_command = command,
 };
index 0103ca2..6d68357 100644 (file)
@@ -214,7 +214,7 @@ static void fade_plane(int y, int h, int w,
     }
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     FadeContext *fade = inlink->dst->priv;
     AVFilterBufferRef *outpic = inlink->cur_buf;
@@ -255,20 +255,23 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         }
     }
 
-    ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     FadeContext *fade = inlink->dst->priv;
+    int ret;
 
-    ff_end_frame(inlink->dst->outputs[0]);
+    ret = ff_end_frame(inlink->dst->outputs[0]);
 
     if (fade->frame_index >= fade->start_frame &&
         fade->frame_index <= fade->stop_frame)
         fade->factor += fade->fade_per_frame;
     fade->factor = av_clip_uint16(fade->factor);
     fade->frame_index++;
+
+    return ret;
 }
 
 AVFilter avfilter_vf_fade = {
@@ -279,17 +282,17 @@ AVFilter avfilter_vf_fade = {
     .priv_size     = sizeof(FadeContext),
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .config_props    = config_props,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .draw_slice      = draw_slice,
-                                    .end_frame       = end_frame,
-                                    .min_perms       = AV_PERM_READ | AV_PERM_WRITE,
-                                    .rej_perms       = AV_PERM_PRESERVE, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .config_props    = config_props,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .draw_slice      = draw_slice,
+                                          .end_frame       = end_frame,
+                                          .min_perms       = AV_PERM_READ | AV_PERM_WRITE,
+                                          .rej_perms       = AV_PERM_PRESERVE, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index be753be..6573ac8 100644 (file)
@@ -116,21 +116,35 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
     return ff_get_video_buffer(outlink, perms, w, h);
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterContext   *ctx        = inlink->dst;
     AVFilterLink      *outlink    = ctx->outputs[0];
 
     AVFilterBufferRef *outpicref, *for_next_filter;
+    int ret = 0;
 
     outpicref = avfilter_ref_buffer(inpicref, ~0);
-    outlink->out_buf = outpicref;
+    if (!outpicref)
+        return AVERROR(ENOMEM);
 
     for_next_filter = avfilter_ref_buffer(outpicref, ~0);
-    ff_start_frame(outlink, for_next_filter);
+    if (!for_next_filter) {
+        avfilter_unref_bufferp(&outpicref);
+        return AVERROR(ENOMEM);
+    }
+
+    ret = ff_start_frame(outlink, for_next_filter);
+    if (ret < 0) {
+        avfilter_unref_bufferp(&outpicref);
+        return ret;
+    }
+
+    outlink->out_buf = outpicref;
+    return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext   *ctx        = inlink->dst;
     FieldOrderContext *fieldorder = ctx->priv;
@@ -144,11 +158,12 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
      *  and that complexity will be added later */
     if (  !inpicref->video->interlaced
         || inpicref->video->top_field_first == fieldorder->dst_tff) {
-        ff_draw_slice(outlink, y, h, slice_dir);
+        return ff_draw_slice(outlink, y, h, slice_dir);
     }
+    return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext   *ctx        = inlink->dst;
     FieldOrderContext *fieldorder = ctx->priv;
@@ -212,7 +227,7 @@ static void end_frame(AVFilterLink *inlink)
                 "not interlaced or field order already correct\n");
     }
 
-    ff_end_frame(outlink);
+    return ff_end_frame(outlink);
 }
 
 AVFilter avfilter_vf_fieldorder = {
@@ -221,17 +236,17 @@ AVFilter avfilter_vf_fieldorder = {
     .init          = init,
     .priv_size     = sizeof(FieldOrderContext),
     .query_formats = query_formats,
-    .inputs        = (const AVFilterPad[]) {{ .name       = "default",
-                                        .type             = AVMEDIA_TYPE_VIDEO,
-                                        .config_props     = config_input,
-                                        .start_frame      = start_frame,
-                                        .get_video_buffer = get_video_buffer,
-                                        .draw_slice       = draw_slice,
-                                        .end_frame        = end_frame,
-                                        .min_perms        = AV_PERM_READ,
-                                        .rej_perms        = AV_PERM_REUSE2|AV_PERM_PRESERVE,},
-                                      { .name = NULL}},
-    .outputs       = (const AVFilterPad[]) {{ .name       = "default",
-                                        .type             = AVMEDIA_TYPE_VIDEO, },
-                                      { .name = NULL}},
+    .inputs        = (const AVFilterPad[]) {{ .name             = "default",
+                                              .type             = AVMEDIA_TYPE_VIDEO,
+                                              .config_props     = config_input,
+                                              .start_frame      = start_frame,
+                                              .get_video_buffer = get_video_buffer,
+                                              .draw_slice       = draw_slice,
+                                              .end_frame        = end_frame,
+                                              .min_perms        = AV_PERM_READ,
+                                              .rej_perms        = AV_PERM_REUSE2|AV_PERM_PRESERVE,},
+                                            { .name = NULL}},
+    .outputs       = (const AVFilterPad[]) {{ .name             = "default",
+                                              .type             = AVMEDIA_TYPE_VIDEO, },
+                                            { .name = NULL}},
 };
index 9565daa..1a76183 100644 (file)
@@ -103,16 +103,16 @@ AVFilter avfilter_vf_format = {
 
     .priv_size = sizeof(FormatContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= ff_null_get_video_buffer,
-                                    .start_frame     = ff_null_start_frame,
-                                    .draw_slice      = ff_null_draw_slice,
-                                    .end_frame       = ff_null_end_frame, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= ff_null_get_video_buffer,
+                                          .start_frame     = ff_null_start_frame,
+                                          .draw_slice      = ff_null_draw_slice,
+                                          .end_frame       = ff_null_end_frame, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };
 #endif /* CONFIG_FORMAT_FILTER */
 
@@ -133,15 +133,15 @@ AVFilter avfilter_vf_noformat = {
 
     .priv_size = sizeof(FormatContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= ff_null_get_video_buffer,
-                                    .start_frame     = ff_null_start_frame,
-                                    .draw_slice      = ff_null_draw_slice,
-                                    .end_frame       = ff_null_end_frame, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= ff_null_get_video_buffer,
+                                          .start_frame     = ff_null_start_frame,
+                                          .draw_slice      = ff_null_draw_slice,
+                                          .end_frame       = ff_null_end_frame, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };
 #endif /* CONFIG_NOFORMAT_FILTER */
index 16122de..3fdac4f 100644 (file)
@@ -143,9 +143,11 @@ static int request_frame(AVFilterLink *outlink)
             buf->pts = av_rescale_q(s->first_pts, ctx->inputs[0]->time_base,
                                     outlink->time_base) + s->frames_out;
 
-            ff_start_frame(outlink, buf);
-            ff_draw_slice(outlink, 0, outlink->h, 1);
-            ff_end_frame(outlink);
+            if ((ret = ff_start_frame(outlink, buf)) < 0 ||
+                (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+                (ret = ff_end_frame(outlink)) < 0)
+                return ret;
+
             s->frames_out++;
         }
         return 0;
@@ -159,28 +161,33 @@ static int write_to_fifo(AVFifoBuffer *fifo, AVFilterBufferRef *buf)
     int ret;
 
     if (!av_fifo_space(fifo) &&
-        (ret = av_fifo_realloc2(fifo, 2*av_fifo_size(fifo))))
+        (ret = av_fifo_realloc2(fifo, 2*av_fifo_size(fifo)))) {
+        avfilter_unref_bufferp(&buf);
         return ret;
+    }
 
     av_fifo_generic_write(fifo, &buf, sizeof(buf), NULL);
     return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext    *ctx = inlink->dst;
     FPSContext           *s = ctx->priv;
     AVFilterLink   *outlink = ctx->outputs[0];
     AVFilterBufferRef  *buf = inlink->cur_buf;
     int64_t delta;
-    int i;
+    int i, ret;
 
     inlink->cur_buf = NULL;
     s->frames_in++;
     /* discard frames until we get the first timestamp */
     if (s->pts == AV_NOPTS_VALUE) {
         if (buf->pts != AV_NOPTS_VALUE) {
-            write_to_fifo(s->fifo, buf);
+            ret = write_to_fifo(s->fifo, buf);
+            if (ret < 0)
+                return ret;
+
             s->first_pts = s->pts = buf->pts;
         } else {
             av_log(ctx, AV_LOG_WARNING, "Discarding initial frame(s) with no "
@@ -188,13 +195,12 @@ static void end_frame(AVFilterLink *inlink)
             avfilter_unref_buffer(buf);
             s->drop++;
         }
-        return;
+        return 0;
     }
 
     /* now wait for the next timestamp */
     if (buf->pts == AV_NOPTS_VALUE) {
-        write_to_fifo(s->fifo, buf);
-        return;
+        return write_to_fifo(s->fifo, buf);
     }
 
     /* number of output frames */
@@ -211,10 +217,10 @@ static void end_frame(AVFilterLink *inlink)
 
         av_fifo_generic_read(s->fifo, &tmp, sizeof(tmp), NULL);
         flush_fifo(s->fifo);
-        write_to_fifo(s->fifo, tmp);
+        ret = write_to_fifo(s->fifo, tmp);
 
         avfilter_unref_buffer(buf);
-        return;
+        return ret;
     }
 
     /* can output >= 1 frames */
@@ -224,31 +230,51 @@ static void end_frame(AVFilterLink *inlink)
 
         /* duplicate the frame if needed */
         if (!av_fifo_size(s->fifo) && i < delta - 1) {
+            AVFilterBufferRef *dup = avfilter_ref_buffer(buf_out, AV_PERM_READ);
+
             av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n");
-            write_to_fifo(s->fifo, avfilter_ref_buffer(buf_out, AV_PERM_READ));
+            if (dup)
+                ret = write_to_fifo(s->fifo, dup);
+            else
+                ret = AVERROR(ENOMEM);
+
+            if (ret < 0) {
+                avfilter_unref_bufferp(&buf_out);
+                avfilter_unref_bufferp(&buf);
+                return ret;
+            }
+
             s->dup++;
         }
 
         buf_out->pts = av_rescale_q(s->first_pts, inlink->time_base,
                                     outlink->time_base) + s->frames_out;
 
-        ff_start_frame(outlink, buf_out);
-        ff_draw_slice(outlink, 0, outlink->h, 1);
-        ff_end_frame(outlink);
+        if ((ret = ff_start_frame(outlink, buf_out)) < 0 ||
+            (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+            (ret = ff_end_frame(outlink)) < 0) {
+            avfilter_unref_bufferp(&buf);
+            return ret;
+        }
+
         s->frames_out++;
     }
     flush_fifo(s->fifo);
 
-    write_to_fifo(s->fifo, buf);
+    ret = write_to_fifo(s->fifo, buf);
     s->pts = s->first_pts + av_rescale_q(s->frames_out, outlink->time_base, inlink->time_base);
+
+    return ret;
 }
 
-static void null_start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
+static int null_start_frame(AVFilterLink *link, AVFilterBufferRef *buf)
 {
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
+    return 0;
 }
 
 AVFilter avfilter_vf_fps = {
@@ -260,15 +286,15 @@ AVFilter avfilter_vf_fps = {
 
     .priv_size = sizeof(FPSContext),
 
-    .inputs    = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame     = null_start_frame,
-                                    .draw_slice      = null_draw_slice,
-                                    .end_frame       = end_frame, },
-                                  { .name = NULL}},
-    .outputs   = (AVFilterPad[]) {{ .name            = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = request_frame,
-                                    .config_props    = config_props},
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame     = null_start_frame,
+                                          .draw_slice      = null_draw_slice,
+                                          .end_frame       = end_frame, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = request_frame,
+                                          .config_props    = config_props},
+                                        { .name = NULL}},
 };
index f367264..0292f56 100644 (file)
@@ -340,20 +340,26 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     Frei0rContext *frei0r = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef  *inpicref =  inlink->cur_buf;
     AVFilterBufferRef *outpicref = outlink->out_buf;
+    int ret;
 
     frei0r->update(frei0r->instance, inpicref->pts * av_q2d(inlink->time_base) * 1000,
                    (const uint32_t *)inpicref->data[0],
                    (uint32_t *)outpicref->data[0]);
-    ff_draw_slice(outlink, 0, outlink->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, outlink->h, 1)) ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_frei0r = {
@@ -366,17 +372,17 @@ AVFilter avfilter_vf_frei0r = {
 
     .priv_size = sizeof(Frei0rContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = null_draw_slice,
-                                    .config_props     = config_input_props,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_READ },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = null_draw_slice,
+                                          .config_props     = config_input_props,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_READ },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
 
 static av_cold int source_init(AVFilterContext *ctx, const char *args)
@@ -432,18 +438,38 @@ static int source_request_frame(AVFilterLink *outlink)
 {
     Frei0rContext *frei0r = outlink->src->priv;
     AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+    AVFilterBufferRef *buf_out;
+    int ret;
+
+    if (!picref)
+        return AVERROR(ENOMEM);
+
     picref->video->sample_aspect_ratio = (AVRational) {1, 1};
     picref->pts = frei0r->pts++;
     picref->pos = -1;
 
-    ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
+    buf_out = avfilter_ref_buffer(picref, ~0);
+    if (!buf_out) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = ff_start_frame(outlink, buf_out);
+    if (ret < 0)
+        goto fail;
+
     frei0r->update(frei0r->instance, av_rescale_q(picref->pts, frei0r->time_base, (AVRational){1,1000}),
                    NULL, (uint32_t *)picref->data[0]);
-    ff_draw_slice(outlink, 0, outlink->h, 1);
-    ff_end_frame(outlink);
+    ret = ff_draw_slice(outlink, 0, outlink->h, 1);
+    if (ret < 0)
+        goto fail;
+
+    ret = ff_end_frame(outlink);
+
+fail:
     avfilter_unref_buffer(picref);
 
-    return 0;
+    return ret;
 }
 
 AVFilter avfilter_vsrc_frei0r_src = {
@@ -458,9 +484,9 @@ AVFilter avfilter_vsrc_frei0r_src = {
 
     .inputs    = (const AVFilterPad[]) {{ .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = source_request_frame,
-                                    .config_props    = source_config_props },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = source_request_frame,
+                                          .config_props    = source_config_props },
+                                        { .name = NULL}},
 };
index a35e3b0..e540e51 100644 (file)
@@ -180,32 +180,53 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
+    AVFilterBufferRef *outpicref = NULL, *for_next_filter;
+    int ret = 0;
 
     if (inpicref->perms & AV_PERM_PRESERVE) {
         outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
         outpicref->video->w = outlink->w;
         outpicref->video->h = outlink->h;
-    } else
+    } else {
         outpicref = avfilter_ref_buffer(inpicref, ~0);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+    }
+
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
+    if (ret < 0) {
+        avfilter_unref_bufferp(&outpicref);
+        return ret;
+    }
 
     outlink->out_buf = outpicref;
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     GradFunContext *gf = inlink->dst->priv;
     AVFilterBufferRef *inpic = inlink->cur_buf;
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *outpic = outlink->out_buf;
-    int p;
+    int p, ret;
 
     for (p = 0; p < 4 && inpic->data[p]; p++) {
         int w = inlink->w;
@@ -223,8 +244,10 @@ static void end_frame(AVFilterLink *inlink)
             av_image_copy_plane(outpic->data[p], outpic->linesize[p], inpic->data[p], inpic->linesize[p], w, h);
     }
 
-    ff_draw_slice(outlink, 0, inlink->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, inlink->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_gradfun = {
@@ -235,15 +258,15 @@ AVFilter avfilter_vf_gradfun = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_input,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_READ, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_input,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_READ, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 459cfab..413c566 100644 (file)
@@ -83,7 +83,7 @@ static int config_props(AVFilterLink *inlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
 
@@ -95,10 +95,10 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
     if (av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL)
         memcpy(inlink->dst->outputs[0]->out_buf->data[1], picref->data[1], AVPALETTE_SIZE);
 
-    ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
+    return ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     FlipContext *flip = inlink->dst->priv;
     AVFilterBufferRef *inpic  = inlink->cur_buf;
@@ -159,7 +159,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         }
     }
 
-    ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
 }
 
 AVFilter avfilter_vf_hflip = {
@@ -168,14 +168,14 @@ AVFilter avfilter_vf_hflip = {
     .priv_size = sizeof(FlipContext),
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame     = start_frame,
-                                    .draw_slice      = draw_slice,
-                                    .config_props    = config_props,
-                                    .min_perms       = AV_PERM_READ, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame     = start_frame,
+                                          .draw_slice      = draw_slice,
+                                          .config_props    = config_props,
+                                          .min_perms       = AV_PERM_READ, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index c18bb8f..cb46c5b 100644 (file)
@@ -290,9 +290,12 @@ static int config_input(AVFilterLink *inlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     HQDN3DContext *hqdn3d = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -300,6 +303,7 @@ static void end_frame(AVFilterLink *inlink)
     AVFilterBufferRef *outpic = outlink->out_buf;
     int cw = inpic->video->w >> hqdn3d->hsub;
     int ch = inpic->video->h >> hqdn3d->vsub;
+    int ret;
 
     deNoise(inpic->data[0], outpic->data[0],
             hqdn3d->Line, &hqdn3d->Frame[0], inpic->video->w, inpic->video->h,
@@ -320,8 +324,10 @@ static void end_frame(AVFilterLink *inlink)
             hqdn3d->Coefs[2],
             hqdn3d->Coefs[3]);
 
-    ff_draw_slice(outlink, 0, inpic->video->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, inpic->video->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_hqdn3d = {
@@ -333,14 +339,14 @@ AVFilter avfilter_vf_hqdn3d = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = null_draw_slice,
-                                    .config_props     = config_input,
-                                    .end_frame        = end_frame },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = null_draw_slice,
+                                          .config_props     = config_input,
+                                          .end_frame        = end_frame },
+                                        { .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };
index d192be7..02d073d 100644 (file)
@@ -169,7 +169,7 @@ static void filter(AVFilterContext *ctx)
     av_log(ctx, AV_LOG_DEBUG, "Single frame:%s, Multi frame:%s\n", type2str(type), type2str(idet->last_type));
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = link->dst;
     IDETContext *idet = ctx->priv;
@@ -181,21 +181,21 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     idet->next = picref;
 
     if (!idet->cur)
-        return;
+        return 0;
 
     if (!idet->prev)
         idet->prev = avfilter_ref_buffer(idet->cur, AV_PERM_READ);
 
-    ff_start_frame(ctx->outputs[0], avfilter_ref_buffer(idet->cur, AV_PERM_READ));
+    return ff_start_frame(ctx->outputs[0], avfilter_ref_buffer(idet->cur, AV_PERM_READ));
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     AVFilterContext *ctx = link->dst;
     IDETContext *idet = ctx->priv;
 
     if (!idet->cur)
-        return;
+        return 0;
 
     if (!idet->csp)
         idet->csp = &av_pix_fmt_descriptors[link->format];
@@ -205,7 +205,7 @@ static void end_frame(AVFilterLink *link)
     filter(ctx);
 
     ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
-    ff_end_frame(ctx->outputs[0]);
+    return ff_end_frame(ctx->outputs[0]);
 }
 
 static int request_frame(AVFilterLink *link)
@@ -311,7 +311,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 AVFilter avfilter_vf_idet = {
     .name          = "idet",
index b7c73db..fa16041 100644 (file)
@@ -67,7 +67,10 @@ static int query_formats(AVFilterContext *ctx)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
 typedef struct {
     const char *name;
@@ -351,7 +354,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     memset(ocv, 0, sizeof(*ocv));
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     OCVContext *ocv = ctx->priv;
@@ -359,14 +362,17 @@ static void end_frame(AVFilterLink *inlink)
     AVFilterBufferRef *inpicref  = inlink ->cur_buf;
     AVFilterBufferRef *outpicref = outlink->out_buf;
     IplImage inimg, outimg;
+    int ret;
 
     fill_iplimage_from_picref(&inimg , inpicref , inlink->format);
     fill_iplimage_from_picref(&outimg, outpicref, inlink->format);
     ocv->end_frame_filter(ctx, &inimg, &outimg);
     fill_picref_from_iplimage(outpicref, &outimg, inlink->format);
 
-    ff_draw_slice(outlink, 0, outlink->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
 AVFilter avfilter_vf_ocv = {
@@ -379,14 +385,14 @@ AVFilter avfilter_vf_ocv = {
     .init = init,
     .uninit = uninit,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_READ },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_READ },
+                                        { .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 252aac1..a9b9e8a 100644 (file)
@@ -275,7 +275,7 @@ static int config_props(AVFilterLink *inlink)
     return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = inlink->dst;
     LutContext *lut = ctx->priv;
@@ -332,9 +332,22 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         }
     }
 
-    ff_draw_slice(outlink, y, h, slice_dir);
+    return ff_draw_slice(outlink, y, h, slice_dir);
 }
 
+static const AVFilterPad inputs[] = {
+    { .name            = "default",
+      .type            = AVMEDIA_TYPE_VIDEO,
+      .draw_slice      = draw_slice,
+      .config_props    = config_props,
+      .min_perms       = AV_PERM_READ, },
+    { .name = NULL}
+};
+static const AVFilterPad outputs[] = {
+    { .name            = "default",
+      .type            = AVMEDIA_TYPE_VIDEO, },
+    { .name = NULL}
+};
 #define DEFINE_LUT_FILTER(name_, description_, init_)                   \
     AVFilter avfilter_vf_##name_ = {                                    \
         .name          = #name_,                                        \
@@ -345,15 +358,8 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         .uninit        = uninit,                                        \
         .query_formats = query_formats,                                 \
                                                                         \
-        .inputs    = (const AVFilterPad[]) {{ .name      = "default",   \
-                                        .type            = AVMEDIA_TYPE_VIDEO, \
-                                        .draw_slice      = draw_slice,  \
-                                        .config_props    = config_props, \
-                                        .min_perms       = AV_PERM_READ, }, \
-                                      { .name = NULL}},                 \
-        .outputs   = (const AVFilterPad[]) {{ .name      = "default",   \
-                                        .type            = AVMEDIA_TYPE_VIDEO, }, \
-                                      { .name = NULL}},                 \
+        .inputs        = inputs,                                        \
+        .outputs       = outputs,                                       \
     }
 
 #if CONFIG_LUT_FILTER
index 8ae8947..4fa02c7 100644 (file)
@@ -848,15 +848,17 @@ static int request_frame(AVFilterLink *outlink)
     return ret;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
+    return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     MPContext *m = inlink->dst->priv;
     AVFilterBufferRef *inpic  = inlink->cur_buf;
@@ -883,6 +885,7 @@ static void end_frame(AVFilterLink *inlink)
         av_log(m->avfctx, AV_LOG_DEBUG, "put_image() says skip\n");
     }
     free_mp_image(mpi);
+    return 0;
 }
 
 AVFilter avfilter_vf_mp = {
index 935c92a..5c4704e 100644 (file)
@@ -31,14 +31,14 @@ AVFilter avfilter_vf_null = {
 
     .priv_size = 0,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame,
-                                    .end_frame        = ff_null_end_frame },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame,
+                                          .end_frame        = ff_null_end_frame },
+                                        { .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 9f8163d..935274f 100644 (file)
@@ -145,8 +145,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&over->x_expr);
     av_freep(&over->y_expr);
 
-    if (over->overpicref)
-        avfilter_unref_bufferp(&over->overpicref);
+    avfilter_unref_bufferp(&over->overpicref);
     ff_bufqueue_discard_all(&over->queue_main);
     ff_bufqueue_discard_all(&over->queue_over);
 }
@@ -506,7 +505,7 @@ static void flush_frames(AVFilterContext *ctx)
     while (!try_push_frame(ctx));
 }
 
-static void start_frame_main(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame_main(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterContext *ctx = inlink->dst;
     OverlayContext *over = ctx->priv;
@@ -519,9 +518,10 @@ static void start_frame_main(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
         av_assert1(inpicref == inlink->cur_buf);
         inlink->cur_buf = NULL;
     }
+    return 0;
 }
 
-static void draw_slice_main(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice_main(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = inlink->dst;
     OverlayContext *over = ctx->priv;
@@ -536,10 +536,10 @@ static void draw_slice_main(AVFilterLink *inlink, int y, int h, int slice_dir)
                     over->overpicref->video->w, over->overpicref->video->h,
                     y, outpicref->video->w, h);
     }
-    ff_draw_slice(outlink, y, h, slice_dir);
+    return ff_draw_slice(outlink, y, h, slice_dir);
 }
 
-static void end_frame_main(AVFilterLink *inlink)
+static int end_frame_main(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
@@ -547,15 +547,16 @@ static void end_frame_main(AVFilterLink *inlink)
     flush_frames(ctx);
 
     if (!outpicref)
-        return;
-    ff_end_frame(ctx->outputs[0]);
+        return 0;
+    return ff_end_frame(ctx->outputs[0]);
 }
 
-static void start_frame_over(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame_over(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
+    return 0;
 }
 
-static void end_frame_over(AVFilterLink *inlink)
+static int end_frame_over(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     OverlayContext *over = ctx->priv;
@@ -566,7 +567,7 @@ static void end_frame_over(AVFilterLink *inlink)
     inpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base,
                                  ctx->outputs[0]->time_base);
     ff_bufqueue_add(ctx, &over->queue_over, inpicref);
-    try_push_frame(ctx);
+    return try_push_frame(ctx);
 }
 
 static int request_frame(AVFilterLink *outlink)
@@ -597,7 +598,10 @@ static int request_frame(AVFilterLink *outlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
 AVFilter avfilter_vf_overlay = {
     .name      = "overlay",
@@ -610,27 +614,27 @@ AVFilter avfilter_vf_overlay = {
 
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "main",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer= get_video_buffer,
-                                    .config_props    = config_input_main,
-                                    .start_frame     = start_frame_main,
-                                    .draw_slice      = draw_slice_main,
-                                    .end_frame       = end_frame_main,
-                                    .min_perms       = AV_PERM_READ,
-                                    .rej_perms       = AV_PERM_REUSE2|AV_PERM_PRESERVE, },
-                                  { .name            = "overlay",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .config_props    = config_input_overlay,
-                                    .start_frame     = start_frame_over,
-                                    .draw_slice      = null_draw_slice,
-                                    .end_frame       = end_frame_over,
-                                    .min_perms       = AV_PERM_READ,
-                                    .rej_perms       = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .config_props    = config_output,
-                                    .request_frame   = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "main",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer= get_video_buffer,
+                                          .config_props    = config_input_main,
+                                          .start_frame     = start_frame_main,
+                                          .draw_slice      = draw_slice_main,
+                                          .end_frame       = end_frame_main,
+                                          .min_perms       = AV_PERM_READ,
+                                          .rej_perms       = AV_PERM_REUSE2|AV_PERM_PRESERVE, },
+                                        { .name            = "overlay",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .config_props    = config_input_overlay,
+                                          .start_frame     = start_frame_over,
+                                          .draw_slice      = null_draw_slice,
+                                          .end_frame       = end_frame_over,
+                                          .min_perms       = AV_PERM_READ,
+                                          .rej_perms       = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .config_props    = config_output,
+                                          .request_frame   = request_frame, },
+                                        { .name = NULL}},
 };
index ba7020a..3e9dfa2 100644 (file)
@@ -226,6 +226,9 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int
                                                     h + (pad->h - pad->in_h));
     int plane;
 
+    if (!picref)
+        return NULL;
+
     picref->video->w = w;
     picref->video->h = h;
 
@@ -259,12 +262,15 @@ static int does_clip(PadContext *pad, AVFilterBufferRef *outpicref, int plane, i
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     PadContext *pad = inlink->dst->priv;
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
     AVFilterBufferRef *for_next_filter;
-    int plane;
+    int plane, ret = 0;
+
+    if (!outpicref)
+        return AVERROR(ENOMEM);
 
     for (plane = 0; plane < 4 && outpicref->data[plane] && pad->draw.pixelstep[plane]; plane++) {
         int hsub = pad->draw.hsub[plane];
@@ -292,22 +298,37 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
         outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES,
                                         FFMAX(inlink->w, pad->w),
                                         FFMAX(inlink->h, pad->h));
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(outpicref, inpicref);
     }
 
-    inlink->dst->outputs[0]->out_buf = outpicref;
-
     outpicref->video->w = pad->w;
     outpicref->video->h = pad->h;
 
     for_next_filter = avfilter_ref_buffer(outpicref, ~0);
-    ff_start_frame(inlink->dst->outputs[0], for_next_filter);
+    if (!for_next_filter) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = ff_start_frame(inlink->dst->outputs[0], for_next_filter);
+    if (ret < 0)
+        goto fail;
+
+    inlink->dst->outputs[0]->out_buf = outpicref;
+    return 0;
+
+fail:
+    avfilter_unref_bufferp(&outpicref);
+    return ret;
 }
 
-static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice)
+static int draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir, int before_slice)
 {
     PadContext *pad = link->dst->priv;
-    int bar_y, bar_h = 0;
+    int bar_y, bar_h = 0, ret = 0;
 
     if        (slice_dir * before_slice ==  1 && y == pad->y) {
         /* top bar */
@@ -324,15 +345,17 @@ static void draw_send_bar_slice(AVFilterLink *link, int y, int h, int slice_dir,
                           link->dst->outputs[0]->out_buf->data,
                           link->dst->outputs[0]->out_buf->linesize,
                           0, bar_y, pad->w, bar_h);
-        ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir);
+        ret = ff_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir);
     }
+    return ret;
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     PadContext *pad = link->dst->priv;
     AVFilterBufferRef *outpic = link->dst->outputs[0]->out_buf;
     AVFilterBufferRef *inpic = link->cur_buf;
+    int ret;
 
     y += pad->y;
 
@@ -340,7 +363,7 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
     h = ff_draw_round_to_sub(&pad->draw, 1, -1, h);
 
     if (!h)
-        return;
+        return 0;
     draw_send_bar_slice(link, y, h, slice_dir, 1);
 
     /* left border */
@@ -357,9 +380,11 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
     /* right border */
     ff_fill_rectangle(&pad->draw, &pad->color, outpic->data, outpic->linesize,
                       pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h);
-    ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
+    ret = ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
+    if (ret < 0)
+        return ret;
 
-    draw_send_bar_slice(link, y, h, slice_dir, -1);
+    return draw_send_bar_slice(link, y, h, slice_dir, -1);
 }
 
 AVFilter avfilter_vf_pad = {
@@ -370,16 +395,16 @@ AVFilter avfilter_vf_pad = {
     .init          = init,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_input,
-                                    .get_video_buffer = get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice, },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_output, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_input,
+                                          .get_video_buffer = get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice, },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_output, },
+                                        { .name = NULL}},
 };
index 73ae255..2e09d8c 100644 (file)
@@ -51,16 +51,18 @@ static int config_props(AVFilterLink *inlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     PixdescTestContext *priv = inlink->dst->priv;
     AVFilterLink *outlink    = inlink->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
-    int i;
+    AVFilterBufferRef *outpicref, *for_next_filter;
+    int i, ret = 0;
+
+    outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE,
+                                    outlink->w, outlink->h);
+    if (!outpicref)
+        return AVERROR(ENOMEM);
 
-    outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
-                                           outlink->w, outlink->h);
-    outpicref = outlink->out_buf;
     avfilter_copy_buffer_ref_props(outpicref, picref);
 
     for (i = 0; i < 4; i++) {
@@ -78,10 +80,22 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         priv->pix_desc->flags & PIX_FMT_PSEUDOPAL)
         memcpy(outpicref->data[1], picref->data[1], AVPALETTE_SIZE);
 
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
+    if (ret < 0) {
+        avfilter_unref_bufferp(&outpicref);
+        return ret;
+    }
+
+    outlink->out_buf = outpicref;
+    return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     PixdescTestContext *priv = inlink->dst->priv;
     AVFilterBufferRef *inpic    = inlink->cur_buf;
@@ -108,7 +122,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         }
     }
 
-    ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
 }
 
 AVFilter avfilter_vf_pixdesctest = {
@@ -118,15 +132,15 @@ AVFilter avfilter_vf_pixdesctest = {
     .priv_size = sizeof(PixdescTestContext),
     .uninit    = uninit,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame     = start_frame,
-                                    .draw_slice      = draw_slice,
-                                    .config_props    = config_props,
-                                    .min_perms       = AV_PERM_READ, },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame     = start_frame,
+                                          .draw_slice      = draw_slice,
+                                          .config_props    = config_props,
+                                          .min_perms       = AV_PERM_READ, },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index df67193..7b0a662 100644 (file)
@@ -472,7 +472,7 @@ static void blur_image(int ***mask,
     }
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef *outpicref;
@@ -487,10 +487,10 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
         outpicref = inpicref;
 
     outlink->out_buf = outpicref;
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    return ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     RemovelogoContext *removelogo = inlink->dst->priv;
     AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -515,7 +515,7 @@ static void end_frame(AVFilterLink *inlink)
                inlink->w/2, inlink->h/2, direct, &removelogo->half_mask_bbox);
 
     ff_draw_slice(outlink, 0, inlink->h, 1);
-    ff_end_frame(outlink);
+    return ff_end_frame(outlink);
 }
 
 static void uninit(AVFilterContext *ctx)
@@ -540,7 +540,7 @@ static void uninit(AVFilterContext *ctx)
     }
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 AVFilter avfilter_vf_removelogo = {
     .name          = "removelogo",
index 7df03fc..143ff70 100644 (file)
@@ -272,11 +272,12 @@ fail:
     return ret;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     ScaleContext *scale = link->dst->priv;
     AVFilterLink *outlink = link->dst->outputs[0];
-    AVFilterBufferRef *outpicref;
+    AVFilterBufferRef *outpicref, *for_next_filter;
+    int ret = 0;
 
     if(   picref->video->w != link->w
        || picref->video->h != link->h
@@ -295,19 +296,23 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 
 
     if (!scale->sws) {
-        ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
-        return;
+        outpicref = avfilter_ref_buffer(picref, ~0);
+        if (!outpicref)
+            return AVERROR(ENOMEM);
+        return ff_start_frame(outlink, outpicref);
     }
 
     scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w;
     scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
 
     outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN, outlink->w, outlink->h);
+    if (!outpicref)
+        return AVERROR(ENOMEM);
+
     avfilter_copy_buffer_ref_props(outpicref, picref);
     outpicref->video->w = outlink->w;
     outpicref->video->h = outlink->h;
 
-    outlink->out_buf = outpicref;
     if(scale->output_is_pal)
         ff_set_systematic_pal2(outpicref->data[1], outlink->format == PIX_FMT_PAL8 ? PIX_FMT_BGR8 : outlink->format);
 
@@ -317,7 +322,19 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
               INT_MAX);
 
     scale->slice_y = 0;
-    ff_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0));
+    for_next_filter = avfilter_ref_buffer(outpicref, ~0);
+    if (for_next_filter)
+        ret = ff_start_frame(outlink, for_next_filter);
+    else
+        ret = AVERROR(ENOMEM);
+
+    if (ret < 0) {
+        avfilter_unref_bufferp(&outpicref);
+        return ret;
+    }
+
+    outlink->out_buf = outpicref;
+    return 0;
 }
 
 static int scale_slice(AVFilterLink *link, struct SwsContext *sws, int y, int h, int mul, int field)
@@ -346,14 +363,13 @@ static int scale_slice(AVFilterLink *link, struct SwsContext *sws, int y, int h,
                          out,out_stride);
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     ScaleContext *scale = link->dst->priv;
-    int out_h;
+    int out_h, ret;
 
     if (!scale->sws) {
-        ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
-        return;
+        return ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
     }
 
     if (scale->slice_y == 0 && slice_dir == -1)
@@ -369,9 +385,10 @@ static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 
     if (slice_dir == -1)
         scale->slice_y -= out_h;
-    ff_draw_slice(link->dst->outputs[0], scale->slice_y, out_h, slice_dir);
+    ret = ff_draw_slice(link->dst->outputs[0], scale->slice_y, out_h, slice_dir);
     if (slice_dir == 1)
         scale->slice_y += out_h;
+    return ret;
 }
 
 AVFilter avfilter_vf_scale = {
@@ -385,14 +402,14 @@ AVFilter avfilter_vf_scale = {
 
     .priv_size = sizeof(ScaleContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .min_perms        = AV_PERM_READ, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .config_props     = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .min_perms        = AV_PERM_READ, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .config_props     = config_props, },
+                                        { .name = NULL}},
 };
index b187fa3..4d19b33 100644 (file)
@@ -269,12 +269,13 @@ static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *picref)
     return res;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     SelectContext *select = inlink->dst->priv;
 
     select->select = select_frame(inlink->dst, picref);
     if (select->select) {
+        AVFilterBufferRef *buf_out;
         /* frame was requested through poll_frame */
         if (select->cache_frames) {
             if (!av_fifo_space(select->pending_frames))
@@ -283,29 +284,36 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
             else
                 av_fifo_generic_write(select->pending_frames, &picref,
                                       sizeof(picref), NULL);
-            return;
+            return 0;
         }
-        ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
+        buf_out = avfilter_ref_buffer(picref, ~0);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+        return ff_start_frame(inlink->dst->outputs[0], buf_out);
     }
+
+    return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     SelectContext *select = inlink->dst->priv;
 
     if (select->select && !select->cache_frames)
-        ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+        return ff_draw_slice(inlink->dst->outputs[0], y, h, slice_dir);
+    return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     SelectContext *select = inlink->dst->priv;
 
     if (select->select) {
         if (select->cache_frames)
-            return;
-        ff_end_frame(inlink->dst->outputs[0]);
+            return 0;
+        return ff_end_frame(inlink->dst->outputs[0]);
     }
+    return 0;
 }
 
 static int request_frame(AVFilterLink *outlink)
@@ -317,12 +325,14 @@ static int request_frame(AVFilterLink *outlink)
 
     if (av_fifo_size(select->pending_frames)) {
         AVFilterBufferRef *picref;
+        int ret;
+
         av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL);
-        ff_start_frame(outlink, avfilter_ref_buffer(picref, ~0));
-        ff_draw_slice(outlink, 0, outlink->h, 1);
-        ff_end_frame(outlink);
-        avfilter_unref_buffer(picref);
-        return 0;
+        if ((ret = ff_start_frame(outlink, picref)) < 0 ||
+            (ret = ff_draw_slice(outlink, 0, outlink->h, 1)) < 0 ||
+            (ret = ff_end_frame(outlink)) < 0);
+
+        return ret;
     }
 
     while (!select->select) {
@@ -402,17 +412,17 @@ AVFilter avfilter_vf_select = {
 
     .priv_size = sizeof(SelectContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .config_props     = config_input,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .end_frame        = end_frame },
-                                  { .name = NULL }},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .poll_frame       = poll_frame,
-                                    .request_frame    = request_frame, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .config_props     = config_input,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .end_frame        = end_frame },
+                                        { .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .poll_frame       = poll_frame,
+                                          .request_frame    = request_frame, },
+                                        { .name = NULL}},
 };
index 4be4fd8..93d30c7 100644 (file)
@@ -69,7 +69,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     SetFieldContext *setfield = inlink->dst->priv;
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
@@ -80,7 +80,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
         outpicref->video->interlaced = 1;
         outpicref->video->top_field_first = setfield->mode;
     }
-    ff_start_frame(inlink->dst->outputs[0], outpicref);
+    return ff_start_frame(inlink->dst->outputs[0], outpicref);
 }
 
 AVFilter avfilter_vf_setfield = {
index 3fdbd96..4e2c8f8 100644 (file)
@@ -92,12 +92,15 @@ static int config_input(AVFilterLink *inlink)
 #define D2TS(d)  (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
 #define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
 {
     SetPTSContext *setpts = inlink->dst->priv;
     double d;
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
 
+    if (!outpicref)
+        return AVERROR(ENOMEM);
+
     if (isnan(setpts->var_values[VAR_STARTPTS]))
         setpts->var_values[VAR_STARTPTS] = TS2D(inpicref->pts);
 
@@ -121,7 +124,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref)
     setpts->var_values[VAR_N] += 1.0;
     setpts->var_values[VAR_PREV_INPTS ] = TS2D(inpicref ->pts);
     setpts->var_values[VAR_PREV_OUTPTS] = TS2D(outpicref->pts);
-    ff_start_frame(inlink->dst->outputs[0], outpicref);
+    return ff_start_frame(inlink->dst->outputs[0], outpicref);
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -139,13 +142,13 @@ AVFilter avfilter_vf_setpts = {
 
     .priv_size = sizeof(SetPTSContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .config_props     = config_input,
-                                    .start_frame      = start_frame, },
-                                  { .name = NULL }},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .config_props     = config_input,
+                                          .start_frame      = start_frame, },
+                                        { .name = NULL }},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index fb522a3..1c65563 100644 (file)
@@ -41,7 +41,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     ShowInfoContext *showinfo = ctx->priv;
@@ -81,7 +81,7 @@ static void end_frame(AVFilterLink *inlink)
     av_log(ctx, AV_LOG_INFO, "]\n");
 
     showinfo->frame++;
-    ff_end_frame(inlink->dst->outputs[0]);
+    return ff_end_frame(inlink->dst->outputs[0]);
 }
 
 AVFilter avfilter_vf_showinfo = {
@@ -91,15 +91,15 @@ AVFilter avfilter_vf_showinfo = {
     .priv_size = sizeof(ShowInfoContext),
     .init      = init,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = ff_null_start_frame_keep_ref,
-                                    .end_frame        = end_frame,
-                                    .min_perms        = AV_PERM_READ, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = ff_null_start_frame_keep_ref,
+                                          .end_frame        = end_frame,
+                                          .min_perms        = AV_PERM_READ, },
+                                        { .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO },
+                                        { .name = NULL}},
 };
index 0c924ac..e7679a0 100644 (file)
@@ -59,7 +59,7 @@ static int config_props(AVFilterLink *link)
     return 0;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     SliceContext *slice = link->dst->priv;
 
@@ -75,27 +75,34 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     av_log(link->dst, AV_LOG_DEBUG, "h:%d\n", slice->h);
     link->cur_buf = NULL;
 
-    ff_start_frame(link->dst->outputs[0], picref);
+    return ff_start_frame(link->dst->outputs[0], picref);
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     SliceContext *slice = link->dst->priv;
-    int y2;
+    int y2, ret = 0;
 
     if (slice_dir == 1) {
-        for (y2 = y; y2 + slice->h <= y + h; y2 += slice->h)
-            ff_draw_slice(link->dst->outputs[0], y2, slice->h, slice_dir);
+        for (y2 = y; y2 + slice->h <= y + h; y2 += slice->h) {
+            ret = ff_draw_slice(link->dst->outputs[0], y2, slice->h, slice_dir);
+            if (ret < 0)
+                return ret;
+        }
 
         if (y2 < y + h)
-            ff_draw_slice(link->dst->outputs[0], y2, y + h - y2, slice_dir);
+            return ff_draw_slice(link->dst->outputs[0], y2, y + h - y2, slice_dir);
     } else if (slice_dir == -1) {
-        for (y2 = y + h; y2 - slice->h >= y; y2 -= slice->h)
-            ff_draw_slice(link->dst->outputs[0], y2 - slice->h, slice->h, slice_dir);
+        for (y2 = y + h; y2 - slice->h >= y; y2 -= slice->h) {
+            ret = ff_draw_slice(link->dst->outputs[0], y2 - slice->h, slice->h, slice_dir);
+            if (ret < 0)
+                return ret;
+        }
 
         if (y2 > y)
-            ff_draw_slice(link->dst->outputs[0], y, y2 - y, slice_dir);
+            return ff_draw_slice(link->dst->outputs[0], y, y2 - y, slice_dir);
     }
+    return 0;
 }
 
 AVFilter avfilter_vf_slicify = {
@@ -106,15 +113,15 @@ AVFilter avfilter_vf_slicify = {
 
     .priv_size = sizeof(SliceContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = ff_null_get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .config_props     = config_props,
-                                    .end_frame        = ff_null_end_frame, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = ff_null_get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .config_props     = config_props,
+                                          .end_frame        = ff_null_end_frame, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index cbd9fcb..0b48155 100644 (file)
@@ -302,9 +302,9 @@ static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { return 0; }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
     AVFilterBufferRef  *inpicref =  inlink->cur_buf;
@@ -315,7 +315,7 @@ static void end_frame(AVFilterLink *inlink)
                inlink->w, inlink->h);
 
     ff_draw_slice(outlink, 0, outlink->h, 1);
-    ff_end_frame(outlink);
+    return ff_end_frame(outlink);
 }
 
 AVFilter avfilter_vf_super2xsai = {
index 1a13eda..94015d9 100644 (file)
@@ -46,7 +46,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
     return picref;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
 {
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
 
@@ -56,7 +56,7 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
     outpicref->linesize[1] = inpicref->linesize[2];
     outpicref->linesize[2] = inpicref->linesize[1];
 
-    ff_start_frame(link->dst->outputs[0], outpicref);
+    return ff_start_frame(link->dst->outputs[0], outpicref);
 }
 
 static int query_formats(AVFilterContext *ctx)
index 4359635..8e73de9 100644 (file)
@@ -68,7 +68,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     int i, j;
     AVFilterContext *ctx = inlink->dst;
@@ -86,6 +86,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
         }
         p += picref->linesize[0];
     }
+    return 0;
 }
 
 /**
@@ -106,7 +107,7 @@ static double frame_sum_square_err(const int *hist, const double *median)
     return sum_sq_err;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int  end_frame(AVFilterLink *inlink)
 {
     int i, j, best_frame_idx = 0;
     double avg_hist[HIST_SIZE] = {0}, sq_err, min_sq_err = -1;
@@ -122,7 +123,7 @@ static void end_frame(AVFilterLink *inlink)
     // no selection until the buffer of N frames is filled up
     if (thumb->n < thumb->n_frames - 1) {
         thumb->n++;
-        return;
+        return 0;
     }
 
     // average histogram of the N frames
@@ -156,7 +157,7 @@ static void end_frame(AVFilterLink *inlink)
     ff_start_frame(outlink, picref);
     thumb->frames[best_frame_idx].buf = NULL;
     ff_draw_slice(outlink, 0, inlink->h, 1);
-    ff_end_frame(outlink);
+    return ff_end_frame(outlink);
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
@@ -170,7 +171,7 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&thumb->frames);
 }
 
-static void null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { }
+static int null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { return 0; }
 
 static int request_frame(AVFilterLink *link)
 {
index 8ed7333..a6c7e7a 100644 (file)
@@ -96,23 +96,23 @@ static int config_props(AVFilterLink *outlink)
  * buffers are fed to start_frame in the order they were obtained from
  * get_buffer (think B-frames). */
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx  = inlink->dst;
     TileContext *tile    = ctx->priv;
     AVFilterLink *outlink = ctx->outputs[0];
 
     if (tile->current)
-        return;
+        return 0;
     outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
                                                  outlink->w, outlink->h);
     avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
     outlink->out_buf->video->w = outlink->w;
     outlink->out_buf->video->h = outlink->h;
-    ff_start_frame(outlink, outlink->out_buf);
+    return ff_start_frame(outlink, outlink->out_buf);
 }
 
-static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx  = inlink->dst;
     TileContext *tile    = ctx->priv;
@@ -126,6 +126,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
                        x0, y0 + y, 0, y, inlink->cur_buf->video->w, h);
     /* TODO if tile->w == 1 && slice_dir is always 1, we could draw_slice
      * immediately. */
+    return 0;
 }
 
 static void draw_blank_frame(AVFilterContext *ctx)
@@ -153,14 +154,15 @@ static void end_last_frame(AVFilterContext *ctx)
     tile->current = 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx  = inlink->dst;
     TileContext *tile    = ctx->priv;
 
-    avfilter_unref_buffer(inlink->cur_buf);
+    avfilter_unref_bufferp(&inlink->cur_buf);
     if (++tile->current == tile->w * tile->h)
         end_last_frame(ctx);
+    return 0;
 }
 
 static int request_frame(AVFilterLink *outlink)
index d511d72..559f64b 100644 (file)
@@ -198,7 +198,7 @@ void copy_picture_field(uint8_t *dst[4], int dst_linesize[4],
     }
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = inlink->dst;
     TInterlaceContext *tinterlace = ctx->priv;
@@ -206,9 +206,10 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
     avfilter_unref_buffer(tinterlace->cur);
     tinterlace->cur  = tinterlace->next;
     tinterlace->next = picref;
+    return 0;
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     AVFilterLink *outlink = ctx->outputs[0];
@@ -220,7 +221,7 @@ static void end_frame(AVFilterLink *inlink)
 
     /* we need at least two frames */
     if (!tinterlace->cur)
-        return;
+        return 0;
 
     switch (tinterlace->mode) {
     case MODE_MERGE: /* move the odd frame into the upper field of the new image, even into
@@ -324,6 +325,8 @@ static void end_frame(AVFilterLink *inlink)
     ff_end_frame(outlink);
 
     tinterlace->frame++;
+
+    return 0;
 }
 
 static int poll_frame(AVFilterLink *outlink)
@@ -359,7 +362,7 @@ static int request_frame(AVFilterLink *outlink)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 AVFilter avfilter_vf_tinterlace = {
     .name          = "tinterlace",
index b5a742c..3a17d6d 100644 (file)
@@ -114,12 +114,16 @@ static int config_props_output(AVFilterLink *outlink)
     return 0;
 }
 
-static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterLink *outlink = inlink->dst->outputs[0];
+    AVFilterBufferRef *buf_out;
 
     outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE,
                                            outlink->w, outlink->h);
+    if (!outlink->out_buf)
+        return AVERROR(ENOMEM);
+
     outlink->out_buf->pts = picref->pts;
 
     if (picref->video->sample_aspect_ratio.num == 0) {
@@ -129,16 +133,19 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         outlink->out_buf->video->sample_aspect_ratio.den = picref->video->sample_aspect_ratio.num;
     }
 
-    ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
+    buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
+    if (!buf_out)
+        return AVERROR(ENOMEM);
+    return ff_start_frame(outlink, buf_out);
 }
 
-static void end_frame(AVFilterLink *inlink)
+static int end_frame(AVFilterLink *inlink)
 {
     TransContext *trans = inlink->dst->priv;
     AVFilterBufferRef *inpic  = inlink->cur_buf;
     AVFilterBufferRef *outpic = inlink->dst->outputs[0]->out_buf;
     AVFilterLink *outlink = inlink->dst->outputs[0];
-    int plane;
+    int plane, ret;
 
     for (plane = 0; outpic->data[plane]; plane++) {
         int hsub = plane == 1 || plane == 2 ? trans->hsub : 0;
@@ -189,11 +196,13 @@ static void end_frame(AVFilterLink *inlink)
         }
     }
 
-    ff_draw_slice(outlink, 0, outpic->video->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_draw_slice(outlink, 0, outpic->video->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
+    return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { return 0; }
 
 AVFilter avfilter_vf_transpose = {
     .name      = "transpose",
@@ -204,15 +213,15 @@ AVFilter avfilter_vf_transpose = {
 
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame     = start_frame,
-                                    .draw_slice      = null_draw_slice,
-                                    .end_frame       = end_frame,
-                                    .min_perms       = AV_PERM_READ, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .config_props    = config_props_output,
-                                    .type            = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame     = start_frame,
+                                          .draw_slice      = null_draw_slice,
+                                          .end_frame       = end_frame,
+                                          .min_perms       = AV_PERM_READ, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .config_props    = config_props_output,
+                                          .type            = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 53381f5..13fa108 100644 (file)
@@ -213,24 +213,28 @@ static av_cold void uninit(AVFilterContext *ctx)
     free_filter_param(&unsharp->chroma);
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     UnsharpContext *unsharp = link->dst->priv;
     AVFilterBufferRef *in  = link->cur_buf;
     AVFilterBufferRef *out = link->dst->outputs[0]->out_buf;
     int cw = SHIFTUP(link->w, unsharp->hsub);
     int ch = SHIFTUP(link->h, unsharp->vsub);
+    int ret;
 
     apply_unsharp(out->data[0], out->linesize[0], in->data[0], in->linesize[0], link->w, link->h, &unsharp->luma);
     apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw,      ch,      &unsharp->chroma);
     apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw,      ch,      &unsharp->chroma);
 
-    ff_draw_slice(link->dst->outputs[0], 0, link->h, 1);
-    ff_end_frame(link->dst->outputs[0]);
+    if ((ret = ff_draw_slice(link->dst->outputs[0], 0, link->h, 1)) < 0 ||
+        (ret = ff_end_frame(link->dst->outputs[0])) < 0)
+        return ret;
+    return 0;
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
+    return 0;
 }
 
 AVFilter avfilter_vf_unsharp = {
@@ -243,15 +247,15 @@ AVFilter avfilter_vf_unsharp = {
     .uninit = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .draw_slice       = draw_slice,
-                                    .end_frame        = end_frame,
-                                    .config_props     = config_props,
-                                    .min_perms        = AV_PERM_READ, },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .draw_slice       = draw_slice,
+                                          .end_frame        = end_frame,
+                                          .config_props     = config_props,
+                                          .min_perms        = AV_PERM_READ, },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 11129b2..3c06aba 100644 (file)
@@ -52,6 +52,9 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
         return ff_default_get_video_buffer(link, perms, w, h);
 
     picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h);
+    if (!picref)
+        return NULL;
+
     for (i = 0; i < 4; i ++) {
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
 
@@ -64,12 +67,15 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
     return picref;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
 {
     FlipContext *flip = link->dst->priv;
     AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0);
     int i;
 
+    if (!outpicref)
+        return AVERROR(ENOMEM);
+
     for (i = 0; i < 4; i ++) {
         int vsub = i == 1 || i == 2 ? flip->vsub : 0;
 
@@ -79,14 +85,14 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref)
         }
     }
 
-    ff_start_frame(link->dst->outputs[0], outpicref);
+    return ff_start_frame(link->dst->outputs[0], outpicref);
 }
 
-static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+static int draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     AVFilterContext *ctx = link->dst;
 
-    ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
+    return ff_draw_slice(ctx->outputs[0], link->h - (y+h), h, -1 * slice_dir);
 }
 
 AVFilter avfilter_vf_vflip = {
@@ -95,14 +101,14 @@ AVFilter avfilter_vf_vflip = {
 
     .priv_size = sizeof(FlipContext),
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .get_video_buffer = get_video_buffer,
-                                    .start_frame      = start_frame,
-                                    .draw_slice       = draw_slice,
-                                    .config_props     = config_input, },
-                                  { .name = NULL}},
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .get_video_buffer = get_video_buffer,
+                                          .start_frame      = start_frame,
+                                          .draw_slice       = draw_slice,
+                                          .config_props     = config_input, },
+                                        { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO, },
+                                        { .name = NULL}},
 };
index 46ae1dd..bf63636 100644 (file)
@@ -134,9 +134,8 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic,
             }
         }
     }
-#if HAVE_MMX
-    __asm__ volatile("emms \n\t" : : : "memory");
-#endif
+
+    emms_c();
 }
 
 static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h)
@@ -157,11 +156,11 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w,
     return picref;
 }
 
-static void return_frame(AVFilterContext *ctx, int is_second)
+static int return_frame(AVFilterContext *ctx, int is_second)
 {
     YADIFContext *yadif = ctx->priv;
     AVFilterLink *link= ctx->outputs[0];
-    int tff;
+    int tff, ret;
 
     if (yadif->parity == -1) {
         tff = yadif->cur->video->interlaced ?
@@ -173,6 +172,9 @@ static void return_frame(AVFilterContext *ctx, int is_second)
     if (is_second) {
         yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE |
                                          AV_PERM_REUSE, link->w, link->h);
+        if (!yadif->out)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
         yadif->out->video->interlaced = 0;
     }
@@ -193,15 +195,19 @@ static void return_frame(AVFilterContext *ctx, int is_second)
         } else {
             yadif->out->pts = AV_NOPTS_VALUE;
         }
-        ff_start_frame(ctx->outputs[0], yadif->out);
+        ret = ff_start_frame(ctx->outputs[0], yadif->out);
+        if (ret < 0)
+            return ret;
     }
-    ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
-    ff_end_frame(ctx->outputs[0]);
+    if ((ret = ff_draw_slice(ctx->outputs[0], 0, link->h, 1)) < 0 ||
+        (ret = ff_end_frame(ctx->outputs[0])) < 0)
+        return ret;
 
     yadif->frame_pending = (yadif->mode&1) && !is_second;
+    return 0;
 }
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterContext *ctx = link->dst;
     YADIFContext *yadif = ctx->priv;
@@ -218,46 +224,52 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
     yadif->next = picref;
 
     if (!yadif->cur)
-        return;
+        return 0;
 
     if (yadif->auto_enable && !yadif->cur->video->interlaced) {
         yadif->out  = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
-        avfilter_unref_buffer(yadif->prev);
-        yadif->prev = NULL;
+        if (!yadif->out)
+            return AVERROR(ENOMEM);
+
+        avfilter_unref_bufferp(&yadif->prev);
         if (yadif->out->pts != AV_NOPTS_VALUE)
             yadif->out->pts *= 2;
-        ff_start_frame(ctx->outputs[0], yadif->out);
-        return;
+        return ff_start_frame(ctx->outputs[0], yadif->out);
     }
 
-    if (!yadif->prev)
-        yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ);
+    if (!yadif->prev &&
+        !(yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ)))
+        return AVERROR(ENOMEM);
 
     yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE |
                                      AV_PERM_REUSE, link->w, link->h);
+    if (!yadif->out)
+        return AVERROR(ENOMEM);
 
     avfilter_copy_buffer_ref_props(yadif->out, yadif->cur);
     yadif->out->video->interlaced = 0;
     if (yadif->out->pts != AV_NOPTS_VALUE)
         yadif->out->pts *= 2;
-    ff_start_frame(ctx->outputs[0], yadif->out);
+    return ff_start_frame(ctx->outputs[0], yadif->out);
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
     AVFilterContext *ctx = link->dst;
     YADIFContext *yadif = ctx->priv;
 
     if (!yadif->out)
-        return;
+        return 0;
 
     if (yadif->auto_enable && !yadif->cur->video->interlaced) {
-        ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
-        ff_end_frame(ctx->outputs[0]);
-        return;
+        int ret = ff_draw_slice(ctx->outputs[0], 0, link->h, 1);
+        if (ret >= 0)
+            ret = ff_end_frame(ctx->outputs[0]);
+        return ret;
     }
 
     return_frame(ctx, 0);
+    return 0;
 }
 
 static int request_frame(AVFilterLink *link)
@@ -280,6 +292,9 @@ static int request_frame(AVFilterLink *link)
 
         if (ret == AVERROR_EOF && yadif->cur) {
             AVFilterBufferRef *next = avfilter_ref_buffer(yadif->next, AV_PERM_READ);
+            if (!next)
+                return AVERROR(ENOMEM);
+
             next->pts = yadif->next->pts * 2 - yadif->cur->pts;
 
             start_frame(link->src->inputs[0], next);
@@ -324,9 +339,9 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
     YADIFContext *yadif = ctx->priv;
 
-    if (yadif->prev) avfilter_unref_buffer(yadif->prev);
-    if (yadif->cur ) avfilter_unref_buffer(yadif->cur );
-    if (yadif->next) avfilter_unref_buffer(yadif->next);
+    if (yadif->prev) avfilter_unref_bufferp(&yadif->prev);
+    if (yadif->cur ) avfilter_unref_bufferp(&yadif->cur );
+    if (yadif->next) avfilter_unref_bufferp(&yadif->next);
 }
 
 static int query_formats(AVFilterContext *ctx)
@@ -382,7 +397,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     return 0;
 }
 
-static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { }
+static int null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+{
+    return 0;
+}
 
 static int config_props(AVFilterLink *link)
 {
@@ -403,19 +421,19 @@ AVFilter avfilter_vf_yadif = {
     .uninit        = uninit,
     .query_formats = query_formats,
 
-    .inputs    = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .start_frame      = start_frame,
-                                    .get_video_buffer = get_video_buffer,
-                                    .draw_slice       = null_draw_slice,
-                                    .end_frame        = end_frame,
-                                    .rej_perms        = AV_PERM_REUSE2, },
-                                  { .name = NULL}},
-
-    .outputs   = (const AVFilterPad[]) {{ .name       = "default",
-                                    .type             = AVMEDIA_TYPE_VIDEO,
-                                    .poll_frame       = poll_frame,
-                                    .request_frame    = request_frame,
-                                    .config_props     = config_props, },
-                                  { .name = NULL}},
+    .inputs    = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .start_frame      = start_frame,
+                                          .get_video_buffer = get_video_buffer,
+                                          .draw_slice       = null_draw_slice,
+                                          .end_frame        = end_frame,
+                                          .rej_perms        = AV_PERM_REUSE2, },
+                                        { .name = NULL}},
+
+    .outputs   = (const AVFilterPad[]) {{ .name             = "default",
+                                          .type             = AVMEDIA_TYPE_VIDEO,
+                                          .poll_frame       = poll_frame,
+                                          .request_frame    = request_frame,
+                                          .config_props     = config_props, },
+                                        { .name = NULL}},
 };
index 0eed221..92b16b2 100644 (file)
@@ -149,13 +149,15 @@ AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, int w, int
     return ret;
 }
 
-void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+int ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
     AVFilterBufferRef *buf_out = avfilter_ref_buffer(picref, ~0);
-    ff_start_frame(link->dst->outputs[0], buf_out);
+    if (!buf_out)
+        return AVERROR(ENOMEM);
+    return ff_start_frame(link->dst->outputs[0], buf_out);
 }
 
-static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
+static int default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
 {
     AVFilterLink *outlink = NULL;
 
@@ -163,21 +165,37 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref)
         outlink = inlink->dst->outputs[0];
 
     if (outlink) {
+        AVFilterBufferRef *buf_out;
         outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
+        if (!outlink->out_buf)
+            return AVERROR(ENOMEM);
+
         avfilter_copy_buffer_ref_props(outlink->out_buf, picref);
         outlink->out_buf->video->w = outlink->w;
         outlink->out_buf->video->h = outlink->h;
-        ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0));
+        buf_out = avfilter_ref_buffer(outlink->out_buf, ~0);
+        if (!buf_out)
+            return AVERROR(ENOMEM);
+
+        return ff_start_frame(outlink, buf_out);
     }
+    return 0;
+}
+
+static void clear_link(AVFilterLink *link)
+{
+    avfilter_unref_bufferp(&link->cur_buf);
+    avfilter_unref_bufferp(&link->src_buf);
+    avfilter_unref_bufferp(&link->out_buf);
 }
 
 /* XXX: should we do the duplicating of the picture ref here, instead of
  * forcing the source filter to do it? */
-void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
-    void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
+    int (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
     AVFilterPad *dst = link->dstpad;
-    int perms = picref->perms;
+    int ret, perms = picref->perms;
     AVFilterCommand *cmd= link->dst->command_queue;
     int64_t pts;
 
@@ -196,6 +214,11 @@ void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
                 link->dstpad->min_perms, link->dstpad->rej_perms);
 
         link->cur_buf = ff_get_video_buffer(link, dst->min_perms, link->w, link->h);
+        if (!link->cur_buf) {
+            avfilter_unref_bufferp(&picref);
+            return AVERROR(ENOMEM);
+        }
+
         link->src_buf = picref;
         avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);
 
@@ -215,22 +238,26 @@ void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
         cmd= link->dst->command_queue;
     }
     pts = link->cur_buf->pts;
-    start_frame(link, link->cur_buf);
+    ret = start_frame(link, link->cur_buf);
     ff_update_link_current_pts(link,link->cur_buf ?  link->cur_buf->pts : pts);
+    if (ret < 0)
+        clear_link(link);
+
+    return ret;
 }
 
-void ff_null_start_frame_keep_ref(AVFilterLink *inlink,
+int ff_null_start_frame_keep_ref(AVFilterLink *inlink,
                                                 AVFilterBufferRef *picref)
 {
-    ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
+    return ff_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0));
 }
 
-void ff_null_end_frame(AVFilterLink *link)
+int ff_null_end_frame(AVFilterLink *link)
 {
-    ff_end_frame(link->dst->outputs[0]);
+    return ff_end_frame(link->dst->outputs[0]);
 }
 
-static void default_end_frame(AVFilterLink *inlink)
+static int default_end_frame(AVFilterLink *inlink)
 {
     AVFilterLink *outlink = NULL;
 
@@ -238,37 +265,32 @@ static void default_end_frame(AVFilterLink *inlink)
         outlink = inlink->dst->outputs[0];
 
     if (outlink) {
-        ff_end_frame(outlink);
+        return ff_end_frame(outlink);
     }
+    return 0;
 }
 
-void ff_end_frame(AVFilterLink *link)
+int ff_end_frame(AVFilterLink *link)
 {
-    void (*end_frame)(AVFilterLink *);
+    int (*end_frame)(AVFilterLink *);
+    int ret;
 
     if (!(end_frame = link->dstpad->end_frame))
         end_frame = default_end_frame;
 
-    end_frame(link);
+    ret = end_frame(link);
 
-    /* unreference the source picture if we're feeding the destination filter
-     * a copied version dues to permission issues */
-    if (link->src_buf) {
-        avfilter_unref_buffer(link->src_buf);
-        link->src_buf = NULL;
-    }
-    if(link->cur_buf != link->out_buf)
-        avfilter_unref_bufferp(&link->cur_buf);
-    link->cur_buf = NULL;
-    avfilter_unref_bufferp(&link->out_buf);
+    clear_link(link);
+
+    return ret;
 }
 
-void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+int ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
-    ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
+    return ff_draw_slice(link->dst->outputs[0], y, h, slice_dir);
 }
 
-static void default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
+static int default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir)
 {
     AVFilterLink *outlink = NULL;
 
@@ -276,14 +298,15 @@ static void default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir
         outlink = inlink->dst->outputs[0];
 
     if (outlink)
-        ff_draw_slice(outlink, y, h, slice_dir);
+        return ff_draw_slice(outlink, y, h, slice_dir);
+    return 0;
 }
 
-void ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
+int ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 {
     uint8_t *src[4], *dst[4];
-    int i, j, vsub;
-    void (*draw_slice)(AVFilterLink *, int, int, int);
+    int i, j, vsub, ret;
+    int (*draw_slice)(AVFilterLink *, int, int, int);
 
     FF_TPRINTF_START(NULL, draw_slice); ff_tlog_link(NULL, link, 0); ff_tlog(NULL, " y:%d h:%d dir:%d\n", y, h, slice_dir);
 
@@ -317,11 +340,14 @@ void ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
 
     if (!(draw_slice = link->dstpad->draw_slice))
         draw_slice = default_draw_slice;
-    draw_slice(link, y, h, slice_dir);
+    ret = draw_slice(link, y, h, slice_dir);
+    if (ret < 0)
+        clear_link(link);
+    return ret;
 }
 
-void avfilter_default_end_frame(AVFilterLink *inlink)
+int avfilter_default_end_frame(AVFilterLink *inlink)
 {
-    default_end_frame(inlink);
+    return default_end_frame(inlink);
 }
 
index 28835b9..e30980e 100644 (file)
@@ -42,9 +42,9 @@ AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w
 AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms,
                                        int w, int h);
 
-void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
-void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
-void ff_null_end_frame(AVFilterLink *link);
+int ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
+int ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
+int ff_null_end_frame(AVFilterLink *link);
 
 /**
  * Notify the next filter of the start of a frame.
@@ -54,20 +54,25 @@ void ff_null_end_frame(AVFilterLink *link);
  *               frame need only be valid once draw_slice() is called for that
  *               portion. The receiving filter will free this reference when
  *               it no longer needs it.
+ *
+ * @return >= 0 on success, a negative AVERROR on error. This function will
+ * unreference picref in case of error.
  */
-void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
+int ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
 
 /**
  * Pass video frame along and keep an internal reference for later use.
  */
-void ff_null_start_frame_keep_ref(AVFilterLink *inlink, AVFilterBufferRef *picref);
+int ff_null_start_frame_keep_ref(AVFilterLink *inlink, AVFilterBufferRef *picref);
 
 /**
  * Notify the next filter that the current frame has finished.
  *
  * @param link the output link the frame was sent over
+ *
+ * @return >= 0 on success, a negative AVERROR on error
  */
-void ff_end_frame(AVFilterLink *link);
+int ff_end_frame(AVFilterLink *link);
 
 /**
  * Send a slice to the next filter.
@@ -83,7 +88,9 @@ void ff_end_frame(AVFilterLink *link);
  *             from the top slice to the bottom slice if the value is 1,
  *             from the bottom slice to the top slice if the value is -1,
  *             for other values the behavior of the function is undefined.
+ *
+ * @return >= 0 on success, a negative AVERROR on error.
  */
-void ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
+int ff_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
 
 #endif /* AVFILTER_VIDEO_H */
index 82d2d32..f6c0460 100644 (file)
 #include "avfilter.h"
 #include "internal.h"
 
-static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
+static int start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
 {
+    return 0;
 }
 
-static void end_frame(AVFilterLink *link)
+static int end_frame(AVFilterLink *link)
 {
+    return 0;
 }
 
 AVFilter avfilter_vsink_nullsink = {
index e9f7424..1f26a50 100644 (file)
@@ -149,18 +149,38 @@ static int color_request_frame(AVFilterLink *link)
 {
     ColorContext *color = link->src->priv;
     AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h);
+    AVFilterBufferRef *buf_out;
+    int ret;
+
+    if (!picref)
+        return AVERROR(ENOMEM);
+
     picref->video->sample_aspect_ratio = (AVRational) {1, 1};
     picref->pts = color->pts++;
     picref->pos = -1;
 
-    ff_start_frame(link, avfilter_ref_buffer(picref, ~0));
+    buf_out = avfilter_ref_buffer(picref, ~0);
+    if (!buf_out) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
+    ret = ff_start_frame(link, buf_out);
+    if (ret < 0)
+        goto fail;
+
     ff_fill_rectangle(&color->draw, &color->color, picref->data, picref->linesize,
                       0, 0, color->w, color->h);
-    ff_draw_slice(link, 0, color->h, 1);
-    ff_end_frame(link);
+    ret = ff_draw_slice(link, 0, color->h, 1);
+    if (ret < 0)
+        goto fail;
+
+    ret = ff_end_frame(link);
+
+fail:
     avfilter_unref_buffer(picref);
 
-    return 0;
+    return ret;
 }
 
 AVFilter avfilter_vsrc_color = {
@@ -174,9 +194,9 @@ AVFilter avfilter_vsrc_color = {
 
     .inputs    = (const AVFilterPad[]) {{ .name = NULL}},
 
-    .outputs   = (const AVFilterPad[]) {{ .name      = "default",
-                                    .type            = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame   = color_request_frame,
-                                    .config_props    = color_config_props },
-                                  { .name = NULL}},
+    .outputs   = (const AVFilterPad[]) {{ .name            = "default",
+                                          .type            = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame   = color_request_frame,
+                                          .config_props    = color_config_props },
+                                        { .name = NULL}},
 };
index e5681c8..7229d4d 100644 (file)
@@ -134,10 +134,14 @@ static int request_frame(AVFilterLink *outlink)
 {
     TestSourceContext *test = outlink->src->priv;
     AVFilterBufferRef *picref;
+    int ret;
 
     if (test->max_pts >= 0 && test->pts >= test->max_pts)
         return AVERROR_EOF;
     picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h);
+    if (!picref)
+        return AVERROR(ENOMEM);
+
     picref->pts = test->pts++;
     picref->pos = -1;
     picref->video->key_frame = 1;
@@ -147,9 +151,10 @@ static int request_frame(AVFilterLink *outlink)
     test->fill_picture_fn(outlink->src, picref);
     test->nb_frame++;
 
-    ff_start_frame(outlink, picref);
-    ff_draw_slice(outlink, 0, test->h, 1);
-    ff_end_frame(outlink);
+    if ((ret = ff_start_frame(outlink, picref)) < 0 ||
+        (ret = ff_draw_slice(outlink, 0, test->h, 1)) < 0 ||
+        (ret = ff_end_frame(outlink)) < 0)
+        return ret;
 
     return 0;
 }
@@ -401,10 +406,10 @@ AVFilter avfilter_vsrc_testsrc = {
     .inputs    = (const AVFilterPad[]) {{ .name = NULL}},
 
     .outputs   = (const AVFilterPad[]) {{ .name = "default",
-                                    .type = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame = request_frame,
-                                    .config_props  = config_props, },
-                                  { .name = NULL }},
+                                          .type = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame = request_frame,
+                                          .config_props  = config_props, },
+                                        { .name = NULL }},
 };
 
 #endif /* CONFIG_TESTSRC_FILTER */
@@ -525,10 +530,10 @@ AVFilter avfilter_vsrc_rgbtestsrc = {
     .inputs    = (const AVFilterPad[]) {{ .name = NULL}},
 
     .outputs   = (const AVFilterPad[]) {{ .name = "default",
-                                    .type = AVMEDIA_TYPE_VIDEO,
-                                    .request_frame = request_frame,
-                                    .config_props  = rgbtest_config_props, },
-                                  { .name = NULL }},
+                                          .type = AVMEDIA_TYPE_VIDEO,
+                                          .request_frame = request_frame,
+                                          .config_props  = rgbtest_config_props, },
+                                        { .name = NULL }},
 };
 
 #endif /* CONFIG_RGBTESTSRC_FILTER */
index 1e0fd07..388283f 100644 (file)
  * G.723.1 demuxer
  */
 
+#include "libavutil/audioconvert.h"
 #include "avformat.h"
 #include "internal.h"
 
-static const uint8_t frame_size[4] = {24, 20, 4, 1};
+static const uint8_t frame_size[4] = { 24, 20, 4, 1 };
 
 static int g723_1_init(AVFormatContext *s)
 {
@@ -37,12 +38,14 @@ static int g723_1_init(AVFormatContext *s)
     if (!st)
         return AVERROR(ENOMEM);
 
-    st->codec->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codec->codec_id    = CODEC_ID_G723_1;
-    st->codec->channels    = 1;
-    st->codec->sample_rate = 8000;
+    st->codec->codec_type     = AVMEDIA_TYPE_AUDIO;
+    st->codec->codec_id       = CODEC_ID_G723_1;
+    st->codec->channel_layout = AV_CH_LAYOUT_MONO;
+    st->codec->channels       = 1;
+    st->codec->sample_rate    = 8000;
 
     avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
+    st->start_time = 0;
 
     return 0;
 }
@@ -77,6 +80,6 @@ AVInputFormat ff_g723_1_demuxer = {
     .long_name   = NULL_IF_CONFIG_SMALL("G.723.1 format"),
     .read_header = g723_1_init,
     .read_packet = g723_1_read_packet,
-    .extensions = "tco,rco,g723_1",
-    .flags = AVFMT_GENERIC_INDEX
+    .extensions  = "tco,rco,g723_1",
+    .flags       = AVFMT_GENERIC_INDEX
 };
index 42aa961..bb61042 100644 (file)
@@ -656,8 +656,9 @@ static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb,
             av_log(matroska->ctx, AV_LOG_ERROR,
                    "Read error at pos. %"PRIu64" (0x%"PRIx64")\n",
                    pos, pos);
+            return pb->error ? pb->error : AVERROR(EIO);
         }
-        return AVERROR(EIO); /* EOS or actual I/O error */
+        return AVERROR_EOF;
     }
 
     /* get the length of the EBML number */
index 0b977a4..43af99e 100644 (file)
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFORMAT_VERSION_MAJOR 54
-#define LIBAVFORMAT_VERSION_MINOR 18
+#define LIBAVFORMAT_VERSION_MINOR 19
 #define LIBAVFORMAT_VERSION_MICRO 100
 
 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
index 9b52f07..d9afb30 100644 (file)
@@ -54,6 +54,7 @@ include $(SRC_PATH)/tests/fate/demux.mak
 include $(SRC_PATH)/tests/fate/dfa.mak
 include $(SRC_PATH)/tests/fate/dpcm.mak
 include $(SRC_PATH)/tests/fate/ea.mak
+include $(SRC_PATH)/tests/fate/filter.mak
 include $(SRC_PATH)/tests/fate/flac.mak
 include $(SRC_PATH)/tests/fate/fft.mak
 include $(SRC_PATH)/tests/fate/h264.mak
diff --git a/tests/fate/filter.mak b/tests/fate/filter.mak
new file mode 100644 (file)
index 0000000..cd309ab
--- /dev/null
@@ -0,0 +1,10 @@
+FATE_ASYNCTS += fate-filter-asyncts
+fate-filter-asyncts: SRC = $(SAMPLES)/nellymoser/nellymoser-discont.flv
+fate-filter-asyncts: CMD = pcm -i $(SRC) -af aresample=min_comp=0.001:min_hard_comp=0.1
+fate-filter-asyncts: CMP = oneoff
+fate-filter-asyncts: REF = $(SAMPLES)/nellymoser/nellymoser-discont.pcm
+
+FATE_FILTER += $(FATE_ASYNCTS)
+FATE_SAMPLES_AVCONV += $(FATE_ASYNCTS)
+
+fate-filter: $(FATE_FILTER)