2
2
* Interplay MVE File Demuxer
3
3
* Copyright (c) 2003 The ffmpeg Project
5
* This file is part of FFmpeg.
5
* This file is part of Libav.
7
* FFmpeg is free software; you can redistribute it and/or
7
* Libav is free software; you can redistribute it and/or
8
8
* modify it under the terms of the GNU Lesser General Public
9
9
* License as published by the Free Software Foundation; either
10
10
* version 2.1 of the License, or (at your option) any later version.
12
* FFmpeg is distributed in the hope that it will be useful,
12
* Libav is distributed in the hope that it will be useful,
13
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
15
* Lesser General Public License for more details.
17
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with FFmpeg; if not, write to the Free Software
18
* License along with Libav; if not, write to the Free Software
19
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
133
133
s->audio_chunk_size -= 6;
136
url_fseek(pb, s->audio_chunk_offset, SEEK_SET);
136
avio_seek(pb, s->audio_chunk_offset, SEEK_SET);
137
137
s->audio_chunk_offset = 0;
139
139
if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size))
163
163
return CHUNK_NOMEM;
165
165
pkt->pos= s->decode_map_chunk_offset;
166
url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET);
166
avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET);
167
167
s->decode_map_chunk_offset = 0;
169
if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) !=
169
if (avio_read(pb, pkt->data, s->decode_map_chunk_size) !=
170
170
s->decode_map_chunk_size) {
171
171
av_free_packet(pkt);
172
172
return CHUNK_EOF;
175
url_fseek(pb, s->video_chunk_offset, SEEK_SET);
175
avio_seek(pb, s->video_chunk_offset, SEEK_SET);
176
176
s->video_chunk_offset = 0;
178
if (get_buffer(pb, pkt->data + s->decode_map_chunk_size,
178
if (avio_read(pb, pkt->data + s->decode_map_chunk_size,
179
179
s->video_chunk_size) != s->video_chunk_size) {
180
180
av_free_packet(pkt);
181
181
return CHUNK_EOF;
204
204
/* This function loads and processes a single chunk in an IP movie file.
205
205
* It returns the type of chunk that was processed. */
206
static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb,
206
static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb,
209
209
unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
225
225
return chunk_type;
227
227
/* read the next chunk, wherever the file happens to be pointing */
229
229
return CHUNK_EOF;
230
if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
230
if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
231
231
CHUNK_PREAMBLE_SIZE)
232
232
return CHUNK_BAD;
233
233
chunk_size = AV_RL16(&chunk_preamble[0]);
271
271
while ((chunk_size > 0) && (chunk_type != CHUNK_BAD)) {
273
273
/* read the next chunk, wherever the file happens to be pointing */
274
if (pb->eof_reached) {
275
275
chunk_type = CHUNK_EOF;
278
if (get_buffer(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
278
if (avio_read(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) !=
279
279
CHUNK_PREAMBLE_SIZE) {
280
280
chunk_type = CHUNK_BAD;
300
300
case OPCODE_END_OF_STREAM:
301
301
debug_ipmovie("end of stream\n");
302
url_fseek(pb, opcode_size, SEEK_CUR);
302
avio_skip(pb, opcode_size);
305
305
case OPCODE_END_OF_CHUNK:
306
306
debug_ipmovie("end of chunk\n");
307
url_fseek(pb, opcode_size, SEEK_CUR);
307
avio_skip(pb, opcode_size);
310
310
case OPCODE_CREATE_TIMER:
360
360
case OPCODE_START_STOP_AUDIO:
361
361
debug_ipmovie("start/stop audio\n");
362
url_fseek(pb, opcode_size, SEEK_CUR);
362
avio_skip(pb, opcode_size);
365
365
case OPCODE_INIT_VIDEO_BUFFERS:
393
393
case OPCODE_UNKNOWN_14:
394
394
case OPCODE_UNKNOWN_15:
395
395
debug_ipmovie("unknown (but documented) opcode %02X\n", opcode_type);
396
url_fseek(pb, opcode_size, SEEK_CUR);
396
avio_skip(pb, opcode_size);
399
399
case OPCODE_SEND_BUFFER:
400
400
debug_ipmovie("send buffer\n");
401
url_fseek(pb, opcode_size, SEEK_CUR);
401
avio_skip(pb, opcode_size);
404
404
case OPCODE_AUDIO_FRAME:
405
405
debug_ipmovie("audio frame\n");
407
407
/* log position and move on for now */
408
s->audio_chunk_offset = url_ftell(pb);
408
s->audio_chunk_offset = avio_tell(pb);
409
409
s->audio_chunk_size = opcode_size;
410
url_fseek(pb, opcode_size, SEEK_CUR);
410
avio_skip(pb, opcode_size);
413
413
case OPCODE_SILENCE_FRAME:
414
414
debug_ipmovie("silence frame\n");
415
url_fseek(pb, opcode_size, SEEK_CUR);
415
avio_skip(pb, opcode_size);
418
418
case OPCODE_INIT_VIDEO_MODE:
419
419
debug_ipmovie("initialize video mode\n");
420
url_fseek(pb, opcode_size, SEEK_CUR);
420
avio_skip(pb, opcode_size);
423
423
case OPCODE_CREATE_GRADIENT:
424
424
debug_ipmovie("create gradient\n");
425
url_fseek(pb, opcode_size, SEEK_CUR);
425
avio_skip(pb, opcode_size);
428
428
case OPCODE_SET_PALETTE:
465
465
case OPCODE_SET_PALETTE_COMPRESSED:
466
466
debug_ipmovie("set palette compressed\n");
467
url_fseek(pb, opcode_size, SEEK_CUR);
467
avio_skip(pb, opcode_size);
470
470
case OPCODE_SET_DECODING_MAP:
471
471
debug_ipmovie("set decoding map\n");
473
473
/* log position and move on for now */
474
s->decode_map_chunk_offset = url_ftell(pb);
474
s->decode_map_chunk_offset = avio_tell(pb);
475
475
s->decode_map_chunk_size = opcode_size;
476
url_fseek(pb, opcode_size, SEEK_CUR);
476
avio_skip(pb, opcode_size);
479
479
case OPCODE_VIDEO_DATA:
480
480
debug_ipmovie("set video data\n");
482
482
/* log position and move on for now */
483
s->video_chunk_offset = url_ftell(pb);
483
s->video_chunk_offset = avio_tell(pb);
484
484
s->video_chunk_size = opcode_size;
485
url_fseek(pb, opcode_size, SEEK_CUR);
485
avio_skip(pb, opcode_size);
496
496
/* make a note of where the stream is sitting */
497
s->next_chunk_offset = url_ftell(pb);
497
s->next_chunk_offset = avio_tell(pb);
499
499
/* dispatch the first of any pending packets */
500
500
if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY))
521
521
AVFormatParameters *ap)
523
523
IPMVEContext *ipmovie = s->priv_data;
524
ByteIOContext *pb = s->pb;
524
AVIOContext *pb = s->pb;
527
527
unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE];
529
529
uint8_t signature_buffer[sizeof(signature)];
531
get_buffer(pb, signature_buffer, sizeof(signature_buffer));
531
avio_read(pb, signature_buffer, sizeof(signature_buffer));
532
532
while (memcmp(signature_buffer, signature, sizeof(signature))) {
533
533
memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1);
534
signature_buffer[sizeof(signature_buffer) - 1] = get_byte(pb);
534
signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb);
536
536
return AVERROR_EOF;
538
538
/* initialize private context members */
541
541
ipmovie->decode_map_chunk_offset = 0;
543
543
/* on the first read, this will position the stream at the first chunk */
544
ipmovie->next_chunk_offset = url_ftell(pb) + 4;
544
ipmovie->next_chunk_offset = avio_tell(pb) + 4;
546
546
/* process the first chunk which should be CHUNK_INIT_VIDEO */
547
547
if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO)
550
550
/* peek ahead to the next chunk-- if it is an init audio chunk, process
551
551
* it; if it is the first video chunk, this is a silent file */
552
if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
552
if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) !=
553
553
CHUNK_PREAMBLE_SIZE)
554
554
return AVERROR(EIO);
555
555
chunk_type = AV_RL16(&chunk_preamble[2]);
556
url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
556
avio_seek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR);
558
558
if (chunk_type == CHUNK_VIDEO)
559
559
ipmovie->audio_type = CODEC_ID_NONE; /* no audio */