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