annotate mm.c @ 1315:af1ced65c24c libavformat

add support for grayscale rawvideo avi patch by Philippe De Muyter %phdm A macqel P be% Original thread: Date: Sep 15, 2006 10:18 AM Subject: [Ffmpeg-devel] [PATCH] ffmpeg does not recognize his own grayscale rawvideo avi's
author gpoirier
date Fri, 15 Sep 2006 09:42:51 +0000
parents 5c7b35fc0588
children 0899bfe4105c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
950
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
1 /*
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
2 * American Laser Games MM Format Demuxer
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
3 * Copyright (c) 2006 Peter Ross
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
4 *
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
9 *
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
13 * Lesser General Public License for more details.
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
14 *
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
1187
5c7b35fc0588 Fix FSF postal address.
diego
parents: 1169
diff changeset
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
950
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
18 */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
19
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
20 /**
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
21 * @file mm.c
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
22 * American Laser Games MM Format Demuxer
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
23 * by Peter Ross (suxen_drol at hotmail dot com)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
24 *
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
25 * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
26 * including Mad Dog McCree and Crime Patrol.
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
27 *
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
28 * Technical details here:
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
29 * http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
30 */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
31
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
32 #include "avformat.h"
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
33
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
34 #define MM_PREAMBLE_SIZE 6
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
35
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
36 #define MM_TYPE_HEADER 0x0
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
37 #define MM_TYPE_INTER 0x5
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
38 #define MM_TYPE_INTRA 0x8
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
39 #define MM_TYPE_INTRA_HH 0xc
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
40 #define MM_TYPE_INTER_HH 0xd
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
41 #define MM_TYPE_INTRA_HHV 0xe
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
42 #define MM_TYPE_INTER_HHV 0xf
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
43 #define MM_TYPE_AUDIO 0x15
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
44 #define MM_TYPE_PALETTE 0x31
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
45
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
46 #define MM_HEADER_LEN_V 0x16 /* video only */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
47 #define MM_HEADER_LEN_AV 0x18 /* video + audio */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
48
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
49 #define MM_PALETTE_COUNT 128
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
50 #define MM_PALETTE_SIZE (MM_PALETTE_COUNT*3)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
51
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
52 typedef struct {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
53 AVPaletteControl palette_control;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
54 unsigned int audio_pts, video_pts;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
55 } MmDemuxContext;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
56
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
57 static int mm_probe(AVProbeData *p)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
58 {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
59 /* the first chunk is always the header */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
60 if (p->buf_size < MM_PREAMBLE_SIZE)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
61 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
62 if (LE_16(&p->buf[0]) != MM_TYPE_HEADER)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
63 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
64 if (LE_32(&p->buf[2]) != MM_HEADER_LEN_V && LE_32(&p->buf[2]) != MM_HEADER_LEN_AV)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
65 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
66
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
67 /* only return half certainty since this check is a bit sketchy */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
68 return AVPROBE_SCORE_MAX / 2;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
69 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
70
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
71 static int mm_read_header(AVFormatContext *s,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
72 AVFormatParameters *ap)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
73 {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
74 MmDemuxContext *mm = (MmDemuxContext *)s->priv_data;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
75 ByteIOContext *pb = &s->pb;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
76 AVStream *st;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
77
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
78 unsigned int type, length;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
79 unsigned int frame_rate, width, height;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
80
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
81 type = get_le16(pb);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
82 length = get_le32(pb);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
83
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
84 if (type != MM_TYPE_HEADER)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
85 return AVERROR_INVALIDDATA;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
86
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
87 /* read header */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
88 get_le16(pb); /* total number of chunks */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
89 frame_rate = get_le16(pb);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
90 get_le16(pb); /* ibm-pc video bios mode */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
91 width = get_le16(pb);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
92 height = get_le16(pb);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
93 url_fseek(pb, length - 10, SEEK_CUR); /* unknown data */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
94
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
95 /* video stream */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
96 st = av_new_stream(s, 0);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
97 if (!st)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
98 return AVERROR_NOMEM;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
99 st->codec->codec_type = CODEC_TYPE_VIDEO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
100 st->codec->codec_id = CODEC_ID_MMVIDEO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
101 st->codec->codec_tag = 0; /* no fourcc */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
102 st->codec->width = width;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
103 st->codec->height = height;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
104 st->codec->palctrl = &mm->palette_control;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
105 av_set_pts_info(st, 64, 1, frame_rate);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
106
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
107 /* audio stream */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
108 if (length == MM_HEADER_LEN_AV) {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
109 st = av_new_stream(s, 0);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
110 if (!st)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
111 return AVERROR_NOMEM;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
112 st->codec->codec_type = CODEC_TYPE_AUDIO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
113 st->codec->codec_tag = 0; /* no fourcc */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
114 st->codec->codec_id = CODEC_ID_PCM_U8;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
115 st->codec->channels = 1;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
116 st->codec->sample_rate = 8000;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
117 av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
118 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
119
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
120 mm->palette_control.palette_changed = 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
121 mm->audio_pts = 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
122 mm->video_pts = 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
123 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
124 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
125
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
126 static int mm_read_packet(AVFormatContext *s,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
127 AVPacket *pkt)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
128 {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
129 MmDemuxContext *mm = (MmDemuxContext *)s->priv_data;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
130 ByteIOContext *pb = &s->pb;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
131 unsigned char preamble[MM_PREAMBLE_SIZE];
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
132 unsigned char pal[MM_PALETTE_SIZE];
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
133 unsigned int type, length;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
134 int i;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
135
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
136 while(1) {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
137
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
138 if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
139 return AVERROR_IO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
140 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
141
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
142 type = LE_16(&preamble[0]);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
143 length = LE_16(&preamble[2]);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
144
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
145 switch(type) {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
146 case MM_TYPE_PALETTE :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
147 url_fseek(pb, 4, SEEK_CUR); /* unknown data */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
148 if (get_buffer(pb, pal, MM_PALETTE_SIZE) != MM_PALETTE_SIZE)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
149 return AVERROR_IO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
150 url_fseek(pb, length - (4 + MM_PALETTE_SIZE), SEEK_CUR);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
151
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
152 for (i=0; i<MM_PALETTE_COUNT; i++) {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
153 int r = pal[i*3 + 0];
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
154 int g = pal[i*3 + 1];
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
155 int b = pal[i*3 + 2];
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
156 mm->palette_control.palette[i] = (r << 16) | (g << 8) | (b);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
157 /* repeat palette, where each components is multiplied by four */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
158 mm->palette_control.palette[i+128] = (r << 18) | (g << 10) | (b<<2);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
159 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
160 mm->palette_control.palette_changed = 1;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
161 break;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
162
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
163 case MM_TYPE_INTER :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
164 case MM_TYPE_INTRA :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
165 case MM_TYPE_INTRA_HH :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
166 case MM_TYPE_INTER_HH :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
167 case MM_TYPE_INTRA_HHV :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
168 case MM_TYPE_INTER_HHV :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
169 /* output preamble + data */
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
170 if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE))
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
171 return AVERROR_NOMEM;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
172 memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
173 if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
174 return AVERROR_IO;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
175 pkt->size = length + MM_PREAMBLE_SIZE;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
176 pkt->stream_index = 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
177 pkt->pts = mm->video_pts++;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
178 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
179
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
180 case MM_TYPE_AUDIO :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
181 if (av_get_packet(&s->pb, pkt, length)<0)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
182 return AVERROR_NOMEM;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
183 pkt->size = length;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
184 pkt->stream_index = 1;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
185 pkt->pts = mm->audio_pts++;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
186 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
187
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
188 default :
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
189 av_log(NULL, AV_LOG_INFO, "mm: unknown chunk type 0x%x\n", type);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
190 url_fseek(pb, length, SEEK_CUR);
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
191 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
192 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
193
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
194 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
195 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
196
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
197 static int mm_read_close(AVFormatContext *s)
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
198 {
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
199 return 0;
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
200 }
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
201
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
202 AVInputFormat mm_demuxer = {
950
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
203 "mm",
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
204 "American Laser Games MM format",
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
205 sizeof(MmDemuxContext),
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
206 mm_probe,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
207 mm_read_header,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
208 mm_read_packet,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
209 mm_read_close,
3a64595e57be complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff changeset
210 };