annotate vqf.c @ 6435:67433b0c29d5 libavformat

move h264 demuxer to its own file
author aurel
date Sun, 29 Aug 2010 21:28:51 +0000
parents fcdf61a4a6ce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
1 /*
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
2 * VQF demuxer
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
3 * Copyright (c) 2009 Vitor Sessak
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
4 *
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
5 * This file is part of FFmpeg.
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
6 *
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
11 *
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
15 * Lesser General Public License for more details.
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
16 *
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
20 */
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
21
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
22 #include "avformat.h"
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
23 #include "libavutil/intreadwrite.h"
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
24
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
25 typedef struct VqfContext {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
26 int frame_bit_len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
27 uint8_t last_frame_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
28 int remaining_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
29 } VqfContext;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
30
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
31 static int vqf_probe(AVProbeData *probe_packet)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
32 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
33 if (AV_RL32(probe_packet->buf) != MKTAG('T','W','I','N'))
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
34 return 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
35
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
36 if (!memcmp(probe_packet->buf + 4, "97012000", 8))
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
37 return AVPROBE_SCORE_MAX;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
38
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
39 if (!memcmp(probe_packet->buf + 4, "00052200", 8))
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
40 return AVPROBE_SCORE_MAX;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
41
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
42 return AVPROBE_SCORE_MAX/2;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
43 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
44
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
45 static void add_metadata(AVFormatContext *s, const char *tag,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
46 unsigned int tag_len, unsigned int remaining)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
47 {
5446
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
48 int len = FFMIN(tag_len, remaining);
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
49 char *buf;
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
50
5446
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
51 if (len == UINT_MAX)
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
52 return;
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
53
5446
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
54 buf = av_malloc(len+1);
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
55 if (!buf)
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
56 return;
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
57 get_buffer(s->pb, buf, len);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
58 buf[len] = 0;
5446
4211f91f69b1 Use AV_METADATA_DONT_STRDUP* / use av_malloced metadata instead of strduped
michael
parents: 4668
diff changeset
59 av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL);
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
60 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
61
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
62 static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
63 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
64 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
65 AVStream *st = av_new_stream(s, 0);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
66 int chunk_tag;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
67 int rate_flag = -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
68 int header_size;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
69 int read_bitrate = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
70 int size;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
71
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
72 if (!st)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
73 return AVERROR(ENOMEM);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
74
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
75 url_fskip(s->pb, 12);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
76
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
77 header_size = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
78
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5446
diff changeset
79 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
80 st->codec->codec_id = CODEC_ID_TWINVQ;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
81 st->start_time = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
82
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
83 do {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
84 int len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
85 chunk_tag = get_le32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
86
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
87 if (chunk_tag == MKTAG('D','A','T','A'))
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
88 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
89
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
90 len = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
91
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
92 if ((unsigned) len > INT_MAX/2) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
93 av_log(s, AV_LOG_ERROR, "Malformed header\n");
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
94 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
95 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
96
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
97 header_size -= 8;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
98
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
99 switch(chunk_tag){
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
100 case MKTAG('C','O','M','M'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
101 st->codec->channels = get_be32(s->pb) + 1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
102 read_bitrate = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
103 rate_flag = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
104 url_fskip(s->pb, len-12);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
105
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
106 st->codec->bit_rate = read_bitrate*1000;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
107 st->codec->bits_per_coded_sample = 16;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
108 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
109 case MKTAG('N','A','M','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
110 add_metadata(s, "title" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
111 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
112 case MKTAG('(','c',')',' '):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
113 add_metadata(s, "copyright", len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
114 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
115 case MKTAG('A','U','T','H'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
116 add_metadata(s, "author" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
117 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
118 case MKTAG('A','L','B','M'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
119 add_metadata(s, "album" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
120 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
121 case MKTAG('T','R','C','K'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
122 add_metadata(s, "track" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
123 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
124 case MKTAG('C','O','M','T'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
125 add_metadata(s, "comment" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
126 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
127 case MKTAG('F','I','L','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
128 add_metadata(s, "filename" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
129 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
130 case MKTAG('D','S','I','Z'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
131 add_metadata(s, "size" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
132 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
133 case MKTAG('D','A','T','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
134 add_metadata(s, "date" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
135 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
136 case MKTAG('G','E','N','R'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
137 add_metadata(s, "genre" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
138 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
139 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
140 av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
141 ((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1],
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
142 ((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
143 url_fskip(s->pb, FFMIN(len, header_size));
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
144 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
145 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
146
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
147 header_size -= len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
148
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
149 } while (header_size >= 0);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
150
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
151 switch (rate_flag) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
152 case -1:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
153 av_log(s, AV_LOG_ERROR, "COMM tag not found!\n");
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
154 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
155 case 44:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
156 st->codec->sample_rate = 44100;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
157 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
158 case 22:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
159 st->codec->sample_rate = 22050;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
160 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
161 case 11:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
162 st->codec->sample_rate = 11025;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
163 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
164 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
165 st->codec->sample_rate = rate_flag*1000;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
166 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
167 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
168
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
169 switch (((st->codec->sample_rate/1000) << 8) +
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
170 read_bitrate/st->codec->channels) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
171 case (11<<8) + 8 :
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
172 case (8 <<8) + 8 :
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
173 case (11<<8) + 10:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
174 case (22<<8) + 32:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
175 size = 512;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
176 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
177 case (16<<8) + 16:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
178 case (22<<8) + 20:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
179 case (22<<8) + 24:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
180 size = 1024;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
181 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
182 case (44<<8) + 40:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
183 case (44<<8) + 48:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
184 size = 2048;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
185 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
186 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
187 av_log(s, AV_LOG_ERROR, "Mode not suported: %d Hz, %d kb/s.\n",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
188 st->codec->sample_rate, st->codec->bit_rate);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
189 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
190 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
191 c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate;
5949
fcdf61a4a6ce Use a suitable timebase in VQF demuxer
vitor
parents: 5910
diff changeset
192 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
4668
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
193
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
194 return 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
195 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
196
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
197 static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
198 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
199 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
200 int ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
201 int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
202
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
203 pkt->pos = url_ftell(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
204 pkt->stream_index = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
205
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
206 if (av_new_packet(pkt, size+2) < 0)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
207 return AVERROR(EIO);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
208
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
209 pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
210 pkt->data[1] = c->last_frame_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
211 ret = get_buffer(s->pb, pkt->data+2, size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
212
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
213 if (ret<=0) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
214 av_free_packet(pkt);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
215 return AVERROR(EIO);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
216 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
217
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
218 c->last_frame_bits = pkt->data[size+1];
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
219 c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
220
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
221 return size+2;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
222 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
223
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
224 static int vqf_read_seek(AVFormatContext *s,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
225 int stream_index, int64_t timestamp, int flags)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
226 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
227 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
228 AVStream *st;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
229 int ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
230 int64_t pos;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
231
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
232 st = s->streams[stream_index];
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
233 pos = av_rescale_rnd(timestamp * st->codec->bit_rate,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
234 st->time_base.num,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
235 st->time_base.den * (int64_t)c->frame_bit_len,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
236 (flags & AVSEEK_FLAG_BACKWARD) ?
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
237 AV_ROUND_DOWN : AV_ROUND_UP);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
238 pos *= c->frame_bit_len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
239
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
240 st->cur_dts = av_rescale(pos, st->time_base.den,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
241 st->codec->bit_rate * (int64_t)st->time_base.num);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
242
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
243 if ((ret = url_fseek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
244 return ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
245
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
246 c->remaining_bits = -7 - ((pos-7)&7);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
247 return 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
248 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
249
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
250 AVInputFormat vqf_demuxer = {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
251 "vqf",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
252 NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
253 sizeof(VqfContext),
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
254 vqf_probe,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
255 vqf_read_header,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
256 vqf_read_packet,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
257 NULL,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
258 vqf_read_seek,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
259 .extensions = "vqf",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
260 };