| @@ -283,10 +283,6 @@ static int alloc_huffman(MpegEncContext *s) · 282 unmodified lines |
| 283 | 283 | size_t num_mbs, num_blocks, num_codes; |
| 284 | 284 | int blocks_per_mb; |
| 285 | 285 | |
| 286 | | − // We need to init this here as the mjpeg init is called before the common init, |
| 287 | | − s->mb_width = (s->width + 15) / 16; |
| 288 | | − s->mb_height = (s->height + 15) / 16; |
| 289 | | − |
| 290 | 286 | switch (s->chroma_format) { |
| 291 | 287 | case CHROMA_420: blocks_per_mb = 6; break; |
| 292 | 288 | case CHROMA_422: blocks_per_mb = 8; break; |
| @@ -305,34 +301,30 @@ static int alloc_huffman(MpegEncContext *s) · 12 unmodified lines |
| 305 | 301 | return 0; |
| 306 | 302 | } |
| 307 | 303 | |
| 308 | | −av_cold int ff_mjpeg_encode_init(MpegEncContext *s) |
| 304 | +static av_cold int mjpeg_encode_init(AVCodecContext *avctx) |
| 309 | 305 | { |
| 310 | | − MJpegContext *const m = &((MJPEGEncContext*)s)->mjpeg; |
| 311 | | − int ret, use_slices; |
| 306 | + MJPEGEncContext *const m2 = avctx->priv_data; |
| 307 | + MJpegContext *const m = &m2->mjpeg; |
| 308 | + MpegEncContext *const s = &m2->mpeg.s; |
| 309 | + int ret; |
| 312 | 310 | |
| 313 | 311 | s->mjpeg_ctx = m; |
| 314 | | − use_slices = s->avctx->slices > 0 ? s->avctx->slices > 1 : |
| 315 | | − (s->avctx->active_thread_type & FF_THREAD_SLICE) && |
| 316 | | − s->avctx->thread_count > 1; |
| 317 | | − |
| 318 | | − if (use_slices) |
| 319 | | − m->huffman = HUFFMAN_TABLE_DEFAULT; |
| 320 | 312 | |
| 321 | 313 | if (s->mpv_flags & FF_MPV_FLAG_QP_RD) { |
| 322 | 314 | // Used to produce garbage with MJPEG. |
| 323 | | − av_log(s->avctx, AV_LOG_ERROR, |
| 315 | + av_log(avctx, AV_LOG_ERROR, |
| 324 | 316 | "QP RD is no longer compatible with MJPEG or AMV\n"); |
| 325 | 317 | return AVERROR(EINVAL); |
| 326 | 318 | } |
| 327 | 319 | |
| 328 | 320 | /* The following check is automatically true for AMV, |
| 329 | 321 | * but it doesn't hurt either. */ |
| 330 | | − ret = ff_mjpeg_encode_check_pix_fmt(s->avctx); |
| 322 | + ret = ff_mjpeg_encode_check_pix_fmt(avctx); |
| 331 | 323 | if (ret < 0) |
| 332 | 324 | return ret; |
| 333 | 325 | |
| 334 | | − if (s->width > 65500 || s->height > 65500) { |
| 335 | | − av_log(s->avctx, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n"); |
| 326 | + if (avctx->width > 65500 || avctx->height > 65500) { |
| 327 | + av_log(avctx, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n"); |
| 336 | 328 | return AVERROR(EINVAL); |
| 337 | 329 | } |
| 338 | 330 | |
| @@ -366,9 +358,16 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s) · 27 unmodified lines |
| 366 | 358 | s->intra_chroma_ac_vlc_length = |
| 367 | 359 | s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len; |
| 368 | 360 | |
| 361 | + ret = ff_mpv_encode_init(avctx); |
| 362 | + if (ret < 0) |
| 363 | + return ret; |
| 364 | + |
| 369 | 365 | // Buffers start out empty. |
| 370 | 366 | m->huff_ncode = 0; |
| 371 | 367 | |
| 368 | + if (s->slice_context_count > 1) |
| 369 | + m->huffman = HUFFMAN_TABLE_DEFAULT; |
| 370 | + |
| 372 | 371 | if (m->huffman == HUFFMAN_TABLE_OPTIMAL) |
| 373 | 372 | return alloc_huffman(s); |
| 374 | 373 | |
| @@ -681,7 +680,7 @@ const FFCodec ff_mjpeg_encoder = { · 306 unmodified lines |
| 681 | 680 | .p.type = AVMEDIA_TYPE_VIDEO, |
| 682 | 681 | .p.id = AV_CODEC_ID_MJPEG, |
| 683 | 682 | .priv_data_size = sizeof(MJPEGEncContext), |
| 684 | | − .init = ff_mpv_encode_init, |
| 683 | + .init = mjpeg_encode_init, |
| 685 | 684 | FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), |
| 686 | 685 | .close = mjpeg_encode_close, |
| 687 | 686 | .p.capabilities = AV_CODEC_CAP_DR1 | |
| @@ -711,7 +710,7 @@ const FFCodec ff_amv_encoder = { · 23 unmodified lines |
| 711 | 710 | .p.id = AV_CODEC_ID_AMV, |
| 712 | 711 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, |
| 713 | 712 | .priv_data_size = sizeof(MJPEGEncContext), |
| 714 | | − .init = ff_mpv_encode_init, |
| 713 | + .init = mjpeg_encode_init, |
| 715 | 714 | FF_CODEC_ENCODE_CB(amv_encode_picture), |
| 716 | 715 | .close = mjpeg_encode_close, |
| 717 | 716 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, |