Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
vsrc_buffer: fix check from 7ae7c41.
libxvid: Reorder functions to avoid forward declarations; make functions static.
libxvid: drop some pointless dead code
wmal: vertical alignment cosmetics
wmal: Warn about missing bitstream splicing feature and ask for sample.
wmal: Skip seekable_frame_in_packet.
wmal: Drop unused variable num_possible_block_size.
avfiltergraph: make the AVFilterInOut alloc/free API public
graphparser: allow specifying sws flags in the graph description.
graphparser: fix the order of connecting unlabeled links.
graphparser: add avfilter_graph_parse2().
vsrc_buffer: allow using a NULL buffer to signal EOF.
swscale: handle last pixel if lines have an odd width.
qdm2: fix a dubious pointer cast
WMAL: Do not try to read rawpcm coefficients if bits is invalid
mov: Fix detecting there is no sync sample.
tiffdec: K&R cosmetics
avf: has_duration does not check the global one
dsputil: fix optimized emu_edge function on Win64.

Conflicts:
doc/APIchanges
libavcodec/libxvid_rc.c
libavcodec/libxvidff.c
libavcodec/tiff.c
libavcodec/wmalosslessdec.c
libavfilter/avfiltergraph.h
libavfilter/graphparser.c
libavfilter/version.h
libavfilter/vsrc_buffer.c
libswscale/output.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/04/15 04:49:01
Showing 18 changed files
... ...
@@ -19,6 +19,9 @@ API changes, most recent first:
19 19
 2012-03-26 - a67d9cf - lavfi 2.66.100
20 20
   Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
21 21
 
22
+2012-xx-xx - xxxxxxx - lavfi 2.16.0 - avfiltergraph.h
23
+  Add avfilter_graph_parse2()
24
+
22 25
 2012-xx-xx - xxxxxxx - lavu 51.27.0 - samplefmt.h
23 26
   Add av_get_packed_sample_fmt() and av_get_planar_sample_fmt()
24 27
 
... ...
@@ -76,6 +76,12 @@ In a complete filterchain all the unlabelled filter input and output
76 76
 pads must be connected. A filtergraph is considered valid if all the
77 77
 filter input and output pads of all the filterchains are connected.
78 78
 
79
+Libavfilter will automatically insert scale filters where format
80
+conversion is required. It is possible to specify swscale flags
81
+for those automatically inserted scalers by prepending
82
+@code{sws_flags=@var{flags};}
83
+to the filtergraph description.
84
+
79 85
 Follows a BNF description for the filtergraph syntax:
80 86
 @example
81 87
 @var{NAME}             ::= sequence of alphanumeric characters and '_'
... ...
@@ -84,7 +90,7 @@ Follows a BNF description for the filtergraph syntax:
84 84
 @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted)
85 85
 @var{FILTER}           ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}]
86 86
 @var{FILTERCHAIN}      ::= @var{FILTER} [,@var{FILTERCHAIN}]
87
-@var{FILTERGRAPH}      ::= @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
87
+@var{FILTERGRAPH}      ::= [sws_flags=@var{flags};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
88 88
 @end example
89 89
 
90 90
 @c man end FILTERGRAPH DESCRIPTION
... ...
@@ -31,16 +31,12 @@
31 31
 #undef NDEBUG
32 32
 #include <assert.h>
33 33
 
34
-extern unsigned int xvid_debug;
35
-
36 34
 int ff_xvid_rate_control_init(MpegEncContext *s){
37 35
     char *tmp_name;
38 36
     int fd, i;
39 37
     xvid_plg_create_t xvid_plg_create = { 0 };
40 38
     xvid_plugin_2pass2_t xvid_2pass2  = { 0 };
41 39
 
42
-//xvid_debug=-1;
43
-
44 40
     fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx);
45 41
     if (fd == -1) {
46 42
         av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n");
... ...
@@ -58,7 +54,6 @@ int ff_xvid_rate_control_init(MpegEncContext *s){
58 58
             frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
59 59
             rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
60 60
 
61
-//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp);
62 61
         if (write(fd, tmp, strlen(tmp)) < 0) {
63 62
             av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno));
64 63
             return AVERROR(errno);
... ...
@@ -72,11 +72,276 @@ struct xvid_ff_pass1 {
72 72
     struct xvid_context *context;   /**< Pointer to private context */
73 73
 };
74 74
 
75
-/* Prototypes - See function implementation for details */
76
-int xvid_strip_vol_header(AVCodecContext *avctx, AVPacket *pkt, unsigned int header_len, unsigned int frame_len);
77
-int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2);
78
-void xvid_correct_framerate(AVCodecContext *avctx);
75
+/*
76
+ * Xvid 2-Pass Kludge Section
77
+ *
78
+ * Xvid's default 2-pass doesn't allow us to create data as we need to, so
79
+ * this section spends time replacing the first pass plugin so we can write
80
+ * statistic information as libavcodec requests in. We have another kludge
81
+ * that allows us to pass data to the second pass in Xvid without a custom
82
+ * rate-control plugin.
83
+ */
84
+
85
+
86
+/**
87
+ * Initialize the two-pass plugin and context.
88
+ *
89
+ * @param param Input construction parameter structure
90
+ * @param handle Private context handle
91
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success.
92
+ */
93
+static int xvid_ff_2pass_create(xvid_plg_create_t * param,
94
+                                void ** handle) {
95
+    struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *)param->param;
96
+    char *log = x->context->twopassbuffer;
97
+
98
+    /* Do a quick bounds check */
99
+    if( log == NULL )
100
+        return XVID_ERR_FAIL;
101
+
102
+    /* We use snprintf() */
103
+    /* This is because we can safely prevent a buffer overflow */
104
+    log[0] = 0;
105
+    snprintf(log, BUFFER_REMAINING(log),
106
+        "# ffmpeg 2-pass log file, using xvid codec\n");
107
+    snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
108
+        "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
109
+        XVID_VERSION_MAJOR(XVID_VERSION),
110
+        XVID_VERSION_MINOR(XVID_VERSION),
111
+        XVID_VERSION_PATCH(XVID_VERSION));
112
+
113
+    *handle = x->context;
114
+    return 0;
115
+}
116
+
117
+/**
118
+ * Destroy the two-pass plugin context.
119
+ *
120
+ * @param ref Context pointer for the plugin
121
+ * @param param Destrooy context
122
+ * @return Returns 0, success guaranteed
123
+ */
124
+static int xvid_ff_2pass_destroy(struct xvid_context *ref,
125
+                                xvid_plg_destroy_t *param) {
126
+    /* Currently cannot think of anything to do on destruction */
127
+    /* Still, the framework should be here for reference/use */
128
+    if( ref->twopassbuffer != NULL )
129
+        ref->twopassbuffer[0] = 0;
130
+    return 0;
131
+}
132
+
133
+/**
134
+ * Enable fast encode mode during the first pass.
135
+ *
136
+ * @param ref Context pointer for the plugin
137
+ * @param param Frame data
138
+ * @return Returns 0, success guaranteed
139
+ */
140
+static int xvid_ff_2pass_before(struct xvid_context *ref,
141
+                                xvid_plg_data_t *param) {
142
+    int motion_remove;
143
+    int motion_replacements;
144
+    int vop_remove;
145
+
146
+    /* Nothing to do here, result is changed too much */
147
+    if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
148
+        return 0;
149
+
150
+    /* We can implement a 'turbo' first pass mode here */
151
+    param->quant = 2;
152
+
153
+    /* Init values */
154
+    motion_remove = ~XVID_ME_CHROMA_PVOP &
155
+                    ~XVID_ME_CHROMA_BVOP &
156
+                    ~XVID_ME_EXTSEARCH16 &
157
+                    ~XVID_ME_ADVANCEDDIAMOND16;
158
+    motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
159
+                          XVID_ME_SKIP_DELTASEARCH |
160
+                          XVID_ME_FASTREFINE16 |
161
+                          XVID_ME_BFRAME_EARLYSTOP;
162
+    vop_remove = ~XVID_VOP_MODEDECISION_RD &
163
+                 ~XVID_VOP_FAST_MODEDECISION_RD &
164
+                 ~XVID_VOP_TRELLISQUANT &
165
+                 ~XVID_VOP_INTER4V &
166
+                 ~XVID_VOP_HQACPRED;
167
+
168
+    param->vol_flags &= ~XVID_VOL_GMC;
169
+    param->vop_flags &= vop_remove;
170
+    param->motion_flags &= motion_remove;
171
+    param->motion_flags |= motion_replacements;
172
+
173
+    return 0;
174
+}
175
+
176
+/**
177
+ * Capture statistic data and write it during first pass.
178
+ *
179
+ * @param ref Context pointer for the plugin
180
+ * @param param Statistic data
181
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success
182
+ */
183
+static int xvid_ff_2pass_after(struct xvid_context *ref,
184
+                                xvid_plg_data_t *param) {
185
+    char *log = ref->twopassbuffer;
186
+    const char *frame_types = " ipbs";
187
+    char frame_type;
188
+
189
+    /* Quick bounds check */
190
+    if( log == NULL )
191
+        return XVID_ERR_FAIL;
192
+
193
+    /* Convert the type given to us into a character */
194
+    if( param->type < 5 && param->type > 0 ) {
195
+        frame_type = frame_types[param->type];
196
+    } else {
197
+        return XVID_ERR_FAIL;
198
+    }
199
+
200
+    snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
201
+        "%c %d %d %d %d %d %d\n",
202
+        frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
203
+        param->stats.ublks, param->stats.length, param->stats.hlength);
204
+
205
+    return 0;
206
+}
207
+
208
+/**
209
+ * Dispatch function for our custom plugin.
210
+ * This handles the dispatch for the Xvid plugin. It passes data
211
+ * on to other functions for actual processing.
212
+ *
213
+ * @param ref Context pointer for the plugin
214
+ * @param cmd The task given for us to complete
215
+ * @param p1 First parameter (varies)
216
+ * @param p2 Second parameter (varies)
217
+ * @return Returns XVID_ERR_xxxx on failure, or 0 on success
218
+ */
219
+static int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2)
220
+{
221
+    switch( cmd ) {
222
+        case XVID_PLG_INFO:
223
+        case XVID_PLG_FRAME:
224
+            return 0;
225
+
226
+        case XVID_PLG_BEFORE:
227
+            return xvid_ff_2pass_before(ref, p1);
228
+
229
+        case XVID_PLG_CREATE:
230
+            return xvid_ff_2pass_create(p1, p2);
79 231
 
232
+        case XVID_PLG_AFTER:
233
+            return xvid_ff_2pass_after(ref, p1);
234
+
235
+        case XVID_PLG_DESTROY:
236
+            return xvid_ff_2pass_destroy(ref, p1);
237
+
238
+        default:
239
+            return XVID_ERR_FAIL;
240
+    }
241
+}
242
+
243
+/**
244
+ * Routine to create a global VO/VOL header for MP4 container.
245
+ * What we do here is extract the header from the Xvid bitstream
246
+ * as it is encoded. We also strip the repeated headers from the
247
+ * bitstream when a global header is requested for MPEG-4 ISO
248
+ * compliance.
249
+ *
250
+ * @param avctx AVCodecContext pointer to context
251
+ * @param frame Pointer to encoded frame data
252
+ * @param header_len Length of header to search
253
+ * @param frame_len Length of encoded frame data
254
+ * @return Returns new length of frame data
255
+ */
256
+static int xvid_strip_vol_header(AVCodecContext *avctx,
257
+                  AVPacket *pkt,
258
+                  unsigned int header_len,
259
+                  unsigned int frame_len) {
260
+    int vo_len = 0, i;
261
+
262
+    for( i = 0; i < header_len - 3; i++ ) {
263
+        if( pkt->data[i] == 0x00 &&
264
+            pkt->data[i+1] == 0x00 &&
265
+            pkt->data[i+2] == 0x01 &&
266
+            pkt->data[i+3] == 0xB6 ) {
267
+            vo_len = i;
268
+            break;
269
+        }
270
+    }
271
+
272
+    if( vo_len > 0 ) {
273
+        /* We need to store the header, so extract it */
274
+        if( avctx->extradata == NULL ) {
275
+            avctx->extradata = av_malloc(vo_len);
276
+            memcpy(avctx->extradata, pkt->data, vo_len);
277
+            avctx->extradata_size = vo_len;
278
+        }
279
+        /* Less dangerous now, memmove properly copies the two
280
+           chunks of overlapping data */
281
+        memmove(pkt->data, &pkt->data[vo_len], frame_len - vo_len);
282
+        pkt->size = frame_len - vo_len;
283
+    }
284
+    return 0;
285
+}
286
+
287
+/**
288
+ * Routine to correct a possibly erroneous framerate being fed to us.
289
+ * Xvid currently chokes on framerates where the ticks per frame is
290
+ * extremely large. This function works to correct problems in this area
291
+ * by estimating a new framerate and taking the simpler fraction of
292
+ * the two presented.
293
+ *
294
+ * @param avctx Context that contains the framerate to correct.
295
+ */
296
+static void xvid_correct_framerate(AVCodecContext *avctx)
297
+{
298
+    int frate, fbase;
299
+    int est_frate, est_fbase;
300
+    int gcd;
301
+    float est_fps, fps;
302
+
303
+    frate = avctx->time_base.den;
304
+    fbase = avctx->time_base.num;
305
+
306
+    gcd = av_gcd(frate, fbase);
307
+    if( gcd > 1 ) {
308
+        frate /= gcd;
309
+        fbase /= gcd;
310
+    }
311
+
312
+    if( frate <= 65000 && fbase <= 65000 ) {
313
+        avctx->time_base.den = frate;
314
+        avctx->time_base.num = fbase;
315
+        return;
316
+    }
317
+
318
+    fps = (float)frate / (float)fbase;
319
+    est_fps = roundf(fps * 1000.0) / 1000.0;
320
+
321
+    est_frate = (int)est_fps;
322
+    if( est_fps > (int)est_fps ) {
323
+        est_frate = (est_frate + 1) * 1000;
324
+        est_fbase = (int)roundf((float)est_frate / est_fps);
325
+    } else
326
+        est_fbase = 1;
327
+
328
+    gcd = av_gcd(est_frate, est_fbase);
329
+    if( gcd > 1 ) {
330
+        est_frate /= gcd;
331
+        est_fbase /= gcd;
332
+    }
333
+
334
+    if( fbase > est_fbase ) {
335
+        avctx->time_base.den = est_frate;
336
+        avctx->time_base.num = est_fbase;
337
+        av_log(avctx, AV_LOG_DEBUG,
338
+            "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
339
+            est_fps, (((est_fps - fps)/fps) * 100.0));
340
+    } else {
341
+        avctx->time_base.den = frate;
342
+        avctx->time_base.num = fbase;
343
+    }
344
+}
80 345
 
