~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/westwood.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
    /* Probabilistic content detection strategy: There is no file signature
91
91
     * so perform sanity checks on various header parameters:
92
92
     *   8000 <= sample rate (16 bits) <= 48000  ==> 40001 acceptable numbers
 
93
     *   flags <= 0x03 (2 LSBs are used)         ==> 4 acceptable numbers
93
94
     *   compression type (8 bits) = 1 or 99     ==> 2 acceptable numbers
94
 
     * There is a total of 24 bits. The number space contains 2^24 =
95
 
     * 16777216 numbers. There are 40001 * 2 = 80002 acceptable combinations
96
 
     * of numbers. There is a 80002/16777216 = 0.48% chance of a false
97
 
     * positive.
 
95
     *   first audio chunk signature (32 bits)   ==> 1 acceptable number
 
96
     * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 =
 
97
     * 320008 acceptable number combinations.
98
98
     */
99
99
 
100
 
    if (p->buf_size < AUD_HEADER_SIZE)
 
100
    if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE)
101
101
        return 0;
102
102
 
103
103
    /* check sample rate */
105
105
    if ((field < 8000) || (field > 48000))
106
106
        return 0;
107
107
 
 
108
    /* enforce the rule that the top 6 bits of this flags field are reserved (0);
 
109
     * this might not be true, but enforce it until deemed unnecessary */
 
110
    if (p->buf[10] & 0xFC)
 
111
        return 0;
 
112
 
108
113
    /* note: only check for WS IMA (type 99) right now since there is no
109
114
     * support for type 1 */
110
115
    if (p->buf[11] != 99)
111
116
        return 0;
112
117
 
 
118
    /* read ahead to the first audio chunk and validate the first header signature */
 
119
    if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE)
 
120
        return 0;
 
121
 
113
122
    /* return 1/2 certainty since this file check is a little sketchy */
114
123
    return AVPROBE_SCORE_MAX / 2;
115
124
}
117
126
static int wsaud_read_header(AVFormatContext *s,
118
127
                             AVFormatParameters *ap)
119
128
{
120
 
    WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
121
 
    ByteIOContext *pb = &s->pb;
 
129
    WsAudDemuxContext *wsaud = s->priv_data;
 
130
    ByteIOContext *pb = s->pb;
122
131
    AVStream *st;
123
132
    unsigned char header[AUD_HEADER_SIZE];
124
133
 
125
134
    if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE)
126
 
        return AVERROR_IO;
 
135
        return AVERROR(EIO);
127
136
    wsaud->audio_samplerate = AV_RL16(&header[0]);
128
137
    if (header[11] == 99)
129
138
        wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS;
138
147
    /* initialize the audio decoder stream */
139
148
    st = av_new_stream(s, 0);
140
149
    if (!st)
141
 
        return AVERROR_NOMEM;
 
150
        return AVERROR(ENOMEM);
142
151
    av_set_pts_info(st, 33, 1, wsaud->audio_samplerate);
143
152
    st->codec->codec_type = CODEC_TYPE_AUDIO;
144
153
    st->codec->codec_id = wsaud->audio_type;
159
168
static int wsaud_read_packet(AVFormatContext *s,
160
169
                             AVPacket *pkt)
161
170
{
162
 
    WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
163
 
    ByteIOContext *pb = &s->pb;
 
171
    WsAudDemuxContext *wsaud = s->priv_data;
 
172
    ByteIOContext *pb = s->pb;
164
173
    unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE];
165
174
    unsigned int chunk_size;
166
175
    int ret = 0;
167
176
 
168
177
    if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) !=
169
178
        AUD_CHUNK_PREAMBLE_SIZE)
170
 
        return AVERROR_IO;
 
179
        return AVERROR(EIO);
171
180
 
172
181
    /* validate the chunk */
173
182
    if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE)
176
185
    chunk_size = AV_RL16(&preamble[0]);
177
186
    ret= av_get_packet(pb, pkt, chunk_size);
178
187
    if (ret != chunk_size)
