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