1 /*****************************************************************************
2 * mash.c: Video decoder using openmash codec implementations
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Sigmund Augdal <sigmunau@idi.ntnu.no>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
28 #include <vlc/decoder.h>
33 /*****************************************************************************
34 * decoder_sys_t : video decoder descriptor
35 *****************************************************************************/
42 IntraP64Decoder *p_decoder;
48 /****************************************************************************
50 ****************************************************************************/
51 static int OpenDecoder ( vlc_object_t * );
52 static void CloseDecoder ( vlc_object_t * );
54 static void *DecodeBlock ( decoder_t *, block_t ** );
57 static picture_t *DecodeFrame( decoder_t *, block_t * );
58 static block_t *SendFrame ( decoder_t *, block_t * );
61 /*****************************************************************************
63 *****************************************************************************/
65 set_description( _("Video decoder using openmash") );
66 set_capability( "decoder", 50 );
67 set_callbacks( OpenDecoder, CloseDecoder );
70 /*****************************************************************************
71 * OpenDecoder: probe the decoder and return score
72 *****************************************************************************/
73 static int OpenDecoder( vlc_object_t *p_this )
75 decoder_t *p_dec = (decoder_t*)p_this;
78 switch( p_dec->fmt_in.i_codec )
81 case VLC_FOURCC('h','2','6','1'):
82 case VLC_FOURCC('H','2','6','1'):
89 /* Allocate the memory needed to store the decoder's structure */
90 if( ( p_dec->p_sys = p_sys =
91 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
93 msg_Err( p_dec, "out of memory" );
98 p_sys->b_inited = VLC_FALSE;
101 /* Set output properties */
102 p_dec->fmt_out.i_cat = VIDEO_ES;
103 p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
106 p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
108 p_sys->p_decoder = new IntraP64Decoder();
114 /*****************************************************************************
115 * CloseDecoder: decoder destruction
116 *****************************************************************************/
117 static void CloseDecoder( vlc_object_t *p_this )
119 decoder_t *p_dec = (decoder_t*)p_this;
120 free( p_dec->p_sys );
124 /****************************************************************************
125 * DecodeBlock: the whole thing
126 ****************************************************************************
127 * This function must be fed with complete frames.
128 ****************************************************************************/
129 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
131 decoder_sys_t *p_sys = p_dec->p_sys;
134 uint32_t i_video_header;
136 int cc, sbit, ebit, mba, gob, quant, mvdh, mvdv;
137 int i_width, i_height;
139 if( !pp_block || !*pp_block ) return NULL;
143 if( !p_sys->i_pts && !p_block->i_pts && !p_block->i_dts )
145 /* We've just started the stream, wait for the first PTS. */
146 block_Release( p_block );
151 /* Date management */
152 if( p_block->i_pts > 0 || p_block->i_dts > 0 )
154 if( p_block->i_pts > 0 ) p_sys->i_pts = p_block->i_pts;
155 else if( p_block->i_dts > 0 ) p_sys->i_pts = p_block->i_dts;
158 i_video_header = *(uint32_t*)p_block->p_buffer; /* yes, it is native endian */
159 sbit = i_video_header >> 29; /* start bit position */
160 ebit = (i_video_header >> 26) & 7; /* end bit position */
161 msg_Dbg( p_dec, "sbit, ebit: %d,%d", sbit, ebit );
162 gob = (i_video_header >> 20) & 0xf; /* GOB number */
165 msg_Warn( p_dec, "invalid gob, buggy vic streamer?");
167 mba = (i_video_header >> 15) & 0x1f; /* Macroblock address predictor */
168 quant = (i_video_header >> 10) & 0x1f; /* quantizer */
169 mvdh = (i_video_header >> 5) & 0x1f; /* horizontal motion vector data */
170 mvdv = i_video_header & 0x1f; /* vertical motion vector data */
171 cc = p_block->i_buffer - 4;
172 msg_Dbg( p_dec, "packet size %d", cc );
174 /* Find out p_vdec->i_raw_size */
175 p_sys->p_decoder->decode( p_block->p_buffer + 4 /*bp?*/,
184 i_width = p_sys->p_decoder->width();
185 i_height = p_sys->p_decoder->height();
186 if( !p_sys->b_inited )
188 msg_Dbg( p_dec, "video size is perhaps %dx%d", i_width,
190 vout_InitFormat( &p_dec->fmt_out.video, VLC_FOURCC('I','4','2','0'),
192 VOUT_ASPECT_FACTOR * i_width / i_height );
193 p_sys->b_inited = VLC_TRUE;
197 // p_sys->p_decoder->sync();
198 if( p_block->i_flags & BLOCK_FLAG_END_OF_FRAME )
200 p_pic = p_dec->pf_vout_buffer_new( p_dec );
203 block_Release( p_block );
206 p_sys->p_decoder->sync();
207 p_sys->i_counter = 0;
208 p_frame = p_sys->p_decoder->frame();
209 p_dec->p_vlc->pf_memcpy( p_pic->p[0].p_pixels, p_frame, i_width*i_height );
210 p_frame += i_width * i_height;
211 p_dec->p_vlc->pf_memcpy( p_pic->p[1].p_pixels, p_frame, i_width*i_height/4 );
212 p_frame += i_width * i_height/4;
213 p_dec->p_vlc->pf_memcpy( p_pic->p[2].p_pixels, p_frame, i_width*i_height/4 );
214 p_pic->date = p_sys->i_pts;
216 block_Release( p_block);