annotate interplayvideo.c @ 1439:a4d00b1f0271 libavcodec

initial commit for Id RoQ and Interplay MVE multimedia subsystems
author tmmm
date Tue, 02 Sep 2003 04:32:02 +0000
parents
children 92c1f24f7754
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1439
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
1 /*
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
2 * Interplay MVE Video Decoder
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
3 * Copyright (C) 2003 the ffmpeg project
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
4 *
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
9 *
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
13 * Lesser General Public License for more details.
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
14 *
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
18 *
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
19 */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
20
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
21 /**
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
22 * @file roqvideo.c
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
23 * Interplay MVE Video Decoder by Mike Melanson
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
24 * For more information about the Interplay MVE format, visit:
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
25 * http://www.pcisys.net/~melanson/codecs/
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
26 */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
27
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
28 #include <stdio.h>
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
29 #include <stdlib.h>
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
30 #include <string.h>
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
31 #include <unistd.h>
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
32
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
33 #include "common.h"
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
34 #include "avcodec.h"
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
35 #include "dsputil.h"
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
36
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
37 typedef struct IpvideoContext {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
38
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
39 AVCodecContext *avctx;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
40 DSPContext dsp;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
41 AVFrame last_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
42 AVFrame current_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
43 int first_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
44 int receiving_decoding_map;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
45 unsigned char *decoding_map;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
46 int decoding_map_size;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
47
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
48 unsigned char *buf;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
49 int size;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
50
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
51 } IpvideoContext;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
52
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
53 static int ipvideo_decode_init(AVCodecContext *avctx)
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
54 {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
55 IpvideoContext *s = avctx->priv_data;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
56
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
57 s->avctx = avctx;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
58 avctx->pix_fmt = PIX_FMT_YUV444P;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
59 avctx->has_b_frames = 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
60 dsputil_init(&s->dsp, avctx);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
61
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
62 s->first_frame = 1;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
63 s->receiving_decoding_map = 1; /* decoding map will be received first */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
64
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
65 /* decoding map contains 4 bits of information per 8x8 block */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
66 s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
67 s->decoding_map = av_malloc(s->decoding_map_size);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
68
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
69 return 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
70 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
71
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
72 static int ipvideo_decode_frame(AVCodecContext *avctx,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
73 void *data, int *data_size,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
74 uint8_t *buf, int buf_size)
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
75 {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
76 IpvideoContext *s = avctx->priv_data;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
77
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
78 if (s->receiving_decoding_map) {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
79 /* receiving the decoding map on this iteration */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
80 s->receiving_decoding_map = 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
81
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
82 if (buf_size != s->decoding_map_size)
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
83 printf (" Interplay video: buf_size != decoding_map_size (%d != %d)\n",
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
84 buf_size, s->decoding_map_size);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
85 else
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
86 memcpy(s->decoding_map, buf, buf_size);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
87
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
88 *data_size = 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
89 *(AVFrame*)data = s->last_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
90 } else {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
91 /* receiving the compressed video data on this iteration */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
92 s->receiving_decoding_map = 1;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
93 s->buf = buf;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
94 s->size = buf_size;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
95
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
96 if (avctx->get_buffer(avctx, &s->current_frame)) {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
97 printf (" Interplay Video: get_buffer() failed\n");
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
98 return -1;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
99 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
100
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
101 // ipvideo_decode_frame(s);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
102 memset(s->current_frame.data[0], 0x80, s->current_frame.linesize[0] * avctx->height);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
103 memset(s->current_frame.data[1], 0x80, s->current_frame.linesize[1] * avctx->height / 4);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
104 memset(s->current_frame.data[2], 0x80, s->current_frame.linesize[2] * avctx->height / 4);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
105
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
106 /* release the last frame if it is allocated */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
107 if (s->first_frame)
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
108 s->first_frame = 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
109 else
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
110 avctx->release_buffer(avctx, &s->last_frame);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
111
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
112 /* shuffle frames */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
113 s->last_frame = s->current_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
114
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
115 *data_size = sizeof(AVFrame);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
116 *(AVFrame*)data = s->current_frame;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
117 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
118
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
119 /* always report that the buffer was completely consumed */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
120 return buf_size;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
121 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
122
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
123 static int ipvideo_decode_end(AVCodecContext *avctx)
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
124 {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
125 IpvideoContext *s = avctx->priv_data;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
126
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
127 /* release the last frame */
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
128 avctx->release_buffer(avctx, &s->last_frame);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
129
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
130 av_free(s->decoding_map);
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
131
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
132 return 0;
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
133 }
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
134
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
135 AVCodec interplay_video_decoder = {
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
136 "interplayvideo",
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
137 CODEC_TYPE_VIDEO,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
138 CODEC_ID_INTERPLAY_VIDEO,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
139 sizeof(IpvideoContext),
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
140 ipvideo_decode_init,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
141 NULL,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
142 ipvideo_decode_end,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
143 ipvideo_decode_frame,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
144 CODEC_CAP_DR1,
a4d00b1f0271 initial commit for Id RoQ and Interplay MVE multimedia subsystems
tmmm
parents:
diff changeset
145 };