annotate apc.c @ 6239:d7ec9ef45438 libavformat

Associate .tga with format image2.
author cehoyos
date Wed, 07 Jul 2010 10:19:59 +0000
parents 536e5527c1e0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
1 /*
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
2 * CRYO APC audio format demuxer
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
3 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
4 *
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
5 * This file is part of FFmpeg.
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
6 *
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
11 *
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
15 * Lesser General Public License for more details.
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
16 *
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
20 */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
21
3284
7e3332b84926 string.h is a system header file, so use <> for it.
diego
parents: 2771
diff changeset
22 #include <string.h>
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
23 #include "avformat.h"
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
24
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
25 static int apc_probe(AVProbeData *p)
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
26 {
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
27 if (!strncmp(p->buf, "CRYO_APC", 8))
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
28 return AVPROBE_SCORE_MAX;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
29
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
30 return 0;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
31 }
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
32
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
33 static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap)
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
34 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
35 ByteIOContext *pb = s->pb;
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
36 AVStream *st;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
37
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
38 get_le32(pb); /* CRYO */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
39 get_le32(pb); /* _APC */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
40 get_le32(pb); /* 1.20 */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
41
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
42 st = av_new_stream(s, 0);
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
43 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2001
diff changeset
44 return AVERROR(ENOMEM);
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
45
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 3908
diff changeset
46 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
47 st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
48
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
49 get_le32(pb); /* number of samples */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
50 st->codec->sample_rate = get_le32(pb);
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
51
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
52 st->codec->extradata_size = 2 * 4;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
53 st->codec->extradata = av_malloc(st->codec->extradata_size +
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
54 FF_INPUT_BUFFER_PADDING_SIZE);
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
55 if (!st->codec->extradata)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2001
diff changeset
56 return AVERROR(ENOMEM);
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
57
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
58 /* initial predictor values for adpcm decoder */
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
59 get_buffer(pb, st->codec->extradata, 2 * 4);
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
60
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
61 st->codec->channels = 1;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
62 if (get_le32(pb))
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
63 st->codec->channels = 2;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
64
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
65 st->codec->bits_per_coded_sample = 4;
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
66 st->codec->bit_rate = st->codec->bits_per_coded_sample * st->codec->channels
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
67 * st->codec->sample_rate;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
68 st->codec->block_align = 1;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
69
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
70 return 0;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
71 }
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
72
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
73 #define MAX_READ_SIZE 4096
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
74
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
75 static int apc_read_packet(AVFormatContext *s, AVPacket *pkt)
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
76 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2274
diff changeset
77 if (av_get_packet(s->pb, pkt, MAX_READ_SIZE) <= 0)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
78 return AVERROR(EIO);
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
79 pkt->stream_index = 0;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
80 return 0;
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
81 }
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
82
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
83 AVInputFormat apc_demuxer = {
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
84 "apc",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3284
diff changeset
85 NULL_IF_CONFIG_SMALL("CRYO APC format"),
1990
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
86 0,
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
87 apc_probe,
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
88 apc_read_header,
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
89 apc_read_packet,
e7a4bc0aa0fe CRYO APC demuxer
diego
parents:
diff changeset
90 };