81 346
 /**
82 347
  * Create the private context for the encoder.
... ...
@@ -509,274 +774,6 @@ static av_cold int xvid_encode_close(AVCodecContext *avctx) {
509 509
 }
510 510
 
511 511
 /**
512
- * Routine to create a global VO/VOL header for MP4 container.
513
- * What we do here is extract the header from the Xvid bitstream
514
- * as it is encoded. We also strip the repeated headers from the
515
- * bitstream when a global header is requested for MPEG-4 ISO
516
- * compliance.
517
- *
518
- * @param avctx AVCodecContext pointer to context
519
- * @param frame Pointer to encoded frame data
520
- * @param header_len Length of header to search
521
- * @param frame_len Length of encoded frame data
522
- * @return Returns new length of frame data
523
- */
524
-int xvid_strip_vol_header(AVCodecContext *avctx,
525
-                  AVPacket *pkt,
526
-                  unsigned int header_len,
527
-                  unsigned int frame_len) {
528
-    int vo_len = 0, i;
529
-
530
-    for( i = 0; i < header_len - 3; i++ ) {
531
-        if( pkt->data[i] == 0x00 &&
532
-            pkt->data[i+1] == 0x00 &&
533
-            pkt->data[i+2] == 0x01 &&
534
-            pkt->data[i+3] == 0xB6 ) {
535
-            vo_len = i;
536
-            break;
537
-        }
538
-    }
539
-
540
-    if( vo_len > 0 ) {
541
-        /* We need to store the header, so extract it */
542
-        if( avctx->extradata == NULL ) {
543
-            avctx->extradata = av_malloc(vo_len);
544
-            memcpy(avctx->extradata, pkt->data, vo_len);
545
-            avctx->extradata_size = vo_len;
546
-        }
547
-        /* Less dangerous now, memmove properly copies the two
548
-           chunks of overlapping data */
549
-        memmove(pkt->data, &pkt->data[vo_len], frame_len - vo_len);
550
-        pkt->size = frame_len - vo_len;
551
-    }
552
-    return 0;
553
-}
554
-
555
-/**
556
- * Routine to correct a possibly erroneous framerate being fed to us.
557
- * Xvid currently chokes on framerates where the ticks per frame is
558
- * extremely large. This function works to correct problems in this area
559
- * by estimating a new framerate and taking the simpler fraction of
560
- * the two presented.
561
- *
562
- * @param avctx Context that contains the framerate to correct.
563
- */
564
-void xvid_correct_framerate(AVCodecContext *avctx) {
565
-    int frate, fbase;
566
-    int est_frate, est_fbase;
567
-    int gcd;
568
-    float est_fps, fps;
569
-
570
-    frate = avctx->time_base.den;
571
-    fbase = avctx->time_base.num;
572
-
573
-    gcd = av_gcd(frate, fbase);
574
-    if( gcd > 1 ) {
575
-        frate /= gcd;
576
-        fbase /= gcd;
577
-    }
578
-
579
-    if( frate <= 65000 && fbase <= 65000 ) {
580
-        avctx->time_base.den = frate;
581
-        avctx->time_base.num = fbase;
582
-        return;
583
-    }
584
-
585
-    fps = (float)frate / (float)fbase;
586
-    est_fps = roundf(fps * 1000.0) / 1000.0;
587
-
588
-    est_frate = (int)est_fps;
589
-    if( est_fps > (int)est_fps ) {
590
-        est_frate = (est_frate + 1) * 1000;
591
-        est_fbase = (int)roundf((float)est_frate / est_fps);
592
-    } else
593
-        est_fbase = 1;
594
-
595
-    gcd = av_gcd(est_frate, est_fbase);
596
-    if( gcd > 1 ) {
597
-        est_frate /= gcd;
598
-        est_fbase /= gcd;
599
-    }
600
-
601
-    if( fbase > est_fbase ) {
602
-        avctx->time_base.den = est_frate;
603
-        avctx->time_base.num = est_fbase;
604
-        av_log(avctx, AV_LOG_DEBUG,
605
-            "Xvid: framerate re-estimated: %.2f, %.3f%% correction\n",
606
-            est_fps, (((est_fps - fps)/fps) * 100.0));
607
-    } else {
608
-        avctx->time_base.den = frate;
609
-        avctx->time_base.num = fbase;
610
-    }
611
-}
612
-
613
-/*
614
- * Xvid 2-Pass Kludge Section
615
- *
616
- * Xvid's default 2-pass doesn't allow us to create data as we need to, so
617
- * this section spends time replacing the first pass plugin so we can write
618
- * statistic information as libavcodec requests in. We have another kludge
619
- * that allows us to pass data to the second pass in Xvid without a custom
620
- * rate-control plugin.
621
- */
622
-
623
-/**
624
- * Initialize the two-pass plugin and context.
625
- *
626
- * @param param Input construction parameter structure
627
- * @param handle Private context handle
628
- * @return Returns XVID_ERR_xxxx on failure, or 0 on success.
629
- */
630
-static int xvid_ff_2pass_create(xvid_plg_create_t * param,
631
-                                void ** handle) {
632
-    struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *)param->param;
633
-    char *log = x->context->twopassbuffer;
634
-
635
-    /* Do a quick bounds check */
636
-    if( log == NULL )
637
-        return XVID_ERR_FAIL;
638
-
639
-    /* We use snprintf() */
640
-    /* This is because we can safely prevent a buffer overflow */
641
-    log[0] = 0;
642
-    snprintf(log, BUFFER_REMAINING(log),
643
-        "# ffmpeg 2-pass log file, using xvid codec\n");
644
-    snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
645
-        "# Do not modify. libxvidcore version: %d.%d.%d\n\n",
646
-        XVID_VERSION_MAJOR(XVID_VERSION),
647
-        XVID_VERSION_MINOR(XVID_VERSION),
648
-        XVID_VERSION_PATCH(XVID_VERSION));
649
-
650
-    *handle = x->context;
651
-    return 0;
652
-}
653
-
654
-/**
655
- * Destroy the two-pass plugin context.
656
- *
657
- * @param ref Context pointer for the plugin
658
- * @param param Destrooy context
659
- * @return Returns 0, success guaranteed
660
- */
661
-static int xvid_ff_2pass_destroy(struct xvid_context *ref,
662
-                                xvid_plg_destroy_t *param) {
663
-    /* Currently cannot think of anything to do on destruction */
664
-    /* Still, the framework should be here for reference/use */
665
-    if( ref->twopassbuffer != NULL )
666
-        ref->twopassbuffer[0] = 0;
667
-    return 0;
668
-}
669
-
670
-/**
671
- * Enable fast encode mode during the first pass.
672
- *
673
- * @param ref Context pointer for the plugin
674
- * @param param Frame data
675
- * @return Returns 0, success guaranteed
676
- */
677
-static int xvid_ff_2pass_before(struct xvid_context *ref,
678
-                                xvid_plg_data_t *param) {
679
-    int motion_remove;
680
-    int motion_replacements;
681
-    int vop_remove;
682
-
683
-    /* Nothing to do here, result is changed too much */
684
-    if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
685
-        return 0;
686
-
687
-    /* We can implement a 'turbo' first pass mode here */
688
-    param->quant = 2;
689
-
690
-    /* Init values */
691
-    motion_remove = ~XVID_ME_CHROMA_PVOP &
692
-                    ~XVID_ME_CHROMA_BVOP &
693
-                    ~XVID_ME_EXTSEARCH16 &
694
-                    ~XVID_ME_ADVANCEDDIAMOND16;
695
-    motion_replacements = XVID_ME_FAST_MODEINTERPOLATE |
696
-                          XVID_ME_SKIP_DELTASEARCH |
697
-                          XVID_ME_FASTREFINE16 |
698
-                          XVID_ME_BFRAME_EARLYSTOP;
699
-    vop_remove = ~XVID_VOP_MODEDECISION_RD &
700
-                 ~XVID_VOP_FAST_MODEDECISION_RD &
701
-                 ~XVID_VOP_TRELLISQUANT &
702
-                 ~XVID_VOP_INTER4V &
703
-                 ~XVID_VOP_HQACPRED;
704
-
705
-    param->vol_flags &= ~XVID_VOL_GMC;
706
-    param->vop_flags &= vop_remove;
707
-    param->motion_flags &= motion_remove;
708
-    param->motion_flags |= motion_replacements;
709
-
710
-    return 0;
711
-}
712
-
713
-/**
714
- * Capture statistic data and write it during first pass.
715
- *
716
- * @param ref Context pointer for the plugin
717
- * @param param Statistic data
718
- * @return Returns XVID_ERR_xxxx on failure, or 0 on success
719
- */
720
-static int xvid_ff_2pass_after(struct xvid_context *ref,
721
-                                xvid_plg_data_t *param) {
722
-    char *log = ref->twopassbuffer;
723
-    const char *frame_types = " ipbs";
724
-    char frame_type;
725
-
726
-    /* Quick bounds check */
727
-    if( log == NULL )
728
-        return XVID_ERR_FAIL;
729
-
730
-    /* Convert the type given to us into a character */
731
-    if( param->type < 5 && param->type > 0 ) {
732
-        frame_type = frame_types[param->type];
733
-    } else {
734
-        return XVID_ERR_FAIL;
735
-    }
736
-
737
-    snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log),
738
-        "%c %d %d %d %d %d %d\n",
739
-        frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks,
740
-        param->stats.ublks, param->stats.length, param->stats.hlength);
741
-
742
-    return 0;
743
-}
744
-
745
-/**
746
- * Dispatch function for our custom plugin.
747
- * This handles the dispatch for the Xvid plugin. It passes data
748
- * on to other functions for actual processing.
749
- *
750
- * @param ref Context pointer for the plugin
751
- * @param cmd The task given for us to complete
752
- * @param p1 First parameter (varies)
753
- * @param p2 Second parameter (varies)
754
- * @return Returns XVID_ERR_xxxx on failure, or 0 on success
755
- */
756
-int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) {
757
-    switch( cmd ) {
758
-        case XVID_PLG_INFO:
759
-        case XVID_PLG_FRAME:
760
-            return 0;
761
-
762
-        case XVID_PLG_BEFORE:
763
-            return xvid_ff_2pass_before(ref, p1);
764
-
765
-        case XVID_PLG_CREATE:
766
-            return xvid_ff_2pass_create(p1, p2);
767
-
768
-        case XVID_PLG_AFTER:
769
-            return xvid_ff_2pass_after(ref, p1);
770
-
771
-        case XVID_PLG_DESTROY:
772
-            return xvid_ff_2pass_destroy(ref, p1);
773
-
774
-        default:
775
-            return XVID_ERR_FAIL;
776
-    }
777
-}
778
-
779
-/**
780 512
  * Xvid codec definition for libavcodec.
781 513
  */
