#include "libavutil/internal.h"
#include "libavutil/timer.h"
#include "avcodec.h"
-#include "dsputil.h"
+#include "blockdsp.h"
+#include "idctdsp.h"
#include "internal.h"
#include "mathops.h"
#include "mpegutils.h"
#include "mpegvideo.h"
#include "mjpegenc.h"
#include "msmpeg4.h"
+#include "qpeldsp.h"
#include "xvmc_internal.h"
#include "thread.h"
#include <limits.h>
mpeg2_dc_scale_table3,
};
+const uint8_t ff_alternate_horizontal_scan[64] = {
+ 0, 1, 2, 3, 8, 9, 16, 17,
+ 10, 11, 4, 5, 6, 7, 15, 14,
+ 13, 12, 19, 18, 24, 25, 32, 33,
+ 26, 27, 20, 21, 22, 23, 28, 29,
+ 30, 31, 34, 35, 40, 41, 48, 49,
+ 42, 43, 36, 37, 38, 39, 44, 45,
+ 46, 47, 50, 51, 56, 57, 58, 59,
+ 52, 53, 54, 55, 60, 61, 62, 63,
+};
+
+const uint8_t ff_alternate_vertical_scan[64] = {
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 38, 46, 54, 62, 39, 47, 55, 63,
+};
+
static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s,
int16_t *block, int n, int qscale)
{
ff_init_block_index(s);
ff_update_block_index(s);
- s->dsp.clear_blocks(s->block[0]);
+ s->bdsp.clear_blocks(s->block[0]);
s->dest[0] = s->current_picture.f->data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16;
s->dest[1] = s->current_picture.f->data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
s->dest[2] = s->current_picture.f->data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
- assert(ref == 0);
- ff_MPV_decode_mb(s, s->block);
+ if (ref)
+ av_log(s->avctx, AV_LOG_DEBUG,
+ "Interlaced error concealment is not fully implemented\n");
+ ff_mpv_decode_mb(s, s->block);
}
/* init common dct for both encoder and decoder */
-av_cold int ff_dct_common_init(MpegEncContext *s)
+static av_cold int dct_init(MpegEncContext *s)
{
- ff_dsputil_init(&s->dsp, s->avctx);
+ ff_blockdsp_init(&s->bdsp, s->avctx);
ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
+ ff_mpegvideodsp_init(&s->mdsp);
ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact;
s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
+ if (HAVE_INTRINSICS_NEON)
+ ff_mpv_common_init_neon(s);
+
if (ARCH_ARM)
- ff_MPV_common_init_arm(s);
+ ff_mpv_common_init_arm(s);
if (ARCH_PPC)
- ff_MPV_common_init_ppc(s);
+ ff_mpv_common_init_ppc(s);
if (ARCH_X86)
- ff_MPV_common_init_x86(s);
+ ff_mpv_common_init_x86(s);
+
+ return 0;
+}
+
+av_cold void ff_mpv_idct_init(MpegEncContext *s)
+{
+ ff_idctdsp_init(&s->idsp, s->avctx);
/* load & permutate scantables
* note: only wmv uses different ones
*/
if (s->alternate_scan) {
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan);
+ ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
+ ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
} else {
- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct);
+ ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
+ ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
}
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
- ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
-
- return 0;
+ ff_init_scantable(s->idsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan);
+ ff_init_scantable(s->idsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan);
}
static int frame_size_alloc(MpegEncContext *s, int linesize)
if (s->avctx->hwaccel) {
assert(!pic->hwaccel_picture_private);
- if (s->avctx->hwaccel->priv_data_size) {
- pic->hwaccel_priv_buf = av_buffer_allocz(s->avctx->hwaccel->priv_data_size);
+ if (s->avctx->hwaccel->frame_priv_data_size) {
+ pic->hwaccel_priv_buf = av_buffer_allocz(s->avctx->hwaccel->frame_priv_data_size);
if (!pic->hwaccel_priv_buf) {
av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
return -1;
return 0;
fail:
- return -1; // free() through ff_MPV_common_end()
+ return -1; // free() through ff_mpv_common_end()
}
static void free_duplicate_context(MpegEncContext *s)
{
- if (s == NULL)
+ if (!s)
return;
av_freep(&s->edge_emu_buffer);
// FIXME can parameters change on I-frames?
// in that case dst may need a reinit
if (!s->context_initialized) {
+ int err;
memcpy(s, s1, sizeof(MpegEncContext));
s->avctx = dst;
s->bitstream_buffer = NULL;
s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
- ff_MPV_common_init(s);
+ ff_mpv_idct_init(s);
+ if ((err = ff_mpv_common_init(s)) < 0)
+ return err;
}
if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
s->context_reinit = 0;
s->height = s1->height;
s->width = s1->width;
- if ((err = ff_MPV_common_frame_size_change(s)) < 0)
+ if ((err = ff_mpv_common_frame_size_change(s)) < 0)
return err;
}
UPDATE_PICTURE(last_picture);
UPDATE_PICTURE(next_picture);
+#define REBASE_PICTURE(pic, new_ctx, old_ctx) \
+ ((pic && pic >= old_ctx->picture && \
+ pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
+ &new_ctx->picture[pic - old_ctx->picture] : NULL)
+
s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1);
s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1);
* The changed fields will not depend upon the
* prior state of the MpegEncContext.
*/
-void ff_MPV_common_defaults(MpegEncContext *s)
+void ff_mpv_common_defaults(MpegEncContext *s)
{
s->y_dc_scale_table =
s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
* the changed fields will not depend upon
* the prior state of the MpegEncContext.
*/
-void ff_MPV_decode_defaults(MpegEncContext *s)
+void ff_mpv_decode_defaults(MpegEncContext *s)
{
- ff_MPV_common_defaults(s);
+ ff_mpv_common_defaults(s);
}
static int init_er(MpegEncContext *s)
int i;
er->avctx = s->avctx;
- er->dsp = &s->dsp;
er->mb_index2xy = s->mb_index2xy;
er->mb_num = s->mb_num;
* init common structure for both encoder and decoder.
* this assumes that some variables like width/height are already set
*/
-av_cold int ff_MPV_common_init(MpegEncContext *s)
+av_cold int ff_mpv_common_init(MpegEncContext *s)
{
int i;
int nb_slices = (HAVE_THREADS &&
av_image_check_size(s->width, s->height, 0, s->avctx))
return -1;
- ff_dct_common_init(s);
+ dct_init(s);
s->flags = s->avctx->flags;
s->flags2 = s->avctx->flags2;
/* convert fourcc to upper case */
s->codec_tag = avpriv_toupper4(s->avctx->codec_tag);
- s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag);
-
FF_ALLOCZ_OR_GOTO(s->avctx, s->picture,
MAX_PICTURE_COUNT * sizeof(Picture), fail);
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
return 0;
fail:
- ff_MPV_common_end(s);
+ ff_mpv_common_end(s);
return -1;
}
* Is used during resolution changes to avoid a full reinitialization of the
* codec.
*/
-static int free_context_frame(MpegEncContext *s)
+static void free_context_frame(MpegEncContext *s)
{
int i, j, k;
av_freep(&s->bits_tab);
s->linesize = s->uvlinesize = 0;
-
- return 0;
}
-int ff_MPV_common_frame_size_change(MpegEncContext *s)
+int ff_mpv_common_frame_size_change(MpegEncContext *s)
{
int i, err = 0;
} else
free_duplicate_context(s);
- if ((err = free_context_frame(s)) < 0)
- return err;
+ free_context_frame(s);
if (s->picture)
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
s->mb_height = (s->height + 15) / 16;
if ((s->width || s->height) &&
- av_image_check_size(s->width, s->height, 0, s->avctx))
- return AVERROR_INVALIDDATA;
+ (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
+ goto fail;
if ((err = init_context_frame(s)))
goto fail;
}
for (i = 0; i < nb_slices; i++) {
- if (init_duplicate_context(s->thread_context[i]) < 0)
+ if ((err = init_duplicate_context(s->thread_context[i])) < 0)
goto fail;
s->thread_context[i]->start_mb_y =
(s->mb_height * (i) + nb_slices / 2) / nb_slices;
return 0;
fail:
- ff_MPV_common_end(s);
+ ff_mpv_common_end(s);
return err;
}
/* init common structure for both encoder and decoder */
-void ff_MPV_common_end(MpegEncContext *s)
+void ff_mpv_common_end(MpegEncContext *s)
{
int i;
static inline int pic_is_unused(MpegEncContext *s, Picture *pic)
{
- if (pic->f->buf[0] == NULL)
+ if (!pic->f->buf[0])
return 1;
if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF))
return 1;
if (shared) {
for (i = 0; i < MAX_PICTURE_COUNT; i++) {
- if (s->picture[i].f->buf[0] == NULL)
+ if (!s->picture[i].f->buf[0])
return i;
}
} else {
* generic function called after decoding
* the header and before a frame is decoded.
*/
-int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
+int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
{
int i, ret;
Picture *pic;
release_unused_pictures(s);
- if (s->current_picture_ptr &&
- s->current_picture_ptr->f->buf[0] == NULL) {
+ if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
// we already have a unused image
// (maybe it was set before reading the header)
pic = s->current_picture_ptr;
s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
s->pict_type, s->droppable);
- if ((s->last_picture_ptr == NULL ||
- s->last_picture_ptr->f->buf[0] == NULL) &&
+ if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
(s->pict_type != AV_PICTURE_TYPE_I ||
s->picture_structure != PICT_FRAME)) {
int h_chroma_shift, v_chroma_shift;
ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
}
- if ((s->next_picture_ptr == NULL ||
- s->next_picture_ptr->f->buf[0] == NULL) &&
+ if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
s->pict_type == AV_PICTURE_TYPE_B) {
/* Allocate a dummy frame */
i = ff_find_unused_picture(s, 0);
}
/* called after a frame has been decoded. */
-void ff_MPV_frame_end(MpegEncContext *s)
+void ff_mpv_frame_end(MpegEncContext *s)
{
#if FF_API_XVMC
FF_DISABLE_DEPRECATION_WARNINGS
/**
* find the lowest MB row referenced in the MVs
*/
-int ff_MPV_lowest_referenced_row(MpegEncContext *s, int dir)
+int ff_mpv_lowest_referenced_row(MpegEncContext *s, int dir)
{
int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !s->quarter_sample;
int my, off, i, mvs;
int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
{
s->dct_unquantize_intra(s, block, i, qscale);
- s->dsp.idct_put (dest, line_size, block);
+ s->idsp.idct_put(dest, line_size, block);
}
/* add block[] to dest[] */
int16_t *block, int i, uint8_t *dest, int line_size)
{
if (s->block_last_index[i] >= 0) {
- s->dsp.idct_add (dest, line_size, block);
+ s->idsp.idct_add(dest, line_size, block);
}
}
if (s->block_last_index[i] >= 0) {
s->dct_unquantize_inter(s, block, i, qscale);
- s->dsp.idct_add (dest, line_size, block);
+ s->idsp.idct_add(dest, line_size, block);
}
}
s->interlaced_dct : true if interlaced dct used (mpeg2)
*/
static av_always_inline
-void MPV_decode_mb_internal(MpegEncContext *s, int16_t block[12][64],
+void mpv_decode_mb_internal(MpegEncContext *s, int16_t block[12][64],
int is_mpeg12)
{
const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
for(i=0; i<6; i++){
for(j=0; j<64; j++){
- av_log(s->avctx, AV_LOG_DEBUG, "%5d", block[i][s->dsp.idct_permutation[j]]);
+ av_log(s->avctx, AV_LOG_DEBUG, "%5d",
+ block[i][s->idsp.idct_permutation[j]]);
}
av_log(s->avctx, AV_LOG_DEBUG, "\n");
}
if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) {
if (s->mv_dir & MV_DIR_FORWARD) {
ff_thread_await_progress(&s->last_picture_ptr->tf,
- ff_MPV_lowest_referenced_row(s, 0),
+ ff_mpv_lowest_referenced_row(s, 0),
0);
}
if (s->mv_dir & MV_DIR_BACKWARD) {
ff_thread_await_progress(&s->next_picture_ptr->tf,
- ff_MPV_lowest_referenced_row(s, 1),
+ ff_mpv_lowest_referenced_row(s, 1),
0);
}
}
op_pix = s->hdsp.put_no_rnd_pixels_tab;
}
if (s->mv_dir & MV_DIR_FORWARD) {
- ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f->data, op_pix, op_qpix);
+ ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f->data, op_pix, op_qpix);
op_pix = s->hdsp.avg_pixels_tab;
op_qpix= s->me.qpel_avg;
}
if (s->mv_dir & MV_DIR_BACKWARD) {
- ff_MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f->data, op_pix, op_qpix);
+ ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f->data, op_pix, op_qpix);
}
}
}
}
}else{
- s->dsp.idct_put(dest_y , dct_linesize, block[0]);
- s->dsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
- s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]);
- s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
+ s->idsp.idct_put(dest_y, dct_linesize, block[0]);
+ s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
+ s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]);
+ s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
if(s->chroma_y_shift){
- s->dsp.idct_put(dest_cb, uvlinesize, block[4]);
- s->dsp.idct_put(dest_cr, uvlinesize, block[5]);
+ s->idsp.idct_put(dest_cb, uvlinesize, block[4]);
+ s->idsp.idct_put(dest_cr, uvlinesize, block[5]);
}else{
dct_linesize = uvlinesize << s->interlaced_dct;
dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize * 8;
- s->dsp.idct_put(dest_cb, dct_linesize, block[4]);
- s->dsp.idct_put(dest_cr, dct_linesize, block[5]);
- s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
- s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
+ s->idsp.idct_put(dest_cb, dct_linesize, block[4]);
+ s->idsp.idct_put(dest_cr, dct_linesize, block[5]);
+ s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
+ s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
if(!s->chroma_x_shift){//Chroma444
- s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
- s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
- s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
- s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
+ s->idsp.idct_put(dest_cb + 8, dct_linesize, block[8]);
+ s->idsp.idct_put(dest_cr + 8, dct_linesize, block[9]);
+ s->idsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]);
+ s->idsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]);
}
}
}//gray
}
}
-void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64]){
+void ff_mpv_decode_mb(MpegEncContext *s, int16_t block[12][64])
+{
#if !CONFIG_SMALL
if(s->out_format == FMT_MPEG1) {
- MPV_decode_mb_internal(s, block, 1);
+ mpv_decode_mb_internal(s, block, 1);
} else
#endif
- MPV_decode_mb_internal(s, block, 0);
+ mpv_decode_mb_internal(s, block, 0);
}
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
int i;
MpegEncContext *s = avctx->priv_data;
- if(s==NULL || s->picture==NULL)
+ if (!s || !s->picture)
return;
for (i = 0; i < MAX_PICTURE_COUNT; i++)
s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
}
-void ff_MPV_report_decode_progress(MpegEncContext *s)
+void ff_mpv_report_decode_progress(MpegEncContext *s)
{
if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 0);
}
-
-#if CONFIG_ERROR_RESILIENCE
-void ff_mpeg_set_erpic(ERPicture *dst, Picture *src)
-{
- int i;
-
- if (!src)
- return;
-
- dst->f = src->f;
- dst->tf = &src->tf;
-
- for (i = 0; i < 2; i++) {
- dst->motion_val[i] = src->motion_val[i];
- dst->ref_index[i] = src->ref_index[i];
- }
-
- dst->mb_type = src->mb_type;
- dst->field_picture = src->field_picture;
-}
-
-void ff_mpeg_er_frame_start(MpegEncContext *s)
-{
- ERContext *er = &s->er;
-
- ff_mpeg_set_erpic(&er->cur_pic, s->current_picture_ptr);
- ff_mpeg_set_erpic(&er->next_pic, s->next_picture_ptr);
- ff_mpeg_set_erpic(&er->last_pic, s->last_picture_ptr);
-
- er->pp_time = s->pp_time;
- er->pb_time = s->pb_time;
- er->quarter_sample = s->quarter_sample;
- er->partitioned_frame = s->partitioned_frame;
-
- ff_er_frame_start(er);
-}
-#endif /* CONFIG_ERROR_RESILIENCE */