annotate idroq.c @ 220:1dbacadcd222 libavformat

big/little endian fix storing 64bit stuff in int fix put_v() fix startcodes nut_probe()
author michaelni
date Sat, 06 Sep 2003 14:03:35 +0000
parents 349d63d52e7e
children bca5abd97e43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
211
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
1 /*
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
2 * Id RoQ (.roq) File Demuxer
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
3 * Copyright (c) 2003 The ffmpeg Project
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
4 *
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
9 *
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
13 * Lesser General Public License for more details.
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
14 *
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
18 */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
19
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
20 /**
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
21 * @file idroq.c
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
22 * Id RoQ format file demuxer
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
23 * by Mike Melanson (melanson@pcisys.net)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
24 * for more information on the .roq file format, visit:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
25 * http://www.csse.monash.edu.au/~timf/
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
26 */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
27
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
28 #include "avformat.h"
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
29
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
30 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
31 #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
32 (((uint8_t*)(x))[2] << 16) | \
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
33 (((uint8_t*)(x))[1] << 8) | \
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
34 ((uint8_t*)(x))[0])
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
35
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
36 #define RoQ_MAGIC_NUMBER 0x1084
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
37 #define RoQ_CHUNK_PREAMBLE_SIZE 8
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
38 #define RoQ_AUDIO_SAMPLE_RATE 22050
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
39 #define RoQ_CHUNKS_TO_SCAN 30
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
40
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
41 #define RoQ_INFO 0x1001
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
42 #define RoQ_QUAD_CODEBOOK 0x1002
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
43 #define RoQ_QUAD_VQ 0x1011
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
44 #define RoQ_SOUND_MONO 0x1020
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
45 #define RoQ_SOUND_STEREO 0x1021
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
46
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
47 typedef struct RoqDemuxContext {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
48
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
49 int width;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
50 int height;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
51 int audio_channels;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
52 int framerate;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
53 int frame_pts_inc;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
54
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
55 int video_stream_index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
56 int audio_stream_index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
57
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
58 int64_t video_pts;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
59 unsigned int audio_frame_count;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
60
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
61 } RoqDemuxContext;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
62
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
63 static int roq_probe(AVProbeData *p)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
64 {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
65 if ((LE_16(&p->buf[0]) != RoQ_MAGIC_NUMBER) ||
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
66 (LE_32(&p->buf[2]) != 0xFFFFFFFF))
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
67 return 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
68
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
69 return AVPROBE_SCORE_MAX;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
70 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
71
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
72 static int roq_read_header(AVFormatContext *s,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
73 AVFormatParameters *ap)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
74 {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
75 RoqDemuxContext *roq = s->priv_data;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
76 ByteIOContext *pb = &s->pb;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
77 AVStream *st;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
78 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
79 int i;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
80 unsigned int chunk_size;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
81 unsigned int chunk_type;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
82
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
83 /* get the main header */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
84 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
85 RoQ_CHUNK_PREAMBLE_SIZE)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
86 return AVERROR_IO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
87 roq->framerate = LE_16(&preamble[6]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
88 roq->frame_pts_inc = 90000 / roq->framerate;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
89
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
90 /* set the pts reference (1 pts = 1/90000) */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
91 s->pts_num = 1;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
92 s->pts_den = 90000;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
93
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
94 /* init private context parameters */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
95 roq->width = roq->height = roq->audio_channels = roq->video_pts =
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
96 roq->audio_frame_count = 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
97
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
98 /* scan the first n chunks searching for A/V parameters */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
99 for (i = 0; i < RoQ_CHUNKS_TO_SCAN; i++) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
100 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
101 RoQ_CHUNK_PREAMBLE_SIZE)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
102 return AVERROR_IO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
103
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
104 chunk_type = LE_16(&preamble[0]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
105 chunk_size = LE_32(&preamble[2]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
106
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
107 switch (chunk_type) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
108
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
109 case RoQ_INFO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
110 /* fetch the width and height; reuse the preamble bytes */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
111 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
112 RoQ_CHUNK_PREAMBLE_SIZE)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
113 return AVERROR_IO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
114 roq->width = LE_16(&preamble[0]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
115 roq->height = LE_16(&preamble[2]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
116 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
117
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
118 case RoQ_QUAD_CODEBOOK:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
119 case RoQ_QUAD_VQ:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
120 /* ignore during this scan */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
121 url_fseek(pb, chunk_size, SEEK_CUR);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
122 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
123
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
124 case RoQ_SOUND_MONO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
125 roq->audio_channels = 1;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
126 url_fseek(pb, chunk_size, SEEK_CUR);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
127 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
128
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
129 case RoQ_SOUND_STEREO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
130 roq->audio_channels = 2;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
131 url_fseek(pb, chunk_size, SEEK_CUR);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
132 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
133
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
134 default:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
135 printf (" unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
136 return AVERROR_INVALIDDATA;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
137 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
138 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
139
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
140 /* if all necessary parameters have been gathered, exit early */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
141 if ((roq->width && roq->height) && roq->audio_channels)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
142 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
143 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
144
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
145 /* seek back to the first chunk */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
146 url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_SET);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
147
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
148 /* initialize the decoders */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
149 st = av_new_stream(s, 0);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
150 if (!st)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
151 return AVERROR_NOMEM;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
152 roq->video_stream_index = st->index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
153 st->codec.codec_type = CODEC_TYPE_VIDEO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
154 st->codec.codec_id = CODEC_ID_ROQ;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
155 st->codec.codec_tag = 0; /* no fourcc */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
156 st->codec.width = roq->width;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
157 st->codec.height = roq->height;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
158
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
159 if (roq->audio_channels) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
160 st = av_new_stream(s, 0);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
161 if (!st)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
162 return AVERROR_NOMEM;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
163 roq->audio_stream_index = st->index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
164 st->codec.codec_type = CODEC_TYPE_AUDIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
165 st->codec.codec_id = CODEC_ID_ROQ_DPCM;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
166 st->codec.codec_tag = 0; /* no tag */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
167 st->codec.channels = roq->audio_channels;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
168 st->codec.sample_rate = RoQ_AUDIO_SAMPLE_RATE;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
169 st->codec.bits_per_sample = 16;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
170 st->codec.bit_rate = st->codec.channels * st->codec.sample_rate *
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
171 st->codec.bits_per_sample;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
172 st->codec.block_align = st->codec.channels * st->codec.bits_per_sample;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
173 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
174 printf (" video is %d x %d, audio is %d channels\n",
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
175 roq->width, roq->height, roq->audio_channels);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
176
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
177 return 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
178 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
179
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
180 static int roq_read_packet(AVFormatContext *s,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
181 AVPacket *pkt)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
182 {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
183 RoqDemuxContext *roq = s->priv_data;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
184 ByteIOContext *pb = &s->pb;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
185 int ret = 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
186 unsigned int chunk_size;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
187 unsigned int chunk_type;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
188 unsigned int codebook_size;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
189 unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE];
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
190 int packet_read = 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
191 offset_t codebook_offset;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
192
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
193 while (!packet_read) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
194
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
195 if (url_feof(&s->pb))
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
196 return -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
197
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
198 /* get the next chunk preamble */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
199 if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) !=
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
200 RoQ_CHUNK_PREAMBLE_SIZE)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
201 return -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
202
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
203 chunk_type = LE_16(&preamble[0]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
204 chunk_size = LE_32(&preamble[2]);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
205
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
206 switch (chunk_type) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
207
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
208 case RoQ_INFO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
209 /* don't care about this chunk anymore */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
210 url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
211 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
212
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
213 case RoQ_QUAD_CODEBOOK:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
214 /* packet needs to contain both this codebook and next VQ chunk */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
215 codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
216 codebook_size = chunk_size;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
217 url_fseek(pb, codebook_size, SEEK_CUR);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
218 if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) !=
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
219 RoQ_CHUNK_PREAMBLE_SIZE)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
220 return -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
221 chunk_size = LE_32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 +
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
222 codebook_size;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
223
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
224 /* rewind */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
225 url_fseek(pb, codebook_offset, SEEK_SET);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
226
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
227 /* load up the packet */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
228 if (av_new_packet(pkt, chunk_size))
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
229 return -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
230 pkt->stream_index = roq->video_stream_index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
231 pkt->pts = roq->video_pts;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
232 ret = get_buffer(pb, pkt->data, chunk_size);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
233 if (ret != chunk_size)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
234 ret = -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
235
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
236 roq->video_pts += roq->frame_pts_inc;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
237 packet_read = 1;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
238 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
239
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
240 case RoQ_SOUND_MONO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
241 case RoQ_SOUND_STEREO:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
242 case RoQ_QUAD_VQ:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
243 /* load up the packet */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
244 if (av_new_packet(pkt, chunk_size + RoQ_CHUNK_PREAMBLE_SIZE))
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
245 return -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
246 /* copy over preamble */
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
247 memcpy(pkt->data, preamble, RoQ_CHUNK_PREAMBLE_SIZE);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
248
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
249 if (chunk_type == RoQ_QUAD_VQ) {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
250 pkt->stream_index = roq->video_stream_index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
251 pkt->pts = roq->video_pts;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
252 roq->video_pts += roq->frame_pts_inc;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
253 } else {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
254 pkt->stream_index = roq->audio_stream_index;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
255 pkt->pts = roq->audio_frame_count;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
256 pkt->pts *= 90000;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
257 pkt->pts /= RoQ_AUDIO_SAMPLE_RATE;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
258 roq->audio_frame_count += (chunk_size / roq->audio_channels);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
259 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
260
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
261 ret = get_buffer(pb, pkt->data, chunk_size);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
262 if (ret != chunk_size)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
263 ret = -EIO;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
264
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
265 packet_read = 1;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
266 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
267
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
268 default:
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
269 printf (" unknown RoQ chunk (%04X)\n", chunk_type);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
270 return AVERROR_INVALIDDATA;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
271 break;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
272 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
273 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
274
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
275 return ret;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
276 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
277
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
278 static int roq_read_close(AVFormatContext *s)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
279 {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
280 // RoqDemuxContext *roq = (RoqDemuxContext *)s->priv_data;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
281
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
282 return 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
283 }
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
284
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
285 static AVInputFormat roq_iformat = {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
286 "RoQ",
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
287 "Id RoQ format",
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
288 sizeof(RoqDemuxContext),
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
289 roq_probe,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
290 roq_read_header,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
291 roq_read_packet,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
292 roq_read_close,
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
293 };
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
294
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
295 int roq_init(void)
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
296 {
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
297 av_register_input_format(&roq_iformat);
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
298 return 0;
349d63d52e7e initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
299 }