* 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 | 2012-03-26 - a67d9cf - lavfi 2.66.100 | 19 | 2012-03-26 - a67d9cf - lavfi 2.66.100 |
| 20 | Add avfilter_fill_frame_from_{audio_,}buffer_ref() functions. | 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 | 2012-xx-xx - xxxxxxx - lavu 51.27.0 - samplefmt.h | 25 | 2012-xx-xx - xxxxxxx - lavu 51.27.0 - samplefmt.h |
| 23 | Add av_get_packed_sample_fmt() and av_get_planar_sample_fmt() | 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 | pads must be connected. A filtergraph is considered valid if all the | 76 | pads must be connected. A filtergraph is considered valid if all the |
| 77 | filter input and output pads of all the filterchains are connected. | 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 | Follows a BNF description for the filtergraph syntax: | 85 | Follows a BNF description for the filtergraph syntax: |
| 80 | @example | 86 | @example |
| 81 | @var{NAME} ::= sequence of alphanumeric characters and '_' | 87 | @var{NAME} ::= sequence of alphanumeric characters and '_' |
| @@ -84,7 +90,7 @@ Follows a BNF description for the filtergraph syntax: · 2 unmodified lines | |||
| 84 | @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted) | 90 | @var{FILTER_ARGUMENTS} ::= sequence of chars (eventually quoted) |
| 85 | @var{FILTER} ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}] | 91 | @var{FILTER} ::= [@var{LINKNAMES}] @var{NAME} ["=" @var{ARGUMENTS}] [@var{LINKNAMES}] |
| 86 | @var{FILTERCHAIN} ::= @var{FILTER} [,@var{FILTERCHAIN}] | 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 | @end example | 94 | @end example |
| 89 | 95 | ||
| 90 | @c man end FILTERGRAPH DESCRIPTION | 96 | @c man end FILTERGRAPH DESCRIPTION |
| @@ -31,16 +31,12 @@ · 30 unmodified lines | |||
| 31 | #undef NDEBUG | 31 | #undef NDEBUG |
| 32 | #include <assert.h> | 32 | #include <assert.h> |
| 33 | 33 | ||
| 34 | extern unsigned int xvid_debug; | ||
| 35 | |||
| 36 | int ff_xvid_rate_control_init(MpegEncContext *s){ | 34 | int ff_xvid_rate_control_init(MpegEncContext *s){ |
| 37 | char *tmp_name; | 35 | char *tmp_name; |
| 38 | int fd, i; | 36 | int fd, i; |
| 39 | xvid_plg_create_t xvid_plg_create = { 0 }; | 37 | xvid_plg_create_t xvid_plg_create = { 0 }; |
| 40 | xvid_plugin_2pass2_t xvid_2pass2 = { 0 }; | 38 | xvid_plugin_2pass2_t xvid_2pass2 = { 0 }; |
| 41 | 39 | ||
| 42 | //xvid_debug=-1; | ||
| 43 | |||
| 44 | fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx); | 40 | fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx); |
| 45 | if (fd == -1) { | 41 | if (fd == -1) { |
| 46 | av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n"); | 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 | frame_types[rce->pict_type], (int)lrintf(rce->qscale / FF_QP2LAMBDA), rce->i_count, s->mb_num - rce->i_count - rce->skip_count, | 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 | rce->skip_count, (rce->i_tex_bits + rce->p_tex_bits + rce->misc_bits+7)/8, (rce->header_bits+rce->mv_bits+7)/8); | 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 | if (write(fd, tmp, strlen(tmp)) < 0) { | 57 | if (write(fd, tmp, strlen(tmp)) < 0) { |
| 63 | av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno)); | 58 | av_log(NULL, AV_LOG_ERROR, "Error %s writing 2pass logfile\n", strerror(errno)); |
| 64 | return AVERROR(errno); | 59 | return AVERROR(errno); |
| @@ -72,155 +72,420 @@ struct xvid_ff_pass1 { · 71 unmodified lines | |||
| 72 | struct xvid_context *context; /**< Pointer to private context */ | 72 | struct xvid_context *context; /**< Pointer to private context */ |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | /* Prototypes - See function implementation for details */ | 75 | /* |
| 76 | int xvid_strip_vol_header(AVCodecContext *avctx, AVPacket *pkt, unsigned int header_len, unsigned int frame_len); | 76 | * Xvid 2-Pass Kludge Section |
| 77 | int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); | 77 | * |
| 78 | void xvid_correct_framerate(AVCodecContext *avctx); | 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. | 87 | * Initialize the two-pass plugin and context. |
| 83 | * All buffers are allocated, settings are loaded from the user, | ||
| 84 | * and the encoder context created. | ||
| 85 | * | 88 | * |
| 86 | * @param avctx AVCodecContext pointer to context | 89 | * @param param Input construction parameter structure |
| 87 | * @return Returns 0 on success, -1 on failure | 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) { | 93 | static int xvid_ff_2pass_create(xvid_plg_create_t * param, |
| 90 | int xerr, i; | 94 | void ** handle) { |
| 91 | int xvid_flags = avctx->flags; | 95 | struct xvid_ff_pass1 *x = (struct xvid_ff_pass1 *)param->param; |
| 92 | struct xvid_context *x = avctx->priv_data; | 96 | char *log = x->context->twopassbuffer; |
| 93 | uint16_t *intra, *inter; | ||
| 94 | int fd; | ||
| 95 | 97 | ||
| 96 | xvid_plugin_single_t single = { 0 }; | 98 | /* Do a quick bounds check */ |
| 97 | struct xvid_ff_pass1 rc2pass1 = { 0 }; | 99 | if( log == NULL ) |
| 98 | xvid_plugin_2pass2_t rc2pass2 = { 0 }; | 100 | return XVID_ERR_FAIL; |
| 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]; | ||
| 102 | 101 | ||
| 103 | /* Bring in VOP flags from ffmpeg command-line */ | 102 | /* We use snprintf() */ |
| 104 | x->vop_flags = XVID_VOP_HALFPEL; /* Bare minimum quality */ | 103 | /* This is because we can safely prevent a buffer overflow */ |
| 105 | if( xvid_flags & CODEC_FLAG_4MV ) | 104 | log[0] = 0; |
| 106 | x->vop_flags |= XVID_VOP_INTER4V; /* Level 3 */ | 105 | snprintf(log, BUFFER_REMAINING(log), |
| 107 | if( avctx->trellis | 106 | "# ffmpeg 2-pass log file, using xvid codec\n"); |
| 108 | ) | 107 | snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), |
| 109 | x->vop_flags |= XVID_VOP_TRELLISQUANT; /* Level 5 */ | 108 | "# Do not modify. libxvidcore version: %d.%d.%d\n\n", |
| 110 | if( xvid_flags & CODEC_FLAG_AC_PRED ) | 109 | XVID_VERSION_MAJOR(XVID_VERSION), |
| 111 | x->vop_flags |= XVID_VOP_HQACPRED; /* Level 6 */ | 110 | XVID_VERSION_MINOR(XVID_VERSION), |
| 112 | if( xvid_flags & CODEC_FLAG_GRAY ) | 111 | XVID_VERSION_PATCH(XVID_VERSION)); |
| 113 | x->vop_flags |= XVID_VOP_GREYSCALE; | ||
| 114 | 112 | ||
| 115 | /* Decide which ME quality setting to use */ | 113 | *handle = x->context; |
| 116 | x->me_flags = 0; | 114 | return 0; |
| 117 | switch( avctx->me_method ) { | 115 | } |
| 118 | case ME_FULL: /* Quality 6 */ | ||
| 119 | x->me_flags |= XVID_ME_EXTSEARCH16 | ||
| 120 | | XVID_ME_EXTSEARCH8; | ||
| 121 | 116 | ||
| 122 | case ME_EPZS: /* Quality 4 */ | 117 | /** |
| 123 | x->me_flags |= XVID_ME_ADVANCEDDIAMOND8 | 118 | * Destroy the two-pass plugin context. |
| 124 | | XVID_ME_HALFPELREFINE8 | 119 | * |
| 125 | | XVID_ME_CHROMA_PVOP | 120 | * @param ref Context pointer for the plugin |
| 126 | | XVID_ME_CHROMA_BVOP; | 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 */ | 133 | /** |
| 129 | case ME_PHODS: | 134 | * Enable fast encode mode during the first pass. |
| 130 | case ME_X1: | 135 | * |
| 131 | x->me_flags |= XVID_ME_ADVANCEDDIAMOND16 | 136 | * @param ref Context pointer for the plugin |
| 132 | | XVID_ME_HALFPELREFINE16; | 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 */ | 146 | /* Nothing to do here, result is changed too much */ |
| 135 | default: | 147 | if( param->zone && param->zone->mode == XVID_ZONE_QUANT ) |
| 136 | break; | 148 | return 0; |
| 137 | } | ||
| 138 | 149 | ||
| 139 | /* Decide how we should decide blocks */ | 150 | /* We can implement a 'turbo' first pass mode here */ |
| 140 | switch( avctx->mb_decision ) { | 151 | param->quant = 2; |
| 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; | ||
| 152 | 152 | ||
| 153 | default: | 153 | /* Init values */ |
| 154 | break; | 154 | motion_remove = ~XVID_ME_CHROMA_PVOP & |
| 155 | } | 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 */ | 168 | param->vol_flags &= ~XVID_VOL_GMC; |
| 158 | x->vol_flags = 0; | 169 | param->vop_flags &= vop_remove; |
| 159 | if( xvid_flags & CODEC_FLAG_GMC ) { | 170 | param->motion_flags &= motion_remove; |
| 160 | x->vol_flags |= XVID_VOL_GMC; | 171 | param->motion_flags |= motion_replacements; |
| 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 | } | ||
| 169 | 172 | ||
| 170 | xvid_gbl_init.version = XVID_VERSION; | 173 | return 0; |
| 171 | xvid_gbl_init.debug = 0; | 174 | } |
| 172 | 175 | ||
| 173 | #if ARCH_PPC | 176 | /** |
| 174 | /* Xvid's PPC support is borked, use libavcodec to detect */ | 177 | * Capture statistic data and write it during first pass. |
| 175 | #if HAVE_ALTIVEC | 178 | * |
| 176 | if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { | 179 | * @param ref Context pointer for the plugin |
| 177 | xvid_gbl_init.cpu_flags = XVID_CPU_FORCE | XVID_CPU_ALTIVEC; | 180 | * @param param Statistic data |
| 178 | } else | 181 | * @return Returns XVID_ERR_xxxx on failure, or 0 on success |
| 179 | #endif | 182 | */ |
| 180 | xvid_gbl_init.cpu_flags = XVID_CPU_FORCE; | 183 | static int xvid_ff_2pass_after(struct xvid_context *ref, |
| 181 | #else | 184 | xvid_plg_data_t *param) { |
| 182 | /* Xvid can detect on x86 */ | 185 | char *log = ref->twopassbuffer; |
| 183 | xvid_gbl_init.cpu_flags = 0; | 186 | const char *frame_types = " ipbs"; |
| 184 | #endif | 187 | char frame_type; |
| 185 | 188 | ||
| 186 | /* Initialize */ | 189 | /* Quick bounds check */ |
| 187 | xvid_global(NULL, XVID_GBL_INIT, &xvid_gbl_init, NULL); | 190 | if( log == NULL ) |
| 191 | return XVID_ERR_FAIL; | ||
| 188 | 192 | ||
| 189 | /* Create the encoder reference */ | 193 | /* Convert the type given to us into a character */ |
| 190 | xvid_enc_create.version = XVID_VERSION; | 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 */ | 200 | snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), |
| 193 | xvid_enc_create.width = x->xsize = avctx->width; | 201 | "%c %d %d %d %d %d %d\n", |
| 194 | xvid_enc_create.height = x->ysize = avctx->height; | 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 */ | 205 | return 0; |
| 197 | /* xvid_enc_create.profile = XVID_PROFILE_S_L3; */ | 206 | } |
| 198 | 207 | ||
| 199 | /* We don't use zones */ | 208 | /** |
| 200 | xvid_enc_create.zones = NULL; | 209 | * Dispatch function for our custom plugin. |
| 201 | xvid_enc_create.num_zones = 0; | 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; | 229 | case XVID_PLG_CREATE: |
| 206 | xvid_enc_create.num_plugins = 0; | 230 | return xvid_ff_2pass_create(p1, p2); |
| 207 | 231 | ||
| 208 | /* Initialize Buffers */ | 232 | case XVID_PLG_AFTER: |
| 209 | x->twopassbuffer = NULL; | 233 | return xvid_ff_2pass_after(ref, p1); |
| 210 | x->old_twopassbuffer = NULL; | ||
| 211 | x->twopassfile = NULL; | ||
| 212 | 234 | ||
| 213 | if( xvid_flags & CODEC_FLAG_PASS1 ) { | 235 | case XVID_PLG_DESTROY: |
| 214 | rc2pass1.version = XVID_VERSION; | 236 | return xvid_ff_2pass_destroy(ref, p1); |
| 215 | rc2pass1.context = x; | 237 | |
| 216 | x->twopassbuffer = av_malloc(BUFFER_SIZE); | 238 | default: |
| 217 | x->old_twopassbuffer = av_malloc(BUFFER_SIZE); | 239 | return XVID_ERR_FAIL; |
| 218 | if( x->twopassbuffer == NULL || x->old_twopassbuffer == NULL ) { | 240 | } |
| 219 | av_log(avctx, AV_LOG_ERROR, | 241 | } |
| 220 | "Xvid: Cannot allocate 2-pass log buffers\n"); | 242 | |
| 221 | return -1; | 243 | /** |
| 222 | } | 244 | * Routine to create a global VO/VOL header for MP4 container. |
| 223 | x->twopassbuffer[0] = x->old_twopassbuffer[0] = 0; | 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 | plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; | 490 | plugins[xvid_enc_create.num_plugins].func = xvid_ff_2pass; |
| 226 | plugins[xvid_enc_create.num_plugins].param = &rc2pass1; | 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 | } else { | 599 | } else { |
| 335 | /* We are claiming to be Xvid */ | 600 | /* We are claiming to be Xvid */ |
| 336 | x->quicktime_format = 0; | 601 | x->quicktime_format = 0; |
| 337 | if(!avctx->codec_tag) | 602 | if(!avctx->codec_tag) |
| 338 | avctx->codec_tag = AV_RL32("xvid"); | 603 | avctx->codec_tag = AV_RL32("xvid"); |
| 339 | } | 604 | } |
| 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; | ||
| 634 | 605 | ||
| 635 | /* Do a quick bounds check */ | 606 | /* Bframes */ |
| 636 | if( log == NULL ) | 607 | xvid_enc_create.max_bframes = avctx->max_b_frames; |
| 637 | return XVID_ERR_FAIL; | 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() */ | 612 | /* Create encoder context */ |
| 640 | /* This is because we can safely prevent a buffer overflow */ | 613 | xerr = xvid_encore(NULL, XVID_ENC_CREATE, &xvid_enc_create, NULL); |
| 641 | log[0] = 0; | 614 | if( xerr ) { |
| 642 | snprintf(log, BUFFER_REMAINING(log), | 615 | av_log(avctx, AV_LOG_ERROR, "Xvid: Could not create encoder reference\n"); |
| 643 | "# ffmpeg 2-pass log file, using xvid codec\n"); | 616 | return -1; |
| 644 | snprintf(BUFFER_CAT(log), BUFFER_REMAINING(log), | 617 | } |
| 645 | "# Do not modify. libxvidcore version: %d.%d.%d\n\n", | ||
| 646 | XVID_VERSION_MAJOR(XVID_VERSION), | ||
| 647 | XVID_VERSION_MINOR(XVID_VERSION), | ||
| 648 | XVID_VERSION_PATCH(XVID_VERSION)); | ||
| 649 | 618 | ||
| 650 | *handle = x->context; | 619 | x->encoder_handle = xvid_enc_create.handle; |
| 651 | return 0; | 620 | avctx->coded_frame = &x->encoded_picture; |
| 652 | } | ||
| 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 | return 0; | 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 | 628 | * @param avctx AVCodecContext pointer to context |
| 674 | * @param param Frame data | 629 | * @param frame Pointer to encoded frame buffer |
| 675 | * @return Returns 0, success guaranteed | 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, | 634 | static int xvid_encode_frame(AVCodecContext *avctx, AVPacket *pkt, |
| 678 | xvid_plg_data_t *param) { | 635 | const AVFrame *picture, int *got_packet) |
| 679 | int motion_remove; | 636 | { |
| 680 | int motion_replacements; | 637 | int xerr, i, ret, user_packet = !!pkt->data; |
| 681 | int vop_remove; | 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 */ | 644 | xvid_enc_frame_t xvid_enc_frame = { 0 }; |
| 684 | if( param->zone && param->zone->mode == XVID_ZONE_QUANT ) | 645 | xvid_enc_stats_t xvid_enc_stats = { 0 }; |
| 685 | return 0; | ||
| 686 | 646 | ||
| 687 | /* We can implement a 'turbo' first pass mode here */ | 647 | if ((ret = ff_alloc_packet2(avctx, pkt, mb_width*mb_height*MAX_MB_BYTES + FF_MIN_BUFFER_SIZE)) < 0) |
| 688 | param->quant = 2; | 648 | return ret; |
| 689 | 649 | ||
| 690 | /* Init values */ | 650 | /* Start setting up the frame */ |
| 691 | motion_remove = ~XVID_ME_CHROMA_PVOP & | 651 | xvid_enc_frame.version = XVID_VERSION; |
| 692 | ~XVID_ME_CHROMA_BVOP & | 652 | xvid_enc_stats.version = XVID_VERSION; |
| 693 | ~XVID_ME_EXTSEARCH16 & | 653 | *p = *picture; |
| 694 | ~XVID_ME_ADVANCEDDIAMOND16; | ||
| 695 | motion_replacements = XVID_ME_FAST_MODEINTERPOLATE | | ||
| 696 | XVID_ME_SKIP_DELTASEARCH | | ||
| 697 | XVID_ME_FASTREFINE16 | | ||
| 698 | XVID_ME_BFRAME_EARLYSTOP; | ||
| 699 | vop_remove = ~XVID_VOP_MODEDECISION_RD & | ||
| 700 | ~XVID_VOP_FAST_MODEDECISION_RD & | ||
| 701 | ~XVID_VOP_TRELLISQUANT & | ||
| 702 | ~XVID_VOP_INTER4V & | ||
| 703 | ~XVID_VOP_HQACPRED; | ||
| 704 | 654 | ||
| 705 | param->vol_flags &= ~XVID_VOL_GMC; | 655 | /* Let Xvid know where to put the frame. */ |
| 706 | param->vop_flags &= vop_remove; | 656 | xvid_enc_frame.bitstream = pkt->data; |
| 707 | param->motion_flags &= motion_remove; | 657 | xvid_enc_frame.length = pkt->size; |
| 708 | param->motion_flags |= motion_replacements; | ||
| 709 | 658 | ||
| 710 | return 0; | 659 | /* Initialize input image fields */ |
| 711 | } | 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 | /** | 665 | xvid_enc_frame.input.csp = XVID_CSP_PLANAR; /* YUV420P */ |
| 714 | * Capture statistic data and write it during first pass. | ||
| 715 | * | ||
| 716 | * @param ref Context pointer for the plugin | ||
| 717 | * @param param Statistic data | ||
| 718 | * @return Returns XVID_ERR_xxxx on failure, or 0 on success | ||
| 719 | */ | ||
| 720 | static int xvid_ff_2pass_after(struct xvid_context *ref, | ||
| 721 | xvid_plg_data_t *param) { | ||
| 722 | char *log = ref->twopassbuffer; | ||
| 723 | const char *frame_types = " ipbs"; | ||
| 724 | char frame_type; | ||
| 725 | 666 | ||
| 726 | /* Quick bounds check */ | 667 | for( i = 0; i < 4; i++ ) { |
| 727 | if( log == NULL ) | 668 | xvid_enc_frame.input.plane[i] = picture->data[i]; |
| 728 | return XVID_ERR_FAIL; | 669 | xvid_enc_frame.input.stride[i] = picture->linesize[i]; |
| 670 | } | ||
| 729 | 671 | ||
| 730 | /* Convert the type given to us into a character */ | 672 | /* Encoder Flags */ |
| 731 | if( param->type < 5 && param->type > 0 ) { | 673 | xvid_enc_frame.vop_flags = x->vop_flags; |
| 732 | frame_type = frame_types[param->type]; | 674 | xvid_enc_frame.vol_flags = x->vol_flags; |
| 733 | } else { | 675 | xvid_enc_frame.motion = x->me_flags; |
| 734 | return XVID_ERR_FAIL; | 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), | 693 | /* Quant Setting */ |
| 738 | "%c %d %d %d %d %d %d\n", | 694 | if( x->qscale ) xvid_enc_frame.quant = picture->quality / FF_QP2LAMBDA; |
| 739 | frame_type, param->stats.quant, param->stats.kblks, param->stats.mblks, | 695 | else xvid_enc_frame.quant = 0; |
| 740 | param->stats.ublks, param->stats.length, param->stats.hlength); | ||
| 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. | 752 | * Destroy the private context for the encoder. |
| 747 | * This handles the dispatch for the Xvid plugin. It passes data | 753 | * All buffers are freed, and the Xvid encoder context is destroyed. |
| 748 | * on to other functions for actual processing. | ||
| 749 | * | 754 | * |
| 750 | * @param ref Context pointer for the plugin | 755 | * @param avctx AVCodecContext pointer to context |
| 751 | * @param cmd The task given for us to complete | 756 | * @return Returns 0, success guaranteed |
| 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 | */ | 757 | */ |
| 756 | int xvid_ff_2pass(void *ref, int cmd, void *p1, void *p2) { | 758 | static av_cold int xvid_encode_close(AVCodecContext *avctx) { |
| 757 | switch( cmd ) { | 759 | struct xvid_context *x = avctx->priv_data; |
| 758 | case XVID_PLG_INFO: | ||
| 759 | case XVID_PLG_FRAME: | ||
| 760 | return 0; | ||
| 761 | |||
| 762 | case XVID_PLG_BEFORE: | ||
| 763 | return xvid_ff_2pass_before(ref, p1); | ||
| 764 | |||
| 765 | case XVID_PLG_CREATE: | ||
| 766 | return xvid_ff_2pass_create(p1, p2); | ||
| 767 | |||
| 768 | case XVID_PLG_AFTER: | ||
| 769 | return xvid_ff_2pass_after(ref, p1); | ||
| 770 | 760 | ||
| 771 | case XVID_PLG_DESTROY: | 761 | xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); |
| 772 | return xvid_ff_2pass_destroy(ref, p1); | ||
| 773 | 762 | ||
| 774 | default: | 763 | av_freep(&avctx->extradata); |
| 775 | return XVID_ERR_FAIL; | 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 | /// Parameters built from header parameters, do not change during playback | 140 | /// Parameters built from header parameters, do not change during playback |
| 141 | int group_order; ///< order of frame group | 141 | int group_order; ///< order of frame group |
| 142 | int fft_order; ///< order of FFT (actually fftorder+1) | 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 | int frame_size; ///< size of data frame | 143 | int frame_size; ///< size of data frame |
| 145 | int frequency_range; | 144 | int frequency_range; |
| 146 | int sub_sampling; ///< subsampling: 0=25%, 1=50%, 2=100% */ | 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 | static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet) | 1606 | static void qdm2_calculate_fft (QDM2Context *q, int channel, int sub_packet) |
| 1608 | { | 1607 | { |
| 1609 | const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f; | 1608 | const float gain = (q->channels == 1 && q->nb_channels == 2) ? 0.5f : 1.0f; |
| 1609 | float *out = q->output_buffer + channel; | ||
| 1610 | int i; | 1610 | int i; |
| 1611 | q->fft.complex[channel][0].re *= 2.0f; | 1611 | q->fft.complex[channel][0].re *= 2.0f; |
| 1612 | q->fft.complex[channel][0].im = 0.0f; | 1612 | q->fft.complex[channel][0].im = 0.0f; |
| 1613 | q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); | 1613 | q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); |
| 1614 | /* add samples to output buffer */ | 1614 | /* add samples to output buffer */ |
| 1615 | for (i = 0; i < ((q->fft_frame_size + 15) & ~15); i++) | 1615 | for (i = 0; i < FFALIGN(q->fft_size, 8); i++) { |
| 1616 | q->output_buffer[q->channels * i + channel] += ((float *) q->fft.complex[channel])[i] * gain; | 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 | PRINT("checksum_size",q->checksum_size); | 1691 | PRINT("checksum_size",q->checksum_size); |
| 1689 | PRINT("channels",q->channels); | 1692 | PRINT("channels",q->channels); |
| 1690 | PRINT("nb_channels",q->nb_channels); | 1693 | PRINT("nb_channels",q->nb_channels); |
| 1691 | PRINT("fft_frame_size",q->fft_frame_size); | ||
| 1692 | PRINT("fft_size",q->fft_size); | 1694 | PRINT("fft_size",q->fft_size); |
| 1693 | PRINT("sub_sampling",q->sub_sampling); | 1695 | PRINT("sub_sampling",q->sub_sampling); |
| 1694 | PRINT("fft_order",q->fft_order); | 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 | s->fft_order = av_log2(s->fft_size) + 1; | 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 | // something like max decodable tones | 1849 | // something like max decodable tones |
| 1849 | s->group_order = av_log2(s->group_size) + 1; | 1850 | s->group_order = av_log2(s->group_size) + 1; |
| @@ -52,35 +52,39 @@ typedef struct TiffContext { · 51 unmodified lines | |||
| 52 | 52 | ||
| 53 | int strips, rps, sstype; | 53 | int strips, rps, sstype; |
| 54 | int sot; | 54 | int sot; |
| 55 | const uint8_t* stripdata; | 55 | const uint8_t *stripdata; |
| 56 | const uint8_t* stripsizes; | 56 | const uint8_t *stripsizes; |
| 57 | int stripsize, stripoff; | 57 | int stripsize, stripoff; |
| 58 | LZWState *lzw; | 58 | LZWState *lzw; |
| 59 | } TiffContext; | 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 | unsigned v = le ? AV_RL16(*p) : AV_RB16(*p); | 63 | unsigned v = le ? AV_RL16(*p) : AV_RB16(*p); |
| 63 | *p += 2; | 64 | *p += 2; |
| 64 | return v; | 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 | unsigned v = le ? AV_RL32(*p) : AV_RB32(*p); | 70 | unsigned v = le ? AV_RL32(*p) : AV_RB32(*p); |
| 69 | *p += 4; | 71 | *p += 4; |
| 70 | return v; | 72 | return v; |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | static unsigned tget(const uint8_t **p, int type, int le) { | 75 | static unsigned tget(const uint8_t **p, int type, int le) |
| 74 | switch(type){ | 76 | { |
| 77 | switch (type) { | ||
| 75 | case TIFF_BYTE : return *(*p)++; | 78 | case TIFF_BYTE : return *(*p)++; |
| 76 | case TIFF_SHORT: return tget_short(p, le); | 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 | default : return UINT_MAX; | 81 | default : return UINT_MAX; |
| 79 | } | 82 | } |
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | #if CONFIG_ZLIB | 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 | z_stream zstream = { 0 }; | 89 | z_stream zstream = { 0 }; |
| 86 | int zret; | 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 | int c, line, pixels, code; | 151 | int c, line, pixels, code; |
| 146 | const uint8_t *ssrc = src; | 152 | const uint8_t *ssrc = src; |
| 147 | int width = ((s->width * s->bpp) + 7) >> 3; | 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 | return AVERROR_INVALIDDATA; | 156 | return AVERROR_INVALIDDATA; |
| 151 | 157 | ||
| 152 | #if CONFIG_ZLIB | 158 | #if CONFIG_ZLIB |
| 153 | if(s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE){ | 159 | if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE) { |
| 154 | uint8_t *zbuf; unsigned long outlen; | 160 | uint8_t *zbuf; |
| 161 | unsigned long outlen; | ||
| 155 | int ret; | 162 | int ret; |
| 156 | outlen = width * lines; | 163 | outlen = width * lines; |
| 157 | zbuf = av_malloc(outlen); | 164 | zbuf = av_malloc(outlen); |
| 158 | if (!zbuf) | 165 | if (!zbuf) |
| 159 | return AVERROR(ENOMEM); | 166 | return AVERROR(ENOMEM); |
| 160 | ret = tiff_uncompress(zbuf, &outlen, src, size); | 167 | ret = tiff_uncompress(zbuf, &outlen, src, size); |
| 161 | if(ret != Z_OK){ | 168 | 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); | 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 | av_free(zbuf); | 172 | av_free(zbuf); |
| 164 | return -1; | 173 | return -1; |
| 165 | } | 174 | } |
| 166 | src = zbuf; | 175 | src = zbuf; |
| 167 | for(line = 0; line < lines; line++){ | 176 | for (line = 0; line < lines; line++) { |
| 168 | if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){ | 177 | if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){ |
| 169 | horizontal_fill(s->bpp, dst, 1, src, 0, width, 0); | 178 | horizontal_fill(s->bpp, dst, 1, src, 0, width, 0); |
| 170 | }else{ | 179 | }else{ |
| @@ -177,37 +186,42 @@ static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uin · 6 unmodified lines | |||
| 177 | return 0; | 186 | return 0; |
| 178 | } | 187 | } |
| 179 | #endif | 188 | #endif |
| 180 | if(s->compr == TIFF_LZW){ | 189 | if (s->compr == TIFF_LZW) { |
| 181 | if(ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0){ | 190 | if (ff_lzw_decode_init(s->lzw, 8, src, size, FF_LZW_TIFF) < 0) { |
| 182 | av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); | 191 | av_log(s->avctx, AV_LOG_ERROR, "Error initializing LZW decoder\n"); |
| 183 | return -1; | 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 | int i, ret = 0; | 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 | if (!src2) { | 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 | return AVERROR(ENOMEM); | 204 | return AVERROR(ENOMEM); |
| 193 | } | 205 | } |
| 194 | if(s->fax_opts & 2){ | 206 | if (s->fax_opts & 2) { |
| 195 | av_log(s->avctx, AV_LOG_ERROR, "Uncompressed fax mode is not supported (yet)\n"); | 207 | av_log(s->avctx, AV_LOG_ERROR, |
| 208 | "Uncompressed fax mode is not supported (yet)\n"); | ||
| 196 | av_free(src2); | 209 | av_free(src2); |
| 197 | return -1; | 210 | return -1; |
| 198 | } | 211 | } |
| 199 | if(!s->fill_order){ | 212 | if (!s->fill_order) { |
| 200 | memcpy(src2, src, size); | 213 | memcpy(src2, src, size); |
| 201 | }else{ | 214 | } else { |
| 202 | for(i = 0; i < size; i++) | 215 | for (i = 0; i < size; i++) |
| 203 | src2[i] = av_reverse[src[i]]; | 216 | src2[i] = av_reverse[src[i]]; |
| 204 | } | 217 | } |
| 205 | memset(src2+size, 0, FF_INPUT_BUFFER_PADDING_SIZE); | 218 | memset(src2 + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); |
| 206 | switch(s->compr){ | 219 | switch (s->compr) { |
| 207 | case TIFF_CCITT_RLE: | 220 | case TIFF_CCITT_RLE: |
| 208 | case TIFF_G3: | 221 | case TIFF_G3: |
| 209 | case TIFF_G4: | 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 | break; | 225 | break; |
| 212 | } | 226 | } |
| 213 | if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8) | 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 | av_free(src2); | 232 | av_free(src2); |
| 219 | return ret; | 233 | return ret; |
| 220 | } | 234 | } |
| 221 | for(line = 0; line < lines; line++){ | 235 | for (line = 0; line < lines; line++) { |
| 222 | if(src - ssrc > size){ | 236 | if (src - ssrc > size) { |
| 223 | av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); | 237 | av_log(s->avctx, AV_LOG_ERROR, "Source data overread\n"); |
| 224 | return -1; | 238 | return -1; |
| 225 | } | 239 | } |
| 226 | switch(s->compr){ | 240 | switch (s->compr) { |
| 227 | case TIFF_RAW: | 241 | case TIFF_RAW: |
| 228 | if (ssrc + size - src < width) | 242 | if (ssrc + size - src < width) |
| 229 | return AVERROR_INVALIDDATA; | 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 | src += width; | 252 | src += width; |
| 239 | break; | 253 | break; |
| 240 | case TIFF_PACKBITS: | 254 | case TIFF_PACKBITS: |
| 241 | for(pixels = 0; pixels < width;){ | 255 | for (pixels = 0; pixels < width;) { |
| 242 | code = (int8_t)*src++; | 256 | code = (int8_t) * src++; |
| 243 | if(code >= 0){ | 257 | if (code >= 0) { |
| 244 | code++; | 258 | code++; |
| 245 | if(pixels + code > width){ | 259 | if (pixels + code > width) { |
| 246 | av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n"); | 260 | av_log(s->avctx, AV_LOG_ERROR, |
| 261 | "Copy went out of bounds\n"); | ||
| 247 | return -1; | 262 | return -1; |
| 248 | } | 263 | } |
| 249 | horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), | 264 | horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), |
| 250 | dst, 1, src, 0, code, pixels); | 265 | dst, 1, src, 0, code, pixels); |
| 251 | src += code; | 266 | src += code; |
| 252 | pixels += code; | 267 | pixels += code; |
| 253 | }else if(code != -128){ // -127..-1 | 268 | } else if (code != -128) { // -127..-1 |
| 254 | code = (-code) + 1; | 269 | code = (-code) + 1; |
| 255 | if(pixels + code > width){ | 270 | if (pixels + code > width) { |
| 256 | av_log(s->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); | 271 | av_log(s->avctx, AV_LOG_ERROR, |
| 272 | "Run went out of bounds\n"); | ||
| 257 | return -1; | 273 | return -1; |
| 258 | } | 274 | } |
| 259 | c = *src++; | 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 | break; | 281 | break; |
| 266 | case TIFF_LZW: | 282 | case TIFF_LZW: |
| 267 | pixels = ff_lzw_decode(s->lzw, dst, width); | 283 | pixels = ff_lzw_decode(s->lzw, dst, width); |
| 268 | if(pixels < width){ | 284 | if (pixels < width) { |
| 269 | av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width); | 285 | av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", |
| 286 | pixels, width); | ||
| 270 | return -1; | 287 | return -1; |
| 271 | } | 288 | } |
| 272 | if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8) | 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 | return 0; | 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 | unsigned tag, type, count, off, value = 0; | 365 | unsigned tag, type, count, off, value = 0; |
| 348 | int i, j; | 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 | off = tget_long(&buf, s->le); | 375 | off = tget_long(&buf, s->le); |
| 358 | 376 | ||
| 359 | if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) { | 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 | return 0; | 380 | return 0; |
| 362 | } | 381 | } |
| 363 | 382 | ||
| 364 | if(count == 1){ | 383 | if (count == 1) { |
| 365 | switch(type){ | 384 | switch (type) { |
| 366 | case TIFF_BYTE: | 385 | case TIFF_BYTE: |
| 367 | case TIFF_SHORT: | 386 | case TIFF_SHORT: |
| 368 | buf -= 4; | 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 | buf = NULL; | 393 | buf = NULL; |
| 375 | break; | 394 | break; |
| 376 | case TIFF_STRING: | 395 | case TIFF_STRING: |
| 377 | if(count <= 4){ | 396 | if (count <= 4) { |
| 378 | buf -= 4; | 397 | buf -= 4; |
| 379 | break; | 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)){ | 412 | if (buf && (buf < start || buf > end_buf)) { |
| 394 | av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | 413 | av_log(s->avctx, AV_LOG_ERROR, |
| 414 | "Tag referencing position outside the image\n"); | ||
| 395 | return -1; | 415 | return -1; |
| 396 | } | 416 | } |
| 397 | 417 | ||
| 398 | switch(tag){ | 418 | switch (tag) { |
| 399 | case TIFF_WIDTH: | 419 | case TIFF_WIDTH: |
| 400 | s->width = value; | 420 | s->width = value; |
| 401 | break; | 421 | break; |
| @@ -404,20 +424,25 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 2 unmodified lines | |||
| 404 | break; | 424 | break; |
| 405 | case TIFF_BPP: | 425 | case TIFF_BPP: |
| 406 | s->bppcount = count; | 426 | s->bppcount = count; |
| 407 | if(count > 4){ | 427 | if (count > 4) { |
| 408 | av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count); | 428 | av_log(s->avctx, AV_LOG_ERROR, |
| 429 | "This format is not supported (bpp=%d, %d components)\n", | ||
| 430 | s->bpp, count); | ||
| 409 | return -1; | 431 | return -1; |
| 410 | } | 432 | } |
| 411 | if(count == 1) s->bpp = value; | 433 | if (count == 1) |
| 412 | else{ | 434 | s->bpp = value; |
| 413 | switch(type){ | 435 | else { |
| 436 | switch (type) { | ||
| 414 | case TIFF_BYTE: | 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 | break; | 440 | break; |
| 417 | case TIFF_SHORT: | 441 | case TIFF_SHORT: |
| 418 | case TIFF_LONG: | 442 | case TIFF_LONG: |
| 419 | s->bpp = 0; | 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 | break; | 446 | break; |
| 422 | default: | 447 | default: |
| 423 | s->bpp = -1; | 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 | case TIFF_COMPR: | 462 | case TIFF_COMPR: |
| 438 | s->compr = value; | 463 | s->compr = value; |
| 439 | s->predictor = 0; | 464 | s->predictor = 0; |
| 440 | switch(s->compr){ | 465 | switch (s->compr) { |
| 441 | case TIFF_RAW: | 466 | case TIFF_RAW: |
| 442 | case TIFF_PACKBITS: | 467 | case TIFF_PACKBITS: |
| 443 | case TIFF_LZW: | 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 | #endif | 482 | #endif |
| 458 | case TIFF_JPEG: | 483 | case TIFF_JPEG: |
| 459 | case TIFF_NEWJPEG: | 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 | return -1; | 487 | return -1; |
| 462 | default: | 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 | return -1; | 491 | return -1; |
| 465 | } | 492 | } |
| 466 | break; | 493 | break; |
| 467 | case TIFF_ROWSPERSTRIP: | 494 | case TIFF_ROWSPERSTRIP: |
| 468 | if (type == TIFF_LONG && value == UINT_MAX) | 495 | if (type == TIFF_LONG && value == UINT_MAX) |
| 469 | value = s->avctx->height; | 496 | value = s->avctx->height; |
| 470 | if(value < 1){ | 497 | if (value < 1) { |
| 471 | av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n"); | 498 | av_log(s->avctx, AV_LOG_ERROR, |
| 499 | "Incorrect value of rows per strip\n"); | ||
| 472 | return -1; | 500 | return -1; |
| 473 | } | 501 | } |
| 474 | s->rps = value; | 502 | s->rps = value; |
| 475 | break; | 503 | break; |
| 476 | case TIFF_STRIP_OFFS: | 504 | case TIFF_STRIP_OFFS: |
| 477 | if(count == 1){ | 505 | if (count == 1) { |
| 478 | s->stripdata = NULL; | 506 | s->stripdata = NULL; |
| 479 | s->stripoff = value; | 507 | s->stripoff = value; |
| 480 | }else | 508 | } else |
| 481 | s->stripdata = start + off; | 509 | s->stripdata = start + off; |
| 482 | s->strips = count; | 510 | s->strips = count; |
| 483 | if(s->strips == 1) s->rps = s->height; | 511 | if (s->strips == 1) |
| 512 | s->rps = s->height; | ||
| 484 | s->sot = type; | 513 | s->sot = type; |
| 485 | if(s->stripdata > end_buf){ | 514 | if (s->stripdata > end_buf) { |
| 486 | av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | 515 | av_log(s->avctx, AV_LOG_ERROR, |
| 516 | "Tag referencing position outside the image\n"); | ||
| 487 | return -1; | 517 | return -1; |
| 488 | } | 518 | } |
| 489 | break; | 519 | break; |
| 490 | case TIFF_STRIP_SIZE: | 520 | case TIFF_STRIP_SIZE: |
| 491 | if(count == 1){ | 521 | if (count == 1) { |
| 492 | s->stripsizes = NULL; | 522 | s->stripsizes = NULL; |
| 493 | s->stripsize = value; | 523 | s->stripsize = value; |
| 494 | s->strips = 1; | 524 | s->strips = 1; |
| 495 | }else{ | 525 | } else { |
| 496 | s->stripsizes = start + off; | 526 | s->stripsizes = start + off; |
| 497 | } | 527 | } |
| 498 | s->strips = count; | 528 | s->strips = count; |
| 499 | s->sstype = type; | 529 | s->sstype = type; |
| 500 | if(s->stripsizes > end_buf){ | 530 | if (s->stripsizes > end_buf) { |
| 501 | av_log(s->avctx, AV_LOG_ERROR, "Tag referencing position outside the image\n"); | 531 | av_log(s->avctx, AV_LOG_ERROR, |
| 532 | "Tag referencing position outside the image\n"); | ||
| 502 | return -1; | 533 | return -1; |
| 503 | } | 534 | } |
| 504 | break; | 535 | break; |
| @@ -513,7 +544,7 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 8 unmodified lines | |||
| 513 | s->predictor = value; | 544 | s->predictor = value; |
| 514 | break; | 545 | break; |
| 515 | case TIFF_INVERT: | 546 | case TIFF_INVERT: |
| 516 | switch(value){ | 547 | switch (value) { |
| 517 | case 0: | 548 | case 0: |
| 518 | s->invert = 1; | 549 | s->invert = 1; |
| 519 | break; | 550 | break; |
| @@ -524,13 +555,15 @@ static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t * · 4 unmodified lines | |||
| 524 | case 3: | 555 | case 3: |
| 525 | break; | 556 | break; |
| 526 | default: | 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 | return -1; | 560 | return -1; |
| 529 | } | 561 | } |
| 530 | break; | 562 | break; |
| 531 | case TIFF_FILL_ORDER: | 563 | case TIFF_FILL_ORDER: |
| 532 | if(value < 1 || value > 2){ | 564 | if (value < 1 || value > 2) { |
| 533 | av_log(s->avctx, AV_LOG_ERROR, "Unknown FillOrder value %d, trying default one\n", value); | 565 | av_log(s->avctx, AV_LOG_ERROR, |
| 566 | "Unknown FillOrder value %d, trying default one\n", value); | ||
| 534 | value = 1; | 567 | value = 1; |
| 535 | } | 568 | } |
| 536 | s->fill_order = value - 1; | 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 | gp = buf + count / 3 * off; | 577 | gp = buf + count / 3 * off; |
| 545 | bp = buf + count / 3 * off * 2; | 578 | bp = buf + count / 3 * off * 2; |
| 546 | off = (type_sizes[type] - 1) << 3; | 579 | off = (type_sizes[type] - 1) << 3; |
| 547 | for(i = 0; i < count / 3; i++){ | 580 | for (i = 0; i < count / 3; i++) { |
| 548 | j = 0xff << 24; | 581 | j = 0xff << 24; |
| 549 | j |= (tget(&rp, type, s->le) >> off) << 16; | 582 | j |= (tget(&rp, type, s->le) >> off) << 16; |
| 550 | j |= (tget(&gp, type, s->le) >> off) << 8; | 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 | pal[i] = j; | 585 | pal[i] = j; |
| 553 | } | 586 | } |
| 554 | s->palette_is_set = 1; | 587 | s->palette_is_set = 1; |
| 555 | break; | 588 | break; |
| 556 | case TIFF_PLANAR: | 589 | case TIFF_PLANAR: |
| 557 | if(value == 2){ | 590 | if (value == 2) { |
| 558 | av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n"); | 591 | av_log(s->avctx, AV_LOG_ERROR, "Planar format is not supported\n"); |
| 559 | return -1; | 592 | return -1; |
| 560 | } | 593 | } |
| 561 | break; | 594 | break; |
| 562 | case TIFF_T4OPTIONS: | 595 | case TIFF_T4OPTIONS: |
| 563 | if(s->compr == TIFF_G3) | 596 | if (s->compr == TIFF_G3) |
| 564 | s->fax_opts = value; | 597 | s->fax_opts = value; |
| 565 | break; | 598 | break; |
| 566 | case TIFF_T6OPTIONS: | 599 | case TIFF_T6OPTIONS: |
| 567 | if(s->compr == TIFF_G4) | 600 | if (s->compr == TIFF_G4) |
| 568 | s->fax_opts = value; | 601 | s->fax_opts = value; |
| 569 | break; | 602 | break; |
| 570 | default: | 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 | return 0; | 607 | return 0; |
| 574 | } | 608 | } |
| 575 | 609 | ||
| 576 | static int decode_frame(AVCodecContext *avctx, | 610 | static int decode_frame(AVCodecContext *avctx, |
| 577 | void *data, int *data_size, | 611 | void *data, int *data_size, AVPacket *avpkt) |
| 578 | AVPacket *avpkt) | ||
| 579 | { | 612 | { |
| 580 | const uint8_t *buf = avpkt->data; | 613 | const uint8_t *buf = avpkt->data; |
| 581 | int buf_size = avpkt->size; | 614 | int buf_size = avpkt->size; |
| 582 | TiffContext * const s = avctx->priv_data; | 615 | TiffContext *const s = avctx->priv_data; |
| 583 | AVFrame *picture = data; | 616 | AVFrame *picture = data; |
| 584 | AVFrame * const p = &s->picture; | 617 | AVFrame *const p = &s->picture; |
| 585 | const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; | 618 | const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; |
| 586 | unsigned off; | 619 | unsigned off; |
| 587 | int id, le, ret; | 620 | int id, le, ret; |
| @@ -593,10 +626,13 @@ static int decode_frame(AVCodecContext *avctx, · 5 unmodified lines | |||
| 593 | //parse image header | 626 | //parse image header |
| 594 | if (end_buf - buf < 8) | 627 | if (end_buf - buf < 8) |
| 595 | return AVERROR_INVALIDDATA; | 628 | return AVERROR_INVALIDDATA; |
| 596 | id = AV_RL16(buf); buf += 2; | 629 | id = AV_RL16(buf); |
| 597 | if(id == 0x4949) le = 1; | 630 | buf += 2; |
| 598 | else if(id == 0x4D4D) le = 0; | 631 | if (id == 0x4949) |
| 599 | else{ | 632 | le = 1; |
| 633 | else if (id == 0x4D4D) | ||
| 634 | le = 0; | ||
| 635 | else { | ||
| 600 | av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); | 636 | av_log(avctx, AV_LOG_ERROR, "TIFF header not found\n"); |
| 601 | return -1; | 637 | return -1; |
| 602 | } | 638 | } |
| @@ -606,8 +642,9 @@ static int decode_frame(AVCodecContext *avctx, · 3 unmodified lines | |||
| 606 | s->fill_order = 0; | 642 | s->fill_order = 0; |
| 607 | // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number | 643 | // As TIFF 6.0 specification puts it "An arbitrary but carefully chosen number |
| 608 | // that further identifies the file as a TIFF file" | 644 | // that further identifies the file as a TIFF file" |
| 609 | if(tget_short(&buf, le) != 42){ | 645 | if (tget_short(&buf, le) != 42) { |
| 610 | av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n"); | 646 | av_log(avctx, AV_LOG_ERROR, |
| 647 | "The answer to life, universe and everything is not correct!\n"); | ||
| 611 | return -1; | 648 | return -1; |
| 612 | } | 649 | } |
| 613 | // Reset these pointers so we can tell if they were set this frame | 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 | buf = orig_buf + off; | 658 | buf = orig_buf + off; |
| 622 | entries = tget_short(&buf, le); | 659 | entries = tget_short(&buf, le); |
| 623 | for(i = 0; i < entries; i++){ | 660 | for (i = 0; i < entries; i++) { |
| 624 | if(tiff_decode_tag(s, orig_buf, buf, end_buf) < 0) | 661 | if (tiff_decode_tag(s, orig_buf, buf, end_buf) < 0) |
| 625 | return -1; | 662 | return -1; |
| 626 | buf += 12; | 663 | buf += 12; |
| 627 | } | 664 | } |
| 628 | if(!s->stripdata && !s->stripoff){ | 665 | if (!s->stripdata && !s->stripoff) { |
| 629 | av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); | 666 | av_log(avctx, AV_LOG_ERROR, "Image data is missing\n"); |
| 630 | return -1; | 667 | return -1; |
| 631 | } | 668 | } |
| @@ -633,36 +670,37 @@ static int decode_frame(AVCodecContext *avctx, · 1 unmodified line | |||
| 633 | if ((ret = init_image(s)) < 0) | 670 | if ((ret = init_image(s)) < 0) |
| 634 | return ret; | 671 | return ret; |
| 635 | 672 | ||
| 636 | if(s->strips == 1 && !s->stripsize){ | 673 | if (s->strips == 1 && !s->stripsize) { |
| 637 | av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); | 674 | av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); |
| 638 | s->stripsize = buf_size - s->stripoff; | 675 | s->stripsize = buf_size - s->stripoff; |
| 639 | } | 676 | } |
| 640 | stride = p->linesize[0]; | 677 | stride = p->linesize[0]; |
| 641 | dst = p->data[0]; | 678 | dst = p->data[0]; |
| 642 | for(i = 0; i < s->height; i += s->rps){ | 679 | for (i = 0; i < s->height; i += s->rps) { |
| 643 | if(s->stripsizes) { | 680 | if (s->stripsizes) { |
| 644 | if (s->stripsizes >= end_buf) | 681 | if (s->stripsizes >= end_buf) |
| 645 | return AVERROR_INVALIDDATA; | 682 | return AVERROR_INVALIDDATA; |
| 646 | ssize = tget(&s->stripsizes, s->sstype, s->le); | 683 | ssize = tget(&s->stripsizes, s->sstype, s->le); |
| 647 | } else | 684 | } else |
| 648 | ssize = s->stripsize; | 685 | ssize = s->stripsize; |
| 649 | 686 | ||
| 650 | if(s->stripdata){ | 687 | if (s->stripdata) { |
| 651 | if (s->stripdata >= end_buf) | 688 | if (s->stripdata >= end_buf) |
| 652 | return AVERROR_INVALIDDATA; | 689 | return AVERROR_INVALIDDATA; |
| 653 | soff = tget(&s->stripdata, s->sot, s->le); | 690 | soff = tget(&s->stripdata, s->sot, s->le); |
| 654 | }else | 691 | } else |
| 655 | soff = s->stripoff; | 692 | soff = s->stripoff; |
| 656 | 693 | ||
| 657 | if (soff > buf_size || ssize > buf_size - soff) { | 694 | if (soff > buf_size || ssize > buf_size - soff) { |
| 658 | av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n"); | 695 | av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n"); |
| 659 | return -1; | 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 | break; | 700 | break; |
| 663 | dst += s->rps * stride; | 701 | dst += s->rps * stride; |
| 664 | } | 702 | } |
| 665 | if(s->predictor == 2){ | 703 | if (s->predictor == 2) { |
| 666 | dst = p->data[0]; | 704 | dst = p->data[0]; |
| 667 | soff = s->bpp >> 3; | 705 | soff = s->bpp >> 3; |
| 668 | ssize = s->width * soff; | 706 | ssize = s->width * soff; |
| @@ -681,18 +719,18 @@ static int decode_frame(AVCodecContext *avctx, · 12 unmodified lines | |||
| 681 | dst += stride; | 719 | dst += stride; |
| 682 | } | 720 | } |
| 683 | } else { | 721 | } else { |
| 684 | for(i = 0; i < s->height; i++) { | 722 | for (i = 0; i < s->height; i++) { |
| 685 | for(j = soff; j < ssize; j++) | 723 | for (j = soff; j < ssize; j++) |
| 686 | dst[j] += dst[j - soff]; | 724 | dst[j] += dst[j - soff]; |
| 687 | dst += stride; | 725 | dst += stride; |
| 688 | } | 726 | } |
| 689 | } | 727 | } |
| 690 | } | 728 | } |
| 691 | 729 | ||
| 692 | if(s->invert){ | 730 | if (s->invert) { |
| 693 | dst = s->picture.data[0]; | 731 | dst = s->picture.data[0]; |
| 694 | for(i = 0; i < s->height; i++){ | 732 | for (i = 0; i < s->height; i++) { |
| 695 | for(j = 0; j < s->picture.linesize[0]; j++) | 733 | for (j = 0; j < s->picture.linesize[0]; j++) |
| 696 | dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j]; | 734 | dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<<s->bpp) - 1 : 255) - dst[j]; |
| 697 | dst += s->picture.linesize[0]; | 735 | dst += s->picture.linesize[0]; |
| 698 | } | 736 | } |
| @@ -703,7 +741,8 @@ static int decode_frame(AVCodecContext *avctx, · 4 unmodified lines | |||
| 703 | return buf_size; | 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 | TiffContext *s = avctx->priv_data; | 746 | TiffContext *s = avctx->priv_data; |
| 708 | 747 | ||
| 709 | s->width = 0; | 748 | s->width = 0; |
| @@ -719,10 +758,10 @@ static av_cold int tiff_init(AVCodecContext *avctx){ · 9 unmodified lines | |||
| 719 | 758 | ||
| 720 | static av_cold int tiff_end(AVCodecContext *avctx) | 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 | ff_lzw_decode_close(&s->lzw); | 763 | ff_lzw_decode_close(&s->lzw); |
| 725 | if(s->picture.data[0]) | 764 | if (s->picture.data[0]) |
| 726 | avctx->release_buffer(avctx, &s->picture); | 765 | avctx->release_buffer(avctx, &s->picture); |
| 727 | return 0; | 766 | return 0; |
| 728 | } | 767 | } |
| @@ -229,7 +229,6 @@ static av_cold int decode_init(AVCodecContext *avctx) · 228 unmodified lines | |||
| 229 | s->max_subframe_len_bit = 0; | 229 | s->max_subframe_len_bit = 0; |
| 230 | s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1; | 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 | s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; | 232 | s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; |
| 234 | s->dynamic_range_compression = s->decode_flags & 0x80; | 233 | s->dynamic_range_compression = s->decode_flags & 0x80; |
| 235 | s->bV3RTM = s->decode_flags & 0x100; | 234 | s->bV3RTM = s->decode_flags & 0x100; |
| @@ -940,9 +939,10 @@ static int decode_subframe(WmallDecodeCtx *s) · 704 unmodified lines | |||
| 940 | 939 | ||
| 941 | if (rawpcm_tile) { | 940 | if (rawpcm_tile) { |
| 942 | int bits = s->bits_per_sample - padding_zeroes; | 941 | int bits = s->bits_per_sample - padding_zeroes; |
| 943 | if (bits <= 0 ) { | 942 | if (bits <= 0) { |
| 944 | av_log(s->avctx, AV_LOG_ERROR, "rawpcm_tile bits invalid\n"); | 943 | av_log(s->avctx, AV_LOG_ERROR, |
| 945 | return -1; | 944 | "Invalid number of padding bits in raw PCM tile\n"); |
| 945 | return AVERROR_INVALIDDATA; | ||
| 946 | } | 946 | } |
| 947 | av_dlog(s->avctx, "RAWPCM %d bits per sample. " | 947 | av_dlog(s->avctx, "RAWPCM %d bits per sample. " |
| 948 | "total %d bits, remain=%d\n", bits, | 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 | GetBitContext* gb = &s->pgb; | 1169 | GetBitContext* gb = &s->pgb; |
| 1170 | const uint8_t* buf = avpkt->data; | 1170 | const uint8_t* buf = avpkt->data; |
| 1171 | int buf_size = avpkt->size; | 1171 | int buf_size = avpkt->size; |
| 1172 | int num_bits_prev_frame, packet_sequence_number, | 1172 | int num_bits_prev_frame, packet_sequence_number, spliced_packet; |
| 1173 | seekable_frame_in_packet, spliced_packet; | ||
| 1174 | 1173 | ||
| 1175 | if (s->packet_done || s->packet_loss) { | 1174 | if (s->packet_done || s->packet_loss) { |
| 1176 | s->packet_done = 0; | 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 | /* parse packet header */ | 1185 | /* parse packet header */ |
| 1187 | init_get_bits(gb, buf, s->buf_bit_size); | 1186 | init_get_bits(gb, buf, s->buf_bit_size); |
| 1188 | packet_sequence_number = get_bits(gb, 4); | 1187 | packet_sequence_number = get_bits(gb, 4); |
| 1189 | seekable_frame_in_packet = get_bits1(gb); | 1188 | skip_bits(gb, 1); // Skip seekable_frame_in_packet, currently ununused |
| 1190 | spliced_packet = get_bits1(gb); | 1189 | spliced_packet = get_bits1(gb); |
| 1190 | if (spliced_packet) | ||
| 1191 | av_log_missing_feature(avctx, "Bitstream splicing", 1); | ||
| 1191 | 1192 | ||
| 1192 | /* get number of bits that need to be added to the previous frame */ | 1193 | /* get number of bits that need to be added to the previous frame */ |
| 1193 | num_bits_prev_frame = get_bits(gb, s->log2_frame_size); | 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 | %define valw2 r7w | 594 | %define valw2 r7w |
| 595 | %define valw3 r3w | 595 | %define valw3 r3w |
| 596 | %if WIN64 | 596 | %if WIN64 |
| 597 | %define valw4 r4w | 597 | %define valw4 r7w |
| 598 | %else ; unix64 | 598 | %else ; unix64 |
| 599 | %define valw4 r3w | 599 | %define valw4 r3w |
| 600 | %endif | 600 | %endif |
| @@ -91,11 +91,11 @@ void avfilter_graph_free(AVFilterGraph **graph); · 90 unmodified lines | |||
| 91 | /** | 91 | /** |
| 92 | * A linked-list of the inputs/outputs of the filter chain. | 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 | 94 | * This is mainly useful for avfilter_graph_parse() / avfilter_graph_parse2(), |
| 95 | * function may accept a description of a graph with not connected | 95 | * where it is used to communicate open (unlinked) inputs and outputs from and |
| 96 | * input/output pads. This struct specifies, per each not connected | 96 | * to the caller. |
| 97 | * pad contained in the graph, the filter context and the pad index | 97 | * This struct specifies, per each not connected pad contained in the graph, the |
| 98 | * required for establishing a link. | 98 | * filter context and the pad index required for establishing a link. |
| 99 | */ | 99 | */ |
| 100 | typedef struct AVFilterInOut { | 100 | typedef struct AVFilterInOut { |
| 101 | /** unique name for this input/output in the list */ | 101 | /** unique name for this input/output in the list */ |
| @@ -112,13 +112,14 @@ typedef struct AVFilterInOut { · 10 unmodified lines | |||
| 112 | } AVFilterInOut; | 112 | } AVFilterInOut; |
| 113 | 113 | ||
| 114 | /** | 114 | /** |
| 115 | * Create an AVFilterInOut. | 115 | * Allocate a single AVFilterInOut entry. |
| 116 | * Must be free with avfilter_inout_free(). | 116 | * Must be freed with avfilter_inout_free(). |
| 117 | * @return allocated AVFilterInOut on success, NULL on failure. | ||
| 117 | */ | 118 | */ |
| 118 | AVFilterInOut *avfilter_inout_alloc(void); | 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 | * If *inout is NULL, do nothing. | 123 | * If *inout is NULL, do nothing. |
| 123 | */ | 124 | */ |
| 124 | void avfilter_inout_free(AVFilterInOut **inout); | 125 | void avfilter_inout_free(AVFilterInOut **inout); |
| @@ -140,6 +141,41 @@ int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, · 15 unmodified lines | |||
| 140 | AVFilterInOut **inputs, AVFilterInOut **outputs, | 141 | AVFilterInOut **inputs, AVFilterInOut **outputs, |
| 141 | void *log_ctx); | 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 | * Send a command to one or more filter instances. | 180 | * Send a command to one or more filter instances. |
| 145 | * | 181 | * |
| @@ -32,6 +32,7 @@ · 31 unmodified lines | |||
| 32 | * | 32 | * |
| 33 | * @param buf buffer containing frame data to be passed down the filtergraph. | 33 | * @param buf buffer containing frame data to be passed down the filtergraph. |
| 34 | * This function will take ownership of buf, the user must not free it. | 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 | int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf); | 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 | AVFilterInOut *ret; | 190 | AVFilterInOut *ret; |
| 191 | 191 | ||
| 192 | while (*links && strcmp((*links)->name, label)) | 192 | while (*links && (!(*links)->name || strcmp((*links)->name, label))) |
| 193 | links = &((*links)->next); | 193 | links = &((*links)->next); |
| 194 | 194 | ||
| 195 | ret = *links; | 195 | ret = *links; |
| 196 | 196 | ||
| 197 | if (ret) | 197 | if (ret) { |
| 198 | *links = ret->next; | 198 | *links = ret->next; |
| 199 | ret->next = NULL; | ||
| 200 | } | ||
| 199 | 201 | ||
| 200 | return ret; | 202 | return ret; |
| 201 | } | 203 | } |
| @@ -206,22 +208,31 @@ static void insert_inout(AVFilterInOut **inouts, AVFilterInOut *element) · 4 unmodified lines | |||
| 206 | *inouts = element; | 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 | static int link_filter_inouts(AVFilterContext *filt_ctx, | 223 | static int link_filter_inouts(AVFilterContext *filt_ctx, |
| 210 | AVFilterInOut **curr_inputs, | 224 | AVFilterInOut **curr_inputs, |
| 211 | AVFilterInOut **open_inputs, void *log_ctx) | 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 | AVFilterInOut *p = *curr_inputs; | 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 | if (p->filter_ctx) { | 237 | if (p->filter_ctx) { |
| 227 | if ((ret = link_filter(p->filter_ctx, p->pad_idx, filt_ctx, pad, log_ctx)) < 0) | 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 | static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, | 269 | static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, |
| 259 | AVFilterInOut **open_outputs, void *log_ctx) | 270 | AVFilterInOut **open_outputs, void *log_ctx) |
| 260 | { | 271 | { |
| 272 | AVFilterInOut *parsed_inputs = NULL; | ||
| 261 | int pad = 0; | 273 | int pad = 0; |
| 262 | 274 | ||
| 263 | while (**buf == '[') { | 275 | while (**buf == '[') { |
| @@ -280,12 +292,15 @@ static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, · 16 unmodified lines | |||
| 280 | match->pad_idx = pad; | 292 | match->pad_idx = pad; |
| 281 | } | 293 | } |
| 282 | 294 | ||
| 283 | insert_inout(curr_inputs, match); | 295 | append_inout(&parsed_inputs, &match); |
| 284 | 296 | ||
| 285 | *buf += strspn(*buf, WHITESPACES); | 297 | *buf += strspn(*buf, WHITESPACES); |
| 286 | pad++; | 298 | pad++; |
| 287 | } | 299 | } |
| 288 | 300 | ||
| 301 | append_inout(&parsed_inputs, curr_inputs); | ||
| 302 | *curr_inputs = parsed_inputs; | ||
| 303 | |||
| 289 | return pad; | 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 | return pad; | 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 | int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, | 450 | int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, |
| 338 | AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr, | 451 | AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr, |
| 339 | void *log_ctx) | 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 | int index = 0, ret = 0; | 519 | int index = 0, ret = 0; |
| 342 | char chr = 0; | 520 | char chr = 0; |
| 343 | 521 | ||
| @@ -414,3 +592,5 @@ end: · 70 unmodified lines | |||
| 414 | } | 592 | } |
| 415 | return ret; | 593 | return ret; |
| 416 | } | 594 | } |
| 595 | |||
| 596 | #endif | ||
| @@ -29,8 +29,8 @@ · 28 unmodified lines | |||
| 29 | #include "libavutil/avutil.h" | 29 | #include "libavutil/avutil.h" |
| 30 | 30 | ||
| 31 | #define LIBAVFILTER_VERSION_MAJOR 2 | 31 | #define LIBAVFILTER_VERSION_MAJOR 2 |
| 32 | #define LIBAVFILTER_VERSION_MINOR 69 | 32 | #define LIBAVFILTER_VERSION_MINOR 70 |
| 33 | #define LIBAVFILTER_VERSION_MICRO 101 | 33 | #define LIBAVFILTER_VERSION_MICRO 100 |
| 34 | 34 | ||
| 35 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ | 35 | #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ |
| 36 | LIBAVFILTER_VERSION_MINOR, \ | 36 | LIBAVFILTER_VERSION_MINOR, \ |
| @@ -39,6 +39,7 @@ typedef struct { · 38 unmodified lines | |||
| 39 | AVRational time_base; ///< time_base to set in the output link | 39 | AVRational time_base; ///< time_base to set in the output link |
| 40 | AVRational sample_aspect_ratio; | 40 | AVRational sample_aspect_ratio; |
| 41 | char sws_param[256]; | 41 | char sws_param[256]; |
| 42 | int eof; | ||
| 42 | } BufferSourceContext; | 43 | } BufferSourceContext; |
| 43 | 44 | ||
| 44 | #define CHECK_PARAM_CHANGE(s, c, width, height, format)\ | 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 | AVFilterBufferRef *buf; | 56 | AVFilterBufferRef *buf; |
| 56 | int ret; | 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 | if (!av_fifo_space(c->fifo) && | 65 | if (!av_fifo_space(c->fifo) && |
| 59 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + | 66 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + |
| 60 | sizeof(buf))) < 0) | 67 | sizeof(buf))) < 0) |
| @@ -125,6 +132,12 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 64 unmodified lines | |||
| 125 | BufferSourceContext *c = s->priv; | 132 | BufferSourceContext *c = s->priv; |
| 126 | int ret; | 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 | if (!av_fifo_space(c->fifo) && | 141 | if (!av_fifo_space(c->fifo) && |
| 129 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + | 142 | (ret = av_fifo_realloc2(c->fifo, av_fifo_size(c->fifo) + |
| 130 | sizeof(buf))) < 0) | 143 | sizeof(buf))) < 0) |
| @@ -144,9 +157,17 @@ int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) · 13 unmodified lines | |||
| 144 | int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, | 157 | int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, |
| 145 | const AVFrame *frame, int flags) | 158 | const AVFrame *frame, int flags) |
| 146 | { | 159 | { |
| 160 | BufferSourceContext *c = buffer_src->priv; | ||
| 161 | AVFilterBufferRef *picref; | ||
| 147 | int ret; | 162 | int ret; |
| 148 | AVFilterBufferRef *picref = | 163 | |
| 149 | avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); | 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 | if (!picref) | 171 | if (!picref) |
| 151 | return AVERROR(ENOMEM); | 172 | return AVERROR(ENOMEM); |
| 152 | ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags); | 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 | AVFilterBufferRef *buf; | 247 | AVFilterBufferRef *buf; |
| 227 | 248 | ||
| 228 | if (!av_fifo_size(c->fifo)) { | 249 | if (!av_fifo_size(c->fifo)) { |
| 250 | if (c->eof) | ||
| 251 | return AVERROR_EOF; | ||
| 229 | av_log(link->src, AV_LOG_WARNING, | 252 | av_log(link->src, AV_LOG_WARNING, |
| 230 | "request_frame() called with no available frame!\n"); | 253 | "request_frame() called with no available frame!\n"); |
| 231 | return AVERROR(EINVAL); | 254 | return AVERROR(EINVAL); |
| @@ -243,7 +266,10 @@ static int request_frame(AVFilterLink *link) · 11 unmodified lines | |||
| 243 | static int poll_frame(AVFilterLink *link) | 266 | static int poll_frame(AVFilterLink *link) |
| 244 | { | 267 | { |
| 245 | BufferSourceContext *c = link->src->priv; | 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 | AVFilter avfilter_vsrc_buffer = { | 275 | AVFilter avfilter_vsrc_buffer = { |
| @@ -107,6 +107,7 @@ typedef struct MOVStreamContext { · 106 unmodified lines | |||
| 107 | unsigned int alt_sample_size; ///< always contains sample size from stsz atom | 107 | unsigned int alt_sample_size; ///< always contains sample size from stsz atom |
| 108 | unsigned int sample_count; | 108 | unsigned int sample_count; |
| 109 | int *sample_sizes; | 109 | int *sample_sizes; |
| 110 | int keyframe_absent; | ||
| 110 | unsigned int keyframe_count; | 111 | unsigned int keyframe_count; |
| 111 | int *keyframes; | 112 | int *keyframes; |
| 112 | int time_scale; | 113 | int time_scale; |
| @@ -1618,7 +1618,10 @@ static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) · 1617 unmodified lines | |||
| 1618 | av_dlog(c->fc, "keyframe_count = %d\n", entries); | 1618 | av_dlog(c->fc, "keyframe_count = %d\n", entries); |
| 1619 | 1619 | ||
| 1620 | if (!entries) | 1620 | if (!entries) |
| 1621 | { | ||
| 1622 | sc->keyframe_absent = 1; | ||
| 1621 | return 0; | 1623 | return 0; |
| 1624 | } | ||
| 1622 | if (entries >= UINT_MAX / sizeof(int)) | 1625 | if (entries >= UINT_MAX / sizeof(int)) |
| 1623 | return AVERROR_INVALIDDATA; | 1626 | return AVERROR_INVALIDDATA; |
| 1624 | sc->keyframes = av_malloc(entries * sizeof(int)); | 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 | return; | 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 | keyframe = 1; | 1880 | keyframe = 1; |
| 1878 | if (stss_index + 1 < sc->keyframe_count) | 1881 | if (stss_index + 1 < sc->keyframe_count) |
| 1879 | stss_index++; | 1882 | stss_index++; |
| @@ -1975,6 +1975,8 @@ static int has_duration(AVFormatContext *ic) · 1974 unmodified lines | |||
| 1975 | if (st->duration != AV_NOPTS_VALUE) | 1975 | if (st->duration != AV_NOPTS_VALUE) |
| 1976 | return 1; | 1976 | return 1; |
| 1977 | } | 1977 | } |
| 1978 | if (ic->duration) | ||
| 1979 | return 1; | ||
| 1978 | return 0; | 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 | int i; | 470 | int i; |
| 471 | 471 | ||
| 472 | for (i = 0; i < (dstW >> 1); i++) { | 472 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 473 | int j; | 473 | int j; |
| 474 | int Y1 = 1 << 18; | 474 | int Y1 = 1 << 18; |
| 475 | int Y2 = 1 << 18; | 475 | int Y2 = 1 << 18; |
| @@ -512,7 +512,7 @@ yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], · 36 unmodified lines | |||
| 512 | int uvalpha1 = 4095 - uvalpha; | 512 | int uvalpha1 = 4095 - uvalpha; |
| 513 | int i; | 513 | int i; |
| 514 | 514 | ||
| 515 | for (i = 0; i < (dstW >> 1); i++) { | 515 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 516 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; | 516 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; |
| 517 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; | 517 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; |
| 518 | int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; | 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 | int i; | 539 | int i; |
| 540 | 540 | ||
| 541 | if (uvalpha < 2048) { | 541 | if (uvalpha < 2048) { |
| 542 | for (i = 0; i < (dstW >> 1); i++) { | 542 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 543 | int Y1 = (buf0[i * 2 ]+64) >> 7; | 543 | int Y1 = (buf0[i * 2 ]+64) >> 7; |
| 544 | int Y2 = (buf0[i * 2 + 1]+64) >> 7; | 544 | int Y2 = (buf0[i * 2 + 1]+64) >> 7; |
| 545 | int U = (ubuf0[i] +64) >> 7; | 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 | } else { | 562 | } else { |
| 563 | const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; | 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 | int Y1 = (buf0[i * 2 ] + 64) >> 7; | 565 | int Y1 = (buf0[i * 2 ] + 64) >> 7; |
| 566 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; | 566 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; |
| 567 | int U = (ubuf0[i] + ubuf1[i]+128) >> 8; | 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 | int i; | 609 | int i; |
| 610 | 610 | ||
| 611 | for (i = 0; i < (dstW >> 1); i++) { | 611 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 612 | int j; | 612 | int j; |
| 613 | int Y1 = -0x40000000; | 613 | int Y1 = -0x40000000; |
| 614 | int Y2 = -0x40000000; | 614 | int Y2 = -0x40000000; |
| @@ -671,7 +671,7 @@ yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2], · 56 unmodified lines | |||
| 671 | int uvalpha1 = 4095 - uvalpha; | 671 | int uvalpha1 = 4095 - uvalpha; |
| 672 | int i; | 672 | int i; |
| 673 | 673 | ||
| 674 | for (i = 0; i < (dstW >> 1); i++) { | 674 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 675 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14; | 675 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14; |
| 676 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14; | 676 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14; |
| 677 | int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14; | 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 | int i; | 709 | int i; |
| 710 | 710 | ||
| 711 | if (uvalpha < 2048) { | 711 | if (uvalpha < 2048) { |
| 712 | for (i = 0; i < (dstW >> 1); i++) { | 712 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 713 | int Y1 = (buf0[i * 2] ) >> 2; | 713 | int Y1 = (buf0[i * 2] ) >> 2; |
| 714 | int Y2 = (buf0[i * 2 + 1]) >> 2; | 714 | int Y2 = (buf0[i * 2 + 1]) >> 2; |
| 715 | int U = (ubuf0[i] + (-128 << 11)) >> 2; | 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 | } else { | 738 | } else { |
| 739 | const int32_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; | 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 | int Y1 = (buf0[i * 2] ) >> 2; | 741 | int Y1 = (buf0[i * 2] ) >> 2; |
| 742 | int Y2 = (buf0[i * 2 + 1]) >> 2; | 742 | int Y2 = (buf0[i * 2 + 1]) >> 2; |
| 743 | int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3; | 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 | int i; | 953 | int i; |
| 954 | 954 | ||
| 955 | for (i = 0; i < (dstW >> 1); i++) { | 955 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 956 | int j, A1, A2; | 956 | int j, A1, A2; |
| 957 | int Y1 = 1 << 18; | 957 | int Y1 = 1 << 18; |
| 958 | int Y2 = 1 << 18; | 958 | int Y2 = 1 << 18; |
| @@ -1012,7 +1012,7 @@ yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], · 53 unmodified lines | |||
| 1012 | int uvalpha1 = 4095 - uvalpha; | 1012 | int uvalpha1 = 4095 - uvalpha; |
| 1013 | int i; | 1013 | int i; |
| 1014 | 1014 | ||
| 1015 | for (i = 0; i < (dstW >> 1); i++) { | 1015 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 1016 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; | 1016 | int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; |
| 1017 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; | 1017 | int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; |
| 1018 | int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; | 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 | int i; | 1050 | int i; |
| 1051 | 1051 | ||
| 1052 | if (uvalpha < 2048) { | 1052 | if (uvalpha < 2048) { |
| 1053 | for (i = 0; i < (dstW >> 1); i++) { | 1053 | for (i = 0; i < ((dstW + 1) >> 1); i++) { |
| 1054 | int Y1 = (buf0[i * 2 ] + 64) >> 7; | 1054 | int Y1 = (buf0[i * 2 ] + 64) >> 7; |
| 1055 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; | 1055 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; |
| 1056 | int U = (ubuf0[i] + 64) >> 7; | 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 | } else { | 1078 | } else { |
| 1079 | const int16_t *ubuf1 = ubuf[1], *vbuf1 = vbuf[1]; | 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 | int Y1 = (buf0[i * 2 ] + 64) >> 7; | 1081 | int Y1 = (buf0[i * 2 ] + 64) >> 7; |
| 1082 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; | 1082 | int Y2 = (buf0[i * 2 + 1] + 64) >> 7; |
| 1083 | int U = (ubuf0[i] + ubuf1[i] + 128) >> 8; | 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 | do_lavfi "drawbox" "drawbox=224:24:88:72:#FF8010@0.5" | 40 | do_lavfi "drawbox" "drawbox=224:24:88:72:#FF8010@0.5" |
| 41 | do_lavfi "fade" "fade=in:5:15,fade=out:30:15" | 41 | do_lavfi "fade" "fade=in:5:15,fade=out:30:15" |
| 42 | do_lavfi "null" "null" | 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 | do_lavfi "pad" "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2" | 44 | do_lavfi "pad" "pad=iw*1.5:ih*1.5:iw*0.3:ih*0.2" |
| 45 | do_lavfi "pp" "mp=pp=be/de/tn/l5/al" | 45 | do_lavfi "pp" "mp=pp=be/de/tn/l5/al" |
| 46 | do_lavfi "pp2" "mp=pp=be/fq:16/fa/lb" | 46 | do_lavfi "pp2" "mp=pp=be/fq:16/fa/lb" |