782 514
 AVCodec ff_libxvid_encoder = {
... ...
@@ -140,7 +140,6 @@ typedef struct {
140 140
     /// Parameters built from header parameters, do not change during playback
141 141
     int group_order;         ///< order of frame group
142 142
     int fft_order;           ///< order of FFT (actually fftorder+1)
143
-    int fft_frame_size;      ///< size of fft frame, in components (1 comples = re + im)
144 143
     int frame_size;          ///< size of data frame
145 144
     int frequency_range;
146 145
     int sub_sampling;        ///< subsampling: 0=25%, 1=50%, 2=100% */
... ...
@@ -1607,13 +1606,17 @@ static void qdm2_fft_tone_synthesizer (QDM2Context *q, int sub_packet)
1607 1607
 static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet)
1608 1608
 {
1609 1609
     const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
1610
+    float *out = q->output_buffer + channel;
1610 1611
     int i;
1611 1612
     q->fft.complex[channel][0].re *= 2.0f;
1612 1613
     q->fft.complex[channel][0].im = 0.0f;
1613 1614
     q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
1614 1615
     /* add samples to output buffer */
1615
-    for (i = 0; i < ((q->fft_frame_size + 15) & ~15); i++)
1616
-        q->output_buffer[q->channels * i + channel] += ((float *) q->fft.complex[channel])[i] * gain;
1616
+    for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
1617
+        out[0]           += q->fft.complex[channel][i].re * gain;
1618
+        out[q->channels] += q->fft.complex[channel][i].im * gain;
1619
+        out += 2 * q->channels;
1620
+    }
1617 1621
 }
1618 1622
 
1619 1623
 
... ...
@@ -1688,7 +1691,6 @@ static void dump_context(QDM2Context *q)
1688 1688
     PRINT("checksum_size",q->checksum_size);
1689 1689
     PRINT("channels",q->channels);
1690 1690
     PRINT("nb_channels",q->nb_channels);
1691
-    PRINT("fft_frame_size",q->fft_frame_size);
1692 1691
     PRINT("fft_size",q->fft_size);
1693 1692
     PRINT("sub_sampling",q->sub_sampling);
1694 1693
     PRINT("fft_order",q->fft_order);
... ...
@@ -1843,7 +1845,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx)
1843 1843
     }
1844 1844
 
1845 1845
     s->fft_order = av_log2(s->fft_size) + 1;
1846
-    s->fft_frame_size = 2 * s->fft_size; // complex has two floats
1847 1846
 
1848 1847
     // something like max decodable tones
1849 1848
     s->group_order = av_log2(s->group_size) + 1;
... ...
@@ -52,35 +52,39 @@ typedef struct TiffContext {
52 52
 
53 53
     int strips, rps, sstype;
54 54
     int sot;
55
-    const uint8_t* stripdata;
56
-    const uint8_t* stripsizes;
55
+    const uint8_t *stripdata;
56
+    const uint8_t *stripsizes;
57 57
     int stripsize, stripoff;
58 58
     LZWState *lzw;
59 59
 } TiffContext;
60 60
 
61
-static unsigned tget_short(const uint8_t **p, int le) {
61
+static unsigned tget_short(const uint8_t **p, int le)
62
+{
62 63
     unsigned v = le ? AV_RL16(*p) : AV_RB16(*p);
63 64
     *p += 2;
64 65
     return v;
65 66
 }
66 67
 
67
-static unsigned tget_long(const uint8_t **p, int le) {
68
+static unsigned tget_long(const uint8_t **p, int le)
69
+{
68 70
     unsigned v = le ? AV_RL32(*p) : AV_RB32(*p);
69 71
     *p += 4;
70 72
     return v;
71 73
 }
72 74
 
73
-static unsigned tget(const uint8_t **p, int type, int le) {
74
-    switch(type){
75
+static unsigned tget(const uint8_t **p, int type, int le)
76
+{
77
+    switch (type) {
75 78
     case TIFF_BYTE : return *(*p)++;
76 79
     case TIFF_SHORT: return tget_short(p, le);
77
-    case TIFF_LONG : return tget_long (p, le);
80
+    case TIFF_LONG : return tget_long(p, le);
78 81
     default        : return UINT_MAX;
79 82
     }
80 83
 }
81 84
 
82 85
 #if CONFIG_ZLIB
83
-static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src, int size)
86
+static int tiff_uncompress(uint8_t *dst, unsigned long *len, const uint8_t *src,
87
+                           int size)
84 88
 {
85 89
     z_stream zstream = { 0 };
86 90
     int zret;
... ...
@@ -141,7 +145,9 @@ static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst,
141 141
     }
142 142
 }
143 143
 
144
-static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){
144
+static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
145
+                             const uint8_t *src, int size, int lines)
146
+{
145 147
     int c, line, pixels, code;
146 148
     const uint8_t *ssrc = src;
147 149
     int width = ((s->width * s->bpp) + 7) >> 3;
... ...
@@ -150,21 +156,24 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
150 150
         return AVERROR_INVALIDDATA;
151 151
 
152 152
 #if CONFIG_ZLIB
153
-    if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){
154
-        uint8_t *zbuf; unsigned long outlen;
153
+    if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
154
+        uint8_t *zbuf;
155
+        unsigned long outlen;
155 156
         int ret;
156 157
         outlen = width * lines;
157 158
         zbuf = av_malloc(outlen);
158 159
         if (!zbuf)
159 160
             return AVERROR(ENOMEM);
160 161
         ret = tiff_uncompress(zbuf, &outlen, src, size);
161
-        if(ret != Z_OK){
162
-            av_log(s->avctx, AV_LOG_ERROR, "Uncompressing failed (%lu of %lu) with error %d\n", outlen, (unsigned long)width * lines, ret);
162
+        if (ret != Z_OK) {
163
+            av_log(s->avctx, AV_LOG_ERROR,
164
+                   "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
165
+                   (unsigned long)width * lines, ret);
163 166
             av_free(zbuf);
164 167
             return -1;
165 168
         }
166 169
         src = zbuf;
167
-        for(line = 0; line < lines; line++){
170
+        for (line = 0; line < lines; line++) {
168 171
             if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){
169 172
                 horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
170 173
             }else{
... ...
@@ -177,37 +186,42 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
177 177
         return 0;
178 178
     }
179 179
 #endif
180
-    if(s->compr == TIFF_LZW){
181
-        if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){
180
+    if (s->compr == TIFF_LZW) {
181
+        if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) {
182 182
             av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
183 183
             return -1;
184 184
         }
185 185
     }
186
-    if(s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 || s->compr == TIFF_G4){
186
+    if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
187
+        || s->compr == TIFF_G4) {
187 188
         int i, ret = 0;
188
-        uint8_t *src2 = av_malloc((unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE);
189
+        uint8_t *src2 = av_malloc((unsigned)size +
190
+                                  FF_INPUT_BUFFER_PADDING_SIZE);
189 191
 
190 192
         if (!src2) {
191
-            av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
193
+            av_log(s->avctx, AV_LOG_ERROR,
194
+                   "Error allocating temporary buffer\n");
192 195
             return AVERROR(ENOMEM);
193 196
         }
194
-        if(s->fax_opts & 2){
195
-            av_log(s->avctx, AV_LOG_ERROR, "Uncompressed fax mode is not supported (yet)\n");
197
+        if (s->fax_opts & 2) {
198
+            av_log(s->avctx, AV_LOG_ERROR,
199
+                   "Uncompressed fax mode is not supported (yet)\n");
196 200
             av_free(src2);
197 201
             return -1;
198 202
         }
199
-        if(!s->fill_order){
203
+        if (!s->fill_order) {
200 204
             memcpy(src2, src, size);
201
-        }else{
202
-            for(i = 0; i < size; i++)
205
+        } else {
206
+            for (i = 0; i < size; i++)
203 207
                 src2[i] = av_reverse[src[i]];
204 208
         }
205
-        memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
206
-        switch(s->compr){
209
+        memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
210
+        switch (s->compr) {
207 211
         case TIFF_CCITT_RLE:
208 212
         case TIFF_G3:
209 213
         case TIFF_G4:
210
-            ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts);
214
+            ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
215
+                                  s->compr, s->fax_opts);
211 216
             break;
212 217
         }
213 218
         if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8)
... ...
@@ -218,12 +232,12 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
218 218
         av_free(src2);
219 219
         return ret;
220 220
     }
221
-    for(line = 0; line < lines; line++){
222
-        if(src - ssrc > size){
221
+    for (line = 0; line < lines; line++) {
222
+        if (src - ssrc > size) {
223 223
             av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
224 224
             return -1;
225 225
         }
226
-        switch(s->compr){
226
+        switch (s->compr) {
227 227
         case TIFF_RAW:
228 228
             if (ssrc + size - src < width)
229 229
                 return AVERROR_INVALIDDATA;
... ...
@@ -238,22 +252,24 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
238 238
             src += width;
239 239
             break;
240 240
         case TIFF_PACKBITS:
241
-            for(pixels = 0; pixels < width;){
242
-                code = (int8_t)*src++;
243
-                if(code >= 0){
241
+            for (pixels = 0; pixels < width;) {
242
+                code = (int8_t) * src++;
243
+                if (code >= 0) {
244 244
                     code++;
245
-                    if(pixels + code > width){
246
-                        av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
245
+                    if (pixels + code > width) {
246
+                        av_log(s->avctx, AV_LOG_ERROR,
247
+                               "Copy went out of bounds\n");
247 248
                         return -1;
248 249
                     }
249 250
                     horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8),
250 251
                                     dst, 1, src, 0, code, pixels);
251 252
                     src += code;
252 253
                     pixels += code;
253
-                }else if(code != -128){ // -127..-1
254
+                } else if (code != -128) { // -127..-1
254 255
                     code = (-code) + 1;
255
-                    if(pixels + code > width){
256
-                        av_log(s->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
256
+                    if (pixels + code > width) {
257
+                        av_log(s->avctx, AV_LOG_ERROR,
258
+                               "Run went out of bounds\n");
257 259
                         return -1;
258 260
                     }
259 261
                     c = *src++;
... ...
@@ -265,8 +281,9 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin
265 265
             break;
266 266
         case TIFF_LZW:
267 267
             pixels = ff_lzw_decode(s->lzw, dst, width);
268
-            if(pixels < width){
269
-                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width);
268
+            if (pixels < width) {
269
+                av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
270
+                       pixels, width);
270 271
                 return -1;
271 272
             }
272 273
             if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8)
... ...
@@ -342,7 +359,8 @@ static int init_image(TiffContext *s)
342 342
     return 0;
343 343
 }
344 344
 
345
-static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
345
+static int tiff_decode_tag(TiffContext *s, const uint8_t *start,
346
+                           const uint8_t *buf, const uint8_t *end_buf)
346 347
 {
347 348
     unsigned tag, type, count, off, value = 0;
348 349
     int i, j;
... ...
@@ -357,12 +375,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
357 357
     off = tget_long(&buf, s->le);
358 358
 
359 359
     if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
360
-        av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n", type);
360
+        av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
361
+               type);
361 362
         return 0;
362 363
     }
363 364
 
364
-    if(count == 1){
365
-        switch(type){
365
+    if (count == 1) {
366
+        switch (type) {
366 367
         case TIFF_BYTE:
367 368
         case TIFF_SHORT:
368 369
             buf -= 4;
... ...
@@ -374,7 +393,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
374 374
             buf = NULL;
375 375
             break;
376 376
         case TIFF_STRING:
377
-            if(count <= 4){
377
+            if (count <= 4) {
378 378
                 buf -= 4;
379 379
                 break;
380 380
             }
... ...
@@ -390,12 +409,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
390 390
         }
391 391
     }
392 392
 
393
-    if(buf && (buf < start || buf > end_buf)){
394
-        av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
393
+    if (buf && (buf < start || buf > end_buf)) {
394
+        av_log(s->avctx, AV_LOG_ERROR,
395
+               "Tag referencing position outside the image\n");
395 396
         return -1;
396 397
     }
397 398
 
398
-    switch(tag){
399
+    switch (tag) {
399 400
     case TIFF_WIDTH:
400 401
         s->width = value;
401 402
         break;
... ...
@@ -404,20 +424,25 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
404 404
         break;
405 405
     case TIFF_BPP:
406 406
         s->bppcount = count;
407
-        if(count > 4){
408
-            av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count);
407
+        if (count > 4) {
408
+            av_log(s->avctx, AV_LOG_ERROR,
409
+                   "This format is not supported (bpp=%d, %d components)\n",
410
+                   s->bpp, count);
409 411
             return -1;
410 412
         }
411
-        if(count == 1) s->bpp = value;
412
-        else{
413
-            switch(type){
413
+        if (count == 1)
414
+            s->bpp = value;
415
+        else {
416
+            switch (type) {
414 417
             case TIFF_BYTE:
415
-                s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) + ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
418
+                s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
419
+                         ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
416 420
                 break;
417 421
             case TIFF_SHORT:
418 422
             case TIFF_LONG:
419 423
                 s->bpp = 0;
420
-                for(i = 0; i < count && buf < end_buf; i++) s->bpp += tget(&buf, type, s->le);
424
+                for (i = 0; i < count && buf < end_buf; i++)
425
+                    s->bpp += tget(&buf, type, s->le);
421 426
                 break;
422 427
             default:
423 428
                 s->bpp = -1;
... ...
@@ -437,7 +462,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
437 437
     case TIFF_COMPR:
438 438
         s->compr = value;
439 439
         s->predictor = 0;
440
-        switch(s->compr){
440
+        switch (s->compr) {
441 441
         case TIFF_RAW:
442 442
         case TIFF_PACKBITS:
443 443
         case TIFF_LZW:
... ...
@@ -457,48 +482,54 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
457 457
 #endif
458 458
         case TIFF_JPEG:
459 459
         case TIFF_NEWJPEG:
460
-            av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n");
460
+            av_log(s->avctx, AV_LOG_ERROR,
461
+                   "JPEG compression is not supported\n");
461 462
             return -1;
462 463
         default:
463
-            av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n", s->compr);
464
+            av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
465
+                   s->compr);
464 466
             return -1;
465 467
         }
466 468
         break;
467 469
     case TIFF_ROWSPERSTRIP:
468 470
         if (type == TIFF_LONG && value == UINT_MAX)
469 471
             value = s->avctx->height;
470
-        if(value < 1){
471
-            av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n");
472
+        if (value < 1) {
473
+            av_log(s->avctx, AV_LOG_ERROR,
474
+                   "Incorrect value of rows per strip\n");
472 475
             return -1;
473 476
         }
474 477
         s->rps = value;
475 478
         break;
476 479
     case TIFF_STRIP_OFFS:
477
-        if(count == 1){
480
+        if (count == 1) {
478 481
             s->stripdata = NULL;
479 482
             s->stripoff = value;
480
-        }else
483
+        } else
481 484
             s->stripdata = start + off;
482 485
         s->strips = count;
483
-        if(s->strips == 1) s->rps = s->height;
486
+        if (s->strips == 1)
487
+            s->rps = s->height;
484 488
         s->sot = type;
485
-        if(s->stripdata > end_buf){
486
-            av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
489
+        if (s->stripdata > end_buf) {
490
+            av_log(s->avctx, AV_LOG_ERROR,
491
+                   "Tag referencing position outside the image\n");
487 492
             return -1;
488 493
         }
489 494
         break;
490 495
     case TIFF_STRIP_SIZE:
491
-        if(count == 1){
496
+        if (count == 1) {
492 497
             s->stripsizes = NULL;
493 498
             s->stripsize = value;
494 499
             s->strips = 1;
495
-        }else{
500
+        } else {
496 501
             s->stripsizes = start + off;
497 502
         }
498 503
         s->strips = count;
499 504
         s->sstype = type;
500
-        if(s->stripsizes > end_buf){
501
-            av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
505
+        if (s->stripsizes > end_buf) {
506
+            av_log(s->avctx, AV_LOG_ERROR,
507
+                   "Tag referencing position outside the image\n");
502 508
             return -1;
503 509
         }
504 510
         break;
... ...
@@ -513,7 +544,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
513 513
         s->predictor = value;
514 514
         break;
515 515
     case TIFF_INVERT:
516
-        switch(value){
516
+        switch (value) {
517 517
         case 0:
518 518
             s->invert = 1;
519 519
             break;
... ...
@@ -524,13 +555,15 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
524 524
         case 3:
525 525
             break;
526 526
         default:
527
-            av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n", value);
527
+            av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
528
+                   value);
528 529
             return -1;
529 530
         }
530 531
         break;
531 532
     case TIFF_FILL_ORDER:
532
-        if(value < 1 || value > 2){
533
-            av_log(s->avctx, AV_LOG_ERROR, "Unknown FillOrder value %d, trying default one\n", value);
533
+        if (value < 1 || value > 2) {
534
+            av_log(s->avctx, AV_LOG_ERROR,
535
+                   "Unknown FillOrder value %d, trying default one\n", value);
534 536
             value = 1;
535 537
         }
536 538
         s->fill_order = value - 1;
... ...
@@ -544,44 +577,44 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *
544 544
         gp = buf + count / 3 * off;
545 545
         bp = buf + count / 3 * off * 2;
546 546
         off = (type_sizes[type] - 1) << 3;
547
-        for(i = 0; i < count / 3; i++){
547
+        for (i = 0; i < count / 3; i++) {
548 548
             j = 0xff << 24;
549 549
             j |= (tget(&rp, type, s->le) >> off) << 16;
550 550
             j |= (tget(&gp, type, s->le) >> off) << 8;
551
-            j |= tget(&bp, type, s->le) >> off;
551
+            j |=  tget(&bp, type, s->le) >> off;
552 552
             pal[i] = j;
553 553
         }
554 554
         s->palette_is_set = 1;
555 555
         break;
556 556
     case TIFF_PLANAR:
557
-        if(value == 2){
557
+        if (value == 2) {
558 558
             av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
559 559
             return -1;
560 560
         }
561 561
         break;
562 562
     case TIFF_T4OPTIONS:
563
-        if(s->compr == TIFF_G3)
563
+        if (s->compr == TIFF_G3)
564 564
             s->fax_opts = value;
565 565
         break;
566 566
     case TIFF_T6OPTIONS:
567
-        if(s->compr == TIFF_G4)
567
+        if (s->compr == TIFF_G4)
568 568
             s->fax_opts = value;
569 569
         break;
570 570
     default:
571
-        av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n", tag, tag);
571
+        av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
572
+               tag, tag);
572 573
     }
573 574
     return 0;
574 575
 }
575 576
 
576 577
 static int decode_frame(AVCodecContext *avctx,
577
-                        void *data, int *data_size,
578
-                        AVPacket *avpkt)
578
+                        void *data, int *data_size, AVPacket *avpkt)
579 579
 {
580 580
     const uint8_t *buf = avpkt->data;
581 581
     int buf_size = avpkt->size;
582
-    TiffContext * const s = avctx->priv_data;
582
+    TiffContext *const s = avctx->priv_data;
583 583
     AVFrame *picture = data;
584
-    AVFrame * const p = &s->picture;
584
+    AVFrame *const p = &s->picture;
585 585
     const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
586 586
     unsigned off;
587 587
     int id, le, ret;
... ...
@@ -593,10 +626,13 @@ static int decode_frame(AVCodecContext *avctx,
593 593
     //parse image header
594 594
     if (end_buf - buf < 8)
595 595
         return AVERROR_INVALIDDATA;
596
-    id = AV_RL16(buf); buf += 2;
597
-    if(id == 0x4949) le = 1;
598
-    else if(id == 0x4D4D) le = 0;
599
-    else{
596
+    id = AV_RL16(buf);
597
+    buf += 2;
598
+    if (id == 0x4949)
599
+        le = 1;
600
+    else if (id == 0x4D4D)
601
+        le = 0;
602
+    else {
600 603
         av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
601 604
         return -1;
602 605
     }
... ...
@@ -606,8 +642,9 @@ static int decode_frame(AVCodecContext *avctx,
606 606
     s->fill_order = 0;
607 607
     // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
608 608
     // that further identifies the file as a TIFF file"
609
-    if(tget_short(&buf, le) != 42){
610
-        av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n");
609
+    if (tget_short(&buf, le) != 42) {
610
+        av_log(avctx, AV_LOG_ERROR,
611
+               "The answer to life, universe and everything is not correct!\n");
611 612
         return -1;
612 613
     }
613 614
     // Reset these pointers so we can tell if they were set this frame
... ...
@@ -620,12 +657,12 @@ static int decode_frame(AVCodecContext *avctx,
620 620
     }
621 621
     buf = orig_buf + off;
622 622
     entries = tget_short(&buf, le);
623
-    for(i = 0; i < entries; i++){
624
-        if(tiff_decode_tag(s, orig_buf, buf, end_buf) < 0)
623
+    for (i = 0; i < entries; i++) {
624
+        if (tiff_decode_tag(s, orig_buf, buf, end_buf) < 0)
625 625
             return -1;
626 626
         buf += 12;
627 627
     }
628
-    if(!s->stripdata && !s->stripoff){
628
+    if (!s->stripdata && !s->stripoff) {
629 629
         av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
630 630
         return -1;
631 631
     }
... ...
@@ -633,36 +670,37 @@ static int decode_frame(AVCodecContext *avctx,
633 633
     if ((ret = init_image(s)) < 0)
634 634
         return ret;
635 635
 
636
-    if(s->strips == 1 && !s->stripsize){
636
+    if (s->strips == 1 && !s->stripsize) {
637 637
         av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
638 638
         s->stripsize = buf_size - s->stripoff;
639 639
     }
640 640
     stride = p->linesize[0];
641 641
     dst = p->data[0];
642
-    for(i = 0; i < s->height; i += s->rps){
643
-        if(s->stripsizes) {
642
+    for (i = 0; i < s->height; i += s->rps) {
643
+        if (s->stripsizes) {
644 644
             if (s->stripsizes >= end_buf)
645 645
                 return AVERROR_INVALIDDATA;
646 646
             ssize = tget(&s->stripsizes, s->sstype, s->le);
647 647
         } else
648 648
             ssize = s->stripsize;
649 649
 
650
-        if(s->stripdata){
650
+        if (s->stripdata) {
651 651
             if (s->stripdata >= end_buf)
652 652
                 return AVERROR_INVALIDDATA;
653 653
             soff = tget(&s->stripdata, s->sot, s->le);
654
-        }else
654
+        } else
655 655
             soff = s->stripoff;
656 656
 
657 657
         if (soff > buf_size || ssize > buf_size - soff) {
658 658
             av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
659 659
             return -1;
660 660
         }
661
-        if(tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize, FFMIN(s->rps, s->height - i)) < 0)
661
+        if (tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize,
662
+                              FFMIN(s->rps, s->height - i)) < 0)
662 663
             break;
663 664
         dst += s->rps * stride;
664 665
     }
665
-    if(s->predictor == 2){
666
+    if (s->predictor == 2) {
666 667
         dst = p->data[0];
667 668
         soff = s->bpp >> 3;
668 669
         ssize = s->width * soff;
... ...
@@ -681,18 +719,18 @@ static int decode_frame(AVCodecContext *avctx,
681 681
                 dst += stride;
682 682
             }
683 683
         } else {
684
-            for(i = 0; i < s->height; i++) {
685
-                for(j = soff; j < ssize; j++)
684
+            for (i = 0; i < s->height; i++) {
685
+                for (j = soff; j < ssize; j++)
686 686
                     dst[j] += dst[j - soff];
687 687
                 dst += stride;
688 688
             }
689 689
         }
690 690
     }
691 691
 
692
-    if(s->invert){
692
+    if (s->invert) {
693 693
         dst = s->picture.data[0];
694
-        for(i = 0; i < s->height; i++){
695
-            for(j = 0; j < s->picture.linesize[0]; j++)
694
+        for (i = 0; i < s->height; i++) {
695
+            for (j = 0; j < s->picture.linesize[0]; j++)
696 696
                 dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
697 697
             dst += s->picture.linesize[0];
698 698
         }
... ...
@@ -703,7 +741,8 @@ static int decode_frame(AVCodecContext *avctx,
703 703
     return buf_size;
704 704
 }
705 705
 
706
-static av_cold int tiff_init(AVCodecContext *avctx){
706
+static av_cold int tiff_init(AVCodecContext *avctx)
707
+{
707 708
     TiffContext *s = avctx->priv_data;
708 709
 
709 710
     s->width = 0;
... ...
@@ -719,10 +758,10 @@ static av_cold int tiff_init(AVCodecContext *avctx){
719 719
 
720 720
 static av_cold int tiff_end(AVCodecContext *avctx)
721 721
 {
722
-    TiffContext * const s = avctx->priv_data;
722
+    TiffContext *const s = avctx->priv_data;
723 723
 
724 724
     ff_lzw_decode_close(&s->lzw);
725
-    if(s->picture.data[0])
725
+    if (s->picture.data[0])
726 726
         avctx->release_buffer(avctx, &s->picture);
727 727
     return 0;
728 728
 }
... ...
@@ -229,7 +229,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
229 229
     s->max_subframe_len_bit = 0;
230 230
     s->subframe_len_bits    = av_log2(log2_max_num_subframes) + 1;
231 231
 
232
-    num_possible_block_sizes     = log2_max_num_subframes + 1;
233 232
     s->min_samples_per_subframe  = s->samples_per_frame / s->max_num_subframes;
234 233
     s->dynamic_range_compression = s->decode_flags & 0x80;
235 234
     s->bV3RTM                    = s->decode_flags & 0x100;
... ...
@@ -940,9 +939,10 @@ static int decode_subframe(WmallDecodeCtx *s)
940 940
 
941 941
     if (rawpcm_tile) {
942 942
         int bits = s->bits_per_sample - padding_zeroes;
943
-        if (bits <= 0 ) {
944
-            av_log(s->avctx, AV_LOG_ERROR, "rawpcm_tile bits invalid\n");
945
-            return -1;
943
+        if (bits <= 0) {
944
+            av_log(s->avctx, AV_LOG_ERROR,
945
+                   "Invalid number of padding bits in raw PCM tile\n");
946
+            return AVERROR_INVALIDDATA;
946 947
         }
947 948
         av_dlog(s->avctx, "RAWPCM %d bits per sample. "
948 949
                 "total %d bits, remain=%d\n", bits,
... ...
@@ -1169,8 +1169,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
1169 1169
     GetBitContext* gb  = &s->pgb;
1170 1170
     const uint8_t* buf = avpkt->data;
1171 1171
     int buf_size       = avpkt->size;
1172
-    int num_bits_prev_frame, packet_sequence_number,
1173
-        seekable_frame_in_packet, spliced_packet;
1172
+    int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1174 1173
 
1175 1174
     if (s->packet_done || s->packet_loss) {
1176 1175
         s->packet_done = 0;
... ...
@@ -1185,9 +1184,11 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
1185 1185
 
1186 1186
         /* parse packet header */
1187 1187
         init_get_bits(gb, buf, s->buf_bit_size);
1188
-        packet_sequence_number   = get_bits(gb, 4);
1189
-        seekable_frame_in_packet = get_bits1(gb);
1190
-        spliced_packet           = get_bits1(gb);
1188
+        packet_sequence_number = get_bits(gb, 4);
1189
+        skip_bits(gb, 1);   // Skip seekable_frame_in_packet, currently ununused
1190
+        spliced_packet = get_bits1(gb);
1191
+        if (spliced_packet)
1192
+            av_log_missing_feature(avctx, "Bitstream splicing", 1);
1191 1193
 
1192 1194
         /* get number of bits that need to be added to the previous frame */
1193 1195
         num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
... ...
@@ -594,7 +594,7 @@ cglobal emu_edge_core, 2, 7, 0
594 594
 %define valw2 r7w
595 595
 %define valw3 r3w
596 596
 %if WIN64
597
-%define valw4 r4w
597
+%define valw4 r7w
598 598
 %else ; unix64
599 599
 %define valw4 r3w
600 600
 %endif
... ...
@@ -91,11 +91,11 @@ void avfilter_graph_free(AVFilterGraph **graph);
91 91
 /**
92 92
  * A linked-list of the inputs/outputs of the filter chain.
93 93
  *
94
- * This is mainly useful for avfilter_graph_parse(), since this
95
- * function may accept a description of a graph with not connected
96
- * input/output pads. This struct specifies, per each not connected
97
- * pad contained in the graph, the filter context and the pad index
98
- * required for establishing a link.
94
+ * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(),
95
+ * where it is used to communicate open (unlinked) inputs and outputs from and
96
+ * to the caller.
97
+ * This struct specifies, per each not connected pad contained in the graph, the
98
+ * filter context and the pad index required for establishing a link.
99 99
  */
100 100
 typedef struct AVFilterInOut {
101 101
     /** unique name for this input/output in the list */
... ...
@@ -112,13 +112,14 @@ typedef struct AVFilterInOut {
112 112
 } AVFilterInOut;
113 113
 
114 114
 /**
115
- * Create an AVFilterInOut.
116
- * Must be free with avfilter_inout_free().
115
+ * Allocate a single AVFilterInOut entry.
116
+ * Must be freed with avfilter_inout_free().
117
+ * @return allocated AVFilterInOut on success, NULL on failure.
117 118
  */
118 119
 AVFilterInOut *avfilter_inout_alloc(void);
119 120
 
120 121
 /**
121
- * Free the AVFilterInOut in *inout, and set its pointer to NULL.
122
+ * Free the supplied list of AVFilterInOut and set *inout to NULL.
122 123
  * If *inout is NULL, do nothing.
123 124
  */
124 125
 void avfilter_inout_free(AVFilterInOut **inout);
... ...
@@ -141,6 +142,41 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
141 141
                          void *log_ctx);
142 142
 
143 143
 /**
144
+ * Add a graph described by a string to a graph.
145
+ *
146
+ * @param[in]  graph   the filter graph where to link the parsed graph context
147
+ * @param[in]  filters string to be parsed
148
+ * @param[out] inputs  a linked list of all free (unlinked) inputs of the
149
+ *                     parsed graph will be returned here. It is to be freed
150
+ *                     by the caller using avfilter_inout_free().
151
+ * @param[out] outputs a linked list of all free (unlinked) outputs of the
152
+ *                     parsed graph will be returned here. It is to be freed by the
153
+ *                     caller using avfilter_inout_free().
154
+ * @return zero on success, a negative AVERROR code on error
155
+ *
156
+ * @note the difference between avfilter_graph_parse2() and
157
+ * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
158
+ * the lists of inputs and outputs, which therefore must be known before calling
159
+ * the function. On the other hand, avfilter_graph_parse2() \em returns the
160
+ * inputs and outputs that are left unlinked after parsing the graph and the
161
+ * caller then deals with them. Another difference is that in
162
+ * avfilter_graph_parse(), the inputs parameter describes inputs of the
163
+ * <em>already existing</em> part of the graph; i.e. from the point of view of
164
+ * the newly created part, they are outputs. Similarly the outputs parameter
165
+ * describes outputs of the already existing filters, which are provided as
166
+ * inputs to the parsed filters.
167
+ * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
168
+ * whatsoever to already existing parts of the graph and the inputs parameter
169
+ * will on return contain inputs of the newly parsed part of the graph.
170
+ * Analogously the outputs parameter will contain outputs of the newly created
171
+ * filters.
172
+ */
173
+int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
174
+                          AVFilterInOut **inputs,
175
+                          AVFilterInOut **outputs);
176
+
177
+
178
+/**
144 179
  * Send a command to one or more filter instances.
145 180
  *
146 181
  * @param graph  the filter graph
... ...
@@ -32,6 +32,7 @@
32 32
  *
33 33
  * @param buf buffer containing frame data to be passed down the filtergraph.
34 34
  * This function will take ownership of buf, the user must not free it.
35
+ * A NULL buf signals EOF -- i.e. no more frames will be sent to this filter.
35 36
  */
36 37
 int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
37 38
 
... ...
@@ -189,13 +189,15 @@ static AVFilterInOut *extract_inout(const char *label, AVFilterInOut **links)
189 189
 {
190 190
     AVFilterInOut *ret;
191 191
 
192
-    while (*links && strcmp((*links)->name, label))
192
+    while (*links && (!(*links)->name || strcmp((*links)->name, label)))
193 193
         links = &((*links)->next);
194 194
 
195 195
     ret = *links;
196 196
 
197
-    if (ret)
197
+    if (ret) {
198 198
         *links = ret->next;
199
+        ret->next = NULL;
200
+    }
199 201
 
200 202
     return ret;
201 203
 }
... ...
@@ -206,22 +208,31 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element)
206 206
     *inouts = element;
207 207
 }
208 208
 
209
+static void append_inout(AVFilterInOut **inouts, AVFilterInOut **element)
210
+{
211
+    while (*inouts && (*inouts)->next)
212
+        inouts = &((*inouts)->next);
213
+
214
+    if (!*inouts)
215
+        *inouts = *element;
216
+    else
217
+        (*inouts)->next = *element;
218
+    *element = NULL;
219
+}
220
+
209 221
 static int link_filter_inouts(AVFilterContext *filt_ctx,
210 222
                               AVFilterInOut **curr_inputs,
211 223
                               AVFilterInOut **open_inputs, void *log_ctx)
212 224
 {
213
-    int pad = filt_ctx->input_count, ret;
225
+    int pad, ret;
214 226
 
215
-    while (pad--) {
227
+    for (pad = 0; pad < filt_ctx->input_count; pad++) {
216 228
         AVFilterInOut *p = *curr_inputs;
217
-        if (!p) {
218
-            av_log(log_ctx, AV_LOG_ERROR,
219
-                   "Not enough inputs specified for the \"%s\" filter.\n",
220
-                   filt_ctx->filter->name);
221
-            return AVERROR(EINVAL);
222
-        }
223 229
 
224
-        *curr_inputs = (*curr_inputs)->next;
230
+        if (p)
231
+            *curr_inputs = (*curr_inputs)->next;
232
+        else if (!(p = av_mallocz(sizeof(*p))))
233
+            return AVERROR(ENOMEM);
225 234
 
226 235
         if (p->filter_ctx) {
227 236
             if ((ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx)) < 0)
... ...
@@ -258,6 +269,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx,
258 258
 static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
259 259
                         AVFilterInOut **open_outputs, void *log_ctx)
260 260
 {
261
+    AVFilterInOut *parsed_inputs = NULL;
261 262
     int pad = 0;
262 263
 
263 264
     while (**buf == '[') {
... ...
@@ -280,12 +292,15 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
280 280
             match->pad_idx = pad;
281 281
         }
282 282
 
283
-        insert_inout(curr_inputs, match);
283
+        append_inout(&parsed_inputs, &match);
284 284
 
285 285
         *buf += strspn(*buf, WHITESPACES);
286 286
         pad++;
287 287
     }
288 288
 
289
+    append_inout(&parsed_inputs, curr_inputs);
290
+    *curr_inputs = parsed_inputs;
291
+
289 292
     return pad;
290 293
 }
291 294
 
... ...
@@ -334,10 +349,173 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs,
334 334
     return pad;
335 335
 }
336 336
 
337
+#if FF_API_GRAPH_AVCLASS
338
+#define log_ctx graph
339
+#else
340
+#define log_ctx NULL
341
+#endif
342
+
343
+static int parse_sws_flags(const char **buf, AVFilterGraph *graph)
344
+{
345
+    char *p = strchr(*buf, ';');
346
+
347
+    if (strncmp(*buf, "sws_flags=", 10))
348
+        return 0;
349
+
350
+    if (!p) {
351
+        av_log(log_ctx, AV_LOG_ERROR, "sws_flags not terminated with ';'.\n");
352
+        return AVERROR(EINVAL);
353
+    }
354
+
355
+    *buf += 4;  // keep the 'flags=' part
356
+
357
+    av_freep(&graph->scale_sws_opts);
358
+    if (!(graph->scale_sws_opts = av_mallocz(p - *buf + 1)))
359
+        return AVERROR(ENOMEM);
360
+    av_strlcpy(graph->scale_sws_opts, *buf, p - *buf + 1);
361
+
362
+    *buf = p + 1;
363
+    return 0;
364
+}
365
+
366
+int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
367
+                          AVFilterInOut **inputs,
368
+                          AVFilterInOut **outputs)
369
+{
370
+    int index = 0, ret = 0;
371
+    char chr = 0;
372
+
373
+    AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
374
+
375
+    filters += strspn(filters, WHITESPACES);
376
+
377
+    if ((ret = parse_sws_flags(&filters, graph)) < 0)
378
+        goto fail;
379
+
380
+    do {
381
+        AVFilterContext *filter;
382
+        filters += strspn(filters, WHITESPACES);
383
+
384
+        if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
385
+            goto end;
386
+
387
+        if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
388
+            goto end;
389
+
390
+        if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
391
+            goto end;
392
+
393
+        if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
394
+                                 log_ctx)) < 0)
395
+            goto end;
396
+
397
+        filters += strspn(filters, WHITESPACES);
398
+        chr = *filters++;
399
+
400
+        if (chr == ';' && curr_inputs)
401
+            append_inout(&open_outputs, &curr_inputs);
402
+        index++;
403
+    } while (chr == ',' || chr == ';');
404
+
405
+    if (chr) {
406
+        av_log(log_ctx, AV_LOG_ERROR,
407
+               "Unable to parse graph description substring: \"%s\"\n",
408
+               filters - 1);
409
+        ret = AVERROR(EINVAL);
410
+        goto end;
411
+    }
412
+
413
+    append_inout(&open_outputs, &curr_inputs);
414
+
415
+
416
+    *inputs  = open_inputs;
417
+    *outputs = open_outputs;
418
+    return 0;
419
+
420
+ fail:end:
421
+    for (; graph->filter_count > 0; graph->filter_count--)
422
+        avfilter_free(graph->filters[graph->filter_count - 1]);
423
+    av_freep(&graph->filters);
424
+    avfilter_inout_free(&open_inputs);
425
+    avfilter_inout_free(&open_outputs);
426
+    avfilter_inout_free(&curr_inputs);
427
+
428
+    *inputs  = NULL;
429
+    *outputs = NULL;
430
+
431
+    return ret;
432
+}
433
+#undef log_ctx
434
+
337 435
 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
338 436
                          AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
339 437
                          void *log_ctx)
340 438
 {
439
+#if 0
440
+    int ret;
441
+    AVFilterInOut *open_inputs  = open_inputs_ptr  ? *open_inputs_ptr  : NULL;
442
+    AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
443
+    AVFilterInOut *cur, *match, *inputs = NULL, *outputs = NULL;
444
+
445
+    if ((ret = avfilter_graph_parse2(graph, filters, &inputs, &outputs)) < 0)
446
+        goto fail;
447
+
448
+    /* First input can be omitted if it is "[in]" */
449
+    if (inputs && !inputs->name)
450
+        inputs->name = av_strdup("in");
451
+    for (cur = inputs; cur; cur = cur->next) {
452
+        if (!cur->name) {
453
+              av_log(log_ctx, AV_LOG_ERROR,
454
+                     "Not enough inputs specified for the \"%s\" filter.\n",
455
+                     cur->filter_ctx->filter->name);
456
+              ret = AVERROR(EINVAL);
457
+              goto fail;
458
+        }
459
+        if (!(match = extract_inout(cur->name, &open_outputs)))
460
+            continue;
461
+        ret = avfilter_link(match->filter_ctx, match->pad_idx,
462
+                            cur->filter_ctx,   cur->pad_idx);
463
+        avfilter_inout_free(&match);
464
+        if (ret < 0)
465
+            goto fail;
466
+    }
467
+
468
+    /* Last output can be omitted if it is "[out]" */
469
+    if (outputs && !outputs->name)
470
+        outputs->name = av_strdup("out");
471
+    for (cur = outputs; cur; cur = cur->next) {
472
+        if (!cur->name) {
473
+            av_log(log_ctx, AV_LOG_ERROR,
474
+                   "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
475
+                   filters);
476
+            ret = AVERROR(EINVAL);
477
+            goto fail;
478
+        }
479
+        if (!(match = extract_inout(cur->name, &open_inputs)))
480
+            continue;
481
+        ret = avfilter_link(cur->filter_ctx,   cur->pad_idx,
482
+                            match->filter_ctx, match->pad_idx);
483
+        avfilter_inout_free(&match);
484
+        if (ret < 0)
485
+            goto fail;
486
+    }
487
+
488
+ fail:
489
+    if (ret < 0) {
490
+        for (; graph->filter_count > 0; graph->filter_count--)
491
+            avfilter_free(graph->filters[graph->filter_count - 1]);
492
+        av_freep(&graph->filters);
493
+    }
494
+    avfilter_inout_free(&inputs);
495
+    avfilter_inout_free(&outputs);
496
+    /* clear open_in/outputs only if not passed as parameters */
497
+    if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
498
+    else avfilter_inout_free(&open_inputs);
499
+    if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
500
+    else avfilter_inout_free(&open_outputs);
501
+    return ret;
502
+}
503
+#else
341 504
     int index = 0, ret = 0;
342 505
     char chr = 0;
343 506
 
... ...
@@ -414,3 +592,5 @@ end:
414 414
     }
415 415
     return ret;
416 416
 }
417
+
418
+#endif
... ...
@@ -29,8 +29,8 @@
29 29
 #include "libavutil/avutil.h"
30 30
 
31 31
 #define LIBAVFILTER_VERSION_MAJOR  2
32
-#define LIBAVFILTER_VERSION_MINOR 69
33
-#define LIBAVFILTER_VERSION_MICRO 101
32
+#define LIBAVFILTER_VERSION_MINOR 70
33
+#define LIBAVFILTER_VERSION_MICRO 100
34 34
 
35 35
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
36 36
                                                LIBAVFILTER_VERSION_MINOR, \
... ...
@@ -39,6 +39,7 @@ typedef struct {
39 39
     AVRational        time_base;     ///< time_base to set in the output link
40 40
     AVRational        sample_aspect_ratio;
41 41
     char              sws_param[256];
42
+    int eof;
42 43
 } BufferSourceContext;
43 44
 
44 45
 #define CHECK_PARAM_CHANGE(s, c, width, height, format)\
... ...
@@ -55,6 +56,12 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
55 55
     AVFilterBufferRef *buf;
56 56
     int ret;
57 57
 
58
+    if (!picref) {
59
+        c->eof = 1;
60
+        return 0;
61
+    } else if (c->eof)
62
+        return AVERROR(EINVAL);
63
+
58 64
     if (!av_fifo_space(c->fifo) &&
59 65
         (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
60 66
                                          sizeof(buf))) < 0)
... ...
@@ -125,6 +132,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
125 125
     BufferSourceContext *c = s->priv;
126 126
     int ret;
127 127
 
128
+    if (!buf) {
129
+        c->eof = 1;
130
+        return 0;
131
+    } else if (c->eof)
132
+        return AVERROR(EINVAL);
133
+
128 134
     if (!av_fifo_space(c->fifo) &&
129 135
         (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
130 136
                                          sizeof(buf))) < 0)
... ...
@@ -144,9 +157,17 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf)
144 144
 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
145 145
                              const AVFrame *frame, int flags)
146 146
 {
147
+    BufferSourceContext *c = buffer_src->priv;
148
+    AVFilterBufferRef *picref;
147 149
     int ret;
148
-    AVFilterBufferRef *picref =
149
-        avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE);
150
+
151
+    if (!frame) {
152
+        c->eof = 1;
153
+        return 0;
154
+    } else if (c->eof)
155
+        return AVERROR(EINVAL);
156
+
157
+    picref = avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE);
150 158
     if (!picref)
151 159
         return AVERROR(ENOMEM);
152 160
     ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags);
... ...
@@ -226,6 +247,8 @@ static int request_frame(AVFilterLink *link)
226 226
     AVFilterBufferRef *buf;
227 227
 
228 228
     if (!av_fifo_size(c->fifo)) {
229
+        if (c->eof)
230
+            return AVERROR_EOF;
229 231
         av_log(link->src, AV_LOG_WARNING,
230 232
                "request_frame() called with no available frame!\n");
231 233
         return AVERROR(EINVAL);
... ...
@@ -243,7 +266,10 @@ static int request_frame(AVFilterLink *link)
243 243
 static int poll_frame(AVFilterLink *link)
244 244
 {
245 245
     BufferSourceContext *c = link->src->priv;
246
-    return !!av_fifo_size(c->fifo);
246
+    int size = av_fifo_size(c->fifo);
247
+    if (!size && c->eof)
248
+        return AVERROR_EOF;
249
+    return size/sizeof(AVFilterBufferRef*);
247 250
 }
248 251
 
249 252
 AVFilter avfilter_vsrc_buffer = {
... ...
@@ -107,6 +107,7 @@ typedef struct MOVStreamContext {
107 107
     unsigned int alt_sample_size; ///< always contains sample size from stsz atom
108 108
     unsigned int sample_count;
109 109
     int *sample_sizes;
110
+    int keyframe_absent;
110 111
     unsigned int keyframe_count;
111 112
     int *keyframes;
112 113
     int time_scale;
... ...
@@ -1618,7 +1618,10 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
1618 1618
     av_dlog(c->fc, "keyframe_count = %d\n", entries);
1619 1619
 
1620 1620
     if (!entries)
1621
+    {
1622
+        sc->keyframe_absent = 1;
1621 1623
         return 0;
1624
+    }
1622 1625
     if (entries >= UINT_MAX / sizeof(int))
1623 1626
         return AVERROR_INVALIDDATA;
1624 1627
     sc->keyframes = av_malloc(entries * sizeof(int));
... ...
@@ -1873,7 +1876,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st)
1873 1873
                     return;
1874 1874
                 }
1875 1875
 
1876
-                if (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]) {
1876
+                if (!sc->keyframe_absent && (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index])) {
1877 1877
                     keyframe = 1;
1878 1878
                     if (stss_index + 1 < sc->keyframe_count)
1879 1879
                         stss_index++;
... ...
@@ -1975,6 +1975,8 @@ static int has_duration(AVFormatContext *ic)
1975 1975
         if (st->duration != AV_NOPTS_VALUE)
1976 1976
             return 1;
1977 1977
     }
1978
+    if (ic->duration)
1979
+        return 1;
1978 1980
     return 0;
1979 1981
 }
1980 1982
 
... ...
@@ -469,7 +469,7 @@ yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter,
469 469
 {
470 470
     int i;
471 471
 
472
-    for (i = 0; i < (dstW >> 1); i++) {
472
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
473 473
         int j;
474 474
         int Y1 = 1 << 18;
475 475
         int Y2 = 1 << 18;
... ...
@@ -512,7 +512,7 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2],
512 512
     int uvalpha1 = 4095 - uvalpha;
513 513
     int i;
514 514
 
515
-    for (i = 0; i < (dstW >> 1); i++) {
515
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
516 516
         int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha)  >> 19;
517 517
         int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha)  >> 19;
518 518
         int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha) >> 19;
... ...
@@ -539,7 +539,7 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
539 539
     int i;
540 540
 
541 541
     if (uvalpha < 2048) {
542
-        for (i = 0; i < (dstW >> 1); i++) {
542
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
543 543
             int Y1 = (buf0[i * 2    ]+64) >> 7;
544 544
             int Y2 = (buf0[i * 2 + 1]+64) >> 7;
545 545
             int U  = (ubuf0[i]       +64) >> 7;
... ...
@@ -561,7 +561,7 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0,
561 561
         }
562 562
     } else {
563 563
         const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
564
-        for (i = 0; i < (dstW >> 1); i++) {
564
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
565 565
             int Y1 = (buf0[i * 2    ]    + 64) >> 7;
566 566
             int Y2 = (buf0[i * 2 + 1]    + 64) >> 7;
567 567
             int U  = (ubuf0[i] + ubuf1[i]+128) >> 8;
... ...
@@ -608,7 +608,7 @@ yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter,
608 608
 {
609 609
     int i;
610 610
 
611
-    for (i = 0; i < (dstW >> 1); i++) {
611
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
612 612
         int j;
613 613
         int Y1 = -0x40000000;
614 614
         int Y2 = -0x40000000;
... ...
@@ -671,7 +671,7 @@ yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2],
671 671
     int uvalpha1 = 4095 - uvalpha;
672 672
     int i;
673 673
 
674
-    for (i = 0; i < (dstW >> 1); i++) {
674
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
675 675
         int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha) >> 14;
676 676
         int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha) >> 14;
677 677
         int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha + (-128 << 23)) >> 14;
... ...
@@ -709,7 +709,7 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
709 709
     int i;
710 710
 
711 711
     if (uvalpha < 2048) {
712
-        for (i = 0; i < (dstW >> 1); i++) {
712
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
713 713
             int Y1 = (buf0[i * 2]    ) >> 2;
714 714
             int Y2 = (buf0[i * 2 + 1]) >> 2;
715 715
             int U  = (ubuf0[i] + (-128 << 11)) >> 2;
... ...
@@ -737,7 +737,7 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0,
737 737
         }
738 738
     } else {
739 739
         const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
740
-        for (i = 0; i < (dstW >> 1); i++) {
740
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
741 741
             int Y1 = (buf0[i * 2]    ) >> 2;
742 742
             int Y2 = (buf0[i * 2 + 1]) >> 2;
743 743
             int U  = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
... ...
@@ -952,7 +952,7 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter,
952 952
 {
953 953
     int i;
954 954
 
955
-    for (i = 0; i < (dstW >> 1); i++) {
955
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
956 956
         int j, A1, A2;
957 957
         int Y1 = 1 << 18;
958 958
         int Y2 = 1 << 18;
... ...
@@ -1012,7 +1012,7 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2],
1012 1012
     int uvalpha1 = 4095 - uvalpha;
1013 1013
     int i;
1014 1014
 
1015
-    for (i = 0; i < (dstW >> 1); i++) {
1015
+    for (i = 0; i < ((dstW + 1) >> 1); i++) {
1016 1016
         int Y1 = (buf0[i * 2]     * yalpha1  + buf1[i * 2]     * yalpha)  >> 19;
1017 1017
         int Y2 = (buf0[i * 2 + 1] * yalpha1  + buf1[i * 2 + 1] * yalpha)  >> 19;
1018 1018
         int U  = (ubuf0[i]        * uvalpha1 + ubuf1[i]        * uvalpha) >> 19;
... ...
@@ -1050,7 +1050,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1050 1050
     int i;
1051 1051
 
1052 1052
     if (uvalpha < 2048) {
1053
-        for (i = 0; i < (dstW >> 1); i++) {
1053
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1054 1054
             int Y1 = (buf0[i * 2    ] + 64) >> 7;
1055 1055
             int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
1056 1056
             int U  = (ubuf0[i]        + 64) >> 7;
... ...
@@ -1077,7 +1077,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0,
1077 1077
         }
1078 1078
     } else {
1079 1079
         const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1];
1080
-        for (i = 0; i < (dstW >> 1); i++) {
1080
+        for (i = 0; i < ((dstW + 1) >> 1); i++) {
1081 1081
             int Y1 = (buf0[i * 2    ]     +  64) >> 7;
1082 1082
             int Y2 = (buf0[i * 2 + 1]     +  64) >> 7;
1083 1083
             int U  = (ubuf0[i] + ubuf1[i] + 128) >> 8;
... ...
@@ -40,7 +40,7 @@ do_lavfi "crop_vflip"         "crop=iw-100:ih-100:100:100,vflip"
40 40
 do_lavfi "drawbox"            "drawbox=224:24:88:72:#FF8010@0.5"
41 41
 do_lavfi "fade"               "fade=in:5:15,fade=out:30:15"
42 42
 do_lavfi "null"               "null"
43
-do_lavfi "overlay"            "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo,[o2]overlay=240:16"
43
+do_lavfi "overlay"            "split[m],scale=88:72,pad=96:80:4:4[o2];[m]fifo[o1],[o1][o2]overlay=240:16"
44 44
 do_lavfi "pad"                "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
45 45
 do_lavfi "pp"                 "mp=pp=be/de/tn/l5/al"
46 46
 do_lavfi "pp2"                "mp=pp=be/fq:16/fa/lb"