annotate vqf.c @ 4759:0c9699c40b66 libavformat

PCX encoder that handles 1-, 8-, and 24-bpp pixfmts. Patch by Daniel Verkamp, daniel drv nu
author cehoyos
date Fri, 20 Mar 2009 17:23:45 +0000
parents 1f87eacc3c32
children 4211f91f69b1
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 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
48 char buf[2048];
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
49 int len = FFMIN3(tag_len, remaining, sizeof(buf) - 1);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
50
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
51 if (len != tag_len)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
52 av_log(s, AV_LOG_ERROR, "Warning: truncating metadata!\n");
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
53
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
54 get_buffer(s->pb, buf, len);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
55 buf[len] = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
56 av_metadata_set(&s->metadata, tag, buf);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
57 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
58
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
59 static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
60 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
61 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
62 AVStream *st = av_new_stream(s, 0);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
63 int chunk_tag;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
64 int rate_flag = -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
65 int header_size;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
66 int read_bitrate = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
67 int size;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
68
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
69 if (!st)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
70 return AVERROR(ENOMEM);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
71
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
72 url_fskip(s->pb, 12);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
73
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
74 header_size = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
75
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
76 st->codec->codec_type = CODEC_TYPE_AUDIO;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
77 st->codec->codec_id = CODEC_ID_TWINVQ;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
78 st->start_time = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
79
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
80 do {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
81 int len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
82 chunk_tag = get_le32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
83
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
84 if (chunk_tag == MKTAG('D','A','T','A'))
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
85 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
86
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
87 len = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
88
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
89 if ((unsigned) len > INT_MAX/2) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
90 av_log(s, AV_LOG_ERROR, "Malformed header\n");
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
91 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
92 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
93
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
94 header_size -= 8;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
95
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
96 switch(chunk_tag){
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
97 case MKTAG('C','O','M','M'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
98 st->codec->channels = get_be32(s->pb) + 1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
99 read_bitrate = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
100 rate_flag = get_be32(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
101 url_fskip(s->pb, len-12);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
102
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
103 st->codec->bit_rate = read_bitrate*1000;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
104 st->codec->bits_per_coded_sample = 16;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
105 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
106 case MKTAG('N','A','M','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
107 add_metadata(s, "title" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
108 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
109 case MKTAG('(','c',')',' '):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
110 add_metadata(s, "copyright", len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
111 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
112 case MKTAG('A','U','T','H'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
113 add_metadata(s, "author" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
114 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
115 case MKTAG('A','L','B','M'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
116 add_metadata(s, "album" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
117 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
118 case MKTAG('T','R','C','K'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
119 add_metadata(s, "track" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
120 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
121 case MKTAG('C','O','M','T'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
122 add_metadata(s, "comment" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
123 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
124 case MKTAG('F','I','L','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
125 add_metadata(s, "filename" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
126 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
127 case MKTAG('D','S','I','Z'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
128 add_metadata(s, "size" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
129 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
130 case MKTAG('D','A','T','E'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
131 add_metadata(s, "date" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
132 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
133 case MKTAG('G','E','N','R'):
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
134 add_metadata(s, "genre" , len, header_size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
135 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
136 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
137 av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
138 ((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1],
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
139 ((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
140 url_fskip(s->pb, FFMIN(len, header_size));
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
141 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
142 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
143
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
144 header_size -= len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
145
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
146 } while (header_size >= 0);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
147
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
148 switch (rate_flag) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
149 case -1:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
150 av_log(s, AV_LOG_ERROR, "COMM tag not found!\n");
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
151 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
152 case 44:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
153 st->codec->sample_rate = 44100;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
154 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
155 case 22:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
156 st->codec->sample_rate = 22050;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
157 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
158 case 11:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
159 st->codec->sample_rate = 11025;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
160 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
161 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
162 st->codec->sample_rate = rate_flag*1000;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
163 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
164 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
165
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
166 switch (((st->codec->sample_rate/1000) << 8) +
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
167 read_bitrate/st->codec->channels) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
168 case (11<<8) + 8 :
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
169 case (8 <<8) + 8 :
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
170 case (11<<8) + 10:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
171 case (22<<8) + 32:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
172 size = 512;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
173 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
174 case (16<<8) + 16:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
175 case (22<<8) + 20:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
176 case (22<<8) + 24:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
177 size = 1024;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
178 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
179 case (44<<8) + 40:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
180 case (44<<8) + 48:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
181 size = 2048;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
182 break;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
183 default:
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
184 av_log(s, AV_LOG_ERROR, "Mode not suported: %d Hz, %d kb/s.\n",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
185 st->codec->sample_rate, st->codec->bit_rate);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
186 return -1;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
187 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
188 c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
189
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
190 return 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
191 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
192
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
193 static int vqf_read_packet(AVFormatContext *s, AVPacket *pkt)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
194 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
195 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
196 int ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
197 int size = (c->frame_bit_len - c->remaining_bits + 7)>>3;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
198
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
199 pkt->pos = url_ftell(s->pb);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
200 pkt->stream_index = 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
201
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
202 if (av_new_packet(pkt, size+2) < 0)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
203 return AVERROR(EIO);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
204
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
205 pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
206 pkt->data[1] = c->last_frame_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
207 ret = get_buffer(s->pb, pkt->data+2, size);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
208
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
209 if (ret<=0) {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
210 av_free_packet(pkt);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
211 return AVERROR(EIO);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
212 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
213
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
214 c->last_frame_bits = pkt->data[size+1];
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
215 c->remaining_bits = (size << 3) - c->frame_bit_len + c->remaining_bits;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
216
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
217 return size+2;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
218 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
219
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
220 static int vqf_read_seek(AVFormatContext *s,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
221 int stream_index, int64_t timestamp, int flags)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
222 {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
223 VqfContext *c = s->priv_data;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
224 AVStream *st;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
225 int ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
226 int64_t pos;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
227
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
228 st = s->streams[stream_index];
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
229 pos = av_rescale_rnd(timestamp * st->codec->bit_rate,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
230 st->time_base.num,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
231 st->time_base.den * (int64_t)c->frame_bit_len,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
232 (flags & AVSEEK_FLAG_BACKWARD) ?
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
233 AV_ROUND_DOWN : AV_ROUND_UP);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
234 pos *= c->frame_bit_len;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
235
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
236 st->cur_dts = av_rescale(pos, st->time_base.den,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
237 st->codec->bit_rate * (int64_t)st->time_base.num);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
238
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
239 if ((ret = url_fseek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0)
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
240 return ret;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
241
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
242 c->remaining_bits = -7 - ((pos-7)&7);
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
243 return 0;
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
244 }
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
245
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
246 AVInputFormat vqf_demuxer = {
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
247 "vqf",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
248 NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"),
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
249 sizeof(VqfContext),
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
250 vqf_probe,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
251 vqf_read_header,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
252 vqf_read_packet,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
253 NULL,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
254 vqf_read_seek,
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
255 .extensions = "vqf",
1f87eacc3c32 VQF demuxer
vitor
parents:
diff changeset
256 };