annotate sierravmd.c @ 373:e47d9c8e2054 libavformat

asf patch by (Konstantin Andreyev <kandreyev at bcsii dot com>) 1. Corrected packet sent time. (Packet sent time => previous packet sent time) 2. Corrected payload playing time. (Payload playing time => packet sent time) 3. Used different format for packets with one payload and multi payloads.
author michael
date Fri, 05 Mar 2004 22:10:50 +0000
parents 6f50cb0ead51
children f2760852ed18
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
338
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
1 /*
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
2 * Sierra VMD Format Demuxer
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
3 * Copyright (c) 2004 The ffmpeg Project
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
4 *
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
9 *
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
14 *
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
18 */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
19
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
20 /**
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
21 * @file sierravmd.c
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
22 * Sierra VMD file demuxer
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
23 * by Vladimir "VAG" Gneushev (vagsoft at mail.ru)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
24 */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
25
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
26 #include "avformat.h"
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
27
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
28 #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0])
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
29 #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
30 (((uint8_t*)(x))[2] << 16) | \
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
31 (((uint8_t*)(x))[1] << 8) | \
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
32 ((uint8_t*)(x))[0])
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
33
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
34 #define VMD_HEADER_SIZE 0x0330
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
35 #define BYTES_PER_FRAME_RECORD 16
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
36
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
37 typedef struct {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
38 int stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
39 offset_t frame_offset;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
40 unsigned int frame_size;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
41 int64_t pts;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
42 int keyframe;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
43 unsigned char frame_record[BYTES_PER_FRAME_RECORD];
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
44 } vmd_frame_t;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
45
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
46 typedef struct VmdDemuxContext {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
47 int video_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
48 int audio_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
49
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
50 unsigned int audio_type;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
51 unsigned int audio_samplerate;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
52 unsigned int audio_bits;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
53 unsigned int audio_channels;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
54
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
55 unsigned int frame_count;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
56 vmd_frame_t *frame_table;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
57 unsigned int current_frame;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
58
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
59 unsigned char vmd_header[VMD_HEADER_SIZE];
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
60 } VmdDemuxContext;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
61
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
62 static int vmd_probe(AVProbeData *p)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
63 {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
64 if (p->buf_size < 2)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
65 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
66
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
67 /* check if the first 2 bytes of the file contain the appropriate size
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
68 * of a VMD header chunk */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
69 if (LE_16(&p->buf[0]) != VMD_HEADER_SIZE - 2)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
70 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
71
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
72 /* only return half certainty since this check is a bit sketchy */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
73 return AVPROBE_SCORE_MAX / 2;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
74 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
75
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
76 static int vmd_read_header(AVFormatContext *s,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
77 AVFormatParameters *ap)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
78 {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
79 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
80 ByteIOContext *pb = &s->pb;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
81 AVStream *st;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
82 unsigned int toc_offset;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
83 unsigned char *raw_frame_table;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
84 int raw_frame_table_size;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
85 unsigned char *current_frame_record;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
86 offset_t current_offset;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
87 int i;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
88 int sample_rate;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
89 unsigned int total_frames;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
90 int video_frame_count = 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
91
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
92 /* fetch the main header, including the 2 header length bytes */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
93 url_fseek(pb, 0, SEEK_SET);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
94 if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
95 return -EIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
96
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
97 /* start up the decoders */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
98 st = av_new_stream(s, 0);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
99 if (!st)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
100 return AVERROR_NOMEM;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
101 vmd->video_stream_index = st->index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
102 st->codec.codec_type = CODEC_TYPE_VIDEO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
103 st->codec.codec_id = CODEC_ID_VMDVIDEO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
104 st->codec.codec_tag = 0; /* no fourcc */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
105 st->codec.width = LE_16(&vmd->vmd_header[12]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
106 st->codec.height = LE_16(&vmd->vmd_header[14]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
107 st->codec.extradata_size = VMD_HEADER_SIZE;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
108 st->codec.extradata = av_malloc(VMD_HEADER_SIZE);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
109 memcpy(st->codec.extradata, vmd->vmd_header, VMD_HEADER_SIZE);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
110
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
111 /* if sample rate is 0, assume no audio */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
112 sample_rate = LE_16(&vmd->vmd_header[804]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
113 if (sample_rate) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
114 st = av_new_stream(s, 0);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
115 if (!st)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
116 return AVERROR_NOMEM;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
117 vmd->audio_stream_index = st->index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
118 st->codec.codec_type = CODEC_TYPE_AUDIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
119 st->codec.codec_id = CODEC_ID_VMDAUDIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
120 st->codec.codec_tag = 0; /* no codec tag */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
121 st->codec.channels = (vmd->vmd_header[811] & 0x80) ? 2 : 1;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
122 st->codec.sample_rate = sample_rate;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
123 st->codec.bit_rate = st->codec.sample_rate *
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
124 st->codec.bits_per_sample * st->codec.channels;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
125 st->codec.block_align = LE_16(&vmd->vmd_header[806]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
126 if (st->codec.block_align & 0x8000) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
127 st->codec.bits_per_sample = 16;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
128 st->codec.block_align = -(st->codec.block_align - 0x10000);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
129 } else
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
130 st->codec.bits_per_sample = 8;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
131 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
132
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
133 /* skip over the offset table and load the table of contents; don't
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
134 * care about the offset table since demuxer will calculate those
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
135 * independently */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
136 toc_offset = LE_32(&vmd->vmd_header[812]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
137 vmd->frame_count = LE_16(&vmd->vmd_header[6]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
138 url_fseek(pb, toc_offset + vmd->frame_count * 6, SEEK_SET);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
139
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
140 /* each on-disk VMD frame has an audio part and a video part; demuxer
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
141 * accounts them separately */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
142 vmd->frame_count *= 2;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
143 raw_frame_table = NULL;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
144 vmd->frame_table = NULL;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
145 raw_frame_table_size = vmd->frame_count * BYTES_PER_FRAME_RECORD;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
146 raw_frame_table = av_malloc(raw_frame_table_size);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
147 vmd->frame_table = av_malloc(vmd->frame_count * sizeof(vmd_frame_t));
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
148 if (!raw_frame_table || !vmd->frame_table) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
149 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
150 av_free(vmd->frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
151 return AVERROR_NOMEM;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
152 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
153 if (get_buffer(pb, raw_frame_table, raw_frame_table_size) !=
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
154 raw_frame_table_size) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
155 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
156 av_free(vmd->frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
157 return -EIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
158 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
159
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
160 current_offset = LE_32(&vmd->vmd_header[20]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
161 current_frame_record = raw_frame_table;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
162 total_frames = vmd->frame_count;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
163 i = 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
164 while (total_frames--) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
165
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
166 /* if the frame size is 0, do not count the frame and bring the
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
167 * total frame count down */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
168 vmd->frame_table[i].frame_size = LE_32(&current_frame_record[2]);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
169
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
170 /* this logic is present so that 0-length audio chunks are not
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
171 * accounted */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
172 if (!vmd->frame_table[i].frame_size) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
173 vmd->frame_count--; /* one less frame to count */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
174 current_frame_record += BYTES_PER_FRAME_RECORD;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
175 continue;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
176 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
177
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
178 if (current_frame_record[0] == 0x02)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
179 vmd->frame_table[i].stream_index = vmd->video_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
180 else
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
181 vmd->frame_table[i].stream_index = vmd->audio_stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
182 vmd->frame_table[i].frame_offset = current_offset;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
183 current_offset += vmd->frame_table[i].frame_size;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
184 memcpy(vmd->frame_table[i].frame_record, current_frame_record,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
185 BYTES_PER_FRAME_RECORD);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
186
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
187 if (current_frame_record[0] == 0x02) {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
188 /* assume 15 fps for now */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
189 vmd->frame_table[i].pts = video_frame_count++;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
190 vmd->frame_table[i].pts *= 90000;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
191 vmd->frame_table[i].pts /= 15;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
192 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
193
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
194 current_frame_record += BYTES_PER_FRAME_RECORD;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
195 i++;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
196 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
197
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
198 av_free(raw_frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
199
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
200 /* set the pts reference at 1 pts = 1/90000 sec */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
201 s->pts_num = 1;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
202 s->pts_den = 90000;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
203
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
204 vmd->current_frame = 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
205
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
206 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
207 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
208
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
209 static int vmd_read_packet(AVFormatContext *s,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
210 AVPacket *pkt)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
211 {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
212 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
213 ByteIOContext *pb = &s->pb;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
214 int ret = 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
215 vmd_frame_t *frame;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
216
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
217 if (vmd->current_frame >= vmd->frame_count)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
218 return -EIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
219
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
220 frame = &vmd->frame_table[vmd->current_frame];
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
221 /* position the stream (will probably be there already) */
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
222 url_fseek(pb, frame->frame_offset, SEEK_SET);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
223
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
224 if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD))
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
225 return AVERROR_NOMEM;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
226 memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
227 ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
228 frame->frame_size);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
229
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
230 if (ret != frame->frame_size)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
231 ret = -EIO;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
232 pkt->stream_index = frame->stream_index;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
233 pkt->pts = frame->pts;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
234
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
235 vmd->current_frame++;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
236
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
237 return ret;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
238 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
239
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
240 static int vmd_read_close(AVFormatContext *s)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
241 {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
242 VmdDemuxContext *vmd = (VmdDemuxContext *)s->priv_data;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
243
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
244 av_free(vmd->frame_table);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
245
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
246 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
247 }
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
248
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
249 static AVInputFormat vmd_iformat = {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
250 "vmd",
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
251 "Sierra VMD format",
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
252 sizeof(VmdDemuxContext),
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
253 vmd_probe,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
254 vmd_read_header,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
255 vmd_read_packet,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
256 vmd_read_close,
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
257 };
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
258
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
259 int vmd_init(void)
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
260 {
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
261 av_register_input_format(&vmd_iformat);
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
262 return 0;
6f50cb0ead51 initial commit for Sierra VMD file demuxer
melanson
parents:
diff changeset
263 }