aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-01-14 15:45:05 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-01-14 15:45:05 +0100
commit92b238715929a26d77e99a18fe5996bcb5796149 (patch)
treeea683bd86b4609f3aa5386980cb5c5f24d426799 /libavcodec
parentf9d5bdd0f6526e852ec37528c9b5f97beb71ef07 (diff)
parentdf9036830b15997a3e9c3f2c632ed98d64f9deef (diff)
downloadffmpeg-92b238715929a26d77e99a18fe5996bcb5796149.tar.gz
Merge commit 'df9036830b15997a3e9c3f2c632ed98d64f9deef'
* commit 'df9036830b15997a3e9c3f2c632ed98d64f9deef': truemotion2: return meaningful error codes. tscc: remove some pointless comments and empty lines. tscc: return meaningful error codes. loco: cosmetics, reformat Conflicts: libavcodec/truemotion2.c libavcodec/tscc.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/loco.c78
-rw-r--r--libavcodec/truemotion2.c51
-rw-r--r--libavcodec/tscc.c31
3 files changed, 75 insertions, 85 deletions
diff --git a/libavcodec/loco.c b/libavcodec/loco.c
index b530fd6503..93377e2220 100644
--- a/libavcodec/loco.c
+++ b/libavcodec/loco.c
@@ -30,29 +30,39 @@
#include "internal.h"
#include "mathops.h"
-enum LOCO_MODE {LOCO_UNKN=0, LOCO_CYUY2=-1, LOCO_CRGB=-2, LOCO_CRGBA=-3, LOCO_CYV12=-4,
- LOCO_YUY2=1, LOCO_UYVY=2, LOCO_RGB=3, LOCO_RGBA=4, LOCO_YV12=5};
+enum LOCO_MODE {
+ LOCO_UNKN = 0,
+ LOCO_CYUY2 = -1,
+ LOCO_CRGB = -2,
+ LOCO_CRGBA = -3,
+ LOCO_CYV12 = -4,
+ LOCO_YUY2 = 1,
+ LOCO_UYVY = 2,
+ LOCO_RGB = 3,
+ LOCO_RGBA = 4,
+ LOCO_YV12 = 5,
+};
-typedef struct LOCOContext{
+typedef struct LOCOContext {
AVCodecContext *avctx;
AVFrame pic;
int lossy;
int mode;
} LOCOContext;
-typedef struct RICEContext{
+typedef struct RICEContext {
GetBitContext gb;
int save, run, run2; /* internal rice decoder state */
int sum, count; /* sum and count for getting rice parameter */
int lossy;
-}RICEContext;
+} RICEContext;
static int loco_get_rice_param(RICEContext *r)
{
int cnt = 0;
int val = r->count;
- while(r->sum > val && cnt < 9) {
+ while (r->sum > val && cnt < 9) {
val <<= 1;
cnt++;
}
@@ -65,8 +75,8 @@ static inline void loco_update_rice_param(RICEContext *r, int val)
r->sum += val;
r->count++;
- if(r->count == 16) {
- r->sum >>= 1;
+ if (r->count == 16) {
+ r->sum >>= 1;
r->count >>= 1;
}
}
@@ -80,19 +90,18 @@ static inline int loco_get_rice(RICEContext *r)
return 0;
}
v = get_ur_golomb_jpegls(&r->gb, loco_get_rice_param(r), INT_MAX, 0);
- loco_update_rice_param(r, (v+1)>>1);
+ loco_update_rice_param(r, (v + 1) >> 1);
if (!v) {
if (r->save >= 0) {
r->run = get_ur_golomb_jpegls(&r->gb, 2, INT_MAX, 0);
- if(r->run > 1)
+ if (r->run > 1)
r->save += r->run + 1;
else
r->save -= 3;
- }
- else
+ } else
r->run2++;
} else {
- v = ((v>>1) + r->lossy) ^ -(v&1);
+ v = ((v >> 1) + r->lossy) ^ -(v & 1);
if (r->run2 > 0) {
if (r->run2 > 2)
r->save += r->run2;
@@ -128,16 +137,16 @@ static int loco_decode_plane(LOCOContext *l, uint8_t *data, int width, int heigh
return -1;
init_get_bits(&rc.gb, buf, buf_size*8);
- rc.save = 0;
- rc.run = 0;
- rc.run2 = 0;
+ rc.save = 0;
+ rc.run = 0;
+ rc.run2 = 0;
rc.lossy = l->lossy;
- rc.sum = 8;
+ rc.sum = 8;
rc.count = 1;
/* restore top left pixel */
- val = loco_get_rice(&rc);
+ val = loco_get_rice(&rc);
data[0] = 128 + val;
/* restore top line */
for (i = 1; i < width; i++) {
@@ -164,13 +173,13 @@ static int decode_frame(AVCodecContext *avctx,
void *data, int *got_frame,
AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
- int buf_size = avpkt->size;
LOCOContext * const l = avctx->priv_data;
- AVFrame * const p = &l->pic;
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
+ AVFrame * const p = &l->pic;
int decoded, ret;
- if(p->data[0])
+ if (p->data[0])
avctx->release_buffer(avctx, p);
p->reference = 0;
@@ -237,7 +246,8 @@ stop:
return buf_size < 0 ? -1 : avpkt->size - buf_size;
}
-static av_cold int decode_init(AVCodecContext *avctx){
+static av_cold int decode_init(AVCodecContext *avctx)
+{
LOCOContext * const l = avctx->priv_data;
int version;
@@ -248,7 +258,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
return AVERROR_INVALIDDATA;
}
version = AV_RL32(avctx->extradata);
- switch(version) {
+ switch (version) {
case 1:
l->lossy = 0;
break;
@@ -261,24 +271,29 @@ static av_cold int decode_init(AVCodecContext *avctx){
}
l->mode = AV_RL32(avctx->extradata + 4);
- switch(l->mode) {
- case LOCO_CYUY2: case LOCO_YUY2: case LOCO_UYVY:
+ switch (l->mode) {
+ case LOCO_CYUY2:
+ case LOCO_YUY2:
+ case LOCO_UYVY:
avctx->pix_fmt = AV_PIX_FMT_YUV422P;
break;
- case LOCO_CRGB: case LOCO_RGB:
+ case LOCO_CRGB:
+ case LOCO_RGB:
avctx->pix_fmt = AV_PIX_FMT_BGR24;
break;
- case LOCO_CYV12: case LOCO_YV12:
+ case LOCO_CYV12:
+ case LOCO_YV12:
avctx->pix_fmt = AV_PIX_FMT_YUV420P;
break;
- case LOCO_CRGBA: case LOCO_RGBA:
+ case LOCO_CRGBA:
+ case LOCO_RGBA:
avctx->pix_fmt = AV_PIX_FMT_RGB32;
break;
default:
av_log(avctx, AV_LOG_INFO, "Unknown colorspace, index = %i\n", l->mode);
return AVERROR_INVALIDDATA;
}
- if(avctx->debug & FF_DEBUG_PICT_INFO)
+ if (avctx->debug & FF_DEBUG_PICT_INFO)
av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode);
avcodec_get_frame_defaults(&l->pic);
@@ -286,7 +301,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
return 0;
}
-static av_cold int decode_end(AVCodecContext *avctx){
+static av_cold int decode_end(AVCodecContext *avctx)
+{
LOCOContext * const l = avctx->priv_data;
AVFrame *pic = &l->pic;
diff --git a/libavcodec/truemotion2.c b/libavcodec/truemotion2.c
index 5ba2cf10e7..82e4ec2c9c 100644
--- a/libavcodec/truemotion2.c
+++ b/libavcodec/truemotion2.c
@@ -93,9 +93,10 @@ typedef struct TM2Huff{
static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *huff)
{
+ int ret;
if(length > huff->max_bits) {
av_log(ctx->avctx, AV_LOG_ERROR, "Tree exceeded its given depth (%i)\n", huff->max_bits);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if(!get_bits1(&ctx->gb)) { /* literal */
@@ -104,7 +105,7 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *
}
if(huff->num >= huff->max_num) {
av_log(ctx->avctx, AV_LOG_DEBUG, "Too many literals\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
huff->nums[huff->num] = get_bits_long(&ctx->gb, huff->val_bits);
huff->bits[huff->num] = prefix;
@@ -112,10 +113,10 @@ static int tm2_read_tree(TM2Context *ctx, uint32_t prefix, int length, TM2Huff *
huff->num++;
return 0;
} else { /* non-terminal node */
- if(tm2_read_tree(ctx, prefix << 1, length + 1, huff) == -1)
- return -1;
- if(tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff) == -1)
- return -1;
+ if ((ret = tm2_read_tree(ctx, prefix << 1, length + 1, huff)) < 0)
+ return ret;
+ if ((ret = tm2_read_tree(ctx, (prefix << 1) | 1, length + 1, huff)) < 0)
+ return ret;
}
return 0;
}
@@ -136,11 +137,11 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
(huff.max_bits < 0) || (huff.max_bits > 25)) {
av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect tree parameters - literal length: %i, max code length: %i\n",
huff.val_bits, huff.max_bits);
- return -1;
+ return AVERROR_INVALIDDATA;
}
if((huff.nodes <= 0) || (huff.nodes > 0x10000)) {
av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes);
- return -1;
+ return AVERROR_INVALIDDATA;
}
/* one-node tree */
if(huff.max_bits == 0)
@@ -152,28 +153,24 @@ static int tm2_build_huff_table(TM2Context *ctx, TM2Codes *code)
huff.bits = av_mallocz(huff.max_num * sizeof(uint32_t));
huff.lens = av_mallocz(huff.max_num * sizeof(int));
- if(tm2_read_tree(ctx, 0, 0, &huff) == -1)
- res = -1;
+ res = tm2_read_tree(ctx, 0, 0, &huff);
- if(huff.num != huff.max_num) {
+ if (huff.num != huff.max_num) {
av_log(ctx->avctx, AV_LOG_ERROR, "Got less codes than expected: %i of %i\n",
huff.num, huff.max_num);
- res = -1;
+ res = AVERROR_INVALIDDATA;
}
/* convert codes to vlc_table */
- if(res != -1) {
+ if(res >= 0) {
int i;
res = init_vlc(&code->vlc, huff.max_bits, huff.max_num,
huff.lens, sizeof(int), sizeof(int),
huff.bits, sizeof(uint32_t), sizeof(uint32_t), 0);
- if(res < 0) {
+ if(res < 0)
av_log(ctx->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
- res = -1;
- } else
- res = 0;
- if(res != -1) {
+ else {
code->bits = huff.max_bits;
code->length = huff.max_num;
code->recode = av_malloc(code->length * sizeof(int));
@@ -233,7 +230,7 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
if((d < 1) || (d > TM2_DELTAS) || (mb < 1) || (mb > 32)) {
av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect delta table: %i deltas x %i bits\n", d, mb);
- return -1;
+ return AVERROR_INVALIDDATA;
}
for(i = 0; i < d; i++) {
@@ -251,7 +248,7 @@ static int tm2_read_deltas(TM2Context *ctx, int stream_id) {
static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, int buf_size)
{
- int i;
+ int i, ret;
int skip = 0;
int len, toks, pos;
TM2Codes codes;
@@ -286,8 +283,8 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
if (skip <= pos)
return AVERROR_INVALIDDATA;
init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
- if(tm2_read_deltas(ctx, stream_id) == -1)
- return AVERROR_INVALIDDATA;
+ if ((ret = tm2_read_deltas(ctx, stream_id)) < 0)
+ return ret;
bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
}
}
@@ -303,8 +300,8 @@ static int tm2_read_stream(TM2Context *ctx, const uint8_t *buf, int stream_id, i
if (skip <= pos)
return AVERROR_INVALIDDATA;
init_get_bits(&ctx->gb, buf + pos, (skip - pos) * 8);
- if(tm2_build_huff_table(ctx, &codes) == -1)
- return AVERROR_INVALIDDATA;
+ if ((ret = tm2_build_huff_table(ctx, &codes)) < 0)
+ return ret;
bytestream2_skip(&gb, ((get_bits_count(&ctx->gb) + 31) >> 5) << 2);
toks >>= 1;
@@ -720,7 +717,7 @@ static int tm2_decode_blocks(TM2Context *ctx, AVFrame *p)
if (ctx->tok_lens[TM2_TYPE]<bw*bh){
av_log(ctx->avctx,AV_LOG_ERROR,"Got %i tokens for %i blocks\n",ctx->tok_lens[TM2_TYPE],bw*bh);
- return -1;
+ return AVERROR_INVALIDDATA;
}
memset(ctx->last, 0, 4 * bw * sizeof(int));
@@ -845,7 +842,7 @@ static int decode_frame(AVCodecContext *avctx,
}
p->reference = 3;
p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
- if((ret = avctx->reget_buffer(avctx, p)) < 0){
+ if ((ret = avctx->reget_buffer(avctx, p)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
@@ -888,7 +885,7 @@ static av_cold int decode_init(AVCodecContext *avctx){
if((avctx->width & 3) || (avctx->height & 3)){
av_log(avctx, AV_LOG_ERROR, "Width and height must be multiple of 4\n");
- return AVERROR_INVALIDDATA;
+ return AVERROR(EINVAL);
}
l->avctx = avctx;
diff --git a/libavcodec/tscc.c b/libavcodec/tscc.c
index 2aca0ba3b0..7c2d2319bb 100644
--- a/libavcodec/tscc.c
+++ b/libavcodec/tscc.c
@@ -44,10 +44,6 @@
#include <zlib.h>
-
-/*
- * Decoder context
- */
typedef struct TsccContext {
AVCodecContext *avctx;
@@ -66,11 +62,6 @@ typedef struct TsccContext {
uint32_t pal[256];
} CamtasiaContext;
-/*
- *
- * Decode a frame
- *
- */
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt)
{
@@ -83,7 +74,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
c->pic.reference = 3;
c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if((ret = avctx->reget_buffer(avctx, &c->pic)) < 0){
+ if ((ret = avctx->reget_buffer(avctx, &c->pic)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret;
}
@@ -91,7 +82,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
zret = inflateReset(&c->zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret);
- return AVERROR(EINVAL);
+ return AVERROR_UNKNOWN;
}
c->zstream.next_in = (uint8_t*)encoded;
c->zstream.avail_in = len;
@@ -101,7 +92,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
// Z_DATA_ERROR means empty picture
if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) {
av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret);
- return AVERROR(EINVAL);
+ return AVERROR_UNKNOWN;
}
@@ -129,13 +120,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
return buf_size;
}
-
-
-/*
- *
- * Init tscc decoder
- *
- */
static av_cold int decode_init(AVCodecContext *avctx)
{
CamtasiaContext * const c = avctx->priv_data;
@@ -176,19 +160,12 @@ static av_cold int decode_init(AVCodecContext *avctx)
zret = inflateInit(&c->zstream);
if (zret != Z_OK) {
av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret);
- return AVERROR(ENOMEM);
+ return AVERROR_UNKNOWN;
}
return 0;
}
-
-
-/*
- *
- * Uninit tscc decoder
- *
- */
static av_cold int decode_end(AVCodecContext *avctx)
{
CamtasiaContext * const c = avctx->priv_data;