| @@ -291,9 +291,6 @@ static av_cold void mpv_encode_defaults(MpegEncContext *s) · 290 unmodified lines |
| 291 | s->y_dc_scale_table = | 291 | s->y_dc_scale_table = |
| 292 | s->c_dc_scale_table = ff_mpeg1_dc_scale_table; | 292 | s->c_dc_scale_table = ff_mpeg1_dc_scale_table; |
| 293 | } | 293 | } |
| 294 | | | |
| 295 | s->input_picture_number = 0; | | |
| 296 | s->picture_in_gop_number = 0; | | |
| 297 | } | 294 | } |
| 298 | | 295 | |
| 299 | av_cold void ff_dct_encode_init(MpegEncContext *s) | 296 | av_cold void ff_dct_encode_init(MpegEncContext *s) |
| @@ -354,9 +351,10 @@ static av_cold int me_cmp_init(MPVMainEncContext *const m, AVCodecContext *avctx · 54 unmodified lines |
| 354 | } | 351 | } |
| 355 | | 352 | |
| 356 | #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p)))) | 353 | #define ALLOCZ_ARRAYS(p, mult, numb) ((p) = av_calloc(numb, mult * sizeof(*(p)))) |
| 357 | static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx) | 354 | static av_cold int init_matrices(MPVMainEncContext *const m, AVCodecContext *avctx) |
| 358 | { | 355 | { |
| 359 | const int nb_matrices = 1 + (s->out_format == FMT_MJPEG) + !s->intra_only; | 356 | MpegEncContext *const s = &m->s; |
| | 357 | const int nb_matrices = 1 + (s->out_format == FMT_MJPEG) + !m->intra_only; |
| 360 | const uint16_t *intra_matrix, *inter_matrix; | 358 | const uint16_t *intra_matrix, *inter_matrix; |
| 361 | int ret; | 359 | int ret; |
| 362 | | 360 | |
| @@ -368,14 +366,14 @@ static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx) · 5 unmodified lines |
| 368 | s->q_chroma_intra_matrix = s->q_intra_matrix + 32; | 366 | s->q_chroma_intra_matrix = s->q_intra_matrix + 32; |
| 369 | s->q_chroma_intra_matrix16 = s->q_intra_matrix16 + 32; | 367 | s->q_chroma_intra_matrix16 = s->q_intra_matrix16 + 32; |
| 370 | // No need to set q_inter_matrix | 368 | // No need to set q_inter_matrix |
| 371 | av_assert1(s->intra_only); | 369 | av_assert1(m->intra_only); |
| 372 | // intra_matrix, chroma_intra_matrix will be set later for MJPEG. | 370 | // intra_matrix, chroma_intra_matrix will be set later for MJPEG. |
| 373 | return 0; | 371 | return 0; |
| 374 | } else { | 372 | } else { |
| 375 | s->q_chroma_intra_matrix = s->q_intra_matrix; | 373 | s->q_chroma_intra_matrix = s->q_intra_matrix; |
| 376 | s->q_chroma_intra_matrix16 = s->q_intra_matrix16; | 374 | s->q_chroma_intra_matrix16 = s->q_intra_matrix16; |
| 377 | } | 375 | } |
| 378 | if (!s->intra_only) { | 376 | if (!m->intra_only) { |
| 379 | s->q_inter_matrix = s->q_intra_matrix + 32; | 377 | s->q_inter_matrix = s->q_intra_matrix + 32; |
| 380 | s->q_inter_matrix16 = s->q_intra_matrix16 + 32; | 378 | s->q_inter_matrix16 = s->q_intra_matrix16 + 32; |
| 381 | } | 379 | } |
| @@ -460,7 +458,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 78 unmodified lines |
| 460 | avctx->gop_size, 600); | 458 | avctx->gop_size, 600); |
| 461 | avctx->gop_size = 600; | 459 | avctx->gop_size = 600; |
| 462 | } | 460 | } |
| 463 | s->gop_size = avctx->gop_size; | 461 | m->gop_size = avctx->gop_size; |
| 464 | s->avctx = avctx; | 462 | s->avctx = avctx; |
| 465 | if (avctx->max_b_frames > MPVENC_MAX_B_FRAMES) { | 463 | if (avctx->max_b_frames > MPVENC_MAX_B_FRAMES) { |
| 466 | av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum " | 464 | av_log(avctx, AV_LOG_ERROR, "Too many B-frames requested, maximum " |
| @@ -499,13 +497,13 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 32 unmodified lines |
| 499 | av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); | 497 | av_log(avctx, AV_LOG_ERROR, "intra dc precision too large\n"); |
| 500 | return AVERROR(EINVAL); | 498 | return AVERROR(EINVAL); |
| 501 | } | 499 | } |
| 502 | s->user_specified_pts = AV_NOPTS_VALUE; | 500 | m->user_specified_pts = AV_NOPTS_VALUE; |
| 503 | | 501 | |
| 504 | if (s->gop_size <= 1) { | 502 | if (m->gop_size <= 1) { |
| 505 | s->intra_only = 1; | 503 | m->intra_only = 1; |
| 506 | s->gop_size = 12; | 504 | m->gop_size = 12; |
| 507 | } else { | 505 | } else { |
| 508 | s->intra_only = 0; | 506 | m->intra_only = 0; |
| 509 | } | 507 | } |
| 510 | | 508 | |
| 511 | /* Fixed QSCALE */ | 509 | /* Fixed QSCALE */ |
| @@ -753,14 +751,14 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 241 unmodified lines |
| 753 | case AV_CODEC_ID_MJPEG: | 751 | case AV_CODEC_ID_MJPEG: |
| 754 | case AV_CODEC_ID_AMV: | 752 | case AV_CODEC_ID_AMV: |
| 755 | s->out_format = FMT_MJPEG; | 753 | s->out_format = FMT_MJPEG; |
| 756 | s->intra_only = 1; /* force intra only for jpeg */ | 754 | m->intra_only = 1; /* force intra only for jpeg */ |
| 757 | avctx->delay = 0; | 755 | avctx->delay = 0; |
| 758 | s->low_delay = 1; | 756 | s->low_delay = 1; |
| 759 | break; | 757 | break; |
| 760 | #endif | 758 | #endif |
| 761 | case AV_CODEC_ID_SPEEDHQ: | 759 | case AV_CODEC_ID_SPEEDHQ: |
| 762 | s->out_format = FMT_SPEEDHQ; | 760 | s->out_format = FMT_SPEEDHQ; |
| 763 | s->intra_only = 1; /* force intra only for SHQ */ | 761 | m->intra_only = 1; /* force intra only for SHQ */ |
| 764 | avctx->delay = 0; | 762 | avctx->delay = 0; |
| 765 | s->low_delay = 1; | 763 | s->low_delay = 1; |
| 766 | break; | 764 | break; |
| @@ -885,7 +883,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 118 unmodified lines |
| 885 | s->frame_reconstruction_bitfield = (1 << AV_PICTURE_TYPE_I) | | 883 | s->frame_reconstruction_bitfield = (1 << AV_PICTURE_TYPE_I) | |
| 886 | (1 << AV_PICTURE_TYPE_P) | | 884 | (1 << AV_PICTURE_TYPE_P) | |
| 887 | (1 << AV_PICTURE_TYPE_B); | 885 | (1 << AV_PICTURE_TYPE_B); |
| 888 | } else if (!s->intra_only) { | 886 | } else if (!m->intra_only) { |
| 889 | s->frame_reconstruction_bitfield = (1 << AV_PICTURE_TYPE_I) | | 887 | s->frame_reconstruction_bitfield = (1 << AV_PICTURE_TYPE_I) | |
| 890 | (1 << AV_PICTURE_TYPE_P); | 888 | (1 << AV_PICTURE_TYPE_P); |
| 891 | } else { | 889 | } else { |
| @@ -916,7 +914,7 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 24 unmodified lines |
| 916 | !(s->picture_pool = ff_mpv_alloc_pic_pool(0))) | 914 | !(s->picture_pool = ff_mpv_alloc_pic_pool(0))) |
| 917 | return AVERROR(ENOMEM); | 915 | return AVERROR(ENOMEM); |
| 918 | | 916 | |
| 919 | ret = init_matrices(s, avctx); | 917 | ret = init_matrices(m, avctx); |
| 920 | if (ret < 0) | 918 | if (ret < 0) |
| 921 | return ret; | 919 | return ret; |
| 922 | | 920 | |
| @@ -1259,11 +1257,11 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 336 unmodified lines |
| 1259 | | 1257 | |
| 1260 | if (pic_arg) { | 1258 | if (pic_arg) { |
| 1261 | pts = pic_arg->pts; | 1259 | pts = pic_arg->pts; |
| 1262 | display_picture_number = s->input_picture_number++; | 1260 | display_picture_number = m->input_picture_number++; |
| 1263 | | 1261 | |
| 1264 | if (pts != AV_NOPTS_VALUE) { | 1262 | if (pts != AV_NOPTS_VALUE) { |
| 1265 | if (s->user_specified_pts != AV_NOPTS_VALUE) { | 1263 | if (m->user_specified_pts != AV_NOPTS_VALUE) { |
| 1266 | int64_t last = s->user_specified_pts; | 1264 | int64_t last = m->user_specified_pts; |
| 1267 | | 1265 | |
| 1268 | if (pts <= last) { | 1266 | if (pts <= last) { |
| 1269 | av_log(s->avctx, AV_LOG_ERROR, | 1267 | av_log(s->avctx, AV_LOG_ERROR, |
| @@ -1273,13 +1271,13 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 3 unmodified lines |
| 1273 | } | 1271 | } |
| 1274 | | 1272 | |
| 1275 | if (!s->low_delay && display_picture_number == 1) | 1273 | if (!s->low_delay && display_picture_number == 1) |
| 1276 | s->dts_delta = pts - last; | 1274 | m->dts_delta = pts - last; |
| 1277 | } | 1275 | } |
| 1278 | s->user_specified_pts = pts; | 1276 | m->user_specified_pts = pts; |
| 1279 | } else { | 1277 | } else { |
| 1280 | if (s->user_specified_pts != AV_NOPTS_VALUE) { | 1278 | if (m->user_specified_pts != AV_NOPTS_VALUE) { |
| 1281 | s->user_specified_pts = | 1279 | m->user_specified_pts = |
| 1282 | pts = s->user_specified_pts + 1; | 1280 | pts = m->user_specified_pts + 1; |
| 1283 | av_log(s->avctx, AV_LOG_INFO, | 1281 | av_log(s->avctx, AV_LOG_INFO, |
| 1284 | "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", | 1282 | "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", |
| 1285 | pts); | 1283 | pts); |
| @@ -1612,7 +1610,7 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 326 unmodified lines |
| 1612 | | 1610 | |
| 1613 | /* set next picture type & ordering */ | 1611 | /* set next picture type & ordering */ |
| 1614 | if (m->frame_skip_threshold || m->frame_skip_factor) { | 1612 | if (m->frame_skip_threshold || m->frame_skip_factor) { |
| 1615 | if (s->picture_in_gop_number < s->gop_size && | 1613 | if (m->picture_in_gop_number < m->gop_size && |
| 1616 | s->next_pic.ptr && | 1614 | s->next_pic.ptr && |
| 1617 | skip_check(m, s->input_picture[0], s->next_pic.ptr)) { | 1615 | skip_check(m, s->input_picture[0], s->next_pic.ptr)) { |
| 1618 | // FIXME check that the gop check above is +-1 correct | 1616 | // FIXME check that the gop check above is +-1 correct |
| @@ -1624,13 +1622,13 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 5 unmodified lines |
| 1624 | } | 1622 | } |
| 1625 | } | 1623 | } |
| 1626 | | 1624 | |
| 1627 | if (/*s->picture_in_gop_number >= s->gop_size ||*/ | 1625 | if (/* m->picture_in_gop_number >= m->gop_size || */ |
| 1628 | !s->next_pic.ptr || s->intra_only) { | 1626 | !s->next_pic.ptr || m->intra_only) { |
| 1629 | s->reordered_input_picture[0] = s->input_picture[0]; | 1627 | s->reordered_input_picture[0] = s->input_picture[0]; |
| 1630 | s->input_picture[0] = NULL; | 1628 | s->input_picture[0] = NULL; |
| 1631 | s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; | 1629 | s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; |
| 1632 | s->reordered_input_picture[0]->coded_picture_number = | 1630 | s->reordered_input_picture[0]->coded_picture_number = |
| 1633 | s->coded_picture_number++; | 1631 | m->coded_picture_number++; |
| 1634 | } else { | 1632 | } else { |
| 1635 | int b_frames = 0; | 1633 | int b_frames = 0; |
| 1636 | | 1634 | |
| @@ -1700,10 +1698,10 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 63 unmodified lines |
| 1700 | "warning, too many B-frames in a row\n"); | 1698 | "warning, too many B-frames in a row\n"); |
| 1701 | } | 1699 | } |
| 1702 | | 1700 | |
| 1703 | if (s->picture_in_gop_number + b_frames >= s->gop_size) { | 1701 | if (m->picture_in_gop_number + b_frames >= m->gop_size) { |
| 1704 | if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && | 1702 | if ((s->mpv_flags & FF_MPV_FLAG_STRICT_GOP) && |
| 1705 | s->gop_size > s->picture_in_gop_number) { | 1703 | m->gop_size > m->picture_in_gop_number) { |
| 1706 | b_frames = s->gop_size - s->picture_in_gop_number - 1; | 1704 | b_frames = m->gop_size - m->picture_in_gop_number - 1; |
| 1707 | } else { | 1705 | } else { |
| 1708 | if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) | 1706 | if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) |
| 1709 | b_frames = 0; | 1707 | b_frames = 0; |
| @@ -1720,14 +1718,14 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 10 unmodified lines |
| 1720 | if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) | 1718 | if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) |
| 1721 | s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; | 1719 | s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; |
| 1722 | s->reordered_input_picture[0]->coded_picture_number = | 1720 | s->reordered_input_picture[0]->coded_picture_number = |
| 1723 | s->coded_picture_number++; | 1721 | m->coded_picture_number++; |
| 1724 | for (int i = 0; i < b_frames; i++) { | 1722 | for (int i = 0; i < b_frames; i++) { |
| 1725 | s->reordered_input_picture[i + 1] = s->input_picture[i]; | 1723 | s->reordered_input_picture[i + 1] = s->input_picture[i]; |
| 1726 | s->input_picture[i] = NULL; | 1724 | s->input_picture[i] = NULL; |
| 1727 | s->reordered_input_picture[i + 1]->f->pict_type = | 1725 | s->reordered_input_picture[i + 1]->f->pict_type = |
| 1728 | AV_PICTURE_TYPE_B; | 1726 | AV_PICTURE_TYPE_B; |
| 1729 | s->reordered_input_picture[i + 1]->coded_picture_number = | 1727 | s->reordered_input_picture[i + 1]->coded_picture_number = |
| 1730 | s->coded_picture_number++; | 1728 | m->coded_picture_number++; |
| 1731 | } | 1729 | } |
| 1732 | } | 1730 | } |
| 1733 | | 1731 | |
| @@ -1794,11 +1792,13 @@ fail: · 60 unmodified lines |
| 1794 | return ret; | 1792 | return ret; |
| 1795 | } | 1793 | } |
| 1796 | | 1794 | |
| 1797 | static void frame_end(MpegEncContext *s) | 1795 | static void frame_end(MPVMainEncContext *const m) |
| 1798 | { | 1796 | { |
| | 1797 | MpegEncContext *const s = &m->s; |
| | 1798 | |
| 1799 | if (s->unrestricted_mv && | 1799 | if (s->unrestricted_mv && |
| 1800 | s->cur_pic.reference && | 1800 | s->cur_pic.reference && |
| 1801 | !s->intra_only) { | 1801 | !m->intra_only) { |
| 1802 | int hshift = s->chroma_x_shift; | 1802 | int hshift = s->chroma_x_shift; |
| 1803 | int vshift = s->chroma_y_shift; | 1803 | int vshift = s->chroma_y_shift; |
| 1804 | s->mpvencdsp.draw_edges(s->cur_pic.data[0], | 1804 | s->mpvencdsp.draw_edges(s->cur_pic.data[0], |
| @@ -1878,7 +1878,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, · 73 unmodified lines |
| 1878 | | 1878 | |
| 1879 | s->vbv_ignore_qmax = 0; | 1879 | s->vbv_ignore_qmax = 0; |
| 1880 | | 1880 | |
| 1881 | s->picture_in_gop_number++; | 1881 | m->picture_in_gop_number++; |
| 1882 | | 1882 | |
| 1883 | ret = load_input_picture(m, pic_arg); | 1883 | ret = load_input_picture(m, pic_arg); |
| 1884 | if (ret < 0) | 1884 | if (ret < 0) |
| @@ -1923,7 +1923,7 @@ vbv_retry: · 38 unmodified lines |
| 1923 | if (ret < 0) | 1923 | if (ret < 0) |
| 1924 | return -1; | 1924 | return -1; |
| 1925 | | 1925 | |
| 1926 | frame_end(s); | 1926 | frame_end(m); |
| 1927 | | 1927 | |
| 1928 | if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) && s->out_format == FMT_MJPEG) | 1928 | if ((CONFIG_MJPEG_ENCODER || CONFIG_AMV_ENCODER) && s->out_format == FMT_MJPEG) |
| 1929 | ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); | 1929 | ff_mjpeg_encode_picture_trailer(&s->pb, s->header_bits); |
| @@ -2066,10 +2066,10 @@ vbv_retry: · 136 unmodified lines |
| 2066 | pkt->duration = s->cur_pic.ptr->f->duration; | 2066 | pkt->duration = s->cur_pic.ptr->f->duration; |
| 2067 | if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { | 2067 | if (!s->low_delay && s->pict_type != AV_PICTURE_TYPE_B) { |
| 2068 | if (!s->cur_pic.ptr->coded_picture_number) | 2068 | if (!s->cur_pic.ptr->coded_picture_number) |
| 2069 | pkt->dts = pkt->pts - s->dts_delta; | 2069 | pkt->dts = pkt->pts - m->dts_delta; |
| 2070 | else | 2070 | else |
| 2071 | pkt->dts = s->reordered_pts; | 2071 | pkt->dts = m->reordered_pts; |
| 2072 | s->reordered_pts = pkt->pts; | 2072 | m->reordered_pts = pkt->pts; |
| 2073 | } else | 2073 | } else |
| 2074 | pkt->dts = pkt->pts; | 2074 | pkt->dts = pkt->pts; |
| 2075 | | 2075 | |
| @@ -3882,7 +3882,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 1806 unmodified lines |
| 3882 | s->cur_pic.ptr->f->pict_type = s->pict_type; | 3882 | s->cur_pic.ptr->f->pict_type = s->pict_type; |
| 3883 | | 3883 | |
| 3884 | if (s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY) | 3884 | if (s->cur_pic.ptr->f->flags & AV_FRAME_FLAG_KEY) |
| 3885 | s->picture_in_gop_number=0; | 3885 | m->picture_in_gop_number = 0; |
| 3886 | | 3886 | |
| 3887 | s->mb_x = s->mb_y = 0; | 3887 | s->mb_x = s->mb_y = 0; |
| 3888 | s->last_bits= put_bits_count(&s->pb); | 3888 | s->last_bits= put_bits_count(&s->pb); |
| @@ -3925,7 +3925,7 @@ static int encode_picture(MPVMainEncContext *const m, const AVPacket *pkt) · 36 unmodified lines |
| 3925 | break; | 3925 | break; |
| 3926 | case FMT_MPEG1: | 3926 | case FMT_MPEG1: |
| 3927 | if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) | 3927 | if (CONFIG_MPEG1VIDEO_ENCODER || CONFIG_MPEG2VIDEO_ENCODER) |
| 3928 | ff_mpeg1_encode_picture_header(s); | 3928 | ff_mpeg1_encode_picture_header(m); |
| 3929 | break; | 3929 | break; |
| 3930 | default: | 3930 | default: |
| 3931 | av_assert0(0); | 3931 | av_assert0(0); |