mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-04-24 17:12:34 +02:00
mimic: drop AVPicture usage
Work on the AVFrame references directly. Instead of setting up a flipped/swapped "view" on the pictures, flip/swap them when returning decoded frames to the API user.
This commit is contained in:
parent
6fdd4c678a
commit
6a23a34274
@ -48,7 +48,6 @@ typedef struct MimicContext {
|
|||||||
int prev_index;
|
int prev_index;
|
||||||
|
|
||||||
ThreadFrame frames [16];
|
ThreadFrame frames [16];
|
||||||
AVPicture flipped_ptrs[16];
|
|
||||||
|
|
||||||
DECLARE_ALIGNED(16, int16_t, dct_block)[64];
|
DECLARE_ALIGNED(16, int16_t, dct_block)[64];
|
||||||
|
|
||||||
@ -177,8 +176,6 @@ static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCod
|
|||||||
dst->cur_index = src->next_cur_index;
|
dst->cur_index = src->next_cur_index;
|
||||||
dst->prev_index = src->next_prev_index;
|
dst->prev_index = src->next_prev_index;
|
||||||
|
|
||||||
memcpy(dst->flipped_ptrs, src->flipped_ptrs, sizeof(src->flipped_ptrs));
|
|
||||||
|
|
||||||
for (i = 0; i < FF_ARRAY_ELEMS(dst->frames); i++) {
|
for (i = 0; i < FF_ARRAY_ELEMS(dst->frames); i++) {
|
||||||
ff_thread_release_buffer(avctx, &dst->frames[i]);
|
ff_thread_release_buffer(avctx, &dst->frames[i]);
|
||||||
if (src->frames[i].f->data[0]) {
|
if (src->frames[i].f->data[0]) {
|
||||||
@ -281,9 +278,9 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
|
|||||||
const int is_chroma = !!plane;
|
const int is_chroma = !!plane;
|
||||||
const int qscale = av_clip(10000 - quality, is_chroma ? 1000 : 2000,
|
const int qscale = av_clip(10000 - quality, is_chroma ? 1000 : 2000,
|
||||||
10000) << 2;
|
10000) << 2;
|
||||||
const int stride = ctx->flipped_ptrs[ctx->cur_index ].linesize[plane];
|
const int stride = ctx->frames[ctx->cur_index ].f->linesize[plane];
|
||||||
const uint8_t *src = ctx->flipped_ptrs[ctx->prev_index].data[plane];
|
const uint8_t *src = ctx->frames[ctx->prev_index].f->data[plane];
|
||||||
uint8_t *dst = ctx->flipped_ptrs[ctx->cur_index ].data[plane];
|
uint8_t *dst = ctx->frames[ctx->cur_index ].f->data[plane];
|
||||||
|
|
||||||
for (y = 0; y < ctx->num_vblocks[plane]; y++) {
|
for (y = 0; y < ctx->num_vblocks[plane]; y++) {
|
||||||
for (x = 0; x < ctx->num_hblocks[plane]; x++) {
|
for (x = 0; x < ctx->num_hblocks[plane]; x++) {
|
||||||
@ -306,13 +303,13 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
|
|||||||
} else {
|
} else {
|
||||||
unsigned int backref = get_bits(&ctx->gb, 4);
|
unsigned int backref = get_bits(&ctx->gb, 4);
|
||||||
int index = (ctx->cur_index + backref) & 15;
|
int index = (ctx->cur_index + backref) & 15;
|
||||||
uint8_t *p = ctx->flipped_ptrs[index].data[0];
|
uint8_t *p = ctx->frames[index].f->data[0];
|
||||||
|
|
||||||
if (index != ctx->cur_index && p) {
|
if (index != ctx->cur_index && p) {
|
||||||
ff_thread_await_progress(&ctx->frames[index],
|
ff_thread_await_progress(&ctx->frames[index],
|
||||||
cur_row, 0);
|
cur_row, 0);
|
||||||
p += src -
|
p += src -
|
||||||
ctx->flipped_ptrs[ctx->prev_index].data[plane];
|
ctx->frames[ctx->prev_index].f->data[plane];
|
||||||
ctx->hdsp.put_pixels_tab[1][0](dst, p, stride, 8);
|
ctx->hdsp.put_pixels_tab[1][0](dst, p, stride, 8);
|
||||||
} else {
|
} else {
|
||||||
av_log(ctx->avctx, AV_LOG_ERROR,
|
av_log(ctx->avctx, AV_LOG_ERROR,
|
||||||
@ -339,17 +336,18 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flip the buffer upside-down and put it in the YVU order to match the
|
* Flip the buffer upside-down and put it in the YVU order to revert the
|
||||||
* way Mimic encodes frames.
|
* way Mimic encodes frames.
|
||||||
*/
|
*/
|
||||||
static void prepare_avpic(MimicContext *ctx, AVPicture *dst, AVFrame *src)
|
static void flip_swap_frame(AVFrame *f)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
dst->data[0] = src->data[0] + ( ctx->avctx->height - 1) * src->linesize[0];
|
uint8_t *data_1 = f->data[1];
|
||||||
dst->data[1] = src->data[2] + ((ctx->avctx->height >> 1) - 1) * src->linesize[2];
|
f->data[0] = f->data[0] + ( f->height - 1) * f->linesize[0];
|
||||||
dst->data[2] = src->data[1] + ((ctx->avctx->height >> 1) - 1) * src->linesize[1];
|
f->data[1] = f->data[2] + ((f->height >> 1) - 1) * f->linesize[2];
|
||||||
|
f->data[2] = data_1 + ((f->height >> 1) - 1) * f->linesize[1];
|
||||||
for (i = 0; i < 3; i++)
|
for (i = 0; i < 3; i++)
|
||||||
dst->linesize[i] = -src->linesize[i];
|
f->linesize[i] *= -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mimic_decode_frame(AVCodecContext *avctx, void *data,
|
static int mimic_decode_frame(AVCodecContext *avctx, void *data,
|
||||||
@ -419,9 +417,6 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
ctx->next_prev_index = ctx->cur_index;
|
ctx->next_prev_index = ctx->cur_index;
|
||||||
ctx->next_cur_index = (ctx->cur_index - 1) & 15;
|
ctx->next_cur_index = (ctx->cur_index - 1) & 15;
|
||||||
|
|
||||||
prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index],
|
|
||||||
ctx->frames[ctx->cur_index].f);
|
|
||||||
|
|
||||||
ff_thread_finish_setup(avctx);
|
ff_thread_finish_setup(avctx);
|
||||||
|
|
||||||
av_fast_padded_malloc(&ctx->swap_buf, &ctx->swap_buf_size, swap_buf_size);
|
av_fast_padded_malloc(&ctx->swap_buf, &ctx->swap_buf_size, swap_buf_size);
|
||||||
@ -446,6 +441,8 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
|
|||||||
return res;
|
return res;
|
||||||
*got_frame = 1;
|
*got_frame = 1;
|
||||||
|
|
||||||
|
flip_swap_frame(data);
|
||||||
|
|
||||||
ctx->prev_index = ctx->next_prev_index;
|
ctx->prev_index = ctx->next_prev_index;
|
||||||
ctx->cur_index = ctx->next_cur_index;
|
ctx->cur_index = ctx->next_cur_index;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user