annotate aura.c @ 12385:d0b25641338b libavcodec

VP5/6/8: ~7% faster arithmetic decoding Grab from the bitstream in 16-bit chunks instead of 8-bit chunks. TODO: grab in 32-bit chunks on 64-bit systems.
author darkshikari
date Thu, 12 Aug 2010 01:11:32 +0000
parents 7dd2a45249a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10707
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
1 /*
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
2 * Aura 2 decoder
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
3 *
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
4 * This file is part of FFmpeg.
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
5 *
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
10 *
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
14 * Lesser General Public License for more details.
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
15 *
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
19 */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
20
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
21 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11560
diff changeset
22 * @file
10707
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
23 * Aura 2 decoder
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
24 */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
25
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
26 #include "avcodec.h"
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
27
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
28 typedef struct AuraDecodeContext {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
29 AVCodecContext *avctx;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
30 AVFrame frame;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
31 } AuraDecodeContext;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
32
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
33 static av_cold int aura_decode_init(AVCodecContext *avctx)
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
34 {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
35 AuraDecodeContext *s = avctx->priv_data;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
36
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
37 s->avctx = avctx;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
38 /* width needs to be divisible by 4 for this codec to work */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
39 if (avctx->width & 0x3)
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
40 return -1;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
41 avctx->pix_fmt = PIX_FMT_YUV422P;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
42
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
43 return 0;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
44 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
45
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
46 static int aura_decode_frame(AVCodecContext *avctx,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
47 void *data, int *data_size,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
48 AVPacket *pkt)
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
49 {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
50 AuraDecodeContext *s=avctx->priv_data;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
51
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
52 uint8_t *Y, *U, *V;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
53 uint8_t val;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
54 int x, y;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
55 const uint8_t *buf = pkt->data;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
56
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
57 /* prediction error tables (make it clear that they are signed values) */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
58 const int8_t *delta_table = (const int8_t*)buf + 16;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
59
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
60 if (pkt->size != 48 + avctx->height * avctx->width) {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
61 av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n",
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
62 pkt->size, 48 + avctx->height * avctx->width);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
63 return -1;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
64 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
65
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
66 /* pixel data starts 48 bytes in, after 3x16-byte tables */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
67 buf += 48;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
68
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
69 if(s->frame.data[0])
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
70 avctx->release_buffer(avctx, &s->frame);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
71
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
72 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
73 s->frame.reference = 0;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
74 if(avctx->get_buffer(avctx, &s->frame) < 0) {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
75 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
76 return -1;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
77 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
78
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
79 Y = s->frame.data[0];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
80 U = s->frame.data[1];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
81 V = s->frame.data[2];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
82
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
83 /* iterate through each line in the height */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
84 for (y = 0; y < avctx->height; y++) {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
85 /* reset predictors */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
86 val = *buf++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
87 U[0] = val & 0xF0;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
88 Y[0] = val << 4;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
89 val = *buf++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
90 V[0] = val & 0xF0;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
91 Y[1] = Y[0] + delta_table[val & 0xF];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
92 Y += 2; U++; V++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
93
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
94 /* iterate through the remaining pixel groups (4 pixels/group) */
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
95 for (x = 1; x < (avctx->width >> 1); x++) {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
96 val = *buf++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
97 U[0] = U[-1] + delta_table[val >> 4];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
98 Y[0] = Y[-1] + delta_table[val & 0xF];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
99 val = *buf++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
100 V[0] = V[-1] + delta_table[val >> 4];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
101 Y[1] = Y[ 0] + delta_table[val & 0xF];
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
102 Y += 2; U++; V++;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
103 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
104 Y += s->frame.linesize[0] - avctx->width;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
105 U += s->frame.linesize[1] - (avctx->width >> 1);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
106 V += s->frame.linesize[2] - (avctx->width >> 1);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
107 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
108
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
109 *data_size=sizeof(AVFrame);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
110 *(AVFrame*)data= s->frame;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
111
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
112 return pkt->size;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
113 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
114
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
115 static av_cold int aura_decode_end(AVCodecContext *avctx)
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
116 {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
117 AuraDecodeContext *s = avctx->priv_data;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
118
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
119 if (s->frame.data[0])
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
120 avctx->release_buffer(avctx, &s->frame);
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
121
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
122 return 0;
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
123 }
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
124
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
125 AVCodec aura2_decoder = {
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
126 "aura2",
11560
8a4984c5cacc Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 10707
diff changeset
127 AVMEDIA_TYPE_VIDEO,
10707
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
128 CODEC_ID_AURA2,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
129 sizeof(AuraDecodeContext),
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
130 aura_decode_init,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
131 NULL,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
132 aura_decode_end,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
133 aura_decode_frame,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
134 CODEC_CAP_DR1,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
135 NULL,
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
136 .long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"),
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
137 };
6e3c41fb2eb7 Auravision Aura 2 decoder
kostya
parents:
diff changeset
138