00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include <vlc/vlc.h>
00028 #include <vlc/decoder.h>
00029 #include <vlc/vout.h>
00030
00031 #include <p64/p64.h>
00032
00033
00034
00035
00036 struct decoder_sys_t
00037 {
00038
00039
00040
00041 mtime_t i_pts;
00042 IntraP64Decoder *p_decoder;
00043 vlc_bool_t b_inited;
00044 int i_counter;
00045
00046 };
00047
00048
00049
00050
00051 static int OpenDecoder ( vlc_object_t * );
00052 static void CloseDecoder ( vlc_object_t * );
00053
00054 static void *DecodeBlock ( decoder_t *, block_t ** );
00055
00056 #if 0
00057 static picture_t *DecodeFrame( decoder_t *, block_t * );
00058 static block_t *SendFrame ( decoder_t *, block_t * );
00059 #endif
00060
00061
00062
00063
00064 vlc_module_begin();
00065 set_description( _("Video decoder using openmash") );
00066 set_capability( "decoder", 50 );
00067 set_category( CAT_INPUT );
00068 set_subcategory( SUBCAT_INPUT_VCODEC );
00069 set_callbacks( OpenDecoder, CloseDecoder );
00070 vlc_module_end();
00071
00072
00073
00074
00075 static int OpenDecoder( vlc_object_t *p_this )
00076 {
00077 decoder_t *p_dec = (decoder_t*)p_this;
00078 decoder_sys_t *p_sys;
00079
00080 switch( p_dec->fmt_in.i_codec )
00081 {
00082
00083 case VLC_FOURCC('h','2','6','1'):
00084 case VLC_FOURCC('H','2','6','1'):
00085 break;
00086
00087 default:
00088 return VLC_EGENERIC;
00089 }
00090
00091
00092 if( ( p_dec->p_sys = p_sys =
00093 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
00094 {
00095 msg_Err( p_dec, "out of memory" );
00096 return VLC_EGENERIC;
00097 }
00098
00099 p_sys->i_pts = 0;
00100 p_sys->b_inited = VLC_FALSE;
00101 p_sys->i_counter = 0;
00102
00103
00104 p_dec->fmt_out.i_cat = VIDEO_ES;
00105 p_dec->fmt_out.i_codec = VLC_FOURCC('I','4','2','0');
00106
00107
00108 p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
00109 DecodeBlock;
00110 p_sys->p_decoder = new IntraP64Decoder();
00111
00112
00113 return VLC_SUCCESS;
00114 }
00115
00116
00117
00118
00119 static void CloseDecoder( vlc_object_t *p_this )
00120 {
00121 decoder_t *p_dec = (decoder_t*)p_this;
00122 free( p_dec->p_sys );
00123 }
00124
00125
00126
00127
00128
00129
00130
00131 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
00132 {
00133 decoder_sys_t *p_sys = p_dec->p_sys;
00134 block_t *p_block;
00135 picture_t *p_pic;
00136 uint32_t i_video_header;
00137 uint8_t *p_frame;
00138 int cc, sbit, ebit, mba, gob, quant, mvdh, mvdv;
00139 int i_width, i_height;
00140
00141 if( !pp_block || !*pp_block ) return NULL;
00142
00143 p_block = *pp_block;
00144
00145 if( !p_sys->i_pts && !p_block->i_pts && !p_block->i_dts )
00146 {
00147
00148 block_Release( p_block );
00149 return NULL;
00150 }
00151
00152
00153
00154 if( p_block->i_pts > 0 || p_block->i_dts > 0 )
00155 {
00156 if( p_block->i_pts > 0 ) p_sys->i_pts = p_block->i_pts;
00157 else if( p_block->i_dts > 0 ) p_sys->i_pts = p_block->i_dts;
00158 }
00159
00160 i_video_header = *(uint32_t*)p_block->p_buffer;
00161 sbit = i_video_header >> 29;
00162 ebit = (i_video_header >> 26) & 7;
00163 msg_Dbg( p_dec, "sbit, ebit: %d,%d", sbit, ebit );
00164 gob = (i_video_header >> 20) & 0xf;
00165 if( gob > 12 )
00166 {
00167 msg_Warn( p_dec, "invalid gob, buggy vic streamer?");
00168 }
00169 mba = (i_video_header >> 15) & 0x1f;
00170 quant = (i_video_header >> 10) & 0x1f;
00171 mvdh = (i_video_header >> 5) & 0x1f;
00172 mvdv = i_video_header & 0x1f;
00173 cc = p_block->i_buffer - 4;
00174 msg_Dbg( p_dec, "packet size %d", cc );
00175
00176
00177 p_sys->p_decoder->decode( p_block->p_buffer + 4 ,
00178 cc ,
00179 sbit ,
00180 ebit ,
00181 mba ,
00182 gob ,
00183 quant ,
00184 mvdh ,
00185 mvdv );
00186 i_width = p_sys->p_decoder->width();
00187 i_height = p_sys->p_decoder->height();
00188 if( !p_sys->b_inited )
00189 {
00190 msg_Dbg( p_dec, "video size is perhaps %dx%d", i_width,
00191 i_height);
00192 vout_InitFormat( &p_dec->fmt_out.video, VLC_FOURCC('I','4','2','0'),
00193 i_width, i_height,
00194 VOUT_ASPECT_FACTOR * i_width / i_height );
00195 p_sys->b_inited = VLC_TRUE;
00196 }
00197 p_pic = NULL;
00198 p_sys->i_counter++;
00199
00200 if( p_block->i_flags & BLOCK_FLAG_END_OF_FRAME )
00201 {
00202 p_pic = p_dec->pf_vout_buffer_new( p_dec );
00203 if( !p_pic )
00204 {
00205 block_Release( p_block );
00206 return NULL;
00207 }
00208 p_sys->p_decoder->sync();
00209 p_sys->i_counter = 0;
00210 p_frame = p_sys->p_decoder->frame();
00211 p_dec->p_vlc->pf_memcpy( p_pic->p[0].p_pixels, p_frame, i_width*i_height );
00212 p_frame += i_width * i_height;
00213 p_dec->p_vlc->pf_memcpy( p_pic->p[1].p_pixels, p_frame, i_width*i_height/4 );
00214 p_frame += i_width * i_height/4;
00215 p_dec->p_vlc->pf_memcpy( p_pic->p[2].p_pixels, p_frame, i_width*i_height/4 );
00216 p_pic->date = p_sys->i_pts;
00217 }
00218 block_Release( p_block);
00219 *pp_block = NULL;
00220 return p_pic;
00221
00222 }