* 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
Unified · Split
| @@ -19,6 +19,9 @@ API changes, most recent first: · 18 unmodified lines | ||
| 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 · 75 unmodified lines | ||
| 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: · 2 unmodified lines | ||
| 84 | 90 | @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted) |
| 85 | 91 | @var{FILTER} ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}] |
| 86 | 92 | @var{FILTERCHAIN} ::= @var{FILTER} [,@var{FILTERCHAIN}] |
| 87 | −@var{FILTERGRAPH} ::= @var{FILTERCHAIN} [;@var{FILTERGRAPH}] | |
| 93 | +@var{FILTERGRAPH} ::= [sws_flags=@var{flags};] @var{FILTERCHAIN} [;@var{FILTERGRAPH}] | |
| 88 | 94 | @end example |
| 89 | 95 | |
| 90 | 96 | @c man end FILTERGRAPH DESCRIPTION |
| @@ -31,16 +31,12 @@ · 30 unmodified lines | ||
| 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){ · 11 unmodified lines | ||
| 58 | 54 | frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, |
| 59 | 55 | 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 | 56 | |
| 61 | −//av_log(NULL, AV_LOG_ERROR, "%s\n", tmp); | |
| 62 | 57 | if (write(fd, tmp, strlen(tmp)) < 0) { |
| 63 | 58 | av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno)); |
| 64 | 59 | return AVERROR(errno); |
| @@ -72,155 +72,420 @@ struct xvid_ff_pass1 { · 71 unmodified lines | ||
| 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 | + */ | |
| 79 | 84 | |
| 80 | 85 | |
| 81 | 86 | /** |
| 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. | |
| 85 | 88 | * |
| 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. | |
| 88 | 92 | */ |
| 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; | |
| 95 | 97 | |
| 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; | |
| 102 | 101 | |
| 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)); | |
| 114 | 112 | |
| 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 | +} | |
| 121 | 116 | |
| 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 | +} | |
| 127 | 132 | |
| 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; | |
| 133 | 145 | |
| 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; | |
| 138 | 149 | |
| 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; | |
| 152 | 152 | |
| 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; | |
| 156 | 167 | |
| 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; | |
| 169 | 172 | |
| 170 | − xvid_gbl_init.version = XVID_VERSION; | |
| 171 | − xvid_gbl_init.debug = 0; | |
| 173 | + return 0; | |
| 174 | +} | |
| 172 | 175 | |
| 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; | |
| 185 | 188 | |
| 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; | |
| 188 | 192 | |
| 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 | + } | |
| 191 | 199 | |
| 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); | |
| 195 | 204 | |
| 196 | − /* Xvid can determine the proper profile to use */ | |
| 197 | − /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ | |
| 205 | + return 0; | |
| 206 | +} | |
| 198 | 207 | |
| 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; | |
| 202 | 225 | |
| 203 | − xvid_enc_create.num_threads = avctx->thread_count; | |
| 226 | + case XVID_PLG_BEFORE: | |
| 227 | + return xvid_ff_2pass_before(ref, p1); | |
| 204 | 228 | |
| 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); | |
| 207 | 231 | |
| 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); | |
| 212 | 234 | |
| 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; | |
| 224 | 489 | |
| 225 | 490 | plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; |
| 226 | 491 | plugins[xvid_enc_create.num_plugins].param = &rc2pass1; |
| @@ -334,446 +599,178 @@ static av_cold int xvid_encode_init(AVCodecContext *avctx) { · 107 unmodified lines | ||
| 334 | 599 | } else { |
| 335 | 600 | /* We are claiming to be Xvid */ |
| 336 | 601 | 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 | + } | |
| 634 | 605 | |
| 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; | |
| 638 | 611 | |
| 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 | + } | |
| 649 | 618 | |
| 650 | − *handle = x->context; | |
| 651 | − return 0; | |
| 652 | −} | |
| 619 | + x->encoder_handle = xvid_enc_create.handle; | |
| 620 | + avctx->coded_frame = &x->encoded_picture; | |
| 653 | 621 | |
| 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 | 622 | return 0; |
| 668 | 623 | } |
| 669 | 624 | |
| 670 | 625 | /** |
| 671 | − * Enable fast encode mode during the first pass. | |
| 626 | + * Encode a single frame. | |
| 672 | 627 | * |
| 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 | |
| 676 | 633 | */ |
| 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; | |
| 682 | 643 | |
| 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 }; | |
| 686 | 646 | |
| 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; | |
| 689 | 649 | |
| 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; | |
| 704 | 654 | |
| 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; | |
| 709 | 658 | |
| 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 | + } | |
| 712 | 664 | |
| 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 */ | |
| 725 | 666 | |
| 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 | + } | |
| 729 | 671 | |
| 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; | |
| 735 | 688 | } |
| 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; | |
| 736 | 692 | |
| 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; | |
| 741 | 696 | |
| 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 | + } | |
| 743 | 749 | } |
| 744 | 750 | |
| 745 | 751 | /** |
| 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. | |
| 749 | 754 | * |
| 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 | |
| 755 | 757 | */ |
| 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; | |
| 770 | 760 | |
| 771 | − case XVID_PLG_DESTROY: | |
| 772 | − return xvid_ff_2pass_destroy(ref, p1); | |
| 761 | + xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); | |
| 773 | 762 | |
| 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; | |
| 776 | 768 | } |
| 769 | + av_free(x->twopassfile); | |
| 770 | + av_free(x->intra_matrix); | |
| 771 | + av_free(x->inter_matrix); | |
| 772 | + | |
| 773 | + return 0; | |
| 777 | 774 | } |
| 778 | 775 | |
| 779 | 776 | /** |
| @@ -140,7 +140,6 @@ typedef struct { · 139 unmodified lines | ||
| 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) · 1460 unmodified lines | ||
| 1607 | 1606 | static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet) |
| 1608 | 1607 | { |
| 1609 | 1608 | const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f; |
| 1609 | + float *out = q->output_buffer + channel; | |
| 1610 | 1610 | int i; |
| 1611 | 1611 | q->fft.complex[channel][0].re *= 2.0f; |
| 1612 | 1612 | q->fft.complex[channel][0].im = 0.0f; |
| 1613 | 1613 | q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); |
| 1614 | 1614 | /* 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 | + } | |
| 1617 | 1620 | } |
| 1618 | 1621 | |
| 1619 | 1622 | |
| @@ -1688,7 +1691,6 @@ static void dump_context(QDM2Context *q) · 68 unmodified lines | ||
| 1688 | 1691 | PRINT("checksum_size",q->checksum_size); |
| 1689 | 1692 | PRINT("channels",q->channels); |
| 1690 | 1693 | PRINT("nb_channels",q->nb_channels); |
| 1691 | − PRINT("fft_frame_size",q->fft_frame_size); | |
| 1692 | 1694 | PRINT("fft_size",q->fft_size); |
| 1693 | 1695 | PRINT("sub_sampling",q->sub_sampling); |
| 1694 | 1696 | PRINT("fft_order",q->fft_order); |
| @@ -1843,7 +1845,6 @@ static av_cold int qdm2_decode_init(AVCodecContext *avctx) · 148 unmodified lines | ||
| 1843 | 1845 | } |
| 1844 | 1846 | |
| 1845 | 1847 | s->fft_order = av_log2(s->fft_size) + 1; |
| 1846 | − s->fft_frame_size = 2 * s->fft_size; // complex has two floats | |
| 1847 | 1848 | |
| 1848 | 1849 | // something like max decodable tones |
| 1849 | 1850 | s->group_order = av_log2(s->group_size) + 1; |
| @@ -52,35 +52,39 @@ typedef struct TiffContext { · 51 unmodified lines | ||
| 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, · 54 unmodified lines | ||
| 141 | 145 | } |
| 142 | 146 | } |
| 143 | 147 | |
| 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 | +{ | |
| 145 | 151 | int c, line, pixels, code; |
| 146 | 152 | const uint8_t *ssrc = src; |
| 147 | 153 | 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 | ||
| 150 | 156 | return AVERROR_INVALIDDATA; |
| 151 | 157 | |
| 152 | 158 | #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; | |
| 155 | 162 | int ret; |
| 156 | 163 | outlen = width * lines; |
| 157 | 164 | zbuf = av_malloc(outlen); |
| 158 | 165 | if (!zbuf) |
| 159 | 166 | return AVERROR(ENOMEM); |
| 160 | 167 | 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); | |
| 163 | 172 | av_free(zbuf); |
| 164 | 173 | return -1; |
| 165 | 174 | } |
| 166 | 175 | src = zbuf; |
| 167 | − for(line = 0; line < lines; line++){ | |
| 176 | + for (line = 0; line < lines; line++) { | |
| 168 | 177 | if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){ |
| 169 | 178 | horizontal_fill(s->bpp, dst, 1, src, 0, width, 0); |
| 170 | 179 | }else{ |
| @@ -177,37 +186,42 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 6 unmodified lines | ||
| 177 | 186 | return 0; |
| 178 | 187 | } |
| 179 | 188 | #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) { | |
| 182 | 191 | av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); |
| 183 | 192 | return -1; |
| 184 | 193 | } |
| 185 | 194 | } |
| 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) { | |
| 187 | 197 | 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); | |
| 189 | 200 | |
| 190 | 201 | 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"); | |
| 192 | 204 | return AVERROR(ENOMEM); |
| 193 | 205 | } |
| 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"); | |
| 196 | 209 | av_free(src2); |
| 197 | 210 | return -1; |
| 198 | 211 | } |
| 199 | − if(!s->fill_order){ | |
| 212 | + if (!s->fill_order) { | |
| 200 | 213 | memcpy(src2, src, size); |
| 201 | − }else{ | |
| 202 | − for(i = 0; i < size; i++) | |
| 214 | + } else { | |
| 215 | + for (i = 0; i < size; i++) | |
| 203 | 216 | src2[i] = av_reverse[src[i]]; |
| 204 | 217 | } |
| 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) { | |
| 207 | 220 | case TIFF_CCITT_RLE: |
| 208 | 221 | case TIFF_G3: |
| 209 | 222 | 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); | |
| 211 | 225 | break; |
| 212 | 226 | } |
| 213 | 227 | 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 | ||
| 218 | 232 | av_free(src2); |
| 219 | 233 | return ret; |
| 220 | 234 | } |
| 221 | − for(line = 0; line < lines; line++){ | |
| 222 | − if(src - ssrc > size){ | |
| 235 | + for (line = 0; line < lines; line++) { | |
| 236 | + if (src - ssrc > size) { | |
| 223 | 237 | av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); |
| 224 | 238 | return -1; |
| 225 | 239 | } |
| 226 | − switch(s->compr){ | |
| 240 | + switch (s->compr) { | |
| 227 | 241 | case TIFF_RAW: |
| 228 | 242 | if (ssrc + size - src < width) |
| 229 | 243 | return AVERROR_INVALIDDATA; |
| @@ -238,22 +252,24 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 8 unmodified lines | ||
| 238 | 252 | src += width; |
| 239 | 253 | break; |
| 240 | 254 | 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) { | |
| 244 | 258 | 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"); | |
| 247 | 262 | return -1; |
| 248 | 263 | } |
| 249 | 264 | horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), |
| 250 | 265 | dst, 1, src, 0, code, pixels); |
| 251 | 266 | src += code; |
| 252 | 267 | pixels += code; |
| 253 | − }else if(code != -128){ // -127..-1 | |
| 268 | + } else if (code != -128) { // -127..-1 | |
| 254 | 269 | 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"); | |
| 257 | 273 | return -1; |
| 258 | 274 | } |
| 259 | 275 | c = *src++; |
| @@ -265,8 +281,9 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 5 unmodified lines | ||
| 265 | 281 | break; |
| 266 | 282 | case TIFF_LZW: |
| 267 | 283 | 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); | |
| 270 | 287 | return -1; |
| 271 | 288 | } |
| 272 | 289 | if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8) |
| @@ -342,7 +359,8 @@ static int init_image(TiffContext *s) · 69 unmodified lines | ||
| 342 | 359 | return 0; |
| 343 | 360 | } |
| 344 | 361 | |
| 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) | |
| 346 | 364 | { |
| 347 | 365 | unsigned tag, type, count, off, value = 0; |
| 348 | 366 | int i, j; |
| @@ -357,12 +375,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 8 unmodified lines | ||
| 357 | 375 | off = tget_long(&buf, s->le); |
| 358 | 376 | |
| 359 | 377 | 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); | |
| 361 | 380 | return 0; |
| 362 | 381 | } |
| 363 | 382 | |
| 364 | − if(count == 1){ | |
| 365 | − switch(type){ | |
| 383 | + if (count == 1) { | |
| 384 | + switch (type) { | |
| 366 | 385 | case TIFF_BYTE: |
| 367 | 386 | case TIFF_SHORT: |
| 368 | 387 | buf -= 4; |
| @@ -374,7 +393,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 5 unmodified lines | ||
| 374 | 393 | buf = NULL; |
| 375 | 394 | break; |
| 376 | 395 | case TIFF_STRING: |
| 377 | − if(count <= 4){ | |
| 396 | + if (count <= 4) { | |
| 378 | 397 | buf -= 4; |
| 379 | 398 | break; |
| 380 | 399 | } |
| @@ -390,12 +409,13 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 9 unmodified lines | ||
| 390 | 409 | } |
| 391 | 410 | } |
| 392 | 411 | |
| 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"); | |
| 395 | 415 | return -1; |
| 396 | 416 | } |
| 397 | 417 | |
| 398 | − switch(tag){ | |
| 418 | + switch (tag) { | |
| 399 | 419 | case TIFF_WIDTH: |
| 400 | 420 | s->width = value; |
| 401 | 421 | break; |
| @@ -404,20 +424,25 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 2 unmodified lines | ||
| 404 | 424 | break; |
| 405 | 425 | case TIFF_BPP: |
| 406 | 426 | 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); | |
| 409 | 431 | return -1; |
| 410 | 432 | } |
| 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) { | |
| 414 | 437 | 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); | |
| 416 | 440 | break; |
| 417 | 441 | case TIFF_SHORT: |
| 418 | 442 | case TIFF_LONG: |
| 419 | 443 | 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); | |
| 421 | 446 | break; |
| 422 | 447 | default: |
| 423 | 448 | s->bpp = -1; |
| @@ -437,7 +462,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 13 unmodified lines | ||
| 437 | 462 | case TIFF_COMPR: |
| 438 | 463 | s->compr = value; |
| 439 | 464 | s->predictor = 0; |
| 440 | − switch(s->compr){ | |
| 465 | + switch (s->compr) { | |
| 441 | 466 | case TIFF_RAW: |
| 442 | 467 | case TIFF_PACKBITS: |
| 443 | 468 | case TIFF_LZW: |
| @@ -457,48 +482,54 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 13 unmodified lines | ||
| 457 | 482 | #endif |
| 458 | 483 | case TIFF_JPEG: |
| 459 | 484 | 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"); | |
| 461 | 487 | return -1; |
| 462 | 488 | 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); | |
| 464 | 491 | return -1; |
| 465 | 492 | } |
| 466 | 493 | break; |
| 467 | 494 | case TIFF_ROWSPERSTRIP: |
| 468 | 495 | if (type == TIFF_LONG && value == UINT_MAX) |
| 469 | 496 | 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"); | |
| 472 | 500 | return -1; |
| 473 | 501 | } |
| 474 | 502 | s->rps = value; |
| 475 | 503 | break; |
| 476 | 504 | case TIFF_STRIP_OFFS: |
| 477 | − if(count == 1){ | |
| 505 | + if (count == 1) { | |
| 478 | 506 | s->stripdata = NULL; |
| 479 | 507 | s->stripoff = value; |
| 480 | − }else | |
| 508 | + } else | |
| 481 | 509 | s->stripdata = start + off; |
| 482 | 510 | s->strips = count; |
| 483 | − if(s->strips == 1) s->rps = s->height; | |
| 511 | + if (s->strips == 1) | |
| 512 | + s->rps = s->height; | |
| 484 | 513 | 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"); | |
| 487 | 517 | return -1; |
| 488 | 518 | } |
| 489 | 519 | break; |
| 490 | 520 | case TIFF_STRIP_SIZE: |
| 491 | − if(count == 1){ | |
| 521 | + if (count == 1) { | |
| 492 | 522 | s->stripsizes = NULL; |
| 493 | 523 | s->stripsize = value; |
| 494 | 524 | s->strips = 1; |
| 495 | − }else{ | |
| 525 | + } else { | |
| 496 | 526 | s->stripsizes = start + off; |
| 497 | 527 | } |
| 498 | 528 | s->strips = count; |
| 499 | 529 | 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"); | |
| 502 | 533 | return -1; |
| 503 | 534 | } |
| 504 | 535 | break; |
| @@ -513,7 +544,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 8 unmodified lines | ||
| 513 | 544 | s->predictor = value; |
| 514 | 545 | break; |
| 515 | 546 | case TIFF_INVERT: |
| 516 | − switch(value){ | |
| 547 | + switch (value) { | |
| 517 | 548 | case 0: |
| 518 | 549 | s->invert = 1; |
| 519 | 550 | break; |
| @@ -524,13 +555,15 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 4 unmodified lines | ||
| 524 | 555 | case 3: |
| 525 | 556 | break; |
| 526 | 557 | 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); | |
| 528 | 560 | return -1; |
| 529 | 561 | } |
| 530 | 562 | break; |
| 531 | 563 | 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); | |
| 534 | 567 | value = 1; |
| 535 | 568 | } |
| 536 | 569 | 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 | ||
| 544 | 577 | gp = buf + count / 3 * off; |
| 545 | 578 | bp = buf + count / 3 * off * 2; |
| 546 | 579 | off = (type_sizes[type] - 1) << 3; |
| 547 | − for(i = 0; i < count / 3; i++){ | |
| 580 | + for (i = 0; i < count / 3; i++) { | |
| 548 | 581 | j = 0xff << 24; |
| 549 | 582 | j |= (tget(&rp, type, s->le) >> off) << 16; |
| 550 | 583 | j |= (tget(&gp, type, s->le) >> off) << 8; |
| 551 | − j |= tget(&bp, type, s->le) >> off; | |
| 584 | + j |= tget(&bp, type, s->le) >> off; | |
| 552 | 585 | pal[i] = j; |
| 553 | 586 | } |
| 554 | 587 | s->palette_is_set = 1; |
| 555 | 588 | break; |
| 556 | 589 | case TIFF_PLANAR: |
| 557 | − if(value == 2){ | |
| 590 | + if (value == 2) { | |
| 558 | 591 | av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n"); |
| 559 | 592 | return -1; |
| 560 | 593 | } |
| 561 | 594 | break; |
| 562 | 595 | case TIFF_T4OPTIONS: |
| 563 | − if(s->compr == TIFF_G3) | |
| 596 | + if (s->compr == TIFF_G3) | |
| 564 | 597 | s->fax_opts = value; |
| 565 | 598 | break; |
| 566 | 599 | case TIFF_T6OPTIONS: |
| 567 | − if(s->compr == TIFF_G4) | |
| 600 | + if (s->compr == TIFF_G4) | |
| 568 | 601 | s->fax_opts = value; |
| 569 | 602 | break; |
| 570 | 603 | 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); | |
| 572 | 606 | } |
| 573 | 607 | return 0; |
| 574 | 608 | } |
| 575 | 609 | |
| 576 | 610 | static int decode_frame(AVCodecContext *avctx, |
| 577 | − void *data, int *data_size, | |
| 578 | − AVPacket *avpkt) | |
| 611 | + void *data, int *data_size, AVPacket *avpkt) | |
| 579 | 612 | { |
| 580 | 613 | const uint8_t *buf = avpkt->data; |
| 581 | 614 | int buf_size = avpkt->size; |
| 582 | − TiffContext * const s = avctx->priv_data; | |
| 615 | + TiffContext *const s = avctx->priv_data; | |
| 583 | 616 | AVFrame *picture = data; |
| 584 | − AVFrame * const p = &s->picture; | |
| 617 | + AVFrame *const p = &s->picture; | |
| 585 | 618 | const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; |
| 586 | 619 | unsigned off; |
| 587 | 620 | int id, le, ret; |
| @@ -593,10 +626,13 @@ static int decode_frame(AVCodecContext *avctx, · 5 unmodified lines | ||
| 593 | 626 | //parse image header |
| 594 | 627 | if (end_buf - buf < 8) |
| 595 | 628 | 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 { | |
| 600 | 636 | av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); |
| 601 | 637 | return -1; |
| 602 | 638 | } |
| @@ -606,8 +642,9 @@ static int decode_frame(AVCodecContext *avctx, · 3 unmodified lines | ||
| 606 | 642 | s->fill_order = 0; |
| 607 | 643 | // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number |
| 608 | 644 | // 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"); | |
| 611 | 648 | return -1; |
| 612 | 649 | } |
| 613 | 650 | // 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 | ||
| 620 | 657 | } |
| 621 | 658 | buf = orig_buf + off; |
| 622 | 659 | 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) | |
| 625 | 662 | return -1; |
| 626 | 663 | buf += 12; |
| 627 | 664 | } |
| 628 | − if(!s->stripdata && !s->stripoff){ | |
| 665 | + if (!s->stripdata && !s->stripoff) { | |
| 629 | 666 | av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); |
| 630 | 667 | return -1; |
| 631 | 668 | } |
| @@ -633,36 +670,37 @@ static int decode_frame(AVCodecContext *avctx, · 1 unmodified line | ||
| 633 | 670 | if ((ret = init_image(s)) < 0) |
| 634 | 671 | return ret; |
| 635 | 672 | |
| 636 | − if(s->strips == 1 && !s->stripsize){ | |
| 673 | + if (s->strips == 1 && !s->stripsize) { | |
| 637 | 674 | av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); |
| 638 | 675 | s->stripsize = buf_size - s->stripoff; |
| 639 | 676 | } |
| 640 | 677 | stride = p->linesize[0]; |
| 641 | 678 | 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) { | |
| 644 | 681 | if (s->stripsizes >= end_buf) |
| 645 | 682 | return AVERROR_INVALIDDATA; |
| 646 | 683 | ssize = tget(&s->stripsizes, s->sstype, s->le); |
| 647 | 684 | } else |
| 648 | 685 | ssize = s->stripsize; |
| 649 | 686 | |
| 650 | − if(s->stripdata){ | |
| 687 | + if (s->stripdata) { | |
| 651 | 688 | if (s->stripdata >= end_buf) |
| 652 | 689 | return AVERROR_INVALIDDATA; |
| 653 | 690 | soff = tget(&s->stripdata, s->sot, s->le); |
| 654 | − }else | |
| 691 | + } else | |
| 655 | 692 | soff = s->stripoff; |
| 656 | 693 | |
| 657 | 694 | if (soff > buf_size || ssize > buf_size - soff) { |
| 658 | 695 | av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n"); |
| 659 | 696 | return -1; |
| 660 | 697 | } |
| 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) | |
| 662 | 700 | break; |
| 663 | 701 | dst += s->rps * stride; |
| 664 | 702 | } |
| 665 | − if(s->predictor == 2){ | |
| 703 | + if (s->predictor == 2) { | |
| 666 | 704 | dst = p->data[0]; |
| 667 | 705 | soff = s->bpp >> 3; |
| 668 | 706 | ssize = s->width * soff; |
| @@ -681,18 +719,18 @@ static int decode_frame(AVCodecContext *avctx, · 12 unmodified lines | ||
| 681 | 719 | dst += stride; |
| 682 | 720 | } |
| 683 | 721 | } 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++) | |
| 686 | 724 | dst[j] += dst[j - soff]; |
| 687 | 725 | dst += stride; |
| 688 | 726 | } |
| 689 | 727 | } |
| 690 | 728 | } |
| 691 | 729 | |
| 692 | − if(s->invert){ | |
| 730 | + if (s->invert) { | |
| 693 | 731 | 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++) | |
| 696 | 734 | dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j]; |
| 697 | 735 | dst += s->picture.linesize[0]; |
| 698 | 736 | } |
| @@ -703,7 +741,8 @@ static int decode_frame(AVCodecContext *avctx, · 4 unmodified lines | ||
| 703 | 741 | return buf_size; |
| 704 | 742 | } |
| 705 | 743 | |
| 706 | −static av_cold int tiff_init(AVCodecContext *avctx){ | |
| 744 | +static av_cold int tiff_init(AVCodecContext *avctx) | |
| 745 | +{ | |
| 707 | 746 | TiffContext *s = avctx->priv_data; |
| 708 | 747 | |
| 709 | 748 | s->width = 0; |
| @@ -719,10 +758,10 @@ static av_cold int tiff_init(AVCodecContext *avctx){ · 9 unmodified lines | ||
| 719 | 758 | |
| 720 | 759 | static av_cold int tiff_end(AVCodecContext *avctx) |
| 721 | 760 | { |
| 722 | − TiffContext * const s = avctx->priv_data; | |
| 761 | + TiffContext *const s = avctx->priv_data; | |
| 723 | 762 | |
| 724 | 763 | ff_lzw_decode_close(&s->lzw); |
| 725 | − if(s->picture.data[0]) | |
| 764 | + if (s->picture.data[0]) | |
| 726 | 765 | avctx->release_buffer(avctx, &s->picture); |
| 727 | 766 | return 0; |
| 728 | 767 | } |
| @@ -229,7 +229,6 @@ static av_cold int decode_init(AVCodecContext *avctx) · 228 unmodified lines | ||
| 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) · 704 unmodified lines | ||
| 940 | 939 | |
| 941 | 940 | if (rawpcm_tile) { |
| 942 | 941 | 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; | |
| 946 | 946 | } |
| 947 | 947 | av_dlog(s->avctx, "RAWPCM %d bits per sample. " |
| 948 | 948 | "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 | ||
| 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, · 8 unmodified lines | ||
| 1185 | 1184 | |
| 1186 | 1185 | /* parse packet header */ |
| 1187 | 1186 | 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); | |
| 1191 | 1192 | |
| 1192 | 1193 | /* get number of bits that need to be added to the previous frame */ |
| 1193 | 1194 | num_bits_prev_frame = get_bits(gb, s->log2_frame_size); |
| @@ -594,7 +594,7 @@ cglobal emu_edge_core, 2, 7, 0 · 593 unmodified lines | ||
| 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); · 90 unmodified lines | ||
| 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 { · 10 unmodified lines | ||
| 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); |
| @@ -140,6 +141,41 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 15 unmodified lines | ||
| 140 | 141 | AVFilterInOut **inputs, AVFilterInOut **outputs, |
| 141 | 142 | void *log_ctx); |
| 142 | 143 | |
| 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 | + | |
| 143 | 179 | /** |
| 144 | 180 | * Send a command to one or more filter instances. |
| 145 | 181 | * |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | ||
| 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) · 188 unmodified lines | ||
| 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) · 4 unmodified lines | ||
| 206 | 208 | *inouts = element; |
| 207 | 209 | } |
| 208 | 210 | |
| 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 | + | |
| 209 | 223 | static int link_filter_inouts(AVFilterContext *filt_ctx, |
| 210 | 224 | AVFilterInOut **curr_inputs, |
| 211 | 225 | AVFilterInOut **open_inputs, void *log_ctx) |
| 212 | 226 | { |
| 213 | − int pad = filt_ctx->input_count, ret; | |
| 227 | + int pad, ret; | |
| 214 | 228 | |
| 215 | − while (pad--) { | |
| 229 | + for (pad = 0; pad < filt_ctx->input_count; pad++) { | |
| 216 | 230 | 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 | 231 | |
| 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); | |
| 225 | 236 | |
| 226 | 237 | if (p->filter_ctx) { |
| 227 | 238 | 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 | ||
| 258 | 269 | static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, |
| 259 | 270 | AVFilterInOut **open_outputs, void *log_ctx) |
| 260 | 271 | { |
| 272 | + AVFilterInOut *parsed_inputs = NULL; | |
| 261 | 273 | int pad = 0; |
| 262 | 274 | |
| 263 | 275 | while (**buf == '[') { |
| @@ -280,12 +292,15 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, · 16 unmodified lines | ||
| 280 | 292 | match->pad_idx = pad; |
| 281 | 293 | } |
| 282 | 294 | |
| 283 | − insert_inout(curr_inputs, match); | |
| 295 | + append_inout(&parsed_inputs, &match); | |
| 284 | 296 | |
| 285 | 297 | *buf += strspn(*buf, WHITESPACES); |
| 286 | 298 | pad++; |
| 287 | 299 | } |
| 288 | 300 | |
| 301 | + append_inout(&parsed_inputs, curr_inputs); | |
| 302 | + *curr_inputs = parsed_inputs; | |
| 303 | + | |
| 289 | 304 | return pad; |
| 290 | 305 | } |
| 291 | 306 | |
| @@ -334,10 +349,173 @@ static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, · 42 unmodified lines | ||
| 334 | 349 | return pad; |
| 335 | 350 | } |
| 336 | 351 | |
| 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 | + | |
| 337 | 450 | int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, |
| 338 | 451 | AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr, |
| 339 | 452 | void *log_ctx) |
| 340 | 453 | { |
| 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 | |
| 341 | 519 | int index = 0, ret = 0; |
| 342 | 520 | char chr = 0; |
| 343 | 521 | |
| @@ -414,3 +592,5 @@ end: · 70 unmodified lines | ||
| 414 | 592 | } |
| 415 | 593 | return ret; |
| 416 | 594 | } |
| 595 | + | |
| 596 | +#endif | |
| @@ -29,8 +29,8 @@ · 28 unmodified lines | ||
| 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 { · 38 unmodified lines | ||
| 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, · 10 unmodified lines | ||
| 55 | 56 | AVFilterBufferRef *buf; |
| 56 | 57 | int ret; |
| 57 | 58 | |
| 59 | + if (!picref) { | |
| 60 | + c->eof = 1; | |
| 61 | + return 0; | |
| 62 | + } else if (c->eof) | |
| 63 | + return AVERROR(EINVAL); | |
| 64 | + | |
| 58 | 65 | if (!av_fifo_space(c->fifo) && |
| 59 | 66 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + |
| 60 | 67 | sizeof(buf))) < 0) |
| @@ -125,6 +132,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 64 unmodified lines | ||
| 125 | 132 | BufferSourceContext *c = s->priv; |
| 126 | 133 | int ret; |
| 127 | 134 | |
| 135 | + if (!buf) { | |
| 136 | + c->eof = 1; | |
| 137 | + return 0; | |
| 138 | + } else if (c->eof) | |
| 139 | + return AVERROR(EINVAL); | |
| 140 | + | |
| 128 | 141 | if (!av_fifo_space(c->fifo) && |
| 129 | 142 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + |
| 130 | 143 | sizeof(buf))) < 0) |
| @@ -144,9 +157,17 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 13 unmodified lines | ||
| 144 | 157 | int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, |
| 145 | 158 | const AVFrame *frame, int flags) |
| 146 | 159 | { |
| 160 | + BufferSourceContext *c = buffer_src->priv; | |
| 161 | + AVFilterBufferRef *picref; | |
| 147 | 162 | 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); | |
| 150 | 171 | if (!picref) |
| 151 | 172 | return AVERROR(ENOMEM); |
| 152 | 173 | 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 | ||
| 226 | 247 | AVFilterBufferRef *buf; |
| 227 | 248 | |
| 228 | 249 | if (!av_fifo_size(c->fifo)) { |
| 250 | + if (c->eof) | |
| 251 | + return AVERROR_EOF; | |
| 229 | 252 | av_log(link->src, AV_LOG_WARNING, |
| 230 | 253 | "request_frame() called with no available frame!\n"); |
| 231 | 254 | return AVERROR(EINVAL); |
| @@ -243,7 +266,10 @@ static int request_frame(AVFilterLink *link) · 11 unmodified lines | ||
| 243 | 266 | static int poll_frame(AVFilterLink *link) |
| 244 | 267 | { |
| 245 | 268 | 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*); | |
| 247 | 273 | } |
| 248 | 274 | |
| 249 | 275 | AVFilter avfilter_vsrc_buffer = { |
| @@ -107,6 +107,7 @@ typedef struct MOVStreamContext { · 106 unmodified lines | ||
| 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) · 1617 unmodified lines | ||
| 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) · 248 unmodified lines | ||
| 1873 | 1876 | return; |
| 1874 | 1877 | } |
| 1875 | 1878 | |
| 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])) { | |
| 1877 | 1880 | keyframe = 1; |
| 1878 | 1881 | if (stss_index + 1 < sc->keyframe_count) |
| 1879 | 1882 | stss_index++; |
| @@ -1975,6 +1975,8 @@ static int has_duration(AVFormatContext *ic) · 1974 unmodified lines | ||
| 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, · 468 unmodified lines | ||
| 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], · 36 unmodified lines | ||
| 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, · 20 unmodified lines | ||
| 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, · 15 unmodified lines | ||
| 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, · 40 unmodified lines | ||
| 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], · 56 unmodified lines | ||
| 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, · 31 unmodified lines | ||
| 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, · 21 unmodified lines | ||
| 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, · 208 unmodified lines | ||
| 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], · 53 unmodified lines | ||
| 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, · 31 unmodified lines | ||
| 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, · 20 unmodified lines | ||
| 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" · 39 unmodified lines | ||
| 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" |