• Home
  • Raw
  • Download

Lines Matching refs:s

54 static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,  in dct_unquantize_mpeg1_intra_c()  argument
60 nCoeffs= s->block_last_index[n]; in dct_unquantize_mpeg1_intra_c()
62 block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; in dct_unquantize_mpeg1_intra_c()
64 quant_matrix = s->intra_matrix; in dct_unquantize_mpeg1_intra_c()
66 int j= s->intra_scantable.permutated[i]; in dct_unquantize_mpeg1_intra_c()
83 static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, in dct_unquantize_mpeg1_inter_c() argument
89 nCoeffs= s->block_last_index[n]; in dct_unquantize_mpeg1_inter_c()
91 quant_matrix = s->inter_matrix; in dct_unquantize_mpeg1_inter_c()
93 int j= s->intra_scantable.permutated[i]; in dct_unquantize_mpeg1_inter_c()
112 static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, in dct_unquantize_mpeg2_intra_c() argument
118 if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; in dct_unquantize_mpeg2_intra_c()
121 if(s->alternate_scan) nCoeffs= 63; in dct_unquantize_mpeg2_intra_c()
122 else nCoeffs= s->block_last_index[n]; in dct_unquantize_mpeg2_intra_c()
124 block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; in dct_unquantize_mpeg2_intra_c()
125 quant_matrix = s->intra_matrix; in dct_unquantize_mpeg2_intra_c()
127 int j= s->intra_scantable.permutated[i]; in dct_unquantize_mpeg2_intra_c()
142 static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, in dct_unquantize_mpeg2_intra_bitexact() argument
149 if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; in dct_unquantize_mpeg2_intra_bitexact()
152 if(s->alternate_scan) nCoeffs= 63; in dct_unquantize_mpeg2_intra_bitexact()
153 else nCoeffs= s->block_last_index[n]; in dct_unquantize_mpeg2_intra_bitexact()
155 block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; in dct_unquantize_mpeg2_intra_bitexact()
157 quant_matrix = s->intra_matrix; in dct_unquantize_mpeg2_intra_bitexact()
159 int j= s->intra_scantable.permutated[i]; in dct_unquantize_mpeg2_intra_bitexact()
176 static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, in dct_unquantize_mpeg2_inter_c() argument
183 if (s->q_scale_type) qscale = ff_mpeg2_non_linear_qscale[qscale]; in dct_unquantize_mpeg2_inter_c()
186 if(s->alternate_scan) nCoeffs= 63; in dct_unquantize_mpeg2_inter_c()
187 else nCoeffs= s->block_last_index[n]; in dct_unquantize_mpeg2_inter_c()
189 quant_matrix = s->inter_matrix; in dct_unquantize_mpeg2_inter_c()
191 int j= s->intra_scantable.permutated[i]; in dct_unquantize_mpeg2_inter_c()
210 static void dct_unquantize_h263_intra_c(MpegEncContext *s, in dct_unquantize_h263_intra_c() argument
216 av_assert2(s->block_last_index[n]>=0 || s->h263_aic); in dct_unquantize_h263_intra_c()
220 if (!s->h263_aic) { in dct_unquantize_h263_intra_c()
221 block[0] *= n < 4 ? s->y_dc_scale : s->c_dc_scale; in dct_unquantize_h263_intra_c()
226 if(s->ac_pred) in dct_unquantize_h263_intra_c()
229 nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]; in dct_unquantize_h263_intra_c()
244 static void dct_unquantize_h263_inter_c(MpegEncContext *s, in dct_unquantize_h263_inter_c() argument
250 av_assert2(s->block_last_index[n]>=0); in dct_unquantize_h263_inter_c()
255 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; in dct_unquantize_h263_inter_c()
284 static av_cold int dct_init(MpegEncContext *s) in dct_init() argument
286 ff_blockdsp_init(&s->bdsp, s->avctx); in dct_init()
287 ff_h264chroma_init(&s->h264chroma, 8); //for lowres in dct_init()
288 ff_hpeldsp_init(&s->hdsp, s->avctx->flags); in dct_init()
289 ff_mpegvideodsp_init(&s->mdsp); in dct_init()
290 ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample); in dct_init()
292 if (s->avctx->debug & FF_DEBUG_NOMC) { in dct_init()
295 s->hdsp.avg_pixels_tab[0][i] = gray16; in dct_init()
296 s->hdsp.put_pixels_tab[0][i] = gray16; in dct_init()
297 s->hdsp.put_no_rnd_pixels_tab[0][i] = gray16; in dct_init()
299 s->hdsp.avg_pixels_tab[1][i] = gray8; in dct_init()
300 s->hdsp.put_pixels_tab[1][i] = gray8; in dct_init()
301 s->hdsp.put_no_rnd_pixels_tab[1][i] = gray8; in dct_init()
305 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; in dct_init()
306 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; in dct_init()
307 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; in dct_init()
308 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; in dct_init()
309 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; in dct_init()
310 if (s->avctx->flags & AV_CODEC_FLAG_BITEXACT) in dct_init()
311 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; in dct_init()
312 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; in dct_init()
315 ff_mpv_common_init_neon(s); in dct_init()
318 ff_mpv_common_init_axp(s); in dct_init()
320 ff_mpv_common_init_arm(s); in dct_init()
322 ff_mpv_common_init_ppc(s); in dct_init()
324 ff_mpv_common_init_x86(s); in dct_init()
326 ff_mpv_common_init_mips(s); in dct_init()
331 av_cold void ff_mpv_idct_init(MpegEncContext *s) in ff_mpv_idct_init() argument
333 if (s->codec_id == AV_CODEC_ID_MPEG4) in ff_mpv_idct_init()
334 s->idsp.mpeg4_studio_profile = s->studio_profile; in ff_mpv_idct_init()
335 ff_idctdsp_init(&s->idsp, s->avctx); in ff_mpv_idct_init()
340 if (s->alternate_scan) { in ff_mpv_idct_init()
341 … ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan); in ff_mpv_idct_init()
342 … ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan); in ff_mpv_idct_init()
344 ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct); in ff_mpv_idct_init()
345 ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct); in ff_mpv_idct_init()
347 … ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); in ff_mpv_idct_init()
348 ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); in ff_mpv_idct_init()
351 static int alloc_picture(MpegEncContext *s, Picture *pic) in alloc_picture() argument
353 return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, 0, in alloc_picture()
354 s->chroma_x_shift, s->chroma_y_shift, s->out_format, in alloc_picture()
355 s->mb_stride, s->mb_width, s->mb_height, s->b8_stride, in alloc_picture()
356 &s->linesize, &s->uvlinesize); in alloc_picture()
359 static int init_duplicate_context(MpegEncContext *s) in init_duplicate_context() argument
361 int y_size = s->b8_stride * (2 * s->mb_height + 1); in init_duplicate_context()
362 int c_size = s->mb_stride * (s->mb_height + 1); in init_duplicate_context()
366 if (s->mb_height & 1) in init_duplicate_context()
367 yc_size += 2*s->b8_stride + 2*s->mb_stride; in init_duplicate_context()
369 if (s->encoding) { in init_duplicate_context()
370 if (!FF_ALLOCZ_TYPED_ARRAY(s->me.map, ME_MAP_SIZE) || in init_duplicate_context()
371 !FF_ALLOCZ_TYPED_ARRAY(s->me.score_map, ME_MAP_SIZE)) in init_duplicate_context()
374 if (s->noise_reduction) { in init_duplicate_context()
375 if (!FF_ALLOCZ_TYPED_ARRAY(s->dct_error_sum, 2)) in init_duplicate_context()
379 if (!FF_ALLOCZ_TYPED_ARRAY(s->blocks, 2)) in init_duplicate_context()
381 s->block = s->blocks[0]; in init_duplicate_context()
384 s->pblocks[i] = &s->block[i]; in init_duplicate_context()
387 if (!(s->block32 = av_mallocz(sizeof(*s->block32))) || in init_duplicate_context()
388 !(s->dpcm_macroblock = av_mallocz(sizeof(*s->dpcm_macroblock)))) in init_duplicate_context()
390 s->dpcm_direction = 0; in init_duplicate_context()
392 if (s->avctx->codec_tag == AV_RL32("VCR2")) { in init_duplicate_context()
394 FFSWAP(void *, s->pblocks[4], s->pblocks[5]); in init_duplicate_context()
397 if (s->out_format == FMT_H263) { in init_duplicate_context()
399 if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size)) in init_duplicate_context()
401 s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; in init_duplicate_context()
402 s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; in init_duplicate_context()
403 s->ac_val[2] = s->ac_val[1] + c_size; in init_duplicate_context()
414 static int init_duplicate_contexts(MpegEncContext *s) in init_duplicate_contexts() argument
416 int nb_slices = s->slice_context_count, ret; in init_duplicate_contexts()
422 s->thread_context[i] = av_memdup(s, sizeof(MpegEncContext)); in init_duplicate_contexts()
423 if (!s->thread_context[i]) in init_duplicate_contexts()
425 if ((ret = init_duplicate_context(s->thread_context[i])) < 0) in init_duplicate_contexts()
427 s->thread_context[i]->start_mb_y = in init_duplicate_contexts()
428 (s->mb_height * (i ) + nb_slices / 2) / nb_slices; in init_duplicate_contexts()
429 s->thread_context[i]->end_mb_y = in init_duplicate_contexts()
430 (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; in init_duplicate_contexts()
432 s->start_mb_y = 0; in init_duplicate_contexts()
433 s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices in init_duplicate_contexts()
434 : s->mb_height; in init_duplicate_contexts()
435 return init_duplicate_context(s); in init_duplicate_contexts()
438 static void free_duplicate_context(MpegEncContext *s) in free_duplicate_context() argument
440 if (!s) in free_duplicate_context()
443 av_freep(&s->sc.edge_emu_buffer); in free_duplicate_context()
444 av_freep(&s->me.scratchpad); in free_duplicate_context()
445 s->me.temp = in free_duplicate_context()
446 s->sc.rd_scratchpad = in free_duplicate_context()
447 s->sc.b_scratchpad = in free_duplicate_context()
448 s->sc.obmc_scratchpad = NULL; in free_duplicate_context()
450 av_freep(&s->dct_error_sum); in free_duplicate_context()
451 av_freep(&s->me.map); in free_duplicate_context()
452 av_freep(&s->me.score_map); in free_duplicate_context()
453 av_freep(&s->blocks); in free_duplicate_context()
454 av_freep(&s->block32); in free_duplicate_context()
455 av_freep(&s->dpcm_macroblock); in free_duplicate_context()
456 av_freep(&s->ac_val_base); in free_duplicate_context()
457 s->block = NULL; in free_duplicate_context()
460 static void free_duplicate_contexts(MpegEncContext *s) in free_duplicate_contexts() argument
462 for (int i = 1; i < s->slice_context_count; i++) { in free_duplicate_contexts()
463 free_duplicate_context(s->thread_context[i]); in free_duplicate_contexts()
464 av_freep(&s->thread_context[i]); in free_duplicate_contexts()
466 free_duplicate_context(s); in free_duplicate_contexts()
528 MpegEncContext *s = dst->priv_data, *s1 = src->priv_data; in ff_mpeg_update_thread_context() local
533 av_assert0(s != s1); in ff_mpeg_update_thread_context()
537 if (!s->context_initialized) { in ff_mpeg_update_thread_context()
539 memcpy(s, s1, sizeof(MpegEncContext)); in ff_mpeg_update_thread_context()
541 s->avctx = dst; in ff_mpeg_update_thread_context()
542 s->bitstream_buffer = NULL; in ff_mpeg_update_thread_context()
543 s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; in ff_mpeg_update_thread_context()
548 ff_mpv_idct_init(s); in ff_mpeg_update_thread_context()
549 if((err = ff_mpv_common_init(s)) < 0){ in ff_mpeg_update_thread_context()
550 memset(s, 0, sizeof(MpegEncContext)); in ff_mpeg_update_thread_context()
551 s->avctx = dst; in ff_mpeg_update_thread_context()
557 if (s->height != s1->height || s->width != s1->width || s->context_reinit) { in ff_mpeg_update_thread_context()
558 s->height = s1->height; in ff_mpeg_update_thread_context()
559 s->width = s1->width; in ff_mpeg_update_thread_context()
560 if ((ret = ff_mpv_common_frame_size_change(s)) < 0) in ff_mpeg_update_thread_context()
564 s->avctx->coded_height = s1->avctx->coded_height; in ff_mpeg_update_thread_context()
565 s->avctx->coded_width = s1->avctx->coded_width; in ff_mpeg_update_thread_context()
566 s->avctx->width = s1->avctx->width; in ff_mpeg_update_thread_context()
567 s->avctx->height = s1->avctx->height; in ff_mpeg_update_thread_context()
569 s->quarter_sample = s1->quarter_sample; in ff_mpeg_update_thread_context()
571 s->coded_picture_number = s1->coded_picture_number; in ff_mpeg_update_thread_context()
572 s->picture_number = s1->picture_number; in ff_mpeg_update_thread_context()
574 av_assert0(!s->picture || s->picture != s1->picture); in ff_mpeg_update_thread_context()
575 if(s->picture) in ff_mpeg_update_thread_context()
577 ff_mpeg_unref_picture(s->avctx, &s->picture[i]); in ff_mpeg_update_thread_context()
579 (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0) in ff_mpeg_update_thread_context()
585 ff_mpeg_unref_picture(s->avctx, &s->pic);\ in ff_mpeg_update_thread_context()
587 ret = ff_mpeg_ref_picture(s->avctx, &s->pic, &s1->pic);\ in ff_mpeg_update_thread_context()
589 ret = ff_update_picture_tables(&s->pic, &s1->pic);\ in ff_mpeg_update_thread_context()
603 s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1); in ff_mpeg_update_thread_context()
604 s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1); in ff_mpeg_update_thread_context()
605 s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1); in ff_mpeg_update_thread_context()
608 s->next_p_frame_damaged = s1->next_p_frame_damaged; in ff_mpeg_update_thread_context()
609 s->workaround_bugs = s1->workaround_bugs; in ff_mpeg_update_thread_context()
610 s->padding_bug_score = s1->padding_bug_score; in ff_mpeg_update_thread_context()
613 memcpy(&s->last_time_base, &s1->last_time_base, in ff_mpeg_update_thread_context()
618 s->max_b_frames = s1->max_b_frames; in ff_mpeg_update_thread_context()
619 s->low_delay = s1->low_delay; in ff_mpeg_update_thread_context()
620 s->droppable = s1->droppable; in ff_mpeg_update_thread_context()
623 s->divx_packed = s1->divx_packed; in ff_mpeg_update_thread_context()
627 AV_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) { in ff_mpeg_update_thread_context()
628 av_fast_malloc(&s->bitstream_buffer, in ff_mpeg_update_thread_context()
629 &s->allocated_bitstream_buffer_size, in ff_mpeg_update_thread_context()
631 if (!s->bitstream_buffer) { in ff_mpeg_update_thread_context()
632 s->bitstream_buffer_size = 0; in ff_mpeg_update_thread_context()
636 s->bitstream_buffer_size = s1->bitstream_buffer_size; in ff_mpeg_update_thread_context()
637 memcpy(s->bitstream_buffer, s1->bitstream_buffer, in ff_mpeg_update_thread_context()
639 memset(s->bitstream_buffer + s->bitstream_buffer_size, 0, in ff_mpeg_update_thread_context()
644 if (!s->sc.edge_emu_buffer) in ff_mpeg_update_thread_context()
646 if (ff_mpeg_framesize_alloc(s->avctx, &s->me, in ff_mpeg_update_thread_context()
647 &s->sc, s1->linesize) < 0) { in ff_mpeg_update_thread_context()
648 av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context " in ff_mpeg_update_thread_context()
653 av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not " in ff_mpeg_update_thread_context()
658 memcpy(&s->progressive_sequence, &s1->progressive_sequence, in ff_mpeg_update_thread_context()
662 s->last_pict_type = s1->pict_type; in ff_mpeg_update_thread_context()
664 s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f->quality; in ff_mpeg_update_thread_context()
676 void ff_mpv_common_defaults(MpegEncContext *s) in ff_mpv_common_defaults() argument
678 s->y_dc_scale_table = in ff_mpv_common_defaults()
679 s->c_dc_scale_table = ff_mpeg1_dc_scale_table; in ff_mpv_common_defaults()
680 s->chroma_qscale_table = ff_default_chroma_qscale_table; in ff_mpv_common_defaults()
681 s->progressive_frame = 1; in ff_mpv_common_defaults()
682 s->progressive_sequence = 1; in ff_mpv_common_defaults()
683 s->picture_structure = PICT_FRAME; in ff_mpv_common_defaults()
685 s->coded_picture_number = 0; in ff_mpv_common_defaults()
686 s->picture_number = 0; in ff_mpv_common_defaults()
688 s->f_code = 1; in ff_mpv_common_defaults()
689 s->b_code = 1; in ff_mpv_common_defaults()
691 s->slice_context_count = 1; in ff_mpv_common_defaults()
699 void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) in ff_mpv_decode_init() argument
701 ff_mpv_common_defaults(s); in ff_mpv_decode_init()
703 s->avctx = avctx; in ff_mpv_decode_init()
704 s->width = avctx->coded_width; in ff_mpv_decode_init()
705 s->height = avctx->coded_height; in ff_mpv_decode_init()
706 s->codec_id = avctx->codec->id; in ff_mpv_decode_init()
707 s->workaround_bugs = avctx->workaround_bugs; in ff_mpv_decode_init()
710 s->codec_tag = avpriv_toupper4(avctx->codec_tag); in ff_mpv_decode_init()
716 static int init_context_frame(MpegEncContext *s) in init_context_frame() argument
720 s->mb_width = (s->width + 15) / 16; in init_context_frame()
721 s->mb_stride = s->mb_width + 1; in init_context_frame()
722 s->b8_stride = s->mb_width * 2 + 1; in init_context_frame()
723 mb_array_size = s->mb_height * s->mb_stride; in init_context_frame()
724 mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; in init_context_frame()
728 s->h_edge_pos = s->mb_width * 16; in init_context_frame()
729 s->v_edge_pos = s->mb_height * 16; in init_context_frame()
731 s->mb_num = s->mb_width * s->mb_height; in init_context_frame()
733 s->block_wrap[0] = in init_context_frame()
734 s->block_wrap[1] = in init_context_frame()
735 s->block_wrap[2] = in init_context_frame()
736 s->block_wrap[3] = s->b8_stride; in init_context_frame()
737 s->block_wrap[4] = in init_context_frame()
738 s->block_wrap[5] = s->mb_stride; in init_context_frame()
740 y_size = s->b8_stride * (2 * s->mb_height + 1); in init_context_frame()
741 c_size = s->mb_stride * (s->mb_height + 1); in init_context_frame()
744 if (s->mb_height & 1) in init_context_frame()
745 yc_size += 2*s->b8_stride + 2*s->mb_stride; in init_context_frame()
747 if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_index2xy, s->mb_num + 1)) in init_context_frame()
749 for (y = 0; y < s->mb_height; y++) in init_context_frame()
750 for (x = 0; x < s->mb_width; x++) in init_context_frame()
751 s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride; in init_context_frame()
753s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // F… in init_context_frame()
755 if (s->encoding) { in init_context_frame()
757 if (!FF_ALLOCZ_TYPED_ARRAY(s->p_mv_table_base, mv_table_size) || in init_context_frame()
758 !FF_ALLOCZ_TYPED_ARRAY(s->b_forw_mv_table_base, mv_table_size) || in init_context_frame()
759 !FF_ALLOCZ_TYPED_ARRAY(s->b_back_mv_table_base, mv_table_size) || in init_context_frame()
760 !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_forw_mv_table_base, mv_table_size) || in init_context_frame()
761 !FF_ALLOCZ_TYPED_ARRAY(s->b_bidir_back_mv_table_base, mv_table_size) || in init_context_frame()
762 !FF_ALLOCZ_TYPED_ARRAY(s->b_direct_mv_table_base, mv_table_size)) in init_context_frame()
764 s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; in init_context_frame()
765 s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; in init_context_frame()
766 s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; in init_context_frame()
767 s->b_bidir_forw_mv_table = s->b_bidir_forw_mv_table_base + s->mb_stride + 1; in init_context_frame()
768 s->b_bidir_back_mv_table = s->b_bidir_back_mv_table_base + s->mb_stride + 1; in init_context_frame()
769 s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; in init_context_frame()
772 if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_type, mb_array_size) || in init_context_frame()
773 !FF_ALLOCZ_TYPED_ARRAY(s->lambda_table, mb_array_size) || in init_context_frame()
774 !FF_ALLOC_TYPED_ARRAY (s->cplx_tab, mb_array_size) || in init_context_frame()
775 !FF_ALLOC_TYPED_ARRAY (s->bits_tab, mb_array_size)) in init_context_frame()
779 if (s->codec_id == AV_CODEC_ID_MPEG4 || in init_context_frame()
780 (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) { in init_context_frame()
786 if (!FF_ALLOCZ_TYPED_ARRAY(s->b_field_mv_table_base[i][j][k], mv_table_size)) in init_context_frame()
788 s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + in init_context_frame()
789 s->mb_stride + 1; in init_context_frame()
791 if (!FF_ALLOCZ_TYPED_ARRAY(s->b_field_select_table [i][j], mv_table_size * 2) || in init_context_frame()
792 !FF_ALLOCZ_TYPED_ARRAY(s->p_field_mv_table_base[i][j], mv_table_size)) in init_context_frame()
794 s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; in init_context_frame()
796 if (!FF_ALLOCZ_TYPED_ARRAY(s->p_field_select_table[i], mv_table_size * 2)) in init_context_frame()
800 if (s->out_format == FMT_H263) { in init_context_frame()
802 if (!FF_ALLOCZ_TYPED_ARRAY(s->coded_block_base, y_size + (s->mb_height&1)*2*s->b8_stride) || in init_context_frame()
803 !FF_ALLOCZ_TYPED_ARRAY(s->cbp_table, mb_array_size) || in init_context_frame()
804 !FF_ALLOCZ_TYPED_ARRAY(s->pred_dir_table, mb_array_size)) in init_context_frame()
806 s->coded_block = s->coded_block_base + s->b8_stride + 1; in init_context_frame()
809 if (s->h263_pred || s->h263_plus || !s->encoding) { in init_context_frame()
812 if (!FF_ALLOCZ_TYPED_ARRAY(s->dc_val_base, yc_size)) in init_context_frame()
814 s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; in init_context_frame()
815 s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; in init_context_frame()
816 s->dc_val[2] = s->dc_val[1] + c_size; in init_context_frame()
818 s->dc_val_base[i] = 1024; in init_context_frame()
822 if (!FF_ALLOC_TYPED_ARRAY(s->mbintra_table, mb_array_size) || in init_context_frame()
824 !FF_ALLOCZ_TYPED_ARRAY(s->mbskip_table, mb_array_size + 2)) in init_context_frame()
826 memset(s->mbintra_table, 1, mb_array_size); in init_context_frame()
828 return ff_mpeg_er_init(s); in init_context_frame()
831 static void clear_context(MpegEncContext *s) in clear_context() argument
835 memset(&s->next_picture, 0, sizeof(s->next_picture)); in clear_context()
836 memset(&s->last_picture, 0, sizeof(s->last_picture)); in clear_context()
837 memset(&s->current_picture, 0, sizeof(s->current_picture)); in clear_context()
838 memset(&s->new_picture, 0, sizeof(s->new_picture)); in clear_context()
840 memset(s->thread_context, 0, sizeof(s->thread_context)); in clear_context()
842 s->me.map = NULL; in clear_context()
843 s->me.score_map = NULL; in clear_context()
844 s->dct_error_sum = NULL; in clear_context()
845 s->block = NULL; in clear_context()
846 s->blocks = NULL; in clear_context()
847 s->block32 = NULL; in clear_context()
848 memset(s->pblocks, 0, sizeof(s->pblocks)); in clear_context()
849 s->dpcm_direction = 0; in clear_context()
850 s->dpcm_macroblock = NULL; in clear_context()
851 s->ac_val_base = NULL; in clear_context()
852 s->ac_val[0] = in clear_context()
853 s->ac_val[1] = in clear_context()
854 s->ac_val[2] =NULL; in clear_context()
855 s->sc.edge_emu_buffer = NULL; in clear_context()
856 s->me.scratchpad = NULL; in clear_context()
857 s->me.temp = in clear_context()
858 s->sc.rd_scratchpad = in clear_context()
859 s->sc.b_scratchpad = in clear_context()
860 s->sc.obmc_scratchpad = NULL; in clear_context()
863 s->bitstream_buffer = NULL; in clear_context()
864 s->allocated_bitstream_buffer_size = 0; in clear_context()
865 s->picture = NULL; in clear_context()
866 s->mb_type = NULL; in clear_context()
867 s->p_mv_table_base = NULL; in clear_context()
868 s->b_forw_mv_table_base = NULL; in clear_context()
869 s->b_back_mv_table_base = NULL; in clear_context()
870 s->b_bidir_forw_mv_table_base = NULL; in clear_context()
871 s->b_bidir_back_mv_table_base = NULL; in clear_context()
872 s->b_direct_mv_table_base = NULL; in clear_context()
873 s->p_mv_table = NULL; in clear_context()
874 s->b_forw_mv_table = NULL; in clear_context()
875 s->b_back_mv_table = NULL; in clear_context()
876 s->b_bidir_forw_mv_table = NULL; in clear_context()
877 s->b_bidir_back_mv_table = NULL; in clear_context()
878 s->b_direct_mv_table = NULL; in clear_context()
882 s->b_field_mv_table_base[i][j][k] = NULL; in clear_context()
883 s->b_field_mv_table[i][j][k] = NULL; in clear_context()
885 s->b_field_select_table[i][j] = NULL; in clear_context()
886 s->p_field_mv_table_base[i][j] = NULL; in clear_context()
887 s->p_field_mv_table[i][j] = NULL; in clear_context()
889 s->p_field_select_table[i] = NULL; in clear_context()
892 s->dc_val_base = NULL; in clear_context()
893 s->coded_block_base = NULL; in clear_context()
894 s->mbintra_table = NULL; in clear_context()
895 s->cbp_table = NULL; in clear_context()
896 s->pred_dir_table = NULL; in clear_context()
898 s->mbskip_table = NULL; in clear_context()
900 s->er.error_status_table = NULL; in clear_context()
901 s->er.er_temp_buffer = NULL; in clear_context()
902 s->mb_index2xy = NULL; in clear_context()
903 s->lambda_table = NULL; in clear_context()
905 s->cplx_tab = NULL; in clear_context()
906 s->bits_tab = NULL; in clear_context()
913 av_cold int ff_mpv_common_init(MpegEncContext *s) in ff_mpv_common_init() argument
917 s->avctx->active_thread_type & FF_THREAD_SLICE) ? in ff_mpv_common_init()
918 s->avctx->thread_count : 1; in ff_mpv_common_init()
920 clear_context(s); in ff_mpv_common_init()
922 if (s->encoding && s->avctx->slices) in ff_mpv_common_init()
923 nb_slices = s->avctx->slices; in ff_mpv_common_init()
925 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) in ff_mpv_common_init()
926 s->mb_height = (s->height + 31) / 32 * 2; in ff_mpv_common_init()
928 s->mb_height = (s->height + 15) / 16; in ff_mpv_common_init()
930 if (s->avctx->pix_fmt == AV_PIX_FMT_NONE) { in ff_mpv_common_init()
931 av_log(s->avctx, AV_LOG_ERROR, in ff_mpv_common_init()
936 if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) { in ff_mpv_common_init()
938 if (s->mb_height) in ff_mpv_common_init()
939 max_slices = FFMIN(MAX_THREADS, s->mb_height); in ff_mpv_common_init()
942 av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d)," in ff_mpv_common_init()
947 if ((s->width || s->height) && in ff_mpv_common_init()
948 av_image_check_size(s->width, s->height, 0, s->avctx)) in ff_mpv_common_init()
951 dct_init(s); in ff_mpv_common_init()
954 ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, in ff_mpv_common_init()
955 &s->chroma_x_shift, in ff_mpv_common_init()
956 &s->chroma_y_shift); in ff_mpv_common_init()
960 if (!FF_ALLOCZ_TYPED_ARRAY(s->picture, MAX_PICTURE_COUNT)) in ff_mpv_common_init()
963 s->picture[i].f = av_frame_alloc(); in ff_mpv_common_init()
964 if (!s->picture[i].f) in ff_mpv_common_init()
968 if (!(s->next_picture.f = av_frame_alloc()) || in ff_mpv_common_init()
969 !(s->last_picture.f = av_frame_alloc()) || in ff_mpv_common_init()
970 !(s->current_picture.f = av_frame_alloc()) || in ff_mpv_common_init()
971 !(s->new_picture.f = av_frame_alloc())) in ff_mpv_common_init()
974 if ((ret = init_context_frame(s))) in ff_mpv_common_init()
977 s->parse_context.state = -1; in ff_mpv_common_init()
979 s->context_initialized = 1; in ff_mpv_common_init()
980 memset(s->thread_context, 0, sizeof(s->thread_context)); in ff_mpv_common_init()
981 s->thread_context[0] = s; in ff_mpv_common_init()
982 s->slice_context_count = nb_slices; in ff_mpv_common_init()
985 ret = init_duplicate_contexts(s); in ff_mpv_common_init()
994 ff_mpv_common_end(s); in ff_mpv_common_init()
1004 static void free_context_frame(MpegEncContext *s) in free_context_frame() argument
1008 free_duplicate_contexts(s); in free_context_frame()
1010 av_freep(&s->mb_type); in free_context_frame()
1011 av_freep(&s->p_mv_table_base); in free_context_frame()
1012 av_freep(&s->b_forw_mv_table_base); in free_context_frame()
1013 av_freep(&s->b_back_mv_table_base); in free_context_frame()
1014 av_freep(&s->b_bidir_forw_mv_table_base); in free_context_frame()
1015 av_freep(&s->b_bidir_back_mv_table_base); in free_context_frame()
1016 av_freep(&s->b_direct_mv_table_base); in free_context_frame()
1017 s->p_mv_table = NULL; in free_context_frame()
1018 s->b_forw_mv_table = NULL; in free_context_frame()
1019 s->b_back_mv_table = NULL; in free_context_frame()
1020 s->b_bidir_forw_mv_table = NULL; in free_context_frame()
1021 s->b_bidir_back_mv_table = NULL; in free_context_frame()
1022 s->b_direct_mv_table = NULL; in free_context_frame()
1026 av_freep(&s->b_field_mv_table_base[i][j][k]); in free_context_frame()
1027 s->b_field_mv_table[i][j][k] = NULL; in free_context_frame()
1029 av_freep(&s->b_field_select_table[i][j]); in free_context_frame()
1030 av_freep(&s->p_field_mv_table_base[i][j]); in free_context_frame()
1031 s->p_field_mv_table[i][j] = NULL; in free_context_frame()
1033 av_freep(&s->p_field_select_table[i]); in free_context_frame()
1036 av_freep(&s->dc_val_base); in free_context_frame()
1037 av_freep(&s->coded_block_base); in free_context_frame()
1038 av_freep(&s->mbintra_table); in free_context_frame()
1039 av_freep(&s->cbp_table); in free_context_frame()
1040 av_freep(&s->pred_dir_table); in free_context_frame()
1042 av_freep(&s->mbskip_table); in free_context_frame()
1044 av_freep(&s->er.error_status_table); in free_context_frame()
1045 av_freep(&s->er.er_temp_buffer); in free_context_frame()
1046 av_freep(&s->mb_index2xy); in free_context_frame()
1047 av_freep(&s->lambda_table); in free_context_frame()
1049 av_freep(&s->cplx_tab); in free_context_frame()
1050 av_freep(&s->bits_tab); in free_context_frame()
1052 s->linesize = s->uvlinesize = 0; in free_context_frame()
1055 int ff_mpv_common_frame_size_change(MpegEncContext *s) in ff_mpv_common_frame_size_change() argument
1059 if (!s->context_initialized) in ff_mpv_common_frame_size_change()
1062 free_context_frame(s); in ff_mpv_common_frame_size_change()
1064 if (s->picture) in ff_mpv_common_frame_size_change()
1066 s->picture[i].needs_realloc = 1; in ff_mpv_common_frame_size_change()
1069 s->last_picture_ptr = in ff_mpv_common_frame_size_change()
1070 s->next_picture_ptr = in ff_mpv_common_frame_size_change()
1071 s->current_picture_ptr = NULL; in ff_mpv_common_frame_size_change()
1074 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) in ff_mpv_common_frame_size_change()
1075 s->mb_height = (s->height + 31) / 32 * 2; in ff_mpv_common_frame_size_change()
1077 s->mb_height = (s->height + 15) / 16; in ff_mpv_common_frame_size_change()
1079 if ((s->width || s->height) && in ff_mpv_common_frame_size_change()
1080 (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) in ff_mpv_common_frame_size_change()
1084 err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, in ff_mpv_common_frame_size_change()
1085 &s->chroma_x_shift, in ff_mpv_common_frame_size_change()
1086 &s->chroma_y_shift); in ff_mpv_common_frame_size_change()
1090 if ((err = init_context_frame(s))) in ff_mpv_common_frame_size_change()
1093 memset(s->thread_context, 0, sizeof(s->thread_context)); in ff_mpv_common_frame_size_change()
1094 s->thread_context[0] = s; in ff_mpv_common_frame_size_change()
1096 if (s->width && s->height) { in ff_mpv_common_frame_size_change()
1097 err = init_duplicate_contexts(s); in ff_mpv_common_frame_size_change()
1101 s->context_reinit = 0; in ff_mpv_common_frame_size_change()
1105 free_context_frame(s); in ff_mpv_common_frame_size_change()
1106 s->context_reinit = 1; in ff_mpv_common_frame_size_change()
1111 void ff_mpv_common_end(MpegEncContext *s) in ff_mpv_common_end() argument
1115 if (!s) in ff_mpv_common_end()
1118 free_context_frame(s); in ff_mpv_common_end()
1119 if (s->slice_context_count > 1) in ff_mpv_common_end()
1120 s->slice_context_count = 1; in ff_mpv_common_end()
1122 av_freep(&s->parse_context.buffer); in ff_mpv_common_end()
1123 s->parse_context.buffer_size = 0; in ff_mpv_common_end()
1125 av_freep(&s->bitstream_buffer); in ff_mpv_common_end()
1126 s->allocated_bitstream_buffer_size = 0; in ff_mpv_common_end()
1128 if (!s->avctx) in ff_mpv_common_end()
1131 if (s->picture) { in ff_mpv_common_end()
1133 ff_free_picture_tables(&s->picture[i]); in ff_mpv_common_end()
1134 ff_mpeg_unref_picture(s->avctx, &s->picture[i]); in ff_mpv_common_end()
1135 av_frame_free(&s->picture[i].f); in ff_mpv_common_end()
1138 av_freep(&s->picture); in ff_mpv_common_end()
1139 ff_free_picture_tables(&s->last_picture); in ff_mpv_common_end()
1140 ff_mpeg_unref_picture(s->avctx, &s->last_picture); in ff_mpv_common_end()
1141 av_frame_free(&s->last_picture.f); in ff_mpv_common_end()
1142 ff_free_picture_tables(&s->current_picture); in ff_mpv_common_end()
1143 ff_mpeg_unref_picture(s->avctx, &s->current_picture); in ff_mpv_common_end()
1144 av_frame_free(&s->current_picture.f); in ff_mpv_common_end()
1145 ff_free_picture_tables(&s->next_picture); in ff_mpv_common_end()
1146 ff_mpeg_unref_picture(s->avctx, &s->next_picture); in ff_mpv_common_end()
1147 av_frame_free(&s->next_picture.f); in ff_mpv_common_end()
1148 ff_free_picture_tables(&s->new_picture); in ff_mpv_common_end()
1149 ff_mpeg_unref_picture(s->avctx, &s->new_picture); in ff_mpv_common_end()
1150 av_frame_free(&s->new_picture.f); in ff_mpv_common_end()
1152 s->context_initialized = 0; in ff_mpv_common_end()
1153 s->context_reinit = 0; in ff_mpv_common_end()
1154 s->last_picture_ptr = in ff_mpv_common_end()
1155 s->next_picture_ptr = in ff_mpv_common_end()
1156 s->current_picture_ptr = NULL; in ff_mpv_common_end()
1157 s->linesize = s->uvlinesize = 0; in ff_mpv_common_end()
1181 int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) in ff_mpv_frame_start() argument
1185 s->mb_skipped = 0; in ff_mpv_frame_start()
1193 if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && in ff_mpv_frame_start()
1194 s->last_picture_ptr != s->next_picture_ptr && in ff_mpv_frame_start()
1195 s->last_picture_ptr->f->buf[0]) { in ff_mpv_frame_start()
1196 ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr); in ff_mpv_frame_start()
1202 if (&s->picture[i] != s->last_picture_ptr && in ff_mpv_frame_start()
1203 &s->picture[i] != s->next_picture_ptr && in ff_mpv_frame_start()
1204 s->picture[i].reference && !s->picture[i].needs_realloc) { in ff_mpv_frame_start()
1205 ff_mpeg_unref_picture(s->avctx, &s->picture[i]); in ff_mpv_frame_start()
1209 ff_mpeg_unref_picture(s->avctx, &s->current_picture); in ff_mpv_frame_start()
1210 ff_mpeg_unref_picture(s->avctx, &s->last_picture); in ff_mpv_frame_start()
1211 ff_mpeg_unref_picture(s->avctx, &s->next_picture); in ff_mpv_frame_start()
1215 if (!s->picture[i].reference) in ff_mpv_frame_start()
1216 ff_mpeg_unref_picture(s->avctx, &s->picture[i]); in ff_mpv_frame_start()
1219 if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) { in ff_mpv_frame_start()
1222 pic = s->current_picture_ptr; in ff_mpv_frame_start()
1224 i = ff_find_unused_picture(s->avctx, s->picture, 0); in ff_mpv_frame_start()
1226 av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); in ff_mpv_frame_start()
1229 pic = &s->picture[i]; in ff_mpv_frame_start()
1233 if (!s->droppable) { in ff_mpv_frame_start()
1234 if (s->pict_type != AV_PICTURE_TYPE_B) in ff_mpv_frame_start()
1238 pic->f->coded_picture_number = s->coded_picture_number++; in ff_mpv_frame_start()
1240 if (alloc_picture(s, pic) < 0) in ff_mpv_frame_start()
1243 s->current_picture_ptr = pic; in ff_mpv_frame_start()
1245 s->current_picture_ptr->f->top_field_first = s->top_field_first; in ff_mpv_frame_start()
1246 if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO || in ff_mpv_frame_start()
1247 s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { in ff_mpv_frame_start()
1248 if (s->picture_structure != PICT_FRAME) in ff_mpv_frame_start()
1249 s->current_picture_ptr->f->top_field_first = in ff_mpv_frame_start()
1250 (s->picture_structure == PICT_TOP_FIELD) == s->first_field; in ff_mpv_frame_start()
1252 s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame && in ff_mpv_frame_start()
1253 !s->progressive_sequence; in ff_mpv_frame_start()
1254 s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME; in ff_mpv_frame_start()
1256 s->current_picture_ptr->f->pict_type = s->pict_type; in ff_mpv_frame_start()
1259 s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I; in ff_mpv_frame_start()
1261 if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture, in ff_mpv_frame_start()
1262 s->current_picture_ptr)) < 0) in ff_mpv_frame_start()
1265 if (s->pict_type != AV_PICTURE_TYPE_B) { in ff_mpv_frame_start()
1266 s->last_picture_ptr = s->next_picture_ptr; in ff_mpv_frame_start()
1267 if (!s->droppable) in ff_mpv_frame_start()
1268 s->next_picture_ptr = s->current_picture_ptr; in ff_mpv_frame_start()
1270 ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", in ff_mpv_frame_start()
1271 s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr, in ff_mpv_frame_start()
1272 s->last_picture_ptr ? s->last_picture_ptr->f->data[0] : NULL, in ff_mpv_frame_start()
1273 s->next_picture_ptr ? s->next_picture_ptr->f->data[0] : NULL, in ff_mpv_frame_start()
1274 s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL, in ff_mpv_frame_start()
1275 s->pict_type, s->droppable); in ff_mpv_frame_start()
1277 if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) && in ff_mpv_frame_start()
1278 (s->pict_type != AV_PICTURE_TYPE_I)) { in ff_mpv_frame_start()
1280 av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, in ff_mpv_frame_start()
1282 … if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0]) in ff_mpv_frame_start()
1285 else if (s->pict_type != AV_PICTURE_TYPE_I) in ff_mpv_frame_start()
1290 i = ff_find_unused_picture(s->avctx, s->picture, 0); in ff_mpv_frame_start()
1292 av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); in ff_mpv_frame_start()
1295 s->last_picture_ptr = &s->picture[i]; in ff_mpv_frame_start()
1297 s->last_picture_ptr->reference = 3; in ff_mpv_frame_start()
1298 s->last_picture_ptr->f->key_frame = 0; in ff_mpv_frame_start()
1299 s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P; in ff_mpv_frame_start()
1301 if (alloc_picture(s, s->last_picture_ptr) < 0) { in ff_mpv_frame_start()
1302 s->last_picture_ptr = NULL; in ff_mpv_frame_start()
1308 memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i, in ff_mpv_frame_start()
1310 if (s->last_picture_ptr->f->data[2]) { in ff_mpv_frame_start()
1312 memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i, in ff_mpv_frame_start()
1314 memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i, in ff_mpv_frame_start()
1319 if(s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263){ in ff_mpv_frame_start()
1321 … memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i, 16, avctx->width); in ff_mpv_frame_start()
1325 ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0); in ff_mpv_frame_start()
1326 ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1); in ff_mpv_frame_start()
1328 if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) && in ff_mpv_frame_start()
1329 s->pict_type == AV_PICTURE_TYPE_B) { in ff_mpv_frame_start()
1331 i = ff_find_unused_picture(s->avctx, s->picture, 0); in ff_mpv_frame_start()
1333 av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); in ff_mpv_frame_start()
1336 s->next_picture_ptr = &s->picture[i]; in ff_mpv_frame_start()
1338 s->next_picture_ptr->reference = 3; in ff_mpv_frame_start()
1339 s->next_picture_ptr->f->key_frame = 0; in ff_mpv_frame_start()
1340 s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P; in ff_mpv_frame_start()
1342 if (alloc_picture(s, s->next_picture_ptr) < 0) { in ff_mpv_frame_start()
1343 s->next_picture_ptr = NULL; in ff_mpv_frame_start()
1346 ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0); in ff_mpv_frame_start()
1347 ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1); in ff_mpv_frame_start()
1351 memset(s->last_picture.f->data, 0, sizeof(s->last_picture.f->data)); in ff_mpv_frame_start()
1352 memset(s->next_picture.f->data, 0, sizeof(s->next_picture.f->data)); in ff_mpv_frame_start()
1354 if (s->last_picture_ptr) { in ff_mpv_frame_start()
1355 if (s->last_picture_ptr->f->buf[0] && in ff_mpv_frame_start()
1356 (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture, in ff_mpv_frame_start()
1357 s->last_picture_ptr)) < 0) in ff_mpv_frame_start()
1360 if (s->next_picture_ptr) { in ff_mpv_frame_start()
1361 if (s->next_picture_ptr->f->buf[0] && in ff_mpv_frame_start()
1362 (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture, in ff_mpv_frame_start()
1363 s->next_picture_ptr)) < 0) in ff_mpv_frame_start()
1367 av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && in ff_mpv_frame_start()
1368 s->last_picture_ptr->f->buf[0])); in ff_mpv_frame_start()
1370 if (s->picture_structure!= PICT_FRAME) { in ff_mpv_frame_start()
1373 if (s->picture_structure == PICT_BOTTOM_FIELD) { in ff_mpv_frame_start()
1374 s->current_picture.f->data[i] += in ff_mpv_frame_start()
1375 s->current_picture.f->linesize[i]; in ff_mpv_frame_start()
1377 s->current_picture.f->linesize[i] *= 2; in ff_mpv_frame_start()
1378 s->last_picture.f->linesize[i] *= 2; in ff_mpv_frame_start()
1379 s->next_picture.f->linesize[i] *= 2; in ff_mpv_frame_start()
1386 if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) { in ff_mpv_frame_start()
1387 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; in ff_mpv_frame_start()
1388 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; in ff_mpv_frame_start()
1389 } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { in ff_mpv_frame_start()
1390 s->dct_unquantize_intra = s->dct_unquantize_h263_intra; in ff_mpv_frame_start()
1391 s->dct_unquantize_inter = s->dct_unquantize_h263_inter; in ff_mpv_frame_start()
1393 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; in ff_mpv_frame_start()
1394 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; in ff_mpv_frame_start()
1397 if (s->avctx->debug & FF_DEBUG_NOMC) { in ff_mpv_frame_start()
1398 gray_frame(s->current_picture_ptr->f); in ff_mpv_frame_start()
1405 void ff_mpv_frame_end(MpegEncContext *s) in ff_mpv_frame_end() argument
1409 if (s->current_picture.reference) in ff_mpv_frame_end()
1410 ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0); in ff_mpv_frame_end()
1413 void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict) in ff_print_debug_info() argument
1415 ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type, in ff_print_debug_info()
1416 p->qscale_table, p->motion_val, &s->low_delay, in ff_print_debug_info()
1417 s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample); in ff_print_debug_info()
1420 int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type) in ff_mpv_export_qp_table() argument
1427 if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS)) in ff_mpv_export_qp_table()
1451 static inline int hpel_motion_lowres(MpegEncContext *s, in hpel_motion_lowres() argument
1460 const int lowres = s->avctx->lowres; in hpel_motion_lowres()
1466 if (s->quarter_sample) { in hpel_motion_lowres()
1480 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src, in hpel_motion_lowres()
1481 s->linesize, s->linesize, in hpel_motion_lowres()
1485 src = s->sc.edge_emu_buffer; in hpel_motion_lowres()
1492 src += s->linesize; in hpel_motion_lowres()
1498 static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, in mpeg_motion_lowres() argument
1513 const int lowres = s->avctx->lowres; in mpeg_motion_lowres()
1514 const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 3); in mpeg_motion_lowres()
1517 const int h_edge_pos = s->h_edge_pos >> lowres; in mpeg_motion_lowres()
1518 const int v_edge_pos = s->v_edge_pos >> lowres; in mpeg_motion_lowres()
1519 linesize = s->current_picture.f->linesize[0] << field_based; in mpeg_motion_lowres()
1520 uvlinesize = s->current_picture.f->linesize[1] << field_based; in mpeg_motion_lowres()
1523 if (s->quarter_sample) { in mpeg_motion_lowres()
1534 src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1); in mpeg_motion_lowres()
1537 if (s->out_format == FMT_H263) { in mpeg_motion_lowres()
1542 } else if (s->out_format == FMT_H261) { in mpeg_motion_lowres()
1548 uvsrc_x = s->mb_x * block_s + (mx >> lowres); in mpeg_motion_lowres()
1551 if(s->chroma_y_shift){ in mpeg_motion_lowres()
1556 uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1); in mpeg_motion_lowres()
1559 if(s->chroma_x_shift){ in mpeg_motion_lowres()
1565 uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); in mpeg_motion_lowres()
1582 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y, in mpeg_motion_lowres()
1587 ptr_y = s->sc.edge_emu_buffer; in mpeg_motion_lowres()
1588 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpeg_motion_lowres()
1589 uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; in mpeg_motion_lowres()
1590 uint8_t *vbuf =ubuf + 10 * s->uvlinesize; in mpeg_motion_lowres()
1591 if (s->workaround_bugs & FF_BUG_IEDGE) in mpeg_motion_lowres()
1592 vbuf -= s->uvlinesize; in mpeg_motion_lowres()
1593 s->vdsp.emulated_edge_mc(ubuf, ptr_cb, in mpeg_motion_lowres()
1598 s->vdsp.emulated_edge_mc(vbuf, ptr_cr, in mpeg_motion_lowres()
1610 dest_y += s->linesize; in mpeg_motion_lowres()
1611 dest_cb += s->uvlinesize; in mpeg_motion_lowres()
1612 dest_cr += s->uvlinesize; in mpeg_motion_lowres()
1616 ptr_y += s->linesize; in mpeg_motion_lowres()
1617 ptr_cb += s->uvlinesize; in mpeg_motion_lowres()
1618 ptr_cr += s->uvlinesize; in mpeg_motion_lowres()
1625 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpeg_motion_lowres()
1626 int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h; in mpeg_motion_lowres()
1637 static inline void chroma_4mv_motion_lowres(MpegEncContext *s, in chroma_4mv_motion_lowres() argument
1643 const int lowres = s->avctx->lowres; in chroma_4mv_motion_lowres()
1647 const int h_edge_pos = s->h_edge_pos >> lowres + 1; in chroma_4mv_motion_lowres()
1648 const int v_edge_pos = s->v_edge_pos >> lowres + 1; in chroma_4mv_motion_lowres()
1653 if (s->quarter_sample) { in chroma_4mv_motion_lowres()
1665 src_x = s->mb_x * block_s + (mx >> lowres + 1); in chroma_4mv_motion_lowres()
1666 src_y = s->mb_y * block_s + (my >> lowres + 1); in chroma_4mv_motion_lowres()
1668 offset = src_y * s->uvlinesize + src_x; in chroma_4mv_motion_lowres()
1672 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, in chroma_4mv_motion_lowres()
1673 s->uvlinesize, s->uvlinesize, in chroma_4mv_motion_lowres()
1676 ptr = s->sc.edge_emu_buffer; in chroma_4mv_motion_lowres()
1681 pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); in chroma_4mv_motion_lowres()
1685 s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, in chroma_4mv_motion_lowres()
1686 s->uvlinesize, s->uvlinesize, in chroma_4mv_motion_lowres()
1689 ptr = s->sc.edge_emu_buffer; in chroma_4mv_motion_lowres()
1691 pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); in chroma_4mv_motion_lowres()
1705 static inline void MPV_motion_lowres(MpegEncContext *s, in MPV_motion_lowres() argument
1713 const int lowres = s->avctx->lowres; in MPV_motion_lowres()
1716 mb_x = s->mb_x; in MPV_motion_lowres()
1717 mb_y = s->mb_y; in MPV_motion_lowres()
1719 switch (s->mv_type) { in MPV_motion_lowres()
1721 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1724 s->mv[dir][0][0], s->mv[dir][0][1], in MPV_motion_lowres()
1731 hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * in MPV_motion_lowres()
1732 s->linesize) * block_s, in MPV_motion_lowres()
1736 s->width, s->height, s->linesize, in MPV_motion_lowres()
1737 s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, in MPV_motion_lowres()
1739 s->mv[dir][i][0], s->mv[dir][i][1]); in MPV_motion_lowres()
1741 mx += s->mv[dir][i][0]; in MPV_motion_lowres()
1742 my += s->mv[dir][i][1]; in MPV_motion_lowres()
1745 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) in MPV_motion_lowres()
1746 chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, in MPV_motion_lowres()
1750 if (s->picture_structure == PICT_FRAME) { in MPV_motion_lowres()
1752 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1753 1, 0, s->field_select[dir][0], in MPV_motion_lowres()
1755 s->mv[dir][0][0], s->mv[dir][0][1], in MPV_motion_lowres()
1758 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1759 1, 1, s->field_select[dir][1], in MPV_motion_lowres()
1761 s->mv[dir][1][0], s->mv[dir][1][1], in MPV_motion_lowres()
1764 if (s->picture_structure != s->field_select[dir][0] + 1 && in MPV_motion_lowres()
1765 s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { in MPV_motion_lowres()
1766 ref_picture = s->current_picture_ptr->f->data; in MPV_motion_lowres()
1769 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1770 0, 0, s->field_select[dir][0], in MPV_motion_lowres()
1772 s->mv[dir][0][0], in MPV_motion_lowres()
1773 s->mv[dir][0][1], 2 * block_s, mb_y >> 1); in MPV_motion_lowres()
1780 if (s->picture_structure == s->field_select[dir][i] + 1 || in MPV_motion_lowres()
1781 s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { in MPV_motion_lowres()
1784 ref2picture = s->current_picture_ptr->f->data; in MPV_motion_lowres()
1787 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1788 0, 0, s->field_select[dir][i], in MPV_motion_lowres()
1790 s->mv[dir][i][0], s->mv[dir][i][1] + in MPV_motion_lowres()
1793 dest_y += 2 * block_s * s->linesize; in MPV_motion_lowres()
1794 dest_cb += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; in MPV_motion_lowres()
1795 dest_cr += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; in MPV_motion_lowres()
1799 if (s->picture_structure == PICT_FRAME) { in MPV_motion_lowres()
1803 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1806 s->mv[dir][2 * i + j][0], in MPV_motion_lowres()
1807 s->mv[dir][2 * i + j][1], in MPV_motion_lowres()
1810 pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; in MPV_motion_lowres()
1814 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, in MPV_motion_lowres()
1815 0, 0, s->picture_structure != i + 1, in MPV_motion_lowres()
1817 s->mv[dir][2 * i][0],s->mv[dir][2 * i][1], in MPV_motion_lowres()
1821 pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; in MPV_motion_lowres()
1825 if (!s->first_field) { in MPV_motion_lowres()
1826 ref_picture = s->current_picture_ptr->f->data; in MPV_motion_lowres()
1839 static int lowest_referenced_row(MpegEncContext *s, int dir) in lowest_referenced_row() argument
1841 int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !s->quarter_sample; in lowest_referenced_row()
1844 if (s->picture_structure != PICT_FRAME || s->mcsel) in lowest_referenced_row()
1847 switch (s->mv_type) { in lowest_referenced_row()
1862 my = s->mv[dir][i][1]; in lowest_referenced_row()
1869 return av_clip(s->mb_y + off, 0, s->mb_height - 1); in lowest_referenced_row()
1871 return s->mb_height-1; in lowest_referenced_row()
1875 static inline void put_dct(MpegEncContext *s, in put_dct() argument
1878 s->dct_unquantize_intra(s, block, i, qscale); in put_dct()
1879 s->idsp.idct_put(dest, line_size, block); in put_dct()
1883 static inline void add_dct(MpegEncContext *s, in add_dct() argument
1886 if (s->block_last_index[i] >= 0) { in add_dct()
1887 s->idsp.idct_add(dest, line_size, block); in add_dct()
1891 static inline void add_dequant_dct(MpegEncContext *s, in add_dequant_dct() argument
1894 if (s->block_last_index[i] >= 0) { in add_dequant_dct()
1895 s->dct_unquantize_inter(s, block, i, qscale); in add_dequant_dct()
1897 s->idsp.idct_add(dest, line_size, block); in add_dequant_dct()
1904 void ff_clean_intra_table_entries(MpegEncContext *s) in ff_clean_intra_table_entries() argument
1906 int wrap = s->b8_stride; in ff_clean_intra_table_entries()
1907 int xy = s->block_index[0]; in ff_clean_intra_table_entries()
1909 s->dc_val[0][xy ] = in ff_clean_intra_table_entries()
1910 s->dc_val[0][xy + 1 ] = in ff_clean_intra_table_entries()
1911 s->dc_val[0][xy + wrap] = in ff_clean_intra_table_entries()
1912 s->dc_val[0][xy + 1 + wrap] = 1024; in ff_clean_intra_table_entries()
1914 memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t)); in ff_clean_intra_table_entries()
1915 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t)); in ff_clean_intra_table_entries()
1916 if (s->msmpeg4_version>=3) { in ff_clean_intra_table_entries()
1917 s->coded_block[xy ] = in ff_clean_intra_table_entries()
1918 s->coded_block[xy + 1 ] = in ff_clean_intra_table_entries()
1919 s->coded_block[xy + wrap] = in ff_clean_intra_table_entries()
1920 s->coded_block[xy + 1 + wrap] = 0; in ff_clean_intra_table_entries()
1923 wrap = s->mb_stride; in ff_clean_intra_table_entries()
1924 xy = s->mb_x + s->mb_y * wrap; in ff_clean_intra_table_entries()
1925 s->dc_val[1][xy] = in ff_clean_intra_table_entries()
1926 s->dc_val[2][xy] = 1024; in ff_clean_intra_table_entries()
1928 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t)); in ff_clean_intra_table_entries()
1929 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t)); in ff_clean_intra_table_entries()
1931 s->mbintra_table[xy]= 0; in ff_clean_intra_table_entries()
1945 void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], in mpv_reconstruct_mb_internal() argument
1948 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; in mpv_reconstruct_mb_internal()
1951 s->avctx->hwaccel && s->avctx->hwaccel->decode_mb) { in mpv_reconstruct_mb_internal()
1952 s->avctx->hwaccel->decode_mb(s);//xvmc uses pblocks in mpv_reconstruct_mb_internal()
1956 if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { in mpv_reconstruct_mb_internal()
1959 av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y); in mpv_reconstruct_mb_internal()
1962 av_log(s->avctx, AV_LOG_DEBUG, "%5d", in mpv_reconstruct_mb_internal()
1963 block[i][s->idsp.idct_permutation[j]]); in mpv_reconstruct_mb_internal()
1965 av_log(s->avctx, AV_LOG_DEBUG, "\n"); in mpv_reconstruct_mb_internal()
1969 s->current_picture.qscale_table[mb_xy] = s->qscale; in mpv_reconstruct_mb_internal()
1972 if (!s->mb_intra) { in mpv_reconstruct_mb_internal()
1973 if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) { in mpv_reconstruct_mb_internal()
1974 if(s->mbintra_table[mb_xy]) in mpv_reconstruct_mb_internal()
1975 ff_clean_intra_table_entries(s); in mpv_reconstruct_mb_internal()
1977 s->last_dc[0] = in mpv_reconstruct_mb_internal()
1978 s->last_dc[1] = in mpv_reconstruct_mb_internal()
1979 s->last_dc[2] = 128 << s->intra_dc_precision; in mpv_reconstruct_mb_internal()
1982 else if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) in mpv_reconstruct_mb_internal()
1983 s->mbintra_table[mb_xy]=1; in mpv_reconstruct_mb_internal()
1985 if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor || in mpv_reconstruct_mb_internal()
1986 !(s->encoding && (s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) && in mpv_reconstruct_mb_internal()
1987 s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc in mpv_reconstruct_mb_internal()
1992 …const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong… in mpv_reconstruct_mb_internal()
1993 const int uvlinesize = s->current_picture.f->linesize[1]; in mpv_reconstruct_mb_internal()
1994 …const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band … in mpv_reconstruct_mb_internal()
1995 const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8; in mpv_reconstruct_mb_internal()
1999 if(!s->encoding){ in mpv_reconstruct_mb_internal()
2000 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; in mpv_reconstruct_mb_internal()
2002 if (s->mb_skipped) { in mpv_reconstruct_mb_internal()
2003 s->mb_skipped= 0; in mpv_reconstruct_mb_internal()
2004 av_assert2(s->pict_type!=AV_PICTURE_TYPE_I); in mpv_reconstruct_mb_internal()
2006 } else if(!s->current_picture.reference) { in mpv_reconstruct_mb_internal()
2013 dct_linesize = linesize << s->interlaced_dct; in mpv_reconstruct_mb_internal()
2014 dct_offset = s->interlaced_dct ? linesize : linesize * block_size; in mpv_reconstruct_mb_internal()
2017 dest_y= s->dest[0]; in mpv_reconstruct_mb_internal()
2018 dest_cb= s->dest[1]; in mpv_reconstruct_mb_internal()
2019 dest_cr= s->dest[2]; in mpv_reconstruct_mb_internal()
2021 dest_y = s->sc.b_scratchpad; in mpv_reconstruct_mb_internal()
2022 dest_cb= s->sc.b_scratchpad+16*linesize; in mpv_reconstruct_mb_internal()
2023 dest_cr= s->sc.b_scratchpad+32*linesize; in mpv_reconstruct_mb_internal()
2026 if (!s->mb_intra) { in mpv_reconstruct_mb_internal()
2029 if(!s->encoding){ in mpv_reconstruct_mb_internal()
2031 if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) { in mpv_reconstruct_mb_internal()
2032 if (s->mv_dir & MV_DIR_FORWARD) { in mpv_reconstruct_mb_internal()
2033 ff_thread_await_progress(&s->last_picture_ptr->tf, in mpv_reconstruct_mb_internal()
2034 lowest_referenced_row(s, 0), in mpv_reconstruct_mb_internal()
2037 if (s->mv_dir & MV_DIR_BACKWARD) { in mpv_reconstruct_mb_internal()
2038 ff_thread_await_progress(&s->next_picture_ptr->tf, in mpv_reconstruct_mb_internal()
2039 lowest_referenced_row(s, 1), in mpv_reconstruct_mb_internal()
2045 h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab; in mpv_reconstruct_mb_internal()
2047 if (s->mv_dir & MV_DIR_FORWARD) { in mpv_reconstruct_mb_internal()
2048 … MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f->data, op_pix); in mpv_reconstruct_mb_internal()
2049 op_pix = s->h264chroma.avg_h264_chroma_pixels_tab; in mpv_reconstruct_mb_internal()
2051 if (s->mv_dir & MV_DIR_BACKWARD) { in mpv_reconstruct_mb_internal()
2052 … MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f->data, op_pix); in mpv_reconstruct_mb_internal()
2055 op_qpix = s->me.qpel_put; in mpv_reconstruct_mb_internal()
2056 if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ in mpv_reconstruct_mb_internal()
2057 op_pix = s->hdsp.put_pixels_tab; in mpv_reconstruct_mb_internal()
2059 op_pix = s->hdsp.put_no_rnd_pixels_tab; in mpv_reconstruct_mb_internal()
2061 if (s->mv_dir & MV_DIR_FORWARD) { in mpv_reconstruct_mb_internal()
2062 … ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f->data, op_pix, op_qpix); in mpv_reconstruct_mb_internal()
2063 op_pix = s->hdsp.avg_pixels_tab; in mpv_reconstruct_mb_internal()
2064 op_qpix= s->me.qpel_avg; in mpv_reconstruct_mb_internal()
2066 if (s->mv_dir & MV_DIR_BACKWARD) { in mpv_reconstruct_mb_internal()
2067 … ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f->data, op_pix, op_qpix); in mpv_reconstruct_mb_internal()
2073 if(s->avctx->skip_idct){ in mpv_reconstruct_mb_internal()
2074 if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) in mpv_reconstruct_mb_internal()
2075 ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) in mpv_reconstruct_mb_internal()
2076 || s->avctx->skip_idct >= AVDISCARD_ALL) in mpv_reconstruct_mb_internal()
2081 …if(s->encoding || !( s->msmpeg4_version || s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==A… in mpv_reconstruct_mb_internal()
2082 || (s->codec_id==AV_CODEC_ID_MPEG4 && !s->mpeg_quant))){ in mpv_reconstruct_mb_internal()
2083 … add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2084 … add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2085 … add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2086 … add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2088 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpv_reconstruct_mb_internal()
2089 if (s->chroma_y_shift){ in mpv_reconstruct_mb_internal()
2090 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2091 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2095 … add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2096 … add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2097 … add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2098 … add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2101 } else if(is_mpeg12 || (s->codec_id != AV_CODEC_ID_WMV2)){ in mpv_reconstruct_mb_internal()
2102 add_dct(s, block[0], 0, dest_y , dct_linesize); in mpv_reconstruct_mb_internal()
2103 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); in mpv_reconstruct_mb_internal()
2104 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); in mpv_reconstruct_mb_internal()
2105 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); in mpv_reconstruct_mb_internal()
2107 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpv_reconstruct_mb_internal()
2108 if(s->chroma_y_shift){//Chroma420 in mpv_reconstruct_mb_internal()
2109 add_dct(s, block[4], 4, dest_cb, uvlinesize); in mpv_reconstruct_mb_internal()
2110 add_dct(s, block[5], 5, dest_cr, uvlinesize); in mpv_reconstruct_mb_internal()
2113 dct_linesize = uvlinesize << s->interlaced_dct; in mpv_reconstruct_mb_internal()
2114 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; in mpv_reconstruct_mb_internal()
2116 add_dct(s, block[4], 4, dest_cb, dct_linesize); in mpv_reconstruct_mb_internal()
2117 add_dct(s, block[5], 5, dest_cr, dct_linesize); in mpv_reconstruct_mb_internal()
2118 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize); in mpv_reconstruct_mb_internal()
2119 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize); in mpv_reconstruct_mb_internal()
2120 if(!s->chroma_x_shift){//Chroma444 in mpv_reconstruct_mb_internal()
2121 add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize); in mpv_reconstruct_mb_internal()
2122 add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize); in mpv_reconstruct_mb_internal()
2123 add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize); in mpv_reconstruct_mb_internal()
2124 add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize); in mpv_reconstruct_mb_internal()
2130 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); in mpv_reconstruct_mb_internal()
2135 if (s->avctx->bits_per_raw_sample > 8){ in mpv_reconstruct_mb_internal()
2138 if(s->dpcm_direction == 0) { in mpv_reconstruct_mb_internal()
2139s->idsp.idct_put(dest_y, dct_linesize, (int16_t*)(*s->block32)[0]); in mpv_reconstruct_mb_internal()
2140s->idsp.idct_put(dest_y + act_block_size, dct_linesize, (int16_t*)(*s->block32)[1]); in mpv_reconstruct_mb_internal()
2141s->idsp.idct_put(dest_y + dct_offset, dct_linesize, (int16_t*)(*s->block32)[2]); in mpv_reconstruct_mb_internal()
2142s->idsp.idct_put(dest_y + dct_offset + act_block_size, dct_linesize, (int16_t*)(*s->block32)[3]); in mpv_reconstruct_mb_internal()
2144 dct_linesize = uvlinesize << s->interlaced_dct; in mpv_reconstruct_mb_internal()
2145 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; in mpv_reconstruct_mb_internal()
2147s->idsp.idct_put(dest_cb, dct_linesize, (int16_t*)(*s->block32)[4]); in mpv_reconstruct_mb_internal()
2148s->idsp.idct_put(dest_cr, dct_linesize, (int16_t*)(*s->block32)[5]); in mpv_reconstruct_mb_internal()
2149s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, (int16_t*)(*s->block32)[6]); in mpv_reconstruct_mb_internal()
2150s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, (int16_t*)(*s->block32)[7]); in mpv_reconstruct_mb_internal()
2151 if(!s->chroma_x_shift){//Chroma444 in mpv_reconstruct_mb_internal()
2152s->idsp.idct_put(dest_cb + act_block_size, dct_linesize, (int16_t*)(*s->block32)[8]); in mpv_reconstruct_mb_internal()
2153s->idsp.idct_put(dest_cr + act_block_size, dct_linesize, (int16_t*)(*s->block32)[9]); in mpv_reconstruct_mb_internal()
2154s->idsp.idct_put(dest_cb + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[10]); in mpv_reconstruct_mb_internal()
2155s->idsp.idct_put(dest_cr + act_block_size + dct_offset, dct_linesize, (int16_t*)(*s->block32)[11]); in mpv_reconstruct_mb_internal()
2157 } else if(s->dpcm_direction == 1) { in mpv_reconstruct_mb_internal()
2163 int vsub = i ? s->chroma_y_shift : 0; in mpv_reconstruct_mb_internal()
2164 int hsub = i ? s->chroma_x_shift : 0; in mpv_reconstruct_mb_internal()
2167 dest_pcm[i][w] = (*s->dpcm_macroblock)[i][idx++]; in mpv_reconstruct_mb_internal()
2171 } else if(s->dpcm_direction == -1) { in mpv_reconstruct_mb_internal()
2177 int vsub = i ? s->chroma_y_shift : 0; in mpv_reconstruct_mb_internal()
2178 int hsub = i ? s->chroma_x_shift : 0; in mpv_reconstruct_mb_internal()
2182 dest_pcm[i][w] = (*s->dpcm_macroblock)[i][idx++]; in mpv_reconstruct_mb_internal()
2189 …else if(s->encoding || !(s->codec_id==AV_CODEC_ID_MPEG1VIDEO || s->codec_id==AV_CODEC_ID_MPEG2VIDE… in mpv_reconstruct_mb_internal()
2190 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2191 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2192 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2193 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); in mpv_reconstruct_mb_internal()
2195 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpv_reconstruct_mb_internal()
2196 if(s->chroma_y_shift){ in mpv_reconstruct_mb_internal()
2197 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2198 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2202 … put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2203 … put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2204 … put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2205 … put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale); in mpv_reconstruct_mb_internal()
2209 s->idsp.idct_put(dest_y, dct_linesize, block[0]); in mpv_reconstruct_mb_internal()
2210 s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]); in mpv_reconstruct_mb_internal()
2211 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]); in mpv_reconstruct_mb_internal()
2212 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); in mpv_reconstruct_mb_internal()
2214 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpv_reconstruct_mb_internal()
2215 if(s->chroma_y_shift){ in mpv_reconstruct_mb_internal()
2216 s->idsp.idct_put(dest_cb, uvlinesize, block[4]); in mpv_reconstruct_mb_internal()
2217 s->idsp.idct_put(dest_cr, uvlinesize, block[5]); in mpv_reconstruct_mb_internal()
2220 dct_linesize = uvlinesize << s->interlaced_dct; in mpv_reconstruct_mb_internal()
2221 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; in mpv_reconstruct_mb_internal()
2223 s->idsp.idct_put(dest_cb, dct_linesize, block[4]); in mpv_reconstruct_mb_internal()
2224 s->idsp.idct_put(dest_cr, dct_linesize, block[5]); in mpv_reconstruct_mb_internal()
2225 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]); in mpv_reconstruct_mb_internal()
2226 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]); in mpv_reconstruct_mb_internal()
2227 if(!s->chroma_x_shift){//Chroma444 in mpv_reconstruct_mb_internal()
2228s->idsp.idct_put(dest_cb + block_size, dct_linesize, block[8]); in mpv_reconstruct_mb_internal()
2229s->idsp.idct_put(dest_cr + block_size, dct_linesize, block[9]); in mpv_reconstruct_mb_internal()
2230s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]); in mpv_reconstruct_mb_internal()
2231s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]); in mpv_reconstruct_mb_internal()
2239 s->hdsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16); in mpv_reconstruct_mb_internal()
2240 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { in mpv_reconstruct_mb_internal()
2241s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shi… in mpv_reconstruct_mb_internal()
2242s->hdsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shi… in mpv_reconstruct_mb_internal()
2248 void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]) in ff_mpv_reconstruct_mb() argument
2251 if(s->out_format == FMT_MPEG1) { in ff_mpv_reconstruct_mb()
2252 if(s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, 1); in ff_mpv_reconstruct_mb()
2253 else mpv_reconstruct_mb_internal(s, block, 0, 1); in ff_mpv_reconstruct_mb()
2256 if(s->avctx->lowres) mpv_reconstruct_mb_internal(s, block, 1, 0); in ff_mpv_reconstruct_mb()
2257 else mpv_reconstruct_mb_internal(s, block, 0, 0); in ff_mpv_reconstruct_mb()
2260 void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h) in ff_mpeg_draw_horiz_band() argument
2262 ff_draw_horiz_band(s->avctx, s->current_picture_ptr->f, in ff_mpeg_draw_horiz_band()
2263s->last_picture_ptr ? s->last_picture_ptr->f : NULL, y, h, s->picture_structure, in ff_mpeg_draw_horiz_band()
2264 s->first_field, s->low_delay); in ff_mpeg_draw_horiz_band()
2267 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename in ff_init_block_index() argument
2268 …const int linesize = s->current_picture.f->linesize[0]; //not s->linesize as this would be wrong… in ff_init_block_index()
2269 const int uvlinesize = s->current_picture.f->linesize[1]; in ff_init_block_index()
2270 const int width_of_mb = (4 + (s->avctx->bits_per_raw_sample > 8)) - s->avctx->lowres; in ff_init_block_index()
2271 const int height_of_mb = 4 - s->avctx->lowres; in ff_init_block_index()
2273 s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2; in ff_init_block_index()
2274 s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2; in ff_init_block_index()
2275 s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2; in ff_init_block_index()
2276 s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2; in ff_init_block_index()
2277s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb… in ff_init_block_index()
2278s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb… in ff_init_block_index()
2281 s->dest[0] = s->current_picture.f->data[0] + (int)((s->mb_x - 1U) << width_of_mb); in ff_init_block_index()
2282s->dest[1] = s->current_picture.f->data[1] + (int)((s->mb_x - 1U) << (width_of_mb - s->chroma_x_sh… in ff_init_block_index()
2283s->dest[2] = s->current_picture.f->data[2] + (int)((s->mb_x - 1U) << (width_of_mb - s->chroma_x_sh… in ff_init_block_index()
2285 …if(!(s->pict_type==AV_PICTURE_TYPE_B && s->avctx->draw_horiz_band && s->picture_structure==PICT_FR… in ff_init_block_index()
2287 if(s->picture_structure==PICT_FRAME){ in ff_init_block_index()
2288 s->dest[0] += s->mb_y * linesize << height_of_mb; in ff_init_block_index()
2289 s->dest[1] += s->mb_y * uvlinesize << (height_of_mb - s->chroma_y_shift); in ff_init_block_index()
2290 s->dest[2] += s->mb_y * uvlinesize << (height_of_mb - s->chroma_y_shift); in ff_init_block_index()
2292 s->dest[0] += (s->mb_y>>1) * linesize << height_of_mb; in ff_init_block_index()
2293 s->dest[1] += (s->mb_y>>1) * uvlinesize << (height_of_mb - s->chroma_y_shift); in ff_init_block_index()
2294 s->dest[2] += (s->mb_y>>1) * uvlinesize << (height_of_mb - s->chroma_y_shift); in ff_init_block_index()
2295 av_assert1((s->mb_y&1) == (s->picture_structure == PICT_BOTTOM_FIELD)); in ff_init_block_index()
2302 MpegEncContext *s = avctx->priv_data; in ff_mpeg_flush() local
2304 if (!s || !s->picture) in ff_mpeg_flush()
2308 ff_mpeg_unref_picture(s->avctx, &s->picture[i]); in ff_mpeg_flush()
2309 s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; in ff_mpeg_flush()
2311 ff_mpeg_unref_picture(s->avctx, &s->current_picture); in ff_mpeg_flush()
2312 ff_mpeg_unref_picture(s->avctx, &s->last_picture); in ff_mpeg_flush()
2313 ff_mpeg_unref_picture(s->avctx, &s->next_picture); in ff_mpeg_flush()
2315 s->mb_x= s->mb_y= 0; in ff_mpeg_flush()
2316 s->closed_gop= 0; in ff_mpeg_flush()
2318 s->parse_context.state= -1; in ff_mpeg_flush()
2319 s->parse_context.frame_start_found= 0; in ff_mpeg_flush()
2320 s->parse_context.overread= 0; in ff_mpeg_flush()
2321 s->parse_context.overread_index= 0; in ff_mpeg_flush()
2322 s->parse_context.index= 0; in ff_mpeg_flush()
2323 s->parse_context.last_index= 0; in ff_mpeg_flush()
2324 s->bitstream_buffer_size=0; in ff_mpeg_flush()
2325 s->pp_time=0; in ff_mpeg_flush()
2331 void ff_set_qscale(MpegEncContext * s, int qscale) in ff_set_qscale() argument
2338 s->qscale = qscale; in ff_set_qscale()
2339 s->chroma_qscale= s->chroma_qscale_table[qscale]; in ff_set_qscale()
2341 s->y_dc_scale= s->y_dc_scale_table[ qscale ]; in ff_set_qscale()
2342 s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ]; in ff_set_qscale()
2345 void ff_mpv_report_decode_progress(MpegEncContext *s) in ff_mpv_report_decode_progress() argument
2347 if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred) in ff_mpv_report_decode_progress()
2348 ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 0); in ff_mpv_report_decode_progress()