mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/v210enc: move v210_enc_8/10 function to template file
Signed-off-by: Limin Wang <lance.lmwang@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
5c0f80d26d
commit
c2ab998ff3
90
libavcodec/v210_template.c
Normal file
90
libavcodec/v210_template.c
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
|
||||
* Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
|
||||
*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "bytestream.h"
|
||||
#include "internal.h"
|
||||
|
||||
#define CLIP(v, depth) av_clip(v, 1<<(depth-8), ((1<<depth)-(1<<(depth-8))-1))
|
||||
#define WRITE_PIXELS(a, b, c, depth) \
|
||||
do { \
|
||||
val = CLIP(*a++, depth) << (10-depth); \
|
||||
val |= (CLIP(*b++, depth) << (20-depth)) | \
|
||||
(CLIP(*c++, depth) << (30-depth)); \
|
||||
AV_WL32(dst, val); \
|
||||
dst += 4; \
|
||||
} while (0)
|
||||
|
||||
static void RENAME(v210_enc)(AVCodecContext *avctx,
|
||||
uint8_t *dst, const AVFrame *pic)
|
||||
{
|
||||
V210EncContext *s = avctx->priv_data;
|
||||
int aligned_width = ((avctx->width + 47) / 48) * 48;
|
||||
int stride = aligned_width * 8 / 3;
|
||||
int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4;
|
||||
int h, w;
|
||||
const TYPE *y = (const TYPE *)pic->data[0];
|
||||
const TYPE *u = (const TYPE *)pic->data[1];
|
||||
const TYPE *v = (const TYPE *)pic->data[2];
|
||||
const int sample_size = 6 * s->RENAME(sample_factor);
|
||||
const int sample_w = avctx->width / sample_size;
|
||||
|
||||
for (h = 0; h < avctx->height; h++) {
|
||||
uint32_t val;
|
||||
w = sample_w * sample_size;
|
||||
s->RENAME(pack_line)(y, u, v, dst, w);
|
||||
|
||||
y += w;
|
||||
u += w >> 1;
|
||||
v += w >> 1;
|
||||
dst += sample_w * 16 * s->RENAME(sample_factor);
|
||||
|
||||
for (; w < avctx->width - 5; w += 6) {
|
||||
WRITE_PIXELS(u, y, v, DEPTH);
|
||||
WRITE_PIXELS(y, u, y, DEPTH);
|
||||
WRITE_PIXELS(v, y, u, DEPTH);
|
||||
WRITE_PIXELS(y, v, y, DEPTH);
|
||||
}
|
||||
if (w < avctx->width - 1) {
|
||||
WRITE_PIXELS(u, y, v, DEPTH);
|
||||
|
||||
val = CLIP(*y++, DEPTH) << (10-DEPTH);
|
||||
if (w == avctx->width - 2) {
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
if (w < avctx->width - 3) {
|
||||
val |= (CLIP(*u++, DEPTH) << (20-DEPTH)) | (CLIP(*y++, DEPTH) << (30-DEPTH));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
|
||||
val = CLIP(*v++, DEPTH) << (10-DEPTH) | (CLIP(*y++, DEPTH) << (20-DEPTH));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
|
||||
memset(dst, 0, line_padding);
|
||||
dst += line_padding;
|
||||
y += pic->linesize[0] / BYTES_PER_PIXEL - avctx->width;
|
||||
u += pic->linesize[1] / BYTES_PER_PIXEL - avctx->width / 2;
|
||||
v += pic->linesize[2] / BYTES_PER_PIXEL - avctx->width / 2;
|
||||
}
|
||||
}
|
@ -26,15 +26,25 @@
|
||||
#include "internal.h"
|
||||
#include "v210enc.h"
|
||||
|
||||
#define CLIP(v, depth) av_clip(v, 1 << (depth-8), ((1 << depth)-(1 << (depth-8)) -1))
|
||||
#define WRITE_PIXELS(a, b, c, depth) \
|
||||
do { \
|
||||
val = CLIP(*a++, depth) << (10-depth); \
|
||||
val |= (CLIP(*b++, depth) << (20-depth)) | \
|
||||
(CLIP(*c++, depth) << (30-depth)); \
|
||||
AV_WL32(dst, val); \
|
||||
dst += 4; \
|
||||
} while (0)
|
||||
#define TYPE uint8_t
|
||||
#define DEPTH 8
|
||||
#define BYTES_PER_PIXEL 1
|
||||
#define RENAME(a) a ## _ ## 8
|
||||
#include "v210_template.c"
|
||||
#undef RENAME
|
||||
#undef DEPTH
|
||||
#undef BYTES_PER_PIXEL
|
||||
#undef TYPE
|
||||
|
||||
#define TYPE uint16_t
|
||||
#define DEPTH 10
|
||||
#define BYTES_PER_PIXEL 2
|
||||
#define RENAME(a) a ## _ ## 10
|
||||
#include "v210_template.c"
|
||||
#undef RENAME
|
||||
#undef DEPTH
|
||||
#undef BYTES_PER_PIXEL
|
||||
#undef TYPE
|
||||
|
||||
static void v210_planar_pack_8_c(const uint8_t *y, const uint8_t *u,
|
||||
const uint8_t *v, uint8_t *dst,
|
||||
@ -108,12 +118,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
|
||||
static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
const AVFrame *pic, int *got_packet)
|
||||
{
|
||||
V210EncContext *s = avctx->priv_data;
|
||||
int aligned_width = ((avctx->width + 47) / 48) * 48;
|
||||
int stride = aligned_width * 8 / 3;
|
||||
int line_padding = stride - ((avctx->width * 8 + 11) / 12) * 4;
|
||||
AVFrameSideData *side_data;
|
||||
int h, w, ret;
|
||||
int ret;
|
||||
uint8_t *dst;
|
||||
|
||||
ret = ff_alloc_packet2(avctx, pkt, avctx->height * stride, avctx->height * stride);
|
||||
@ -123,105 +131,10 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
|
||||
}
|
||||
dst = pkt->data;
|
||||
|
||||
if (pic->format == AV_PIX_FMT_YUV422P10) {
|
||||
const uint16_t *y = (const uint16_t *)pic->data[0];
|
||||
const uint16_t *u = (const uint16_t *)pic->data[1];
|
||||
const uint16_t *v = (const uint16_t *)pic->data[2];
|
||||
|
||||
const int sample_size = 6 * s->sample_factor_10;
|
||||
const int sample_w = avctx->width / sample_size;
|
||||
|
||||
for (h = 0; h < avctx->height; h++) {
|
||||
uint32_t val;
|
||||
w = sample_w * sample_size;
|
||||
s->pack_line_10(y, u, v, dst, w);
|
||||
|
||||
y += w;
|
||||
u += w >> 1;
|
||||
v += w >> 1;
|
||||
dst += sample_w * 16 * s->sample_factor_10;
|
||||
|
||||
for (; w < avctx->width - 5; w += 6) {
|
||||
WRITE_PIXELS(u, y, v, 10);
|
||||
WRITE_PIXELS(y, u, y, 10);
|
||||
WRITE_PIXELS(v, y, u, 10);
|
||||
WRITE_PIXELS(y, v, y, 10);
|
||||
}
|
||||
if (w < avctx->width - 1) {
|
||||
WRITE_PIXELS(u, y, v, 10);
|
||||
|
||||
val = CLIP(*y++, 10) << (10-10);
|
||||
if (w == avctx->width - 2) {
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
if (w < avctx->width - 3) {
|
||||
val |= (CLIP(*u++, 10) << (20-10)) | (CLIP(*y++, 10) << (30-10));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
|
||||
val = CLIP(*v++, 10) << (10-10) | (CLIP(*y++, 10) << (20-10));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
|
||||
memset(dst, 0, line_padding);
|
||||
dst += line_padding;
|
||||
y += pic->linesize[0] / 2 - avctx->width;
|
||||
u += pic->linesize[1] / 2 - avctx->width / 2;
|
||||
v += pic->linesize[2] / 2 - avctx->width / 2;
|
||||
}
|
||||
} else if(pic->format == AV_PIX_FMT_YUV422P) {
|
||||
const uint8_t *y = pic->data[0];
|
||||
const uint8_t *u = pic->data[1];
|
||||
const uint8_t *v = pic->data[2];
|
||||
|
||||
const int sample_size = 6 * s->sample_factor_8;
|
||||
const int sample_w = avctx->width / sample_size;
|
||||
|
||||
for (h = 0; h < avctx->height; h++) {
|
||||
uint32_t val;
|
||||
w = sample_w * sample_size;
|
||||
s->pack_line_8(y, u, v, dst, w);
|
||||
|
||||
y += w;
|
||||
u += w >> 1;
|
||||
v += w >> 1;
|
||||
dst += sample_w * 16 * s->sample_factor_8;
|
||||
|
||||
for (; w < avctx->width - 5; w += 6) {
|
||||
WRITE_PIXELS(u, y, v, 8);
|
||||
WRITE_PIXELS(y, u, y, 8);
|
||||
WRITE_PIXELS(v, y, u, 8);
|
||||
WRITE_PIXELS(y, v, y, 8);
|
||||
}
|
||||
if (w < avctx->width - 1) {
|
||||
WRITE_PIXELS(u, y, v, 8);
|
||||
|
||||
val = CLIP(*y++, 8) << (10-8);
|
||||
if (w == avctx->width - 2) {
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
}
|
||||
if (w < avctx->width - 3) {
|
||||
val |= (CLIP(*u++, 8) << (20-8)) | (CLIP(*y++, 8) << (30-8));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
|
||||
val = (CLIP(*v++, 8) << (10-8)) | (CLIP(*y++, 8) << (20-8));
|
||||
AV_WL32(dst, val);
|
||||
dst += 4;
|
||||
}
|
||||
memset(dst, 0, line_padding);
|
||||
dst += line_padding;
|
||||
|
||||
y += pic->linesize[0] - avctx->width;
|
||||
u += pic->linesize[1] - avctx->width / 2;
|
||||
v += pic->linesize[2] - avctx->width / 2;
|
||||
}
|
||||
}
|
||||
if (pic->format == AV_PIX_FMT_YUV422P10)
|
||||
v210_enc_10(avctx, dst, pic);
|
||||
else if(pic->format == AV_PIX_FMT_YUV422P)
|
||||
v210_enc_8(avctx, dst, pic);
|
||||
|
||||
side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_A53_CC);
|
||||
if (side_data && side_data->size) {
|
||||
|
Loading…
Reference in New Issue
Block a user