annotate electronicarts.c @ 666:ffad4fdbd3d1 libavformat

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