Commit b5c3f0b9 authored by Jan Ekström's avatar Jan Ekström Committed by Derek Buitenhuis

utvideo: general cosmetics

General cosmetics, such as keeping lines under 80 characters,
fixing a couple of typos (predition -> prediction) and a
general style fix that was pointed out by Derek when I was having
my sliced multithreading patch in review by him.
Signed-off-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
parent 7eacd70f
...@@ -175,9 +175,10 @@ static int decode_plane(UtvideoContext *c, int plane_no, ...@@ -175,9 +175,10 @@ static int decode_plane(UtvideoContext *c, int plane_no,
continue; continue;
} }
memcpy(c->slice_bits, src + slice_data_start + c->slices * 4, slice_size); memcpy(c->slice_bits, src + slice_data_start + c->slices * 4,
slice_size);
memset(c->slice_bits + slice_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); memset(c->slice_bits + slice_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
c->dsp.bswap_buf((uint32_t*)c->slice_bits, (uint32_t*)c->slice_bits, c->dsp.bswap_buf((uint32_t *) c->slice_bits, (uint32_t *) c->slice_bits,
(slice_data_end - slice_data_start + 3) >> 2); (slice_data_end - slice_data_start + 3) >> 2);
init_get_bits(&gb, c->slice_bits, slice_size * 8); init_get_bits(&gb, c->slice_bits, slice_size * 8);
...@@ -185,7 +186,8 @@ static int decode_plane(UtvideoContext *c, int plane_no, ...@@ -185,7 +186,8 @@ static int decode_plane(UtvideoContext *c, int plane_no,
for (j = sstart; j < send; j++) { for (j = sstart; j < send; j++) {
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
if (get_bits_left(&gb) <= 0) { if (get_bits_left(&gb) <= 0) {
av_log(c->avctx, AV_LOG_ERROR, "Slice decoding ran out of bits\n"); av_log(c->avctx, AV_LOG_ERROR,
"Slice decoding ran out of bits\n");
goto fail; goto fail;
} }
pix = get_vlc2(&gb, vlc.table, vlc.bits, 4); pix = get_vlc2(&gb, vlc.table, vlc.bits, 4);
...@@ -202,8 +204,8 @@ static int decode_plane(UtvideoContext *c, int plane_no, ...@@ -202,8 +204,8 @@ static int decode_plane(UtvideoContext *c, int plane_no,
dest += stride; dest += stride;
} }
if (get_bits_left(&gb) > 32) if (get_bits_left(&gb) > 32)
av_log(c->avctx, AV_LOG_WARNING, "%d bits left after decoding slice\n", av_log(c->avctx, AV_LOG_WARNING,
get_bits_left(&gb)); "%d bits left after decoding slice\n", get_bits_left(&gb));
} }
ff_free_vlc(&vlc); ff_free_vlc(&vlc);
...@@ -216,7 +218,8 @@ fail: ...@@ -216,7 +218,8 @@ fail:
static const int rgb_order[4] = { 1, 2, 0, 3 }; static const int rgb_order[4] = { 1, 2, 0, 3 };
static void restore_rgb_planes(uint8_t *src, int step, int stride, int width, int height) static void restore_rgb_planes(uint8_t *src, int step, int stride, int width,
int height)
{ {
int i, j; int i, j;
uint8_t r, g, b; uint8_t r, g, b;
...@@ -243,8 +246,9 @@ static void restore_median(uint8_t *src, int step, int stride, ...@@ -243,8 +246,9 @@ static void restore_median(uint8_t *src, int step, int stride,
const int cmask = ~rmode; const int cmask = ~rmode;
for (slice = 0; slice < slices; slice++) { for (slice = 0; slice < slices; slice++) {
slice_start = ((slice * height) / slices) & cmask; slice_start = ((slice * height) / slices) & cmask;
slice_height = ((((slice + 1) * height) / slices) & cmask) - slice_start; slice_height = ((((slice + 1) * height) / slices) & cmask) -
slice_start;
bsrc = src + slice_start * stride; bsrc = src + slice_start * stride;
...@@ -253,29 +257,29 @@ static void restore_median(uint8_t *src, int step, int stride, ...@@ -253,29 +257,29 @@ static void restore_median(uint8_t *src, int step, int stride,
A = bsrc[0]; A = bsrc[0];
for (i = step; i < width * step; i += step) { for (i = step; i < width * step; i += step) {
bsrc[i] += A; bsrc[i] += A;
A = bsrc[i]; A = bsrc[i];
} }
bsrc += stride; bsrc += stride;
if (slice_height == 1) if (slice_height == 1)
continue; continue;
// second line - first element has top predition, the rest uses median // second line - first element has top prediction, the rest uses median
C = bsrc[-stride]; C = bsrc[-stride];
bsrc[0] += C; bsrc[0] += C;
A = bsrc[0]; A = bsrc[0];
for (i = step; i < width * step; i += step) { for (i = step; i < width * step; i += step) {
B = bsrc[i - stride]; B = bsrc[i - stride];
bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[i]; A = bsrc[i];
} }
bsrc += stride; bsrc += stride;
// the rest of lines use continuous median prediction // the rest of lines use continuous median prediction
for (j = 2; j < slice_height; j++) { for (j = 2; j < slice_height; j++) {
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
B = bsrc[i - stride]; B = bsrc[i - stride];
bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[i]; A = bsrc[i];
} }
bsrc += stride; bsrc += stride;
} }
...@@ -293,67 +297,69 @@ static void restore_median_il(uint8_t *src, int step, int stride, ...@@ -293,67 +297,69 @@ static void restore_median_il(uint8_t *src, int step, int stride,
int A, B, C; int A, B, C;
uint8_t *bsrc; uint8_t *bsrc;
int slice_start, slice_height; int slice_start, slice_height;
const int cmask = ~(rmode ? 3 : 1); const int cmask = ~(rmode ? 3 : 1);
const int stride2 = stride << 1; const int stride2 = stride << 1;
for (slice = 0; slice < slices; slice++) { for (slice = 0; slice < slices; slice++) {
slice_start = ((slice * height) / slices) & cmask; slice_start = ((slice * height) / slices) & cmask;
slice_height = ((((slice + 1) * height) / slices) & cmask) - slice_start; slice_height = ((((slice + 1) * height) / slices) & cmask) -
slice_start;
slice_height >>= 1; slice_height >>= 1;
bsrc = src + slice_start * stride; bsrc = src + slice_start * stride;
// first line - left neighbour prediction // first line - left neighbour prediction
bsrc[0] += 0x80; bsrc[0] += 0x80;
A = bsrc[0]; A = bsrc[0];
for (i = step; i < width * step; i += step) { for (i = step; i < width * step; i += step) {
bsrc[i] += A; bsrc[i] += A;
A = bsrc[i]; A = bsrc[i];
} }
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
bsrc[stride + i] += A; bsrc[stride + i] += A;
A = bsrc[stride + i]; A = bsrc[stride + i];
} }
bsrc += stride2; bsrc += stride2;
if (slice_height == 1) if (slice_height == 1)
continue; continue;
// second line - first element has top predition, the rest uses median // second line - first element has top prediction, the rest uses median
C = bsrc[-stride2]; C = bsrc[-stride2];
bsrc[0] += C; bsrc[0] += C;
A = bsrc[0]; A = bsrc[0];
for (i = step; i < width * step; i += step) { for (i = step; i < width * step; i += step) {
B = bsrc[i - stride2]; B = bsrc[i - stride2];
bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[i]; A = bsrc[i];
} }
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
B = bsrc[i - stride]; B = bsrc[i - stride];
bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[stride + i]; A = bsrc[stride + i];
} }
bsrc += stride2; bsrc += stride2;
// the rest of lines use continuous median prediction // the rest of lines use continuous median prediction
for (j = 2; j < slice_height; j++) { for (j = 2; j < slice_height; j++) {
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
B = bsrc[i - stride2]; B = bsrc[i - stride2];
bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[i]; A = bsrc[i];
} }
for (i = 0; i < width * step; i += step) { for (i = 0; i < width * step; i += step) {
B = bsrc[i - stride]; B = bsrc[i - stride];
bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C)); bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C));
C = B; C = B;
A = bsrc[i + stride]; A = bsrc[i + stride];
} }
bsrc += stride2; bsrc += stride2;
} }
} }
} }
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{ {
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
...@@ -376,7 +382,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -376,7 +382,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
ff_thread_finish_setup(avctx); ff_thread_finish_setup(avctx);
/* parse plane structure to retrieve frame flags and validate slice offsets */ /* parse plane structure to get frame flags and validate slice offsets */
bytestream2_init(&gb, buf, buf_size); bytestream2_init(&gb, buf, buf_size);
for (i = 0; i < c->planes; i++) { for (i = 0; i < c->planes; i++) {
plane_start[i] = gb.buffer; plane_start[i] = gb.buffer;
...@@ -443,8 +449,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -443,8 +449,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
break; break;
case PIX_FMT_YUV420P: case PIX_FMT_YUV420P:
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
ret = decode_plane(c, i, c->pic.data[i], 1, ret = decode_plane(c, i, c->pic.data[i], 1, c->pic.linesize[i],
c->pic.linesize[i], avctx->width >> !!i, avctx->height >> !!i, avctx->width >> !!i, avctx->height >> !!i,
plane_start[i], c->frame_pred == PRED_LEFT); plane_start[i], c->frame_pred == PRED_LEFT);
if (ret) if (ret)
return ret; return ret;
...@@ -464,8 +470,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ...@@ -464,8 +470,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
break; break;
case PIX_FMT_YUV422P: case PIX_FMT_YUV422P:
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
ret = decode_plane(c, i, c->pic.data[i], 1, ret = decode_plane(c, i, c->pic.data[i], 1, c->pic.linesize[i],
c->pic.linesize[i], avctx->width >> !!i, avctx->height, avctx->width >> !!i, avctx->height,
plane_start[i], c->frame_pred == PRED_LEFT); plane_start[i], c->frame_pred == PRED_LEFT);
if (ret) if (ret)
return ret; return ret;
...@@ -502,7 +508,8 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -502,7 +508,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
ff_dsputil_init(&c->dsp, avctx); ff_dsputil_init(&c->dsp, avctx);
if (avctx->extradata_size < 16) { if (avctx->extradata_size < 16) {
av_log(avctx, AV_LOG_ERROR, "Insufficient extradata size %d, should be at least 16\n", av_log(avctx, AV_LOG_ERROR,
"Insufficient extradata size %d, should be at least 16\n",
avctx->extradata_size); avctx->extradata_size);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
...@@ -510,7 +517,8 @@ static av_cold int decode_init(AVCodecContext *avctx) ...@@ -510,7 +517,8 @@ static av_cold int decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n", av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n",
avctx->extradata[3], avctx->extradata[2], avctx->extradata[3], avctx->extradata[2],
avctx->extradata[1], avctx->extradata[0]); avctx->extradata[1], avctx->extradata[0]);
av_log(avctx, AV_LOG_DEBUG, "Original format %X\n", AV_RB32(avctx->extradata + 4)); av_log(avctx, AV_LOG_DEBUG, "Original format %X\n",
AV_RB32(avctx->extradata + 4));
c->frame_info_size = AV_RL32(avctx->extradata + 8); c->frame_info_size = AV_RL32(avctx->extradata + 8);
c->flags = AV_RL32(avctx->extradata + 12); c->flags = AV_RL32(avctx->extradata + 12);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment