Mercurial > libavcodec.hg
annotate mmvideo.c @ 4785:4ae9ab738aec libavcodec
WMA decoder improvement, output closer to the dmo binary.
Patch by Ian Braithwaite ian braithwaite dot dk
[Ffmpeg-devel] WMA decoder improvement, 2007-03-28 15:50
author | banan |
---|---|
date | Wed, 04 Apr 2007 13:49:55 +0000 |
parents | 05e932ddaaa9 |
children | 66ef3690d108 |
rev | line source |
---|---|
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
1 /* |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
2 * American Laser Games MM Video Decoder |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
3 * Copyright (c) 2006 Peter Ross |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
16 * |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3517
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3517 | 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
20 */ |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
21 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
22 /** |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
23 * @file mm.c |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
24 * American Laser Games MM Video Decoder |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
25 * by Peter Ross (suxen_drol at hotmail dot com) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
26 * |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
27 * The MM format was used by IBM-PC ports of ALG's "arcade shooter" games, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
28 * including Mad Dog McCree and Crime Patrol. |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
29 * |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
30 * Technical details here: |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
31 * http://wiki.multimedia.cx/index.php?title=American_Laser_Games_MM |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
32 */ |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
33 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
34 #include "avcodec.h" |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
35 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
36 #define MM_PREAMBLE_SIZE 6 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
37 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
38 #define MM_TYPE_INTER 0x5 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
39 #define MM_TYPE_INTRA 0x8 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
40 #define MM_TYPE_INTRA_HH 0xc |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
41 #define MM_TYPE_INTER_HH 0xd |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
42 #define MM_TYPE_INTRA_HHV 0xe |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
43 #define MM_TYPE_INTER_HHV 0xf |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
44 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
45 typedef struct MmContext { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
46 AVCodecContext *avctx; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
47 AVFrame frame; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
48 } MmContext; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
49 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
50 static int mm_decode_init(AVCodecContext *avctx) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
51 { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
52 MmContext *s = avctx->priv_data; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
53 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
54 s->avctx = avctx; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
55 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
56 if (s->avctx->palctrl == NULL) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
57 av_log(avctx, AV_LOG_ERROR, "mmvideo: palette expected.\n"); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
58 return -1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
59 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
60 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
61 avctx->pix_fmt = PIX_FMT_PAL8; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
62 avctx->has_b_frames = 0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
63 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
64 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height)) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
65 return -1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
66 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
67 s->frame.reference = 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
68 if (avctx->get_buffer(avctx, &s->frame)) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
69 av_log(s->avctx, AV_LOG_ERROR, "mmvideo: get_buffer() failed\n"); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
70 return -1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
71 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
72 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
73 return 0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
74 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
75 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
76 static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
77 { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
78 int i, x, y; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
79 i=0; x=0; y=0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
80 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
81 while(i<buf_size) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
82 int run_length, color; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
83 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
84 if (buf[i] & 0x80) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
85 run_length = 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
86 color = buf[i]; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
87 i++; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
88 }else{ |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
89 run_length = (buf[i] & 0x7f) + 2; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
90 color = buf[i+1]; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
91 i+=2; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
92 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
93 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
94 if (half_horiz) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
95 run_length *=2; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
96 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
97 if (color) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
98 memset(s->frame.data[0] + y*s->frame.linesize[0] + x, color, run_length); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
99 if (half_vert) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
100 memset(s->frame.data[0] + (y+1)*s->frame.linesize[0] + x, color, run_length); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
101 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
102 x+= run_length; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
103 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
104 if (x >= s->avctx->width) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
105 x=0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
106 y += half_vert ? 2 : 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
107 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
108 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
109 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
110 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
111 static void mm_decode_inter(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
112 { |
4364 | 113 const int data_ptr = 2 + AV_RL16(&buf[0]); |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
114 int d, r, y; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
115 d = data_ptr; r = 2; y = 0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
116 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
117 while(r < data_ptr) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
118 int i, j; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
119 int length = buf[r] & 0x7f; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
120 int x = buf[r+1] + ((buf[r] & 0x80) << 1); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
121 r += 2; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
122 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
123 if (length==0) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
124 y += x; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
125 continue; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
126 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
127 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
128 for(i=0; i<length; i++) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
129 for(j=0; j<8; j++) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
130 int replace = (buf[r+i] >> (7-j)) & 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
131 if (replace) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
132 int color = buf[d]; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
133 s->frame.data[0][y*s->frame.linesize[0] + x] = color; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
134 if (half_horiz) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
135 s->frame.data[0][y*s->frame.linesize[0] + x + 1] = color; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
136 if (half_vert) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
137 s->frame.data[0][(y+1)*s->frame.linesize[0] + x] = color; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
138 if (half_horiz) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
139 s->frame.data[0][(y+1)*s->frame.linesize[0] + x + 1] = color; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
140 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
141 d++; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
142 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
143 x += half_horiz ? 2 : 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
144 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
145 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
146 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
147 r += length; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
148 y += half_vert ? 2 : 1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
149 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
150 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
151 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
152 static int mm_decode_frame(AVCodecContext *avctx, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
153 void *data, int *data_size, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
154 uint8_t *buf, int buf_size) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
155 { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
156 MmContext *s = avctx->priv_data; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
157 AVPaletteControl *palette_control = avctx->palctrl; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
158 int type; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
159 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
160 if (palette_control->palette_changed) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
161 memcpy(s->frame.data[1], palette_control->palette, AVPALETTE_SIZE); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
162 palette_control->palette_changed = 0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
163 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
164 |
4364 | 165 type = AV_RL16(&buf[0]); |
3119
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
166 buf += MM_PREAMBLE_SIZE; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
167 buf_size -= MM_PREAMBLE_SIZE; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
168 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
169 switch(type) { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
170 case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
171 case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
172 case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
173 case MM_TYPE_INTER : mm_decode_inter(s, 0, 0, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
174 case MM_TYPE_INTER_HH : mm_decode_inter(s, 1, 0, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
175 case MM_TYPE_INTER_HHV : mm_decode_inter(s, 1, 1, buf, buf_size); break; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
176 default : |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
177 return -1; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
178 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
179 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
180 *data_size = sizeof(AVFrame); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
181 *(AVFrame*)data = s->frame; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
182 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
183 return buf_size; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
184 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
185 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
186 static int mm_decode_end(AVCodecContext *avctx) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
187 { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
188 MmContext *s = avctx->priv_data; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
189 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
190 if(s->frame.data[0]) |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
191 avctx->release_buffer(avctx, &s->frame); |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
192 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
193 return 0; |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
194 } |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
195 |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
196 AVCodec mmvideo_decoder = { |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
197 "mmvideo", |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
198 CODEC_TYPE_VIDEO, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
199 CODEC_ID_MMVIDEO, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
200 sizeof(MmContext), |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
201 mm_decode_init, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
202 NULL, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
203 mm_decode_end, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
204 mm_decode_frame, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
205 CODEC_CAP_DR1, |
09ae2e981d64
complete American Laser Games MM playback system, courtesy of Peter Ross
melanson
parents:
diff
changeset
|
206 }; |