History

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

Michael Niedermayer committed 14 years ago

Commit 7432bcf2 parents 01bf2ad 7bf9e3318 files · +993 −702Browse files

Unified · Split

18 files
  1. doc/APIchanges +3 −0
  2. doc/filters.texi +7 −1
  3. libavcodec/libxvid_rc.c +0 −5
  4. libavcodec/libxvidff.c +532 −535
  5. libavcodec/qdm2.c +6 −5
  6. libavcodec/tiff.c +146 −107
  7. libavcodec/wmalosslessdec.c +10 −9
  8. libavcodec/x86/dsputil_yasm.asm +1 −1
  9. libavfilter/avfiltergraph.h +44 −8
  10. libavfilter/buffersrc.h +1 −0
  11. libavfilter/graphparser.c +192 −12
  12. libavfilter/version.h +2 −2
  13. libavfilter/vsrc_buffer.c +29 −3
  14. libavformat/isom.h +1 −0
  15. libavformat/mov.c +4 −1
  16. libavformat/utils.c +2 −0
  17. libswscale/output.c +12 −12
  18. tests/lavfi-regression.sh +1 −1
doc/APIchanges+3−0
@@ -19,6 +19,9 @@ API changes, most recent first: · 18 unmodified lines
1919 2012-03-26 - a67d9cf - lavfi 2.66.100
2020 Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions.
2121
22+2012-xx-xx - xxxxxxx - lavfi 2.16.0 - avfiltergraph.h
23+ Add avfilter_graph_parse2()
24+
2225 2012-xx-xx - xxxxxxx - lavu 51.27.0 - samplefmt.h
2326 Add av_get_packed_sample_fmt() and av_get_planar_sample_fmt()
2427
doc/filters.texi+7−1
@@ -76,6 +76,12 @@ In a complete filterchain all the unlabelled filter input and output · 75 unmodified lines
7676 pads must be connected. A filtergraph is considered valid if all the
7777 filter input and output pads of all the filterchains are connected.
7878
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+
7985 Follows a BNF description for the filtergraph syntax:
8086 @example
8187 @var{NAME} ::= sequence of alphanumeric characters and '_'
@@ -84,7 +90,7 @@ Follows a BNF description for the filtergraph syntax: · 2 unmodified lines
8490 @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted)
8591 @var{FILTER} ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}]
8692 @var{FILTERCHAIN} ::= @var{FILTER} [,@var{FILTERCHAIN}]
87−@var{FILTERGRAPH} ::= @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
93+@var{FILTERGRAPH} ::= [sws_flags=@var{flags};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}]
8894 @end example
8995
9096 @c man end FILTERGRAPH DESCRIPTION
libavcodec/libxvid_rc.c+0−5
@@ -31,16 +31,12 @@ · 30 unmodified lines
3131 #undef NDEBUG
3232 #include <assert.h>
3333
34−extern unsigned int xvid_debug;
35−
3634 int ff_xvid_rate_control_init(MpegEncContext *s){
3735 char *tmp_name;
3836 int fd, i;
3937 xvid_plg_create_t xvid_plg_create = { 0 };
4038 xvid_plugin_2pass2_t xvid_2pass2 = { 0 };
4139
42−//xvid_debug=-1;
43−
4440 fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx);
4541 if (fd == -1) {
4642 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){ · 11 unmodified lines
5854 frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count,
5955 rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8);
6056
61−//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp);
6257 if (write(fd, tmp, strlen(tmp)) < 0) {
6358 av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno));
6459 return AVERROR(errno);
libavcodec/libxvidff.c+532−535
@@ -72,155 +72,420 @@ struct xvid_ff_pass1 { · 71 unmodified lines
7272 struct xvid_context *context; /**< Pointer to private context */
7373 };
7474
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+ */
7984
8085
8186 /**
82− * Create the private context for the encoder.
83− * All buffers are allocated, settings are loaded from the user,
84− * and the encoder context created.
87+ * Initialize the two-pass plugin and context.
8588 *
86− * @param avctx AVCodecContext pointer to context
87− * @return Returns 0 on success, -1 on failure
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.
8892 */
89−static av_cold int xvid_encode_init(AVCodecContext *avctx) {
90− int xerr, i;
91− int xvid_flags = avctx->flags;
92− struct xvid_context *x = avctx->priv_data;
93− uint16_t *intra, *inter;
94− int fd;
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;
9597
96− xvid_plugin_single_t single = { 0 };
97− struct xvid_ff_pass1 rc2pass1 = { 0 };
98− xvid_plugin_2pass2_t rc2pass2 = { 0 };
99− xvid_gbl_init_t xvid_gbl_init = { 0 };
100− xvid_enc_create_t xvid_enc_create = { 0 };
101− xvid_enc_plugin_t plugins[7];
98+ /* Do a quick bounds check */
99+ if( log == NULL )
100+ return XVID_ERR_FAIL;
102101
103− /* Bring in VOP flags from ffmpeg command-line */
104− x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
105− if( xvid_flags & CODEC_FLAG_4MV )
106− x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
107− if( avctx->trellis
108− )
109− x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
110− if( xvid_flags & CODEC_FLAG_AC_PRED )
111− x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
112− if( xvid_flags & CODEC_FLAG_GRAY )
113− x->vop_flags |= XVID_VOP_GREYSCALE;
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));
114112
115− /* Decide which ME quality setting to use */
116− x->me_flags = 0;
117− switch( avctx->me_method ) {
118− case ME_FULL: /* Quality 6 */
119− x->me_flags |= XVID_ME_EXTSEARCH16
120− | XVID_ME_EXTSEARCH8;
113+ *handle = x->context;
114+ return 0;
115+}
121116
122− case ME_EPZS: /* Quality 4 */
123− x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
124− | XVID_ME_HALFPELREFINE8
125− | XVID_ME_CHROMA_PVOP
126− | XVID_ME_CHROMA_BVOP;
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+}
127132
128− case ME_LOG: /* Quality 2 */
129− case ME_PHODS:
130− case ME_X1:
131− x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
132− | XVID_ME_HALFPELREFINE16;
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;
133145
134− case ME_ZERO: /* Quality 0 */
135− default:
136− break;
137− }
146+ /* Nothing to do here, result is changed too much */
147+ if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
148+ return 0;
138149
139− /* Decide how we should decide blocks */
140− switch( avctx->mb_decision ) {
141− case 2:
142− x->vop_flags |= XVID_VOP_MODEDECISION_RD;
143− x->me_flags |= XVID_ME_HALFPELREFINE8_RD
144− | XVID_ME_QUARTERPELREFINE8_RD
145− | XVID_ME_EXTSEARCH_RD
146− | XVID_ME_CHECKPREDICTION_RD;
147− case 1:
148− if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) )
149− x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
150− x->me_flags |= XVID_ME_HALFPELREFINE16_RD
151− | XVID_ME_QUARTERPELREFINE16_RD;
150+ /* We can implement a 'turbo' first pass mode here */
151+ param->quant = 2;
152152
153− default:
154− break;
155− }
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;
156167
157− /* Bring in VOL flags from ffmpeg command-line */
158− x->vol_flags = 0;
159− if( xvid_flags & CODEC_FLAG_GMC ) {
160− x->vol_flags |= XVID_VOL_GMC;
161− x->me_flags |= XVID_ME_GME_REFINE;
162− }
163− if( xvid_flags & CODEC_FLAG_QPEL ) {
164− x->vol_flags |= XVID_VOL_QUARTERPEL;
165− x->me_flags |= XVID_ME_QUARTERPELREFINE16;
166− if( x->vop_flags & XVID_VOP_INTER4V )
167− x->me_flags |= XVID_ME_QUARTERPELREFINE8;
168− }
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;
169172
170− xvid_gbl_init.version = XVID_VERSION;
171− xvid_gbl_init.debug = 0;
173+ return 0;
174+}
172175
173−#if ARCH_PPC
174− /* Xvid's PPC support is borked, use libavcodec to detect */
175−#if HAVE_ALTIVEC
176− if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
177− xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
178− } else
179−#endif
180− xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
181−#else
182− /* Xvid can detect on x86 */
183− xvid_gbl_init.cpu_flags = 0;
184−#endif
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;
185188
186− /* Initialize */
187− xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
189+ /* Quick bounds check */
190+ if( log == NULL )
191+ return XVID_ERR_FAIL;
188192
189− /* Create the encoder reference */
190− xvid_enc_create.version = XVID_VERSION;
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+ }
191199
192− /* Store the desired frame size */
193− xvid_enc_create.width = x->xsize = avctx->width;
194− xvid_enc_create.height = x->ysize = avctx->height;
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);
195204
196− /* Xvid can determine the proper profile to use */
197− /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
205+ return 0;
206+}
198207
199− /* We don't use zones */
200− xvid_enc_create.zones = NULL;
201− xvid_enc_create.num_zones = 0;
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;
202225
203− xvid_enc_create.num_threads = avctx->thread_count;
226+ case XVID_PLG_BEFORE:
227+ return xvid_ff_2pass_before(ref, p1);
204228
205− xvid_enc_create.plugins = plugins;
206− xvid_enc_create.num_plugins = 0;
229+ case XVID_PLG_CREATE:
230+ return xvid_ff_2pass_create(p1, p2);
207231
208− /* Initialize Buffers */
209− x->twopassbuffer = NULL;
210− x->old_twopassbuffer = NULL;
211− x->twopassfile = NULL;
232+ case XVID_PLG_AFTER:
233+ return xvid_ff_2pass_after(ref, p1);
212234
213− if( xvid_flags & CODEC_FLAG_PASS1 ) {
214− rc2pass1.version = XVID_VERSION;
215− rc2pass1.context = x;
216− x->twopassbuffer = av_malloc(BUFFER_SIZE);
217− x->old_twopassbuffer = av_malloc(BUFFER_SIZE);
218− if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) {
219− av_log(avctx, AV_LOG_ERROR,
220− "Xvid: Cannot allocate 2-pass log buffers\n");
221− return -1;
222− }
223− x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0;
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+}
345+
346+/**
347+ * Create the private context for the encoder.
348+ * All buffers are allocated, settings are loaded from the user,
349+ * and the encoder context created.
350+ *
351+ * @param avctx AVCodecContext pointer to context
352+ * @return Returns 0 on success, -1 on failure
353+ */
354+static av_cold int xvid_encode_init(AVCodecContext *avctx) {
355+ int xerr, i;
356+ int xvid_flags = avctx->flags;
357+ struct xvid_context *x = avctx->priv_data;
358+ uint16_t *intra, *inter;
359+ int fd;
360+
361+ xvid_plugin_single_t single = { 0 };
362+ struct xvid_ff_pass1 rc2pass1 = { 0 };
363+ xvid_plugin_2pass2_t rc2pass2 = { 0 };
364+ xvid_gbl_init_t xvid_gbl_init = { 0 };
365+ xvid_enc_create_t xvid_enc_create = { 0 };
366+ xvid_enc_plugin_t plugins[7];
367+
368+ /* Bring in VOP flags from ffmpeg command-line */
369+ x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */
370+ if( xvid_flags & CODEC_FLAG_4MV )
371+ x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */
372+ if( avctx->trellis
373+ )
374+ x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */
375+ if( xvid_flags & CODEC_FLAG_AC_PRED )
376+ x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */
377+ if( xvid_flags & CODEC_FLAG_GRAY )
378+ x->vop_flags |= XVID_VOP_GREYSCALE;
379+
380+ /* Decide which ME quality setting to use */
381+ x->me_flags = 0;
382+ switch( avctx->me_method ) {
383+ case ME_FULL: /* Quality 6 */
384+ x->me_flags |= XVID_ME_EXTSEARCH16
385+ | XVID_ME_EXTSEARCH8;
386+
387+ case ME_EPZS: /* Quality 4 */
388+ x->me_flags |= XVID_ME_ADVANCEDDIAMOND8
389+ | XVID_ME_HALFPELREFINE8
390+ | XVID_ME_CHROMA_PVOP
391+ | XVID_ME_CHROMA_BVOP;
392+
393+ case ME_LOG: /* Quality 2 */
394+ case ME_PHODS:
395+ case ME_X1:
396+ x->me_flags |= XVID_ME_ADVANCEDDIAMOND16
397+ | XVID_ME_HALFPELREFINE16;
398+
399+ case ME_ZERO: /* Quality 0 */
400+ default:
401+ break;
402+ }
403+
404+ /* Decide how we should decide blocks */
405+ switch( avctx->mb_decision ) {
406+ case 2:
407+ x->vop_flags |= XVID_VOP_MODEDECISION_RD;
408+ x->me_flags |= XVID_ME_HALFPELREFINE8_RD
409+ | XVID_ME_QUARTERPELREFINE8_RD
410+ | XVID_ME_EXTSEARCH_RD
411+ | XVID_ME_CHECKPREDICTION_RD;
412+ case 1:
413+ if( !(x->vop_flags & XVID_VOP_MODEDECISION_RD) )
414+ x->vop_flags |= XVID_VOP_FAST_MODEDECISION_RD;
415+ x->me_flags |= XVID_ME_HALFPELREFINE16_RD
416+ | XVID_ME_QUARTERPELREFINE16_RD;
417+
418+ default:
419+ break;
420+ }
421+
422+ /* Bring in VOL flags from ffmpeg command-line */
423+ x->vol_flags = 0;
424+ if( xvid_flags & CODEC_FLAG_GMC ) {
425+ x->vol_flags |= XVID_VOL_GMC;
426+ x->me_flags |= XVID_ME_GME_REFINE;
427+ }
428+ if( xvid_flags & CODEC_FLAG_QPEL ) {
429+ x->vol_flags |= XVID_VOL_QUARTERPEL;
430+ x->me_flags |= XVID_ME_QUARTERPELREFINE16;
431+ if( x->vop_flags & XVID_VOP_INTER4V )
432+ x->me_flags |= XVID_ME_QUARTERPELREFINE8;
433+ }
434+
435+ xvid_gbl_init.version = XVID_VERSION;
436+ xvid_gbl_init.debug = 0;
437+
438+#if ARCH_PPC
439+ /* Xvid's PPC support is borked, use libavcodec to detect */
440+#if HAVE_ALTIVEC
441+ if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
442+ xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC;
443+ } else
444+#endif
445+ xvid_gbl_init.cpu_flags = XVID_CPU_FORCE;
446+#else
447+ /* Xvid can detect on x86 */
448+ xvid_gbl_init.cpu_flags = 0;
449+#endif
450+
451+ /* Initialize */
452+ xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL);
453+
454+ /* Create the encoder reference */
455+ xvid_enc_create.version = XVID_VERSION;
456+
457+ /* Store the desired frame size */
458+ xvid_enc_create.width = x->xsize = avctx->width;
459+ xvid_enc_create.height = x->ysize = avctx->height;
460+
461+ /* Xvid can determine the proper profile to use */
462+ /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */
463+
464+ /* We don't use zones */
465+ xvid_enc_create.zones = NULL;
466+ xvid_enc_create.num_zones = 0;
467+
468+ xvid_enc_create.num_threads = avctx->thread_count;
469+
470+ xvid_enc_create.plugins = plugins;
471+ xvid_enc_create.num_plugins = 0;
472+
473+ /* Initialize Buffers */
474+ x->twopassbuffer = NULL;
475+ x->old_twopassbuffer = NULL;
476+ x->twopassfile = NULL;
477+
478+ if( xvid_flags & CODEC_FLAG_PASS1 ) {
479+ rc2pass1.version = XVID_VERSION;
480+ rc2pass1.context = x;
481+ x->twopassbuffer = av_malloc(BUFFER_SIZE);
482+ x->old_twopassbuffer = av_malloc(BUFFER_SIZE);
483+ if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) {
484+ av_log(avctx, AV_LOG_ERROR,
485+ "Xvid: Cannot allocate 2-pass log buffers\n");
486+ return -1;
487+ }
488+ x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0;
224489
225490 plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass;
226491 plugins[xvid_enc_create.num_plugins].param = &rc2pass1;
@@ -334,446 +599,178 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { · 107 unmodified lines
334599 } else {
335600 /* We are claiming to be Xvid */
336601 x->quicktime_format = 0;
337− if(!avctx->codec_tag)
338− avctx->codec_tag = AV_RL32("xvid");
339− }
340−
341− /* Bframes */
342− xvid_enc_create.max_bframes = avctx->max_b_frames;
343− xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
344− xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
345− if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
346−
347− /* Create encoder context */
348− xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
349− if( xerr ) {
350− av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n");
351− return -1;
352− }
353−
354− x->encoder_handle = xvid_enc_create.handle;
355− avctx->coded_frame = &x->encoded_picture;
356−
357− return 0;
358−}
359−
360−/**
361− * Encode a single frame.
362− *
363− * @param avctx AVCodecContext pointer to context
364− * @param frame Pointer to encoded frame buffer
365− * @param buf_size Size of encoded frame buffer
366− * @param data Pointer to AVFrame of unencoded frame
367− * @return Returns 0 on success, -1 on failure
368− */
369−static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
370− const AVFrame *picture, int *got_packet)
371−{
372− int xerr, i, ret, user_packet = !!pkt->data;
373− char *tmp;
374− struct xvid_context *x = avctx->priv_data;
375− AVFrame *p = &x->encoded_picture;
376− int mb_width = (avctx->width + 15) / 16;
377− int mb_height = (avctx->height + 15) / 16;
378−
379− xvid_enc_frame_t xvid_enc_frame = { 0 };
380− xvid_enc_stats_t xvid_enc_stats = { 0 };
381−
382− if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0)
383− return ret;
384−
385− /* Start setting up the frame */
386− xvid_enc_frame.version = XVID_VERSION;
387− xvid_enc_stats.version = XVID_VERSION;
388− *p = *picture;
389−
390− /* Let Xvid know where to put the frame. */
391− xvid_enc_frame.bitstream = pkt->data;
392− xvid_enc_frame.length = pkt->size;
393−
394− /* Initialize input image fields */
395− if( avctx->pix_fmt != PIX_FMT_YUV420P ) {
396− av_log(avctx, AV_LOG_ERROR, "Xvid: Color spaces other than 420p not supported\n");
397− return -1;
398− }
399−
400− xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */
401−
402− for( i = 0; i < 4; i++ ) {
403− xvid_enc_frame.input.plane[i] = picture->data[i];
404− xvid_enc_frame.input.stride[i] = picture->linesize[i];
405− }
406−
407− /* Encoder Flags */
408− xvid_enc_frame.vop_flags = x->vop_flags;
409− xvid_enc_frame.vol_flags = x->vol_flags;
410− xvid_enc_frame.motion = x->me_flags;
411− xvid_enc_frame.type =
412− picture->pict_type == AV_PICTURE_TYPE_I ? XVID_TYPE_IVOP :
413− picture->pict_type == AV_PICTURE_TYPE_P ? XVID_TYPE_PVOP :
414− picture->pict_type == AV_PICTURE_TYPE_B ? XVID_TYPE_BVOP :
415− XVID_TYPE_AUTO;
416−
417− /* Pixel aspect ratio setting */
418− if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.num > 255 ||
419− avctx->sample_aspect_ratio.den < 0 || avctx->sample_aspect_ratio.den > 255) {
420− av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n",
421− avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
422− return -1;
423− }
424− xvid_enc_frame.par = XVID_PAR_EXT;
425− xvid_enc_frame.par_width = avctx->sample_aspect_ratio.num;
426− xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
427−
428− /* Quant Setting */
429− if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
430− else xvid_enc_frame.quant = 0;
431−
432− /* Matrices */
433− xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
434− xvid_enc_frame.quant_inter_matrix = x->inter_matrix;
435−
436− /* Encode */
437− xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE,
438− &xvid_enc_frame, &xvid_enc_stats);
439−
440− /* Two-pass log buffer swapping */
441− avctx->stats_out = NULL;
442− if( x->twopassbuffer ) {
443− tmp = x->old_twopassbuffer;
444− x->old_twopassbuffer = x->twopassbuffer;
445− x->twopassbuffer = tmp;
446− x->twopassbuffer[0] = 0;
447− if( x->old_twopassbuffer[0] != 0 ) {
448− avctx->stats_out = x->old_twopassbuffer;
449− }
450− }
451−
452− if (xerr > 0) {
453− *got_packet = 1;
454−
455− p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
456− if( xvid_enc_stats.type == XVID_TYPE_PVOP )
457− p->pict_type = AV_PICTURE_TYPE_P;
458− else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
459− p->pict_type = AV_PICTURE_TYPE_B;
460− else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
461− p->pict_type = AV_PICTURE_TYPE_S;
462− else
463− p->pict_type = AV_PICTURE_TYPE_I;
464− if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
465− p->key_frame = 1;
466− pkt->flags |= AV_PKT_FLAG_KEY;
467− if( x->quicktime_format )
468− return xvid_strip_vol_header(avctx, pkt,
469− xvid_enc_stats.hlength, xerr);
470− } else
471− p->key_frame = 0;
472−
473− pkt->size = xerr;
474−
475− return 0;
476− } else {
477− if (!user_packet)
478− av_free_packet(pkt);
479− if (!xerr)
480− return 0;
481− av_log(avctx, AV_LOG_ERROR, "Xvid: Encoding Error Occurred: %i\n", xerr);
482− return -1;
483− }
484−}
485−
486−/**
487− * Destroy the private context for the encoder.
488− * All buffers are freed, and the Xvid encoder context is destroyed.
489− *
490− * @param avctx AVCodecContext pointer to context
491− * @return Returns 0, success guaranteed
492− */
493−static av_cold int xvid_encode_close(AVCodecContext *avctx) {
494− struct xvid_context *x = avctx->priv_data;
495−
496− xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
497−
498− av_freep(&avctx->extradata);
499− if( x->twopassbuffer != NULL ) {
500− av_free(x->twopassbuffer);
501− av_free(x->old_twopassbuffer);
502− avctx->stats_out = NULL;
503− }
504− av_free(x->twopassfile);
505− av_free(x->intra_matrix);
506− av_free(x->inter_matrix);
507−
508− return 0;
509−}
510−
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;
602+ if(!avctx->codec_tag)
603+ avctx->codec_tag = AV_RL32("xvid");
604+ }
634605
635− /* Do a quick bounds check */
636− if( log == NULL )
637− return XVID_ERR_FAIL;
606+ /* Bframes */
607+ xvid_enc_create.max_bframes = avctx->max_b_frames;
608+ xvid_enc_create.bquant_offset = 100 * avctx->b_quant_offset;
609+ xvid_enc_create.bquant_ratio = 100 * avctx->b_quant_factor;
610+ if( avctx->max_b_frames > 0 && !x->quicktime_format ) xvid_enc_create.global |= XVID_GLOBAL_PACKED;
638611
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));
612+ /* Create encoder context */
613+ xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL);
614+ if( xerr ) {
615+ av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n");
616+ return -1;
617+ }
649618
650− *handle = x->context;
651− return 0;
652−}
619+ x->encoder_handle = xvid_enc_create.handle;
620+ avctx->coded_frame = &x->encoded_picture;
653621
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;
667622 return 0;
668623 }
669624
670625 /**
671− * Enable fast encode mode during the first pass.
626+ * Encode a single frame.
672627 *
673− * @param ref Context pointer for the plugin
674− * @param param Frame data
675− * @return Returns 0, success guaranteed
628+ * @param avctx AVCodecContext pointer to context
629+ * @param frame Pointer to encoded frame buffer
630+ * @param buf_size Size of encoded frame buffer
631+ * @param data Pointer to AVFrame of unencoded frame
632+ * @return Returns 0 on success, -1 on failure
676633 */
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;
634+static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
635+ const AVFrame *picture, int *got_packet)
636+{
637+ int xerr, i, ret, user_packet = !!pkt->data;
638+ char *tmp;
639+ struct xvid_context *x = avctx->priv_data;
640+ AVFrame *p = &x->encoded_picture;
641+ int mb_width = (avctx->width + 15) / 16;
642+ int mb_height = (avctx->height + 15) / 16;
682643
683− /* Nothing to do here, result is changed too much */
684− if( param->zone && param->zone->mode == XVID_ZONE_QUANT )
685− return 0;
644+ xvid_enc_frame_t xvid_enc_frame = { 0 };
645+ xvid_enc_stats_t xvid_enc_stats = { 0 };
686646
687− /* We can implement a 'turbo' first pass mode here */
688− param->quant = 2;
647+ if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0)
648+ return ret;
689649
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;
650+ /* Start setting up the frame */
651+ xvid_enc_frame.version = XVID_VERSION;
652+ xvid_enc_stats.version = XVID_VERSION;
653+ *p = *picture;
704654
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;
655+ /* Let Xvid know where to put the frame. */
656+ xvid_enc_frame.bitstream = pkt->data;
657+ xvid_enc_frame.length = pkt->size;
709658
710− return 0;
711−}
659+ /* Initialize input image fields */
660+ if( avctx->pix_fmt != PIX_FMT_YUV420P ) {
661+ av_log(avctx, AV_LOG_ERROR, "Xvid: Color spaces other than 420p not supported\n");
662+ return -1;
663+ }
712664
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;
665+ xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */
725666
726− /* Quick bounds check */
727− if( log == NULL )
728− return XVID_ERR_FAIL;
667+ for( i = 0; i < 4; i++ ) {
668+ xvid_enc_frame.input.plane[i] = picture->data[i];
669+ xvid_enc_frame.input.stride[i] = picture->linesize[i];
670+ }
729671
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;
672+ /* Encoder Flags */
673+ xvid_enc_frame.vop_flags = x->vop_flags;
674+ xvid_enc_frame.vol_flags = x->vol_flags;
675+ xvid_enc_frame.motion = x->me_flags;
676+ xvid_enc_frame.type =
677+ picture->pict_type == AV_PICTURE_TYPE_I ? XVID_TYPE_IVOP :
678+ picture->pict_type == AV_PICTURE_TYPE_P ? XVID_TYPE_PVOP :
679+ picture->pict_type == AV_PICTURE_TYPE_B ? XVID_TYPE_BVOP :
680+ XVID_TYPE_AUTO;
681+
682+ /* Pixel aspect ratio setting */
683+ if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.num > 255 ||
684+ avctx->sample_aspect_ratio.den < 0 || avctx->sample_aspect_ratio.den > 255) {
685+ av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n",
686+ avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den);
687+ return -1;
735688 }
689+ xvid_enc_frame.par = XVID_PAR_EXT;
690+ xvid_enc_frame.par_width = avctx->sample_aspect_ratio.num;
691+ xvid_enc_frame.par_height = avctx->sample_aspect_ratio.den;
736692
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);
693+ /* Quant Setting */
694+ if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA;
695+ else xvid_enc_frame.quant = 0;
741696
742− return 0;
697+ /* Matrices */
698+ xvid_enc_frame.quant_intra_matrix = x->intra_matrix;
699+ xvid_enc_frame.quant_inter_matrix = x->inter_matrix;
700+
701+ /* Encode */
702+ xerr = xvid_encore(x->encoder_handle, XVID_ENC_ENCODE,
703+ &xvid_enc_frame, &xvid_enc_stats);
704+
705+ /* Two-pass log buffer swapping */
706+ avctx->stats_out = NULL;
707+ if( x->twopassbuffer ) {
708+ tmp = x->old_twopassbuffer;
709+ x->old_twopassbuffer = x->twopassbuffer;
710+ x->twopassbuffer = tmp;
711+ x->twopassbuffer[0] = 0;
712+ if( x->old_twopassbuffer[0] != 0 ) {
713+ avctx->stats_out = x->old_twopassbuffer;
714+ }
715+ }
716+
717+ if (xerr > 0) {
718+ *got_packet = 1;
719+
720+ p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA;
721+ if( xvid_enc_stats.type == XVID_TYPE_PVOP )
722+ p->pict_type = AV_PICTURE_TYPE_P;
723+ else if( xvid_enc_stats.type == XVID_TYPE_BVOP )
724+ p->pict_type = AV_PICTURE_TYPE_B;
725+ else if( xvid_enc_stats.type == XVID_TYPE_SVOP )
726+ p->pict_type = AV_PICTURE_TYPE_S;
727+ else
728+ p->pict_type = AV_PICTURE_TYPE_I;
729+ if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) {
730+ p->key_frame = 1;
731+ pkt->flags |= AV_PKT_FLAG_KEY;
732+ if( x->quicktime_format )
733+ return xvid_strip_vol_header(avctx, pkt,
734+ xvid_enc_stats.hlength, xerr);
735+ } else
736+ p->key_frame = 0;
737+
738+ pkt->size = xerr;
739+
740+ return 0;
741+ } else {
742+ if (!user_packet)
743+ av_free_packet(pkt);
744+ if (!xerr)
745+ return 0;
746+ av_log(avctx, AV_LOG_ERROR, "Xvid: Encoding Error Occurred: %i\n", xerr);
747+ return -1;
748+ }
743749 }
744750
745751 /**
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.
752+ * Destroy the private context for the encoder.
753+ * All buffers are freed, and the Xvid encoder context is destroyed.
749754 *
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+ * @param avctx AVCodecContext pointer to context
756+ * @return Returns 0, success guaranteed
755757 */
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);
758+static av_cold int xvid_encode_close(AVCodecContext *avctx) {
759+ struct xvid_context *x = avctx->priv_data;
770760
771− case XVID_PLG_DESTROY:
772− return xvid_ff_2pass_destroy(ref, p1);
761+ xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL);
773762
774− default:
775− return XVID_ERR_FAIL;
763+ av_freep(&avctx->extradata);
764+ if( x->twopassbuffer != NULL ) {
765+ av_free(x->twopassbuffer);
766+ av_free(x->old_twopassbuffer);
767+ avctx->stats_out = NULL;
776768 }
769+ av_free(x->twopassfile);
770+ av_free(x->intra_matrix);
771+ av_free(x->inter_matrix);
772+
773+ return 0;
777774 }
778775
779776 /**
libavcodec/qdm2.c+6−5
@@ -140,7 +140,6 @@ typedef struct { · 139 unmodified lines
140140 /// Parameters built from header parameters, do not change during playback
141141 int group_order; ///< order of frame group
142142 int fft_order; ///< order of FFT (actually fftorder+1)
143− int fft_frame_size; ///< size of fft frame, in components (1 comples = re + im)
144143 int frame_size; ///< size of data frame
145144 int frequency_range;
146145 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) · 1460 unmodified lines
16071606 static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet)
16081607 {
16091608 const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f;
1609+ float *out = q->output_buffer + channel;
16101610 int i;
16111611 q->fft.complex[channel][0].re *= 2.0f;
16121612 q->fft.complex[channel][0].im = 0.0f;
16131613 q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]);
16141614 /* 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;
1615+ for (i = 0; i < FFALIGN(q->fft_size, 8); i++) {
1616+ out[0] += q->fft.complex[channel][i].re * gain;
1617+ out[q->channels] += q->fft.complex[channel][i].im * gain;
1618+ out += 2 * q->channels;
1619+ }
16171620 }
16181621
16191622
@@ -1688,7 +1691,6 @@ static void dump_context(QDM2Context *q) · 68 unmodified lines
16881691 PRINT("checksum_size",q->checksum_size);
16891692 PRINT("channels",q->channels);
16901693 PRINT("nb_channels",q->nb_channels);
1691− PRINT("fft_frame_size",q->fft_frame_size);
16921694 PRINT("fft_size",q->fft_size);
16931695 PRINT("sub_sampling",q->sub_sampling);
16941696 PRINT("fft_order",q->fft_order);
@@ -1843,7 +1845,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) · 148 unmodified lines
18431845 }
18441846
18451847 s->fft_order = av_log2(s->fft_size) + 1;
1846− s->fft_frame_size = 2 * s->fft_size; // complex has two floats
18471848
18481849 // something like max decodable tones
18491850 s->group_order = av_log2(s->group_size) + 1;
libavcodec/tiff.c+146−107
@@ -52,35 +52,39 @@ typedef struct TiffContext { · 51 unmodified lines
5252
5353 int strips, rps, sstype;
5454 int sot;
55− const uint8_t* stripdata;
56− const uint8_t* stripsizes;
55+ const uint8_t *stripdata;
56+ const uint8_t *stripsizes;
5757 int stripsize, stripoff;
5858 LZWState *lzw;
5959 } TiffContext;
6060
61−static unsigned tget_short(const uint8_t **p, int le) {
61+static unsigned tget_short(const uint8_t **p, int le)
62+{
6263 unsigned v = le ? AV_RL16(*p) : AV_RB16(*p);
6364 *p += 2;
6465 return v;
6566 }
6667
67−static unsigned tget_long(const uint8_t **p, int le) {
68+static unsigned tget_long(const uint8_t **p, int le)
69+{
6870 unsigned v = le ? AV_RL32(*p) : AV_RB32(*p);
6971 *p += 4;
7072 return v;
7173 }
7274
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) {
7578 case TIFF_BYTE : return *(*p)++;
7679 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);
7881 default : return UINT_MAX;
7982 }
8083 }
8184
8285 #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)
8488 {
8589 z_stream zstream = { 0 };
8690 int zret;
@@ -141,7 +145,9 @@ static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst, · 54 unmodified lines
141145 }
142146 }
143147
144−static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){
148+static int tiff_unpack_strip(TiffContext *s, uint8_t *dst, int stride,
149+ const uint8_t *src, int size, int lines)
150+{
145151 int c, line, pixels, code;
146152 const uint8_t *ssrc = src;
147153 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 · 2 unmodified lines
150156 return AVERROR_INVALIDDATA;
151157
152158 #if CONFIG_ZLIB
153− if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){
154− uint8_t *zbuf; unsigned long outlen;
159+ if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) {
160+ uint8_t *zbuf;
161+ unsigned long outlen;
155162 int ret;
156163 outlen = width * lines;
157164 zbuf = av_malloc(outlen);
158165 if (!zbuf)
159166 return AVERROR(ENOMEM);
160167 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);
168+ if (ret != Z_OK) {
169+ av_log(s->avctx, AV_LOG_ERROR,
170+ "Uncompressing failed (%lu of %lu) with error %d\n", outlen,
171+ (unsigned long)width * lines, ret);
163172 av_free(zbuf);
164173 return -1;
165174 }
166175 src = zbuf;
167− for(line = 0; line < lines; line++){
176+ for (line = 0; line < lines; line++) {
168177 if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){
169178 horizontal_fill(s->bpp, dst, 1, src, 0, width, 0);
170179 }else{
@@ -177,37 +186,42 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 6 unmodified lines
177186 return 0;
178187 }
179188 #endif
180− if(s->compr == TIFF_LZW){
181− if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){
189+ if (s->compr == TIFF_LZW) {
190+ if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) {
182191 av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n");
183192 return -1;
184193 }
185194 }
186− if(s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3 || s->compr == TIFF_G4){
195+ if (s->compr == TIFF_CCITT_RLE || s->compr == TIFF_G3
196+ || s->compr == TIFF_G4) {
187197 int i, ret = 0;
188− uint8_t *src2 = av_malloc((unsigned)size + FF_INPUT_BUFFER_PADDING_SIZE);
198+ uint8_t *src2 = av_malloc((unsigned)size +
199+ FF_INPUT_BUFFER_PADDING_SIZE);
189200
190201 if (!src2) {
191− av_log(s->avctx, AV_LOG_ERROR, "Error allocating temporary buffer\n");
202+ av_log(s->avctx, AV_LOG_ERROR,
203+ "Error allocating temporary buffer\n");
192204 return AVERROR(ENOMEM);
193205 }
194− if(s->fax_opts & 2){
195− av_log(s->avctx, AV_LOG_ERROR, "Uncompressed fax mode is not supported (yet)\n");
206+ if (s->fax_opts & 2) {
207+ av_log(s->avctx, AV_LOG_ERROR,
208+ "Uncompressed fax mode is not supported (yet)\n");
196209 av_free(src2);
197210 return -1;
198211 }
199− if(!s->fill_order){
212+ if (!s->fill_order) {
200213 memcpy(src2, src, size);
201− }else{
202− for(i = 0; i < size; i++)
214+ } else {
215+ for (i = 0; i < size; i++)
203216 src2[i] = av_reverse[src[i]];
204217 }
205− memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
206− switch(s->compr){
218+ memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
219+ switch (s->compr) {
207220 case TIFF_CCITT_RLE:
208221 case TIFF_G3:
209222 case TIFF_G4:
210− ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts);
223+ ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride,
224+ s->compr, s->fax_opts);
211225 break;
212226 }
213227 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 · 4 unmodified lines
218232 av_free(src2);
219233 return ret;
220234 }
221− for(line = 0; line < lines; line++){
222− if(src - ssrc > size){
235+ for (line = 0; line < lines; line++) {
236+ if (src - ssrc > size) {
223237 av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n");
224238 return -1;
225239 }
226− switch(s->compr){
240+ switch (s->compr) {
227241 case TIFF_RAW:
228242 if (ssrc + size - src < width)
229243 return AVERROR_INVALIDDATA;
@@ -238,22 +252,24 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 8 unmodified lines
238252 src += width;
239253 break;
240254 case TIFF_PACKBITS:
241− for(pixels = 0; pixels < width;){
242− code = (int8_t)*src++;
243− if(code >= 0){
255+ for (pixels = 0; pixels < width;) {
256+ code = (int8_t) * src++;
257+ if (code >= 0) {
244258 code++;
245− if(pixels + code > width){
246− av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n");
259+ if (pixels + code > width) {
260+ av_log(s->avctx, AV_LOG_ERROR,
261+ "Copy went out of bounds\n");
247262 return -1;
248263 }
249264 horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8),
250265 dst, 1, src, 0, code, pixels);
251266 src += code;
252267 pixels += code;
253− }else if(code != -128){ // -127..-1
268+ } else if (code != -128) { // -127..-1
254269 code = (-code) + 1;
255− if(pixels + code > width){
256− av_log(s->avctx, AV_LOG_ERROR, "Run went out of bounds\n");
270+ if (pixels + code > width) {
271+ av_log(s->avctx, AV_LOG_ERROR,
272+ "Run went out of bounds\n");
257273 return -1;
258274 }
259275 c = *src++;
@@ -265,8 +281,9 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 5 unmodified lines
265281 break;
266282 case TIFF_LZW:
267283 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);
284+ if (pixels < width) {
285+ av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n",
286+ pixels, width);
270287 return -1;
271288 }
272289 if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8)
@@ -342,7 +359,8 @@ static int init_image(TiffContext *s) · 69 unmodified lines
342359 return 0;
343360 }
344361
345−static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf)
362+static int tiff_decode_tag(TiffContext *s, const uint8_t *start,
363+ const uint8_t *buf, const uint8_t *end_buf)
346364 {
347365 unsigned tag, type, count, off, value = 0;
348366 int i, j;
@@ -357,12 +375,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 8 unmodified lines
357375 off = tget_long(&buf, s->le);
358376
359377 if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) {
360− av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n", type);
378+ av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n",
379+ type);
361380 return 0;
362381 }
363382
364− if(count == 1){
365− switch(type){
383+ if (count == 1) {
384+ switch (type) {
366385 case TIFF_BYTE:
367386 case TIFF_SHORT:
368387 buf -= 4;
@@ -374,7 +393,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 5 unmodified lines
374393 buf = NULL;
375394 break;
376395 case TIFF_STRING:
377− if(count <= 4){
396+ if (count <= 4) {
378397 buf -= 4;
379398 break;
380399 }
@@ -390,12 +409,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 9 unmodified lines
390409 }
391410 }
392411
393− if(buf && (buf < start || buf > end_buf)){
394− av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
412+ if (buf && (buf < start || buf > end_buf)) {
413+ av_log(s->avctx, AV_LOG_ERROR,
414+ "Tag referencing position outside the image\n");
395415 return -1;
396416 }
397417
398− switch(tag){
418+ switch (tag) {
399419 case TIFF_WIDTH:
400420 s->width = value;
401421 break;
@@ -404,20 +424,25 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 2 unmodified lines
404424 break;
405425 case TIFF_BPP:
406426 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);
427+ if (count > 4) {
428+ av_log(s->avctx, AV_LOG_ERROR,
429+ "This format is not supported (bpp=%d, %d components)\n",
430+ s->bpp, count);
409431 return -1;
410432 }
411− if(count == 1) s->bpp = value;
412− else{
413− switch(type){
433+ if (count == 1)
434+ s->bpp = value;
435+ else {
436+ switch (type) {
414437 case TIFF_BYTE:
415− s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) + ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
438+ s->bpp = (off & 0xFF) + ((off >> 8) & 0xFF) +
439+ ((off >> 16) & 0xFF) + ((off >> 24) & 0xFF);
416440 break;
417441 case TIFF_SHORT:
418442 case TIFF_LONG:
419443 s->bpp = 0;
420− for(i = 0; i < count && buf < end_buf; i++) s->bpp += tget(&buf, type, s->le);
444+ for (i = 0; i < count && buf < end_buf; i++)
445+ s->bpp += tget(&buf, type, s->le);
421446 break;
422447 default:
423448 s->bpp = -1;
@@ -437,7 +462,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 13 unmodified lines
437462 case TIFF_COMPR:
438463 s->compr = value;
439464 s->predictor = 0;
440− switch(s->compr){
465+ switch (s->compr) {
441466 case TIFF_RAW:
442467 case TIFF_PACKBITS:
443468 case TIFF_LZW:
@@ -457,48 +482,54 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 13 unmodified lines
457482 #endif
458483 case TIFF_JPEG:
459484 case TIFF_NEWJPEG:
460− av_log(s->avctx, AV_LOG_ERROR, "JPEG compression is not supported\n");
485+ av_log(s->avctx, AV_LOG_ERROR,
486+ "JPEG compression is not supported\n");
461487 return -1;
462488 default:
463− av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n", s->compr);
489+ av_log(s->avctx, AV_LOG_ERROR, "Unknown compression method %i\n",
490+ s->compr);
464491 return -1;
465492 }
466493 break;
467494 case TIFF_ROWSPERSTRIP:
468495 if (type == TIFF_LONG && value == UINT_MAX)
469496 value = s->avctx->height;
470− if(value < 1){
471− av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n");
497+ if (value < 1) {
498+ av_log(s->avctx, AV_LOG_ERROR,
499+ "Incorrect value of rows per strip\n");
472500 return -1;
473501 }
474502 s->rps = value;
475503 break;
476504 case TIFF_STRIP_OFFS:
477− if(count == 1){
505+ if (count == 1) {
478506 s->stripdata = NULL;
479507 s->stripoff = value;
480− }else
508+ } else
481509 s->stripdata = start + off;
482510 s->strips = count;
483− if(s->strips == 1) s->rps = s->height;
511+ if (s->strips == 1)
512+ s->rps = s->height;
484513 s->sot = type;
485− if(s->stripdata > end_buf){
486− av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
514+ if (s->stripdata > end_buf) {
515+ av_log(s->avctx, AV_LOG_ERROR,
516+ "Tag referencing position outside the image\n");
487517 return -1;
488518 }
489519 break;
490520 case TIFF_STRIP_SIZE:
491− if(count == 1){
521+ if (count == 1) {
492522 s->stripsizes = NULL;
493523 s->stripsize = value;
494524 s->strips = 1;
495− }else{
525+ } else {
496526 s->stripsizes = start + off;
497527 }
498528 s->strips = count;
499529 s->sstype = type;
500− if(s->stripsizes > end_buf){
501− av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n");
530+ if (s->stripsizes > end_buf) {
531+ av_log(s->avctx, AV_LOG_ERROR,
532+ "Tag referencing position outside the image\n");
502533 return -1;
503534 }
504535 break;
@@ -513,7 +544,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 8 unmodified lines
513544 s->predictor = value;
514545 break;
515546 case TIFF_INVERT:
516− switch(value){
547+ switch (value) {
517548 case 0:
518549 s->invert = 1;
519550 break;
@@ -524,13 +555,15 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 4 unmodified lines
524555 case 3:
525556 break;
526557 default:
527− av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n", value);
558+ av_log(s->avctx, AV_LOG_ERROR, "Color mode %d is not supported\n",
559+ value);
528560 return -1;
529561 }
530562 break;
531563 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);
564+ if (value < 1 || value > 2) {
565+ av_log(s->avctx, AV_LOG_ERROR,
566+ "Unknown FillOrder value %d, trying default one\n", value);
534567 value = 1;
535568 }
536569 s->fill_order = value - 1;
@@ -544,44 +577,44 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 7 unmodified lines
544577 gp = buf + count / 3 * off;
545578 bp = buf + count / 3 * off * 2;
546579 off = (type_sizes[type] - 1) << 3;
547− for(i = 0; i < count / 3; i++){
580+ for (i = 0; i < count / 3; i++) {
548581 j = 0xff << 24;
549582 j |= (tget(&rp, type, s->le) >> off) << 16;
550583 j |= (tget(&gp, type, s->le) >> off) << 8;
551− j |= tget(&bp, type, s->le) >> off;
584+ j |= tget(&bp, type, s->le) >> off;
552585 pal[i] = j;
553586 }
554587 s->palette_is_set = 1;
555588 break;
556589 case TIFF_PLANAR:
557− if(value == 2){
590+ if (value == 2) {
558591 av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n");
559592 return -1;
560593 }
561594 break;
562595 case TIFF_T4OPTIONS:
563− if(s->compr == TIFF_G3)
596+ if (s->compr == TIFF_G3)
564597 s->fax_opts = value;
565598 break;
566599 case TIFF_T6OPTIONS:
567− if(s->compr == TIFF_G4)
600+ if (s->compr == TIFF_G4)
568601 s->fax_opts = value;
569602 break;
570603 default:
571− av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n", tag, tag);
604+ av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n",
605+ tag, tag);
572606 }
573607 return 0;
574608 }
575609
576610 static int decode_frame(AVCodecContext *avctx,
577− void *data, int *data_size,
578− AVPacket *avpkt)
611+ void *data, int *data_size, AVPacket *avpkt)
579612 {
580613 const uint8_t *buf = avpkt->data;
581614 int buf_size = avpkt->size;
582− TiffContext * const s = avctx->priv_data;
615+ TiffContext *const s = avctx->priv_data;
583616 AVFrame *picture = data;
584− AVFrame * const p = &s->picture;
617+ AVFrame *const p = &s->picture;
585618 const uint8_t *orig_buf = buf, *end_buf = buf + buf_size;
586619 unsigned off;
587620 int id, le, ret;
@@ -593,10 +626,13 @@ static int decode_frame(AVCodecContext *avctx, · 5 unmodified lines
593626 //parse image header
594627 if (end_buf - buf < 8)
595628 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{
629+ id = AV_RL16(buf);
630+ buf += 2;
631+ if (id == 0x4949)
632+ le = 1;
633+ else if (id == 0x4D4D)
634+ le = 0;
635+ else {
600636 av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n");
601637 return -1;
602638 }
@@ -606,8 +642,9 @@ static int decode_frame(AVCodecContext *avctx, · 3 unmodified lines
606642 s->fill_order = 0;
607643 // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number
608644 // 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");
645+ if (tget_short(&buf, le) != 42) {
646+ av_log(avctx, AV_LOG_ERROR,
647+ "The answer to life, universe and everything is not correct!\n");
611648 return -1;
612649 }
613650 // Reset these pointers so we can tell if they were set this frame
@@ -620,12 +657,12 @@ static int decode_frame(AVCodecContext *avctx, · 6 unmodified lines
620657 }
621658 buf = orig_buf + off;
622659 entries = tget_short(&buf, le);
623− for(i = 0; i < entries; i++){
624− if(tiff_decode_tag(s, orig_buf, buf, end_buf) < 0)
660+ for (i = 0; i < entries; i++) {
661+ if (tiff_decode_tag(s, orig_buf, buf, end_buf) < 0)
625662 return -1;
626663 buf += 12;
627664 }
628− if(!s->stripdata && !s->stripoff){
665+ if (!s->stripdata && !s->stripoff) {
629666 av_log(avctx, AV_LOG_ERROR, "Image data is missing\n");
630667 return -1;
631668 }
@@ -633,36 +670,37 @@ static int decode_frame(AVCodecContext *avctx, · 1 unmodified line
633670 if ((ret = init_image(s)) < 0)
634671 return ret;
635672
636− if(s->strips == 1 && !s->stripsize){
673+ if (s->strips == 1 && !s->stripsize) {
637674 av_log(avctx, AV_LOG_WARNING, "Image data size missing\n");
638675 s->stripsize = buf_size - s->stripoff;
639676 }
640677 stride = p->linesize[0];
641678 dst = p->data[0];
642− for(i = 0; i < s->height; i += s->rps){
643− if(s->stripsizes) {
679+ for (i = 0; i < s->height; i += s->rps) {
680+ if (s->stripsizes) {
644681 if (s->stripsizes >= end_buf)
645682 return AVERROR_INVALIDDATA;
646683 ssize = tget(&s->stripsizes, s->sstype, s->le);
647684 } else
648685 ssize = s->stripsize;
649686
650− if(s->stripdata){
687+ if (s->stripdata) {
651688 if (s->stripdata >= end_buf)
652689 return AVERROR_INVALIDDATA;
653690 soff = tget(&s->stripdata, s->sot, s->le);
654− }else
691+ } else
655692 soff = s->stripoff;
656693
657694 if (soff > buf_size || ssize > buf_size - soff) {
658695 av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n");
659696 return -1;
660697 }
661− if(tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize, FFMIN(s->rps, s->height - i)) < 0)
698+ if (tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize,
699+ FFMIN(s->rps, s->height - i)) < 0)
662700 break;
663701 dst += s->rps * stride;
664702 }
665− if(s->predictor == 2){
703+ if (s->predictor == 2) {
666704 dst = p->data[0];
667705 soff = s->bpp >> 3;
668706 ssize = s->width * soff;
@@ -681,18 +719,18 @@ static int decode_frame(AVCodecContext *avctx, · 12 unmodified lines
681719 dst += stride;
682720 }
683721 } else {
684− for(i = 0; i < s->height; i++) {
685− for(j = soff; j < ssize; j++)
722+ for (i = 0; i < s->height; i++) {
723+ for (j = soff; j < ssize; j++)
686724 dst[j] += dst[j - soff];
687725 dst += stride;
688726 }
689727 }
690728 }
691729
692− if(s->invert){
730+ if (s->invert) {
693731 dst = s->picture.data[0];
694− for(i = 0; i < s->height; i++){
695− for(j = 0; j < s->picture.linesize[0]; j++)
732+ for (i = 0; i < s->height; i++) {
733+ for (j = 0; j < s->picture.linesize[0]; j++)
696734 dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j];
697735 dst += s->picture.linesize[0];
698736 }
@@ -703,7 +741,8 @@ static int decode_frame(AVCodecContext *avctx, · 4 unmodified lines
703741 return buf_size;
704742 }
705743
706−static av_cold int tiff_init(AVCodecContext *avctx){
744+static av_cold int tiff_init(AVCodecContext *avctx)
745+{
707746 TiffContext *s = avctx->priv_data;
708747
709748 s->width = 0;
@@ -719,10 +758,10 @@ static av_cold int tiff_init(AVCodecContext *avctx){ · 9 unmodified lines
719758
720759 static av_cold int tiff_end(AVCodecContext *avctx)
721760 {
722− TiffContext * const s = avctx->priv_data;
761+ TiffContext *const s = avctx->priv_data;
723762
724763 ff_lzw_decode_close(&s->lzw);
725− if(s->picture.data[0])
764+ if (s->picture.data[0])
726765 avctx->release_buffer(avctx, &s->picture);
727766 return 0;
728767 }
libavcodec/wmalosslessdec.c+10−9
@@ -229,7 +229,6 @@ static av_cold int decode_init(AVCodecContext *avctx) · 228 unmodified lines
229229 s->max_subframe_len_bit = 0;
230230 s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
231231
232− num_possible_block_sizes = log2_max_num_subframes + 1;
233232 s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
234233 s->dynamic_range_compression = s->decode_flags & 0x80;
235234 s->bV3RTM = s->decode_flags & 0x100;
@@ -940,9 +939,10 @@ static int decode_subframe(WmallDecodeCtx *s) · 704 unmodified lines
940939
941940 if (rawpcm_tile) {
942941 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;
942+ if (bits <= 0) {
943+ av_log(s->avctx, AV_LOG_ERROR,
944+ "Invalid number of padding bits in raw PCM tile\n");
945+ return AVERROR_INVALIDDATA;
946946 }
947947 av_dlog(s->avctx, "RAWPCM %d bits per sample. "
948948 "total %d bits, remain=%d\n", bits,
@@ -1169,8 +1169,7 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 220 unmodified lines
11691169 GetBitContext* gb = &s->pgb;
11701170 const uint8_t* buf = avpkt->data;
11711171 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;
11741173
11751174 if (s->packet_done || s->packet_loss) {
11761175 s->packet_done = 0;
@@ -1185,9 +1184,11 @@ static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, · 8 unmodified lines
11851184
11861185 /* parse packet header */
11871186 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);
1187+ packet_sequence_number = get_bits(gb, 4);
1188+ skip_bits(gb, 1); // Skip seekable_frame_in_packet, currently ununused
1189+ spliced_packet = get_bits1(gb);
1190+ if (spliced_packet)
1191+ av_log_missing_feature(avctx, "Bitstream splicing", 1);
11911192
11921193 /* get number of bits that need to be added to the previous frame */
11931194 num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
libavcodec/x86/dsputil_yasm.asm+1−1
@@ -594,7 +594,7 @@ cglobal emu_edge_core, 2, 7, 0 · 593 unmodified lines
594594 %define valw2 r7w
595595 %define valw3 r3w
596596 %if WIN64
597−%define valw4 r4w
597+%define valw4 r7w
598598 %else ; unix64
599599 %define valw4 r3w
600600 %endif
libavfilter/avfiltergraph.h+44−8
@@ -91,11 +91,11 @@ void avfilter_graph_free(AVFilterGraph **graph); · 90 unmodified lines
9191 /**
9292 * A linked-list of the inputs/outputs of the filter chain.
9393 *
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.
9999 */
100100 typedef struct AVFilterInOut {
101101 /** unique name for this input/output in the list */
@@ -112,13 +112,14 @@ typedef struct AVFilterInOut { · 10 unmodified lines
112112 } AVFilterInOut;
113113
114114 /**
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.
117118 */
118119 AVFilterInOut *avfilter_inout_alloc(void);
119120
120121 /**
121− * Free the AVFilterInOut in *inout, and set its pointer to NULL.
122+ * Free the supplied list of AVFilterInOut and set *inout to NULL.
122123 * If *inout is NULL, do nothing.
123124 */
124125 void avfilter_inout_free(AVFilterInOut **inout);
@@ -140,6 +141,41 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 15 unmodified lines
140141 AVFilterInOut **inputs, AVFilterInOut **outputs,
141142 void *log_ctx);
142143
144+/**
145+ * Add a graph described by a string to a graph.
146+ *
147+ * @param[in] graph the filter graph where to link the parsed graph context
148+ * @param[in] filters string to be parsed
149+ * @param[out] inputs a linked list of all free (unlinked) inputs of the
150+ * parsed graph will be returned here. It is to be freed
151+ * by the caller using avfilter_inout_free().
152+ * @param[out] outputs a linked list of all free (unlinked) outputs of the
153+ * parsed graph will be returned here. It is to be freed by the
154+ * caller using avfilter_inout_free().
155+ * @return zero on success, a negative AVERROR code on error
156+ *
157+ * @note the difference between avfilter_graph_parse2() and
158+ * avfilter_graph_parse() is that in avfilter_graph_parse(), the caller provides
159+ * the lists of inputs and outputs, which therefore must be known before calling
160+ * the function. On the other hand, avfilter_graph_parse2() \em returns the
161+ * inputs and outputs that are left unlinked after parsing the graph and the
162+ * caller then deals with them. Another difference is that in
163+ * avfilter_graph_parse(), the inputs parameter describes inputs of the
164+ * <em>already existing</em> part of the graph; i.e. from the point of view of
165+ * the newly created part, they are outputs. Similarly the outputs parameter
166+ * describes outputs of the already existing filters, which are provided as
167+ * inputs to the parsed filters.
168+ * avfilter_graph_parse2() takes the opposite approach -- it makes no reference
169+ * whatsoever to already existing parts of the graph and the inputs parameter
170+ * will on return contain inputs of the newly parsed part of the graph.
171+ * Analogously the outputs parameter will contain outputs of the newly created
172+ * filters.
173+ */
174+int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
175+ AVFilterInOut **inputs,
176+ AVFilterInOut **outputs);
177+
178+
143179 /**
144180 * Send a command to one or more filter instances.
145181 *
libavfilter/buffersrc.h+1−0
@@ -32,6 +32,7 @@ · 31 unmodified lines
3232 *
3333 * @param buf buffer containing frame data to be passed down the filtergraph.
3434 * 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.
3536 */
3637 int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf);
3738
libavfilter/graphparser.c+192−12
@@ -189,13 +189,15 @@ static AVFilterInOut *extract_inout(const char *label, AVFilterInOut **links) · 188 unmodified lines
189189 {
190190 AVFilterInOut *ret;
191191
192− while (*links && strcmp((*links)->name, label))
192+ while (*links && (!(*links)->name || strcmp((*links)->name, label)))
193193 links = &((*links)->next);
194194
195195 ret = *links;
196196
197− if (ret)
197+ if (ret) {
198198 *links = ret->next;
199+ ret->next = NULL;
200+ }
199201
200202 return ret;
201203 }
@@ -206,22 +208,31 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element) · 4 unmodified lines
206208 *inouts = element;
207209 }
208210
211+static void append_inout(AVFilterInOut **inouts, AVFilterInOut **element)
212+{
213+ while (*inouts && (*inouts)->next)
214+ inouts = &((*inouts)->next);
215+
216+ if (!*inouts)
217+ *inouts = *element;
218+ else
219+ (*inouts)->next = *element;
220+ *element = NULL;
221+}
222+
209223 static int link_filter_inouts(AVFilterContext *filt_ctx,
210224 AVFilterInOut **curr_inputs,
211225 AVFilterInOut **open_inputs, void *log_ctx)
212226 {
213− int pad = filt_ctx->input_count, ret;
227+ int pad, ret;
214228
215− while (pad--) {
229+ for (pad = 0; pad < filt_ctx->input_count; pad++) {
216230 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− }
223231
224− *curr_inputs = (*curr_inputs)->next;
232+ if (p)
233+ *curr_inputs = (*curr_inputs)->next;
234+ else if (!(p = av_mallocz(sizeof(*p))))
235+ return AVERROR(ENOMEM);
225236
226237 if (p->filter_ctx) {
227238 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, · 30 unmodified lines
258269 static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs,
259270 AVFilterInOut **open_outputs, void *log_ctx)
260271 {
272+ AVFilterInOut *parsed_inputs = NULL;
261273 int pad = 0;
262274
263275 while (**buf == '[') {
@@ -280,12 +292,15 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, · 16 unmodified lines
280292 match->pad_idx = pad;
281293 }
282294
283− insert_inout(curr_inputs, match);
295+ append_inout(&parsed_inputs, &match);
284296
285297 *buf += strspn(*buf, WHITESPACES);
286298 pad++;
287299 }
288300
301+ append_inout(&parsed_inputs, curr_inputs);
302+ *curr_inputs = parsed_inputs;
303+
289304 return pad;
290305 }
291306
@@ -334,10 +349,173 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, · 42 unmodified lines
334349 return pad;
335350 }
336351
352+#if FF_API_GRAPH_AVCLASS
353+#define log_ctx graph
354+#else
355+#define log_ctx NULL
356+#endif
357+
358+static int parse_sws_flags(const char **buf, AVFilterGraph *graph)
359+{
360+ char *p = strchr(*buf, ';');
361+
362+ if (strncmp(*buf, "sws_flags=", 10))
363+ return 0;
364+
365+ if (!p) {
366+ av_log(log_ctx, AV_LOG_ERROR, "sws_flags not terminated with ';'.\n");
367+ return AVERROR(EINVAL);
368+ }
369+
370+ *buf += 4; // keep the 'flags=' part
371+
372+ av_freep(&graph->scale_sws_opts);
373+ if (!(graph->scale_sws_opts = av_mallocz(p - *buf + 1)))
374+ return AVERROR(ENOMEM);
375+ av_strlcpy(graph->scale_sws_opts, *buf, p - *buf + 1);
376+
377+ *buf = p + 1;
378+ return 0;
379+}
380+
381+int avfilter_graph_parse2(AVFilterGraph *graph, const char *filters,
382+ AVFilterInOut **inputs,
383+ AVFilterInOut **outputs)
384+{
385+ int index = 0, ret = 0;
386+ char chr = 0;
387+
388+ AVFilterInOut *curr_inputs = NULL, *open_inputs = NULL, *open_outputs = NULL;
389+
390+ filters += strspn(filters, WHITESPACES);
391+
392+ if ((ret = parse_sws_flags(&filters, graph)) < 0)
393+ goto fail;
394+
395+ do {
396+ AVFilterContext *filter;
397+ filters += strspn(filters, WHITESPACES);
398+
399+ if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0)
400+ goto end;
401+
402+ if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0)
403+ goto end;
404+
405+ if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0)
406+ goto end;
407+
408+ if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs,
409+ log_ctx)) < 0)
410+ goto end;
411+
412+ filters += strspn(filters, WHITESPACES);
413+ chr = *filters++;
414+
415+ if (chr == ';' && curr_inputs)
416+ append_inout(&open_outputs, &curr_inputs);
417+ index++;
418+ } while (chr == ',' || chr == ';');
419+
420+ if (chr) {
421+ av_log(log_ctx, AV_LOG_ERROR,
422+ "Unable to parse graph description substring: \"%s\"\n",
423+ filters - 1);
424+ ret = AVERROR(EINVAL);
425+ goto end;
426+ }
427+
428+ append_inout(&open_outputs, &curr_inputs);
429+
430+
431+ *inputs = open_inputs;
432+ *outputs = open_outputs;
433+ return 0;
434+
435+ fail:end:
436+ for (; graph->filter_count > 0; graph->filter_count--)
437+ avfilter_free(graph->filters[graph->filter_count - 1]);
438+ av_freep(&graph->filters);
439+ avfilter_inout_free(&open_inputs);
440+ avfilter_inout_free(&open_outputs);
441+ avfilter_inout_free(&curr_inputs);
442+
443+ *inputs = NULL;
444+ *outputs = NULL;
445+
446+ return ret;
447+}
448+#undef log_ctx
449+
337450 int avfilter_graph_parse(AVFilterGraph *graph, const char *filters,
338451 AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr,
339452 void *log_ctx)
340453 {
454+#if 0
455+ int ret;
456+ AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL;
457+ AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL;
458+ AVFilterInOut *cur, *match, *inputs = NULL, *outputs = NULL;
459+
460+ if ((ret = avfilter_graph_parse2(graph, filters, &inputs, &outputs)) < 0)
461+ goto fail;
462+
463+ /* First input can be omitted if it is "[in]" */
464+ if (inputs && !inputs->name)
465+ inputs->name = av_strdup("in");
466+ for (cur = inputs; cur; cur = cur->next) {
467+ if (!cur->name) {
468+ av_log(log_ctx, AV_LOG_ERROR,
469+ "Not enough inputs specified for the \"%s\" filter.\n",
470+ cur->filter_ctx->filter->name);
471+ ret = AVERROR(EINVAL);
472+ goto fail;
473+ }
474+ if (!(match = extract_inout(cur->name, &open_outputs)))
475+ continue;
476+ ret = avfilter_link(match->filter_ctx, match->pad_idx,
477+ cur->filter_ctx, cur->pad_idx);
478+ avfilter_inout_free(&match);
479+ if (ret < 0)
480+ goto fail;
481+ }
482+
483+ /* Last output can be omitted if it is "[out]" */
484+ if (outputs && !outputs->name)
485+ outputs->name = av_strdup("out");
486+ for (cur = outputs; cur; cur = cur->next) {
487+ if (!cur->name) {
488+ av_log(log_ctx, AV_LOG_ERROR,
489+ "Invalid filterchain containing an unlabelled output pad: \"%s\"\n",
490+ filters);
491+ ret = AVERROR(EINVAL);
492+ goto fail;
493+ }
494+ if (!(match = extract_inout(cur->name, &open_inputs)))
495+ continue;
496+ ret = avfilter_link(cur->filter_ctx, cur->pad_idx,
497+ match->filter_ctx, match->pad_idx);
498+ avfilter_inout_free(&match);
499+ if (ret < 0)
500+ goto fail;
501+ }
502+
503+ fail:
504+ if (ret < 0) {
505+ for (; graph->filter_count > 0; graph->filter_count--)
506+ avfilter_free(graph->filters[graph->filter_count - 1]);
507+ av_freep(&graph->filters);
508+ }
509+ avfilter_inout_free(&inputs);
510+ avfilter_inout_free(&outputs);
511+ /* clear open_in/outputs only if not passed as parameters */
512+ if (open_inputs_ptr) *open_inputs_ptr = open_inputs;
513+ else avfilter_inout_free(&open_inputs);
514+ if (open_outputs_ptr) *open_outputs_ptr = open_outputs;
515+ else avfilter_inout_free(&open_outputs);
516+ return ret;
517+}
518+#else
341519 int index = 0, ret = 0;
342520 char chr = 0;
343521
@@ -414,3 +592,5 @@ end: · 70 unmodified lines
414592 }
415593 return ret;
416594 }
595+
596+#endif
libavfilter/version.h+2−2
@@ -29,8 +29,8 @@ · 28 unmodified lines
2929 #include "libavutil/avutil.h"
3030
3131 #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
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3636 LIBAVFILTER_VERSION_MINOR, \
libavfilter/vsrc_buffer.c+29−3
@@ -39,6 +39,7 @@ typedef struct { · 38 unmodified lines
3939 AVRational time_base; ///< time_base to set in the output link
4040 AVRational sample_aspect_ratio;
4141 char sws_param[256];
42+ int eof;
4243 } BufferSourceContext;
4344
4445 #define CHECK_PARAM_CHANGE(s, c, width, height, format)\
@@ -55,6 +56,12 @@ int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, · 10 unmodified lines
5556 AVFilterBufferRef *buf;
5657 int ret;
5758
59+ if (!picref) {
60+ c->eof = 1;
61+ return 0;
62+ } else if (c->eof)
63+ return AVERROR(EINVAL);
64+
5865 if (!av_fifo_space(c->fifo) &&
5966 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
6067 sizeof(buf))) < 0)
@@ -125,6 +132,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 64 unmodified lines
125132 BufferSourceContext *c = s->priv;
126133 int ret;
127134
135+ if (!buf) {
136+ c->eof = 1;
137+ return 0;
138+ } else if (c->eof)
139+ return AVERROR(EINVAL);
140+
128141 if (!av_fifo_space(c->fifo) &&
129142 (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) +
130143 sizeof(buf))) < 0)
@@ -144,9 +157,17 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 13 unmodified lines
144157 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
145158 const AVFrame *frame, int flags)
146159 {
160+ BufferSourceContext *c = buffer_src->priv;
161+ AVFilterBufferRef *picref;
147162 int ret;
148− AVFilterBufferRef *picref =
149− avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE);
163+
164+ if (!frame) {
165+ c->eof = 1;
166+ return 0;
167+ } else if (c->eof)
168+ return AVERROR(EINVAL);
169+
170+ picref = avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE);
150171 if (!picref)
151172 return AVERROR(ENOMEM);
152173 ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags);
@@ -226,6 +247,8 @@ static int request_frame(AVFilterLink *link) · 73 unmodified lines
226247 AVFilterBufferRef *buf;
227248
228249 if (!av_fifo_size(c->fifo)) {
250+ if (c->eof)
251+ return AVERROR_EOF;
229252 av_log(link->src, AV_LOG_WARNING,
230253 "request_frame() called with no available frame!\n");
231254 return AVERROR(EINVAL);
@@ -243,7 +266,10 @@ static int request_frame(AVFilterLink *link) · 11 unmodified lines
243266 static int poll_frame(AVFilterLink *link)
244267 {
245268 BufferSourceContext *c = link->src->priv;
246− return !!av_fifo_size(c->fifo);
269+ int size = av_fifo_size(c->fifo);
270+ if (!size && c->eof)
271+ return AVERROR_EOF;
272+ return size/sizeof(AVFilterBufferRef*);
247273 }
248274
249275 AVFilter avfilter_vsrc_buffer = {
libavformat/isom.h+1−0
@@ -107,6 +107,7 @@ typedef struct MOVStreamContext { · 106 unmodified lines
107107 unsigned int alt_sample_size; ///< always contains sample size from stsz atom
108108 unsigned int sample_count;
109109 int *sample_sizes;
110+ int keyframe_absent;
110111 unsigned int keyframe_count;
111112 int *keyframes;
112113 int time_scale;
libavformat/mov.c+4−1
@@ -1618,7 +1618,10 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1617 unmodified lines
16181618 av_dlog(c->fc, "keyframe_count = %d\n", entries);
16191619
16201620 if (!entries)
1621+ {
1622+ sc->keyframe_absent = 1;
16211623 return 0;
1624+ }
16221625 if (entries >= UINT_MAX / sizeof(int))
16231626 return AVERROR_INVALIDDATA;
16241627 sc->keyframes = av_malloc(entries * sizeof(int));
@@ -1873,7 +1876,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) · 248 unmodified lines
18731876 return;
18741877 }
18751878
1876− if (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]) {
1879+ if (!sc->keyframe_absent && (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index])) {
18771880 keyframe = 1;
18781881 if (stss_index + 1 < sc->keyframe_count)
18791882 stss_index++;
libavformat/utils.c+2−0
@@ -1975,6 +1975,8 @@ static int has_duration(AVFormatContext *ic) · 1974 unmodified lines
19751975 if (st->duration != AV_NOPTS_VALUE)
19761976 return 1;
19771977 }
1978+ if (ic->duration)
1979+ return 1;
19781980 return 0;
19791981 }
19801982
libswscale/output.c+12−12
@@ -469,7 +469,7 @@ yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, · 468 unmodified lines
469469 {
470470 int i;
471471
472− for (i = 0; i < (dstW >> 1); i++) {
472+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
473473 int j;
474474 int Y1 = 1 << 18;
475475 int Y2 = 1 << 18;
@@ -512,7 +512,7 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], · 36 unmodified lines
512512 int uvalpha1 = 4095 - uvalpha;
513513 int i;
514514
515− for (i = 0; i < (dstW >> 1); i++) {
515+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
516516 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
517517 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
518518 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
@@ -539,7 +539,7 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, · 20 unmodified lines
539539 int i;
540540
541541 if (uvalpha < 2048) {
542− for (i = 0; i < (dstW >> 1); i++) {
542+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
543543 int Y1 = (buf0[i * 2 ]+64) >> 7;
544544 int Y2 = (buf0[i * 2 + 1]+64) >> 7;
545545 int U = (ubuf0[i] +64) >> 7;
@@ -561,7 +561,7 @@ yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, · 15 unmodified lines
561561 }
562562 } else {
563563 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++) {
565565 int Y1 = (buf0[i * 2 ] + 64) >> 7;
566566 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
567567 int U = (ubuf0[i] + ubuf1[i]+128) >> 8;
@@ -608,7 +608,7 @@ yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter, · 40 unmodified lines
608608 {
609609 int i;
610610
611− for (i = 0; i < (dstW >> 1); i++) {
611+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
612612 int j;
613613 int Y1 = -0x40000000;
614614 int Y2 = -0x40000000;
@@ -671,7 +671,7 @@ yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2], · 56 unmodified lines
671671 int uvalpha1 = 4095 - uvalpha;
672672 int i;
673673
674− for (i = 0; i < (dstW >> 1); i++) {
674+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
675675 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14;
676676 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14;
677677 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, · 31 unmodified lines
709709 int i;
710710
711711 if (uvalpha < 2048) {
712− for (i = 0; i < (dstW >> 1); i++) {
712+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
713713 int Y1 = (buf0[i * 2] ) >> 2;
714714 int Y2 = (buf0[i * 2 + 1]) >> 2;
715715 int U = (ubuf0[i] + (-128 << 11)) >> 2;
@@ -737,7 +737,7 @@ yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, · 21 unmodified lines
737737 }
738738 } else {
739739 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++) {
741741 int Y1 = (buf0[i * 2] ) >> 2;
742742 int Y2 = (buf0[i * 2 + 1]) >> 2;
743743 int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3;
@@ -952,7 +952,7 @@ yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter, · 208 unmodified lines
952952 {
953953 int i;
954954
955− for (i = 0; i < (dstW >> 1); i++) {
955+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
956956 int j, A1, A2;
957957 int Y1 = 1 << 18;
958958 int Y2 = 1 << 18;
@@ -1012,7 +1012,7 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], · 53 unmodified lines
10121012 int uvalpha1 = 4095 - uvalpha;
10131013 int i;
10141014
1015− for (i = 0; i < (dstW >> 1); i++) {
1015+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
10161016 int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19;
10171017 int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19;
10181018 int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19;
@@ -1050,7 +1050,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, · 31 unmodified lines
10501050 int i;
10511051
10521052 if (uvalpha < 2048) {
1053− for (i = 0; i < (dstW >> 1); i++) {
1053+ for (i = 0; i < ((dstW + 1) >> 1); i++) {
10541054 int Y1 = (buf0[i * 2 ] + 64) >> 7;
10551055 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
10561056 int U = (ubuf0[i] + 64) >> 7;
@@ -1077,7 +1077,7 @@ yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, · 20 unmodified lines
10771077 }
10781078 } else {
10791079 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++) {
10811081 int Y1 = (buf0[i * 2 ] + 64) >> 7;
10821082 int Y2 = (buf0[i * 2 + 1] + 64) >> 7;
10831083 int U = (ubuf0[i] + ubuf1[i] + 128) >> 8;
tests/lavfi-regression.sh+1−1
@@ -40,7 +40,7 @@ do_lavfi "crop_vflip" "crop=iw-100:ih-100:100:100,vflip" · 39 unmodified lines
4040 do_lavfi "drawbox" "drawbox=224:24:88:72:#FF8010@0.5"
4141 do_lavfi "fade" "fade=in:5:15,fade=out:30:15"
4242 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"
4444 do_lavfi "pad" "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2"
4545 do_lavfi "pp" "mp=pp=be/de/tn/l5/al"
4646 do_lavfi "pp2" "mp=pp=be/fq:16/fa/lb"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t