179
 
        return AVERROR_IO;
 
188
        return AVERROR(EIO);
180
189
    pkt->stream_index = wsaud->audio_stream_index;
181
190
    pkt->pts = wsaud->audio_frame_counter;
182
191
    pkt->pts /= wsaud->audio_samplerate;
189
198
 
190
199
static int wsaud_read_close(AVFormatContext *s)
191
200
{
192
 
//    WsAudDemuxContext *wsaud = (WsAudDemuxContext *)s->priv_data;
 
201
//    WsAudDemuxContext *wsaud = s->priv_data;
193
202
 
194
203
    return 0;
195
204
}
212
221
static int wsvqa_read_header(AVFormatContext *s,
213
222
                             AVFormatParameters *ap)
214
223
{
215
 
    WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
216
 
    ByteIOContext *pb = &s->pb;
 
224
    WsVqaDemuxContext *wsvqa = s->priv_data;
 
225
    ByteIOContext *pb = s->pb;
217
226
    AVStream *st;
218
227
    unsigned char *header;
219
228
    unsigned char scratch[VQA_PREAMBLE_SIZE];
223
232
    /* initialize the video decoder stream */
224
233
    st = av_new_stream(s, 0);
225
234
    if (!st)
226
 
        return AVERROR_NOMEM;
 
235
        return AVERROR(ENOMEM);
227
236
    av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
228
237
    wsvqa->video_stream_index = st->index;
229
238
    st->codec->codec_type = CODEC_TYPE_VIDEO;
240
249
    if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) !=
241
250
        VQA_HEADER_SIZE) {
242
251
        av_free(st->codec->extradata);
243
 
        return AVERROR_IO;
 
252
        return AVERROR(EIO);
244
253
    }
245
254
    st->codec->width = AV_RL16(&header[6]);
246
255
    st->codec->height = AV_RL16(&header[8]);
249
258
    if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) {
250
259
        st = av_new_stream(s, 0);
251
260
        if (!st)
252
 
            return AVERROR_NOMEM;
 
261
            return AVERROR(ENOMEM);
253
262
        av_set_pts_info(st, 33, 1, VQA_FRAMERATE);
254
263
        st->codec->codec_type = CODEC_TYPE_AUDIO;
255
264
        if (AV_RL16(&header[0]) == 1)
279
288
    do {
280
289
        if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) {
281
290
            av_free(st->codec->extradata);
282
 
            return AVERROR_IO;
 
291
            return AVERROR(EIO);
283
292
        }
284
293
        chunk_tag = AV_RB32(&scratch[0]);
285
294
        chunk_size = AV_RB32(&scratch[4]);
314
323
static int wsvqa_read_packet(AVFormatContext *s,
315
324
                             AVPacket *pkt)
316
325
{
317
 
    WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
318
 
    ByteIOContext *pb = &s->pb;
 
326
    WsVqaDemuxContext *wsvqa = s->priv_data;
 
327
    ByteIOContext *pb = s->pb;
319
328
    int ret = -1;
320
329
    unsigned char preamble[VQA_PREAMBLE_SIZE];
321
330
    unsigned int chunk_type;
330
339
        if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) {
331
340
 
332
341
            if (av_new_packet(pkt, chunk_size))
333
 
                return AVERROR_IO;
 
342
                return AVERROR(EIO);
334
343
            ret = get_buffer(pb, pkt->data, chunk_size);
335
344
            if (ret != chunk_size) {
336
345
                av_free_packet(pkt);
337
 
                return AVERROR_IO;
 
346
                return AVERROR(EIO);
338
347
            }
339
348
 
340
349
            if (chunk_type == SND2_TAG) {
371
380
 
372
381
static int wsvqa_read_close(AVFormatContext *s)
373
382
{
374
 
//    WsVqaDemuxContext *wsvqa = (WsVqaDemuxContext *)s->priv_data;
 
383
//    WsVqaDemuxContext *wsvqa = s->priv_data;
375
384
 
376
385
    return 0;
377
386
}