annotate roqvideodec.c @ 5095:ed41cfae128d libavcodec

Codebook generator using the ELBG algorithm patch by Vitor: printf(vitor%d gmail com, 1001) original thread: Re: [FFmpeg-devel] [PATCH] Add a codebook generator (was: [PATCH] RoQ video encoder, take 2) date: 05/28/2007 01:21 PM
author benoit
date Mon, 04 Jun 2007 07:28:34 +0000
parents 20914da7d71b
children 133329117637
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
1 /*
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
2 * Copyright (C) 2003 the ffmpeg project
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
3 *
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
4 * This file is part of FFmpeg.
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
5 *
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
10 *
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
14 * Lesser General Public License for more details.
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
15 *
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
19 *
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
20 */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
21
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
22 /**
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
23 * @file roqvideodec.c
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
24 * Id RoQ Video Decoder by Dr. Tim Ferguson
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
25 * For more information about the Id RoQ format, visit:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
26 * http://www.csse.monash.edu.au/~timf/
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
27 */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
28
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
29 #include <stdio.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
30 #include <stdlib.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
31 #include <string.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
32 #include <unistd.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
33
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
34 #include "avcodec.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
35 #include "bytestream.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
36 #include "dsputil.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
37 #include "roqvideo.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
38
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
39 #define avg2(a,b) av_clip_uint8(((int)(a)+(int)(b)+1)>>1)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
40 #define avg4(a,b,c,d) av_clip_uint8(((int)(a)+(int)(b)+(int)(c)+(int)(d)+2)>>2)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
41
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
42 static void roqvideo_decode_frame(RoqContext *ri)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
43 {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
44 unsigned int chunk_id = 0, chunk_arg = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
45 unsigned long chunk_size = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
46 int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
47 int vqid, bpos, xpos, ypos, xp, yp, x, y, mx, my;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
48 int frame_stats[2][4] = {{0},{0}};
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
49 roq_qcell *qcell;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
50 unsigned char *buf = ri->buf;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
51 unsigned char *buf_end = ri->buf + ri->size;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
52
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
53 while (buf < buf_end) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
54 chunk_id = bytestream_get_le16(&buf);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
55 chunk_size = bytestream_get_le32(&buf);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
56 chunk_arg = bytestream_get_le16(&buf);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
57
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
58 if(chunk_id == RoQ_QUAD_VQ)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
59 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
60 if(chunk_id == RoQ_QUAD_CODEBOOK) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
61 if((nv1 = chunk_arg >> 8) == 0)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
62 nv1 = 256;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
63 if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
64 nv2 = 256;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
65 for(i = 0; i < nv1; i++) {
5090
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
66 ri->cells[i].y[0] = *buf++;
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
67 ri->cells[i].y[1] = *buf++;
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
68 ri->cells[i].y[2] = *buf++;
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
69 ri->cells[i].y[3] = *buf++;
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
70 ri->cells[i].u = *buf++;
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
71 ri->cells[i].v = *buf++;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
72 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
73 for(i = 0; i < nv2; i++)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
74 for(j = 0; j < 4; j++)
5090
20914da7d71b Remove get_byte wrapper
ramiro
parents: 5088
diff changeset
75 ri->qcells[i].idx[j] = *buf++;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
76 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
77 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
78
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
79 bpos = xpos = ypos = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
80 while(bpos < chunk_size) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
81 for (yp = ypos; yp < ypos + 16; yp += 8)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
82 for (xp = xpos; xp < xpos + 16; xp += 8) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
83 if (vqflg_pos < 0) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
84 vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
85 vqflg_pos = 7;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
86 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
87 vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
88 frame_stats[0][vqid]++;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
89 vqflg_pos--;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
90
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
91 switch(vqid) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
92 case RoQ_ID_MOT:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
93 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
94 case RoQ_ID_FCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
95 mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8));
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
96 my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
97 ff_apply_motion_8x8(ri, xp, yp, mx, my);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
98 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
99 case RoQ_ID_SLD:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
100 qcell = ri->qcells + buf[bpos++];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
101 ff_apply_vector_4x4(ri, xp, yp, ri->cells + qcell->idx[0]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
102 ff_apply_vector_4x4(ri, xp+4, yp, ri->cells + qcell->idx[1]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
103 ff_apply_vector_4x4(ri, xp, yp+4, ri->cells + qcell->idx[2]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
104 ff_apply_vector_4x4(ri, xp+4, yp+4, ri->cells + qcell->idx[3]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
105 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
106 case RoQ_ID_CCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
107 for (k = 0; k < 4; k++) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
108 x = xp; y = yp;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
109 if(k & 0x01) x += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
110 if(k & 0x02) y += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
111
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
112 if (vqflg_pos < 0) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
113 vqflg = buf[bpos++];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
114 vqflg |= (buf[bpos++] << 8);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
115 vqflg_pos = 7;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
116 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
117 vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
118 frame_stats[1][vqid]++;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
119 vqflg_pos--;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
120 switch(vqid) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
121 case RoQ_ID_MOT:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
122 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
123 case RoQ_ID_FCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
124 mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8));
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
125 my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
126 ff_apply_motion_4x4(ri, x, y, mx, my);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
127 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
128 case RoQ_ID_SLD:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
129 qcell = ri->qcells + buf[bpos++];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
130 ff_apply_vector_2x2(ri, x, y, ri->cells + qcell->idx[0]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
131 ff_apply_vector_2x2(ri, x+2, y, ri->cells + qcell->idx[1]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
132 ff_apply_vector_2x2(ri, x, y+2, ri->cells + qcell->idx[2]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
133 ff_apply_vector_2x2(ri, x+2, y+2, ri->cells + qcell->idx[3]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
134 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
135 case RoQ_ID_CCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
136 ff_apply_vector_2x2(ri, x, y, ri->cells + buf[bpos]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
137 ff_apply_vector_2x2(ri, x+2, y, ri->cells + buf[bpos+1]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
138 ff_apply_vector_2x2(ri, x, y+2, ri->cells + buf[bpos+2]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
139 ff_apply_vector_2x2(ri, x+2, y+2, ri->cells + buf[bpos+3]);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
140 bpos += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
141 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
142 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
143 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
144 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
145 default:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
146 av_log(ri->avctx, AV_LOG_ERROR, "Unknown vq code: %d\n", vqid);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
147 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
148 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
149
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
150 xpos += 16;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
151 if (xpos >= ri->avctx->width) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
152 xpos -= ri->avctx->width;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
153 ypos += 16;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
154 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
155 if(ypos >= ri->avctx->height)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
156 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
157 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
158 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
159
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
160
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
161 static int roq_decode_init(AVCodecContext *avctx)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
162 {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
163 RoqContext *s = avctx->priv_data;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
164
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
165 s->avctx = avctx;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
166 s->last_frame = &s->frames[0];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
167 s->current_frame = &s->frames[1];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
168 avctx->pix_fmt = PIX_FMT_YUV420P;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
169 dsputil_init(&s->dsp, avctx);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
170
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
171 return 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
172 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
173
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
174 static int roq_decode_frame(AVCodecContext *avctx,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
175 void *data, int *data_size,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
176 uint8_t *buf, int buf_size)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
177 {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
178 RoqContext *s = avctx->priv_data;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
179
5088
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
180 if (avctx->reget_buffer(avctx, s->current_frame)) {
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
181 av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n");
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
182 return -1;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
183 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
184 s->y_stride = s->current_frame->linesize[0];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
185 s->c_stride = s->current_frame->linesize[1];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
186
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
187 s->buf = buf;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
188 s->size = buf_size;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
189 roqvideo_decode_frame(s);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
190
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
191 *data_size = sizeof(AVFrame);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
192 *(AVFrame*)data = *s->current_frame;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
193
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
194 /* shuffle frames */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
195 FFSWAP(AVFrame *, s->current_frame, s->last_frame);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
196
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
197 return buf_size;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
198 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
199
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
200 static int roq_decode_end(AVCodecContext *avctx)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
201 {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
202 RoqContext *s = avctx->priv_data;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
203
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
204 /* release the last frame */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
205 if (s->last_frame->data[0])
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
206 avctx->release_buffer(avctx, s->last_frame);
5088
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
207 if (s->current_frame->data[0])
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
208 avctx->release_buffer(avctx, s->current_frame);
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
209
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
210 return 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
211 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
212
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
213 AVCodec roq_decoder = {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
214 "roqvideo",
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
215 CODEC_TYPE_VIDEO,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
216 CODEC_ID_ROQ,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
217 sizeof(RoqContext),
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
218 roq_decode_init,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
219 NULL,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
220 roq_decode_end,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
221 roq_decode_frame,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
222 CODEC_CAP_DR1,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
223 };