annotate roqvideodec.c @ 8442:60be1c7d8345 libavcodec

Make h264 parser 50% faster.
author michael
date Tue, 23 Dec 2008 02:34:58 +0000
parents ade9051a6a4c
children e9d9d946f213
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 * @file roqvideodec.c
7041
ade9051a6a4c Cosmetics: s/Id/id/ in libavcodec/roqvideodec.c when Id refers to id Software
stefano
parents: 7040
diff changeset
23 * id RoQ Video Decoder by Dr. Tim Ferguson
ade9051a6a4c Cosmetics: s/Id/id/ in libavcodec/roqvideodec.c when Id refers to id Software
stefano
parents: 7040
diff changeset
24 * For more information about the id RoQ format, visit:
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
25 * http://www.csse.monash.edu.au/~timf/
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
26 */
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 #include <stdio.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
29 #include <stdlib.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
30 #include <string.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
31 #include <unistd.h>
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
32
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
33 #include "avcodec.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
34 #include "bytestream.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
35 #include "roqvideo.h"
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
36
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
37 static void roqvideo_decode_frame(RoqContext *ri)
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 unsigned int chunk_id = 0, chunk_arg = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
40 unsigned long chunk_size = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
41 int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
42 int vqid, bpos, xpos, ypos, xp, yp, x, y, mx, my;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
43 int frame_stats[2][4] = {{0},{0}};
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
44 roq_qcell *qcell;
6218
michael
parents: 5524
diff changeset
45 const unsigned char *buf = ri->buf;
6314
de5d97b6c25b Add some const where appropriate
reimar
parents: 6279
diff changeset
46 const unsigned char *buf_end = ri->buf + ri->size;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
47
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
48 while (buf < buf_end) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
49 chunk_id = bytestream_get_le16(&buf);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
50 chunk_size = bytestream_get_le32(&buf);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
51 chunk_arg = bytestream_get_le16(&buf);
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 if(chunk_id == RoQ_QUAD_VQ)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
54 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
55 if(chunk_id == RoQ_QUAD_CODEBOOK) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
56 if((nv1 = chunk_arg >> 8) == 0)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
57 nv1 = 256;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
58 if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
59 nv2 = 256;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
60 for(i = 0; i < nv1; i++) {
5104
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
61 ri->cb2x2[i].y[0] = *buf++;
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
62 ri->cb2x2[i].y[1] = *buf++;
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
63 ri->cb2x2[i].y[2] = *buf++;
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
64 ri->cb2x2[i].y[3] = *buf++;
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
65 ri->cb2x2[i].u = *buf++;
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
66 ri->cb2x2[i].v = *buf++;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
67 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
68 for(i = 0; i < nv2; i++)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
69 for(j = 0; j < 4; j++)
5104
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
70 ri->cb4x4[i].idx[j] = *buf++;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
71 }
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
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
74 bpos = xpos = ypos = 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
75 while(bpos < chunk_size) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
76 for (yp = ypos; yp < ypos + 16; yp += 8)
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
77 for (xp = xpos; xp < xpos + 16; xp += 8) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
78 if (vqflg_pos < 0) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
79 vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
80 vqflg_pos = 7;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
81 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
82 vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
83 frame_stats[0][vqid]++;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
84 vqflg_pos--;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
85
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
86 switch(vqid) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
87 case RoQ_ID_MOT:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
88 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
89 case RoQ_ID_FCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
90 mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8));
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
91 my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
92 ff_apply_motion_8x8(ri, xp, yp, mx, my);
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_SLD:
5104
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
95 qcell = ri->cb4x4 + buf[bpos++];
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
96 ff_apply_vector_4x4(ri, xp, yp, ri->cb2x2 + qcell->idx[0]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
97 ff_apply_vector_4x4(ri, xp+4, yp, ri->cb2x2 + qcell->idx[1]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
98 ff_apply_vector_4x4(ri, xp, yp+4, ri->cb2x2 + qcell->idx[2]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
99 ff_apply_vector_4x4(ri, xp+4, yp+4, ri->cb2x2 + qcell->idx[3]);
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
100 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
101 case RoQ_ID_CCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
102 for (k = 0; k < 4; k++) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
103 x = xp; y = yp;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
104 if(k & 0x01) x += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
105 if(k & 0x02) y += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
106
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
107 if (vqflg_pos < 0) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
108 vqflg = buf[bpos++];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
109 vqflg |= (buf[bpos++] << 8);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
110 vqflg_pos = 7;
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 vqid = (vqflg >> (vqflg_pos * 2)) & 0x3;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
113 frame_stats[1][vqid]++;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
114 vqflg_pos--;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
115 switch(vqid) {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
116 case RoQ_ID_MOT:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
117 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
118 case RoQ_ID_FCC:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
119 mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8));
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
120 my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
121 ff_apply_motion_4x4(ri, x, y, mx, my);
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_SLD:
5104
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
124 qcell = ri->cb4x4 + buf[bpos++];
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
125 ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + qcell->idx[0]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
126 ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + qcell->idx[1]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
127 ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + qcell->idx[2]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
128 ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + qcell->idx[3]);
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
129 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
130 case RoQ_ID_CCC:
5104
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
131 ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + buf[bpos]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
132 ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + buf[bpos+1]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
133 ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + buf[bpos+2]);
b8e8aa53f613 Rename cb field
benoit
parents: 5099
diff changeset
134 ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + buf[bpos+3]);
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
135 bpos += 4;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
136 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
137 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
138 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
139 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
140 default:
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
141 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
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
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
145 xpos += 16;
5188
c2a475157299 add width and height in context and use them
benoit
parents: 5104
diff changeset
146 if (xpos >= ri->width) {
c2a475157299 add width and height in context and use them
benoit
parents: 5104
diff changeset
147 xpos -= ri->width;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
148 ypos += 16;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
149 }
5188
c2a475157299 add width and height in context and use them
benoit
parents: 5104
diff changeset
150 if(ypos >= ri->height)
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
151 break;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
152 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
153 }
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
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
156 static av_cold int roq_decode_init(AVCodecContext *avctx)
5080
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 RoqContext *s = avctx->priv_data;
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 s->avctx = avctx;
5188
c2a475157299 add width and height in context and use them
benoit
parents: 5104
diff changeset
161 s->width = avctx->width;
c2a475157299 add width and height in context and use them
benoit
parents: 5104
diff changeset
162 s->height = avctx->height;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
163 s->last_frame = &s->frames[0];
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
164 s->current_frame = &s->frames[1];
5099
133329117637 Convert RoQ decoder to use YUV 4:4:4 unpacked macroblocks
benoit
parents: 5090
diff changeset
165 avctx->pix_fmt = PIX_FMT_YUV444P;
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
166
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
167 return 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
168 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
169
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
170 static int roq_decode_frame(AVCodecContext *avctx,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
171 void *data, int *data_size,
6279
a6b0998e45d1 some const
michael
parents: 6218
diff changeset
172 const uint8_t *buf, int buf_size)
5080
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 RoqContext *s = avctx->priv_data;
5524
f47bc5359101 fix decoding of samples.mplayerhq.hu/game-formats/idroq/demoEnd.roq
michael
parents: 5215
diff changeset
175 int copy= !s->current_frame->data[0];
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
176
5088
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
177 if (avctx->reget_buffer(avctx, s->current_frame)) {
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
178 av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n");
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
179 return -1;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
180 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
181
5524
f47bc5359101 fix decoding of samples.mplayerhq.hu/game-formats/idroq/demoEnd.roq
michael
parents: 5215
diff changeset
182 if(copy)
f47bc5359101 fix decoding of samples.mplayerhq.hu/game-formats/idroq/demoEnd.roq
michael
parents: 5215
diff changeset
183 av_picture_copy((AVPicture*)s->current_frame, (AVPicture*)s->last_frame,
f47bc5359101 fix decoding of samples.mplayerhq.hu/game-formats/idroq/demoEnd.roq
michael
parents: 5215
diff changeset
184 avctx->pix_fmt, avctx->width, avctx->height);
f47bc5359101 fix decoding of samples.mplayerhq.hu/game-formats/idroq/demoEnd.roq
michael
parents: 5215
diff changeset
185
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
186 s->buf = buf;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
187 s->size = buf_size;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
188 roqvideo_decode_frame(s);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
189
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
190 *data_size = sizeof(AVFrame);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
191 *(AVFrame*)data = *s->current_frame;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
192
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
193 /* shuffle frames */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
194 FFSWAP(AVFrame *, s->current_frame, s->last_frame);
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
195
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
196 return buf_size;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
197 }
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
198
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6484
diff changeset
199 static av_cold int roq_decode_end(AVCodecContext *avctx)
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
200 {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
201 RoqContext *s = avctx->priv_data;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
202
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
203 /* release the last frame */
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
204 if (s->last_frame->data[0])
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
205 avctx->release_buffer(avctx, s->last_frame);
5088
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
206 if (s->current_frame->data[0])
8e206208db1f fix skipped blocks
michael
parents: 5080
diff changeset
207 avctx->release_buffer(avctx, s->current_frame);
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
208
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
209 return 0;
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
210 }
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 AVCodec roq_decoder = {
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
213 "roqvideo",
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
214 CODEC_TYPE_VIDEO,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
215 CODEC_ID_ROQ,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
216 sizeof(RoqContext),
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
217 roq_decode_init,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
218 NULL,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
219 roq_decode_end,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
220 roq_decode_frame,
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
221 CODEC_CAP_DR1,
7041
ade9051a6a4c Cosmetics: s/Id/id/ in libavcodec/roqvideodec.c when Id refers to id Software
stefano
parents: 7040
diff changeset
222 .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"),
5080
e72265f4e518 Split RoQ decoder to accommodate future encoder patch
benoit
parents:
diff changeset
223 };