annotate src/ffmpeg/libavformat/electronicarts.c @ 808:e8776388b02a trunk

[svn] - add ffmpeg
author nenolod
date Mon, 12 Mar 2007 11:18:54 -0700
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
808
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
1 /* Electronic Arts Multimedia File Demuxer
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
2 * Copyright (c) 2004 The ffmpeg Project
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
3 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
4 * This file is part of FFmpeg.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
5 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
10 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
14 * Lesser General Public License for more details.
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
15 *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
19 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
20
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
21 /**
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
22 * @file electronicarts.c
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
23 * Electronic Arts Multimedia file demuxer (WVE/UV2/etc.)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
24 * by Robin Kay (komadori at gekkou.co.uk)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
25 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
26
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
27 #include "avformat.h"
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
28
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
29 #define SCHl_TAG MKTAG('S', 'C', 'H', 'l')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
30 #define PT00_TAG MKTAG('P', 'T', 0x0, 0x0)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
31 #define SCDl_TAG MKTAG('S', 'C', 'D', 'l')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
32 #define pIQT_TAG MKTAG('p', 'I', 'Q', 'T')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
33 #define SCEl_TAG MKTAG('S', 'C', 'E', 'l')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
34 #define _TAG MKTAG('', '', '', '')
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
35
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
36 #define EA_SAMPLE_RATE 22050
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
37 #define EA_BITS_PER_SAMPLE 16
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
38 #define EA_PREAMBLE_SIZE 8
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
39
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
40 typedef struct EaDemuxContext {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
41 int width;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
42 int height;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
43 int video_stream_index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
44 int track_count;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
45
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
46 int audio_stream_index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
47 int audio_frame_counter;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
48
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
49 int64_t audio_pts;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
50 int64_t video_pts;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
51 int video_pts_inc;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
52 float fps;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
53
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
54 int num_channels;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
55 int num_samples;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
56 int compression_type;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
57 } EaDemuxContext;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
58
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
59 static uint32_t read_arbitary(ByteIOContext *pb) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
60 uint8_t size, byte;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
61 int i;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
62 uint32_t word;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
63
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
64 size = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
65
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
66 word = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
67 for (i = 0; i < size; i++) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
68 byte = get_byte(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
69 word <<= 8;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
70 word |= byte;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
71 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
72
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
73 return word;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
74 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
75
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
76 /*
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
77 * Process WVE file header
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
78 * Returns 1 if the WVE file is valid and successfully opened, 0 otherwise
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
79 */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
80 static int process_ea_header(AVFormatContext *s) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
81 int inHeader;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
82 uint32_t blockid, size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
83 EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
84 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
85
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
86 if (get_buffer(pb, (void*)&blockid, 4) != 4) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
87 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
88 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
89 if (le2me_32(blockid) != SCHl_TAG) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
90 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
91 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
92
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
93 if (get_buffer(pb, (void*)&size, 4) != 4) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
94 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
95 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
96 size = le2me_32(size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
97
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
98 if (get_buffer(pb, (void*)&blockid, 4) != 4) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
99 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
100 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
101 if (le2me_32(blockid) != PT00_TAG) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
102 av_log (s, AV_LOG_ERROR, "PT header missing\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
103 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
104 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
105
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
106 inHeader = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
107 while (inHeader) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
108 int inSubheader;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
109 uint8_t byte;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
110 byte = get_byte(pb) & 0xFF;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
111
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
112 switch (byte) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
113 case 0xFD:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
114 av_log (s, AV_LOG_INFO, "entered audio subheader\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
115 inSubheader = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
116 while (inSubheader) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
117 uint8_t subbyte;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
118 subbyte = get_byte(pb) & 0xFF;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
119
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
120 switch (subbyte) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
121 case 0x82:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
122 ea->num_channels = read_arbitary(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
123 av_log (s, AV_LOG_INFO, "num_channels (element 0x82) set to 0x%08x\n", ea->num_channels);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
124 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
125 case 0x83:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
126 ea->compression_type = read_arbitary(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
127 av_log (s, AV_LOG_INFO, "compression_type (element 0x83) set to 0x%08x\n", ea->compression_type);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
128 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
129 case 0x85:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
130 ea->num_samples = read_arbitary(pb);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
131 av_log (s, AV_LOG_INFO, "num_samples (element 0x85) set to 0x%08x\n", ea->num_samples);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
132 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
133 case 0x8A:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
134 av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
135 av_log (s, AV_LOG_INFO, "exited audio subheader\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
136 inSubheader = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
137 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
138 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
139 av_log (s, AV_LOG_INFO, "element 0x%02x set to 0x%08x\n", subbyte, read_arbitary(pb));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
140 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
141 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
142 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
143 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
144 case 0xFF:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
145 av_log (s, AV_LOG_INFO, "end of header block reached\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
146 inHeader = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
147 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
148 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
149 av_log (s, AV_LOG_INFO, "header element 0x%02x set to 0x%08x\n", byte, read_arbitary(pb));
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
150 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
151 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
152 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
153
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
154 if ((ea->num_channels != 2) || (ea->compression_type != 7)) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
155 av_log (s, AV_LOG_ERROR, "unsupported stream type\n");
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
156 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
157 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
158
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
159 /* skip to the start of the data */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
160 url_fseek(pb, size, SEEK_SET);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
161
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
162 return 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
163 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
164
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
165
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
166 static int ea_probe(AVProbeData *p)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
167 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
168 if (p->buf_size < 4)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
169 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
170
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
171 if (LE_32(&p->buf[0]) != SCHl_TAG)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
172 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
173
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
174 return AVPROBE_SCORE_MAX;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
175 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
176
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
177 static int ea_read_header(AVFormatContext *s,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
178 AVFormatParameters *ap)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
179 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
180 EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
181 AVStream *st;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
182
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
183 if (!process_ea_header(s))
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
184 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
185
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
186 #if 0
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
187 /* initialize the video decoder stream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
188 st = av_new_stream(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
189 if (!st)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
190 return AVERROR_NOMEM;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
191 av_set_pts_info(st, 33, 1, 90000);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
192 ea->video_stream_index = st->index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
193 st->codec->codec_type = CODEC_TYPE_VIDEO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
194 st->codec->codec_id = CODEC_ID_EA_MJPEG;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
195 st->codec->codec_tag = 0; /* no fourcc */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
196 #endif
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
197
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
198 /* initialize the audio decoder stream */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
199 st = av_new_stream(s, 0);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
200 if (!st)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
201 return AVERROR_NOMEM;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
202 av_set_pts_info(st, 33, 1, EA_SAMPLE_RATE);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
203 st->codec->codec_type = CODEC_TYPE_AUDIO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
204 st->codec->codec_id = CODEC_ID_ADPCM_EA;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
205 st->codec->codec_tag = 0; /* no tag */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
206 st->codec->channels = ea->num_channels;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
207 st->codec->sample_rate = EA_SAMPLE_RATE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
208 st->codec->bits_per_sample = EA_BITS_PER_SAMPLE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
209 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate *
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
210 st->codec->bits_per_sample / 4;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
211 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
212
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
213 ea->audio_stream_index = st->index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
214 ea->audio_frame_counter = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
215
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
216 return 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
217 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
218
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
219 static int ea_read_packet(AVFormatContext *s,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
220 AVPacket *pkt)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
221 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
222 EaDemuxContext *ea = s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
223 ByteIOContext *pb = &s->pb;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
224 int ret = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
225 int packet_read = 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
226 unsigned char preamble[EA_PREAMBLE_SIZE];
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
227 unsigned int chunk_type, chunk_size;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
228
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
229 while (!packet_read) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
230
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
231 if (get_buffer(pb, preamble, EA_PREAMBLE_SIZE) != EA_PREAMBLE_SIZE)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
232 return AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
233 chunk_type = LE_32(&preamble[0]);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
234 chunk_size = LE_32(&preamble[4]) - EA_PREAMBLE_SIZE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
235
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
236 switch (chunk_type) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
237 /* audio data */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
238 case SCDl_TAG:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
239 ret = av_get_packet(pb, pkt, chunk_size);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
240 if (ret != chunk_size)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
241 ret = AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
242 else {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
243 pkt->stream_index = ea->audio_stream_index;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
244 pkt->pts = 90000;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
245 pkt->pts *= ea->audio_frame_counter;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
246 pkt->pts /= EA_SAMPLE_RATE;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
247
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
248 /* 2 samples/byte, 1 or 2 samples per frame depending
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
249 * on stereo; chunk also has 12-byte header */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
250 ea->audio_frame_counter += ((chunk_size - 12) * 2) /
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
251 ea->num_channels;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
252 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
253
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
254 packet_read = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
255 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
256
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
257 /* ending tag */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
258 case SCEl_TAG:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
259 ret = AVERROR_IO;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
260 packet_read = 1;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
261 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
262
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
263 default:
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
264 url_fseek(pb, chunk_size, SEEK_CUR);
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
265 break;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
266 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
267
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
268 /* ending packet */
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
269 if (chunk_type == SCEl_TAG) {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
270 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
271 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
272
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
273 return ret;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
274 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
275
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
276 static int ea_read_close(AVFormatContext *s)
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
277 {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
278 // EaDemuxContext *ea = (EaDemuxContext *)s->priv_data;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
279
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
280 return 0;
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
281 }
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
282
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
283 AVInputFormat ea_demuxer = {
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
284 "ea",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
285 "Electronic Arts Multimedia Format",
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
286 sizeof(EaDemuxContext),
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
287 ea_probe,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
288 ea_read_header,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
289 ea_read_packet,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
290 ea_read_close,
e8776388b02a [svn] - add ffmpeg
nenolod
parents:
diff changeset
291 };