annotate siff.c @ 3365:19bd4caf27a9 libavformat

consistency cosmetics: indices --> indexes
author diego
date Mon, 26 May 2008 23:14:25 +0000
parents d52c718e83f9
children d280eb6ace33
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
1 /*
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
2 * Beam Software SIFF demuxer
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
3 * Copyright (c) 2007 Konstantin Shishkov.
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
4 *
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
6 *
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
11 *
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
16 *
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
20 */
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
21
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
22 #include "avformat.h"
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
23 #include "riff.h"
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
24
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
25 enum SIFFTags{
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
26 TAG_SIFF = MKTAG('S', 'I', 'F', 'F'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
27 TAG_BODY = MKTAG('B', 'O', 'D', 'Y'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
28 TAG_VBHD = MKTAG('V', 'B', 'H', 'D'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
29 TAG_SHDR = MKTAG('S', 'H', 'D', 'R'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
30 TAG_VBV1 = MKTAG('V', 'B', 'V', '1'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
31 TAG_SOUN = MKTAG('S', 'O', 'U', 'N'),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
32 };
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
33
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
34 enum VBFlags{
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
35 VB_HAS_GMC = 0x01,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
36 VB_HAS_AUDIO = 0x04,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
37 VB_HAS_VIDEO = 0x08,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
38 VB_HAS_PALETTE = 0x10,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
39 VB_HAS_LENGTH = 0x20
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
40 };
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
41
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
42 typedef struct SIFFContext{
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
43 int frames;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
44 int cur_frame;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
45 int rate;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
46 int bits;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
47 int block_align;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
48
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
49 int has_video;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
50 int has_audio;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
51
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
52 int curstrm;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
53 int pktsize;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
54 int gmcsize;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
55 int sndsize;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
56
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
57 int flags;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
58 uint8_t gmc[4];
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
59 }SIFFContext;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
60
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
61 static int siff_probe(AVProbeData *p)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
62 {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
63 /* check file header */
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
64 if (AV_RL32(p->buf) == TAG_SIFF)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
65 return AVPROBE_SCORE_MAX;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
66 else
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
67 return 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
68 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
69
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
70 static int create_audio_stream(AVFormatContext *s, SIFFContext *c)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
71 {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
72 AVStream *ast;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
73 ast = av_new_stream(s, 0);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
74 if (!ast)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
75 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
76 ast->codec->codec_type = CODEC_TYPE_AUDIO;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
77 ast->codec->codec_id = CODEC_ID_PCM_U8;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
78 ast->codec->channels = 1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
79 ast->codec->bits_per_sample = c->bits;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
80 ast->codec->sample_rate = c->rate;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
81 ast->codec->frame_size = c->block_align;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
82 av_set_pts_info(ast, 16, 1, c->rate);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
83 return 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
84 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
85
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
86 static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
87 {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
88 AVStream *st;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
89 int width, height;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
90
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
91 if (get_le32(pb) != TAG_VBHD){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
92 av_log(s, AV_LOG_ERROR, "Header chunk is missing\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
93 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
94 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
95 if(get_be32(pb) != 32){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
96 av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
97 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
98 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
99 if(get_le16(pb) != 1){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
100 av_log(s, AV_LOG_ERROR, "Incorrect header version\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
101 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
102 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
103 width = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
104 height = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
105 url_fskip(pb, 4);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
106 c->frames = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
107 if(!c->frames){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
108 av_log(s, AV_LOG_ERROR, "File contains no frames ???\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
109 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
110 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
111 c->bits = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
112 c->rate = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
113 c->block_align = c->rate * (c->bits >> 3);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
114
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
115 url_fskip(pb, 16); //zeroes
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
116
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
117 st = av_new_stream(s, 0);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
118 if (!st)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
119 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
120 st->codec->codec_type = CODEC_TYPE_VIDEO;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
121 st->codec->codec_id = CODEC_ID_VB;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
122 st->codec->codec_tag = MKTAG('V', 'B', 'V', '1');
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
123 st->codec->width = width;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
124 st->codec->height = height;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
125 st->codec->pix_fmt = PIX_FMT_PAL8;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
126 av_set_pts_info(st, 16, 1, 12);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
127
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
128 c->cur_frame = 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
129 c->has_video = 1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
130 c->has_audio = !!c->rate;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
131 c->curstrm = -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
132 if (c->has_audio && create_audio_stream(s, c) < 0)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
133 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
134 return 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
135 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
136
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
137 static int siff_parse_soun(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
138 {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
139 if (get_le32(pb) != TAG_SHDR){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
140 av_log(s, AV_LOG_ERROR, "Header chunk is missing\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
141 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
142 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
143 if(get_be32(pb) != 8){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
144 av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
145 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
146 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
147 url_fskip(pb, 4); //unknown value
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
148 c->rate = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
149 c->bits = get_le16(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
150 c->block_align = c->rate * (c->bits >> 3);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
151 return create_audio_stream(s, c);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
152 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
153
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
154 static int siff_read_header(AVFormatContext *s, AVFormatParameters *ap)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
155 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
156 ByteIOContext *pb = s->pb;
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
157 SIFFContext *c = s->priv_data;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
158 uint32_t tag;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
159
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
160 if (get_le32(pb) != TAG_SIFF)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
161 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
162 url_fskip(pb, 4); //ignore size
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
163 tag = get_le32(pb);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
164
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
165 if (tag != TAG_VBV1 && tag != TAG_SOUN){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
166 av_log(s, AV_LOG_ERROR, "Not a VBV file\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
167 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
168 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
169
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
170 if (tag == TAG_VBV1 && siff_parse_vbv1(s, c, pb) < 0)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
171 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
172 if (tag == TAG_SOUN && siff_parse_soun(s, c, pb) < 0)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
173 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
174 if (get_le32(pb) != MKTAG('B', 'O', 'D', 'Y')){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
175 av_log(s, AV_LOG_ERROR, "'BODY' chunk is missing\n");
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
176 return -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
177 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
178 url_fskip(pb, 4); //ignore size
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
179
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
180 return 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
181 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
182
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
183 static int siff_read_packet(AVFormatContext *s, AVPacket *pkt)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
184 {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
185 SIFFContext *c = s->priv_data;
2690
0a8f2dc62d01 Remove unused variables, fixes the following warnings:
diego
parents: 2659
diff changeset
186 int size;
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
187
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
188 if (c->has_video){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
189 if (c->cur_frame >= c->frames)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
190 return AVERROR(EIO);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
191 if (c->curstrm == -1){
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
192 c->pktsize = get_le32(s->pb) - 4;
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
193 c->flags = get_le16(s->pb);
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
194 c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
195 if (c->gmcsize)
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
196 get_buffer(s->pb, c->gmc, c->gmcsize);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
197 c->sndsize = (c->flags & VB_HAS_AUDIO) ? get_le32(s->pb): 0;
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
198 c->curstrm = !!(c->flags & VB_HAS_AUDIO);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
199 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
200
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
201 if (!c->curstrm){
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
202 size = c->pktsize - c->sndsize;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
203 if (av_new_packet(pkt, size) < 0)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
204 return AVERROR(ENOMEM);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
205 AV_WL16(pkt->data, c->flags);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
206 if (c->gmcsize)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
207 memcpy(pkt->data + 2, c->gmc, c->gmcsize);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
208 get_buffer(s->pb, pkt->data + 2 + c->gmcsize, size - c->gmcsize - 2);
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
209 pkt->stream_index = 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
210 c->curstrm = -1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
211 }else{
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
212 if (av_get_packet(s->pb, pkt, c->sndsize - 4) < 0)
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
213 return AVERROR(EIO);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
214 pkt->stream_index = 1;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
215 c->curstrm = 0;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
216 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
217 if(!c->cur_frame || c->curstrm)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
218 pkt->flags |= PKT_FLAG_KEY;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
219 if (c->curstrm == -1)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
220 c->cur_frame++;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
221 }else{
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2690
diff changeset
222 size = av_get_packet(s->pb, pkt, c->block_align);
2659
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
223 if(size <= 0)
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
224 return AVERROR(EIO);
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
225 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
226 return pkt->size;
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
227 }
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
228
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
229 AVInputFormat siff_demuxer = {
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
230 "siff",
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
231 "Beam Software SIFF",
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
232 sizeof(SIFFContext),
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
233 siff_probe,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
234 siff_read_header,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
235 siff_read_packet,
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
236 .extensions = "vb,son"
883daa175be1 Beam Software SIFF demuxer and video decoder
kostya
parents:
diff changeset
237 };