[vlc-devel] VLC plugin transcode works fine, but decoder doesn't work for playback

yahui liu yahuior at gmail.com
Thu Aug 18 00:11:55 CEST 2011


Nobody say something?

On Wed, Aug 17, 2011 at 9:50 AM, yahui liu <yahuior at gmail.com> wrote:

> IMSDK is my plugin. Attached vlc-log.txt. And following part is my code for
> playback.
>
> #define ENABLE_DECODE_H264 1
> struct decoder_sys_t
> {
>  sDecodeInputParams Params;
>     mtime_t    i_pts;
>  bool    b_headerDecoded;
>  CDecodingPipeline* pPipeline;
> };
> static int  OpenDecoderH264 ( vlc_object_t *p_this );
> static int  OpenDecoder  ( vlc_object_t *p_this, mfxU32 codecId );
> static void CloseDecoder ( vlc_object_t *p_this );
> static void *DecodeBlock ( decoder_t *p_dec, block_t **pp_block );
> vlc_module_begin ()
>     set_category( CAT_INPUT )
>     set_subcategory( SUBCAT_INPUT_VCODEC )
>  set_shortname( "IMSDK" )
> #ifdef ENABLE_DECODE_H264
>  add_submodule ()
>     set_description( N_("MSDK video decoder H264") )
>     set_capability( "decoder", 100 )
>     set_callbacks( OpenDecoderH264, CloseDecoder )
>  add_shortcut( "msdkdech264" )
> #endif
> vlc_module_end ()
> static int OpenDecoderH264( vlc_object_t *p_this )
> {
>  decoder_t *p_dec = (decoder_t *)p_this;
>  msg_Dbg ( p_dec, "IMSDK Open H264 Decoder (fourcc=%x, origfourcc=%x)
> (MSDK=%x, H264=%x, MPEG=%x)",
>     p_dec->fmt_in.i_codec, p_dec->fmt_in.i_original_fourcc,
>     VLC_CODEC_MSDKH264, VLC_CODEC_H264, VLC_CODEC_MPGV);
>  return OpenDecoder( p_this, MFX_CODEC_AVC );
> }
> static int OpenDecoder( vlc_object_t *p_this, mfxU32 codecId )
> {
>     decoder_t  *p_dec = (decoder_t *)p_this;
>     decoder_sys_t *p_sys;
>  vlc_fourcc_t targetCodec;
>  if(MFX_CODEC_AVC == codecId)
>   targetCodec = VLC_CODEC_H264;
>  else if(MFX_CODEC_MPEG2 == codecId)
>   targetCodec = VLC_CODEC_MPGV;
>  else
>   return VLC_EGENERIC;
>  if( p_dec->fmt_in.i_codec != targetCodec )
>         return VLC_EGENERIC;
>     // Allocate the memory needed to store the decoder's structure
>  if( ( p_dec->p_sys = p_sys =(decoder_sys_t *)calloc(sizeof(decoder_sys_t),
> 1) ) == NULL )
>         return VLC_ENOMEM;
>
>  // Skip decoder command line parsince, does not seem it is supported....
>  //
>  //   config_ChainParse( p_dec, DEC_CFG_PREFIX, ppsz_dec_options,
> p_dec->p_cfg );
> // bool b_forcesw = var_GetBool( p_dec, DEC_CFG_PREFIX "forceswdec" );
> // msg_Dbg ( p_dec, "IMSDK Open Decoder: force SW decode: %d", b_forcesw );
>
>  fp = fopen("stream.h264", "wb");
>
>  p_sys->b_headerDecoded = false;
>     p_sys->i_pts = VLC_TS_INVALID;
>     // Set output properties
>     p_dec->fmt_out.i_cat = VIDEO_ES;
>  // NV12 would be preferred, but it looks like VLC does not fully support
> it.
> #ifdef USE_NV12_FORMAT
>     p_dec->fmt_out.i_codec = VLC_CODEC_NV12;
> #else
>  p_dec->fmt_out.i_codec = VLC_CODEC_YV12;
> #endif
>
>  // Set decoder frame plugin callback
>     p_dec->pf_decode_video = (picture_t *(*)(decoder_t *, block_t **))
> DecodeBlock;
>  // Create MSDK decode pipeline
>     p_sys->pPipeline = new CDecodingPipeline;
>  if(p_sys->pPipeline)
>  {
>   msg_Dbg ( p_dec, "IMSDK Open Decoder: decode pipeline created");
>   //
>   // Setup MSDK decoder parameters
>   //
>   p_sys->Params.videoType  = codecId;
> #ifdef USE_D3D_SURFACE
>   p_sys->Params.bd3dAlloc  = true;  // Use D3D surface for frame storage
> (currently not supported)
> #else
>   p_sys->Params.bd3dAlloc  = false; // Use system memory for frame storage
> #endif
> #ifdef USE_MSDK_DECODE_HW
>   p_sys->Params.bUseHWLib  = true;
> #else
>   p_sys->Params.bUseHWLib  = false;
> #endif
>   if(p_dec->fmt_out.i_codec == VLC_CODEC_NV12)
>    p_sys->Params.nRequestedColorFormat = MFX_FOURCC_NV12;
>   else if(p_dec->fmt_out.i_codec == VLC_CODEC_YV12)
>    p_sys->Params.nRequestedColorFormat = MFX_FOURCC_YV12;
>
>   // Initialize decode pipeline (just the first stage of init)
>   mfxStatus sts = p_sys->pPipeline->Init(&(p_sys->Params), p_dec);
>   msg_Dbg ( p_dec, "IMSDK Open Decoder:Init res=%d", sts);
>
>   if(MFX_ERR_NONE == sts)
>    return VLC_SUCCESS;
>   else
>    return VLC_EGENERIC;
>  }
>  else
>  {
>   msg_Dbg ( p_dec, "IMSDK Open Decoder: decode pipeline creation failed!");
>   return VLC_ENOMEM;
>  }
> }
>
> //
> // DecodeBlock:
> //
> static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
> {
>     decoder_sys_t *p_sys  = p_dec->p_sys;
>     block_t   *p_block;
>  picture_t  *p_pic;
>  mfxStatus  sts   = MFX_ERR_NONE;
>
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: p_dec data:");
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: codecin=%x, codecout=%x
> (NV12=%x,YV12=%x,I420=%x)", p_dec->fmt_in.i_codec, p_dec->fmt_out.i_codec,
> VLC_CODEC_NV12, VLC_CODEC_YV12, VLC_CODEC_I420);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: baserate=%d, rate=%d",
> p_dec->fmt_in.video.i_frame_rate_base, p_dec->fmt_in.video.i_frame_rate);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: width=%d, height=%d",
> p_dec->fmt_in.video.i_width, p_dec->fmt_in.video.i_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: chroma=%x",
> p_dec->fmt_in.video.i_chroma);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: xoff=%d, yoff=%d",
> p_dec->fmt_in.video.i_x_offset, p_dec->fmt_in.video.i_y_offset);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: viswidth=%d, visheight=%d",
> p_dec->fmt_in.video.i_visible_width, p_dec->fmt_in.video.i_visible_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: bitrate=%d, profile=%d,
> level=%d", p_dec->fmt_in.i_bitrate, p_dec->fmt_in.i_profile,
> p_dec->fmt_in.i_level);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: sarnum=%d, sarden=%d",
> p_dec->fmt_in.video.i_sar_num, p_dec->fmt_in.video.i_sar_den);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: IN: extrasize=%d, packed=%d",
> p_dec->fmt_in.i_extra, p_dec->fmt_in.b_packetized);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: baserate=%d, rate=%d",
> p_dec->fmt_out.video.i_frame_rate_base, p_dec->fmt_out.video.i_frame_rate);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: width=%d, height=%d",
> p_dec->fmt_out.video.i_width, p_dec->fmt_out.video.i_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: chroma=%x",
> p_dec->fmt_out.video.i_chroma);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: xoff=%d, yoff=%d",
> p_dec->fmt_out.video.i_x_offset, p_dec->fmt_out.video.i_y_offset);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: viswidth=%d, visheight=%d",
> p_dec->fmt_out.video.i_visible_width,
> p_dec->fmt_out.video.i_visible_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: bitrate=%d, profile=%d,
> level=%d", p_dec->fmt_out.i_bitrate, p_dec->fmt_out.i_profile,
> p_dec->fmt_out.i_level);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: OUT: sarnum=%d, sarden=%d",
> p_dec->fmt_out.video.i_sar_num, p_dec->fmt_out.video.i_sar_den);
>     if( !pp_block || !*pp_block )
>   return NULL;
>     p_block = *pp_block;
>  fwrite(p_block->p_buffer, 1, p_block->i_buffer, fp);
>
>   if(false == p_sys->b_headerDecoded)
>  {
>   sts = p_sys->pPipeline->InitHeader(p_block, p_dec);
>   msg_Dbg ( p_dec, "IMSDK decoder:InitHeader res=%d---------------yahui",
> sts);
>   if(MFX_ERR_NONE == sts)
>   {
>    // Header successfully processed
>    p_sys->b_headerDecoded = true;
>    // Initialize decoder (final init)
>    sts = p_sys->pPipeline->InitDecoder(p_dec);
>    msg_Dbg ( p_dec, "IMSDK decoder:InitDecoder res=%d", sts);
>
>   }
>   else if(MFX_WRN_INCOMPATIBLE_VIDEO_PARAM == sts)
>   {
>    // Header successfully processed (manual init)
>    p_sys->b_headerDecoded = true;
>    // Initialize decoder (final init)
>    sts = p_sys->pPipeline->InitDecoder(p_dec);
>    msg_Dbg ( p_dec, "IMSDK decoder:InitDecoder res=%d", sts);//res =5 for
> playback
>
>    block_Release( *pp_block );
>    return NULL;
>   }
>   else
>   {
>    // At the moment I have found no way of stopping the decoder, VLC just
> continues to to ship data to
>    // the plugin until the full media has been processed
>    block_Release( *pp_block );
>    return NULL;
>   }
>  }
>
>  //
>  // Process frame
>  //
> #ifdef USE_NV12_FORMAT
>  p_dec->fmt_out.i_codec = VLC_CODEC_NV12;
> #else
>  p_dec->fmt_out.i_codec = VLC_CODEC_YV12;
> #endif
>  // Initializations required for plyback case
>  p_dec->fmt_out.video.i_width = p_dec->fmt_in.video.i_width;
>  p_dec->fmt_out.video.i_height = p_dec->fmt_in.video.i_height;
>  p_dec->fmt_out.video.i_visible_width =
> p_dec->fmt_in.video.i_visible_width;
>  p_dec->fmt_out.video.i_visible_height =
> p_dec->fmt_in.video.i_visible_height;
>  p_dec->fmt_out.video.i_x_offset = p_dec->fmt_in.video.i_x_offset;
>  p_dec->fmt_out.video.i_y_offset = p_dec->fmt_in.video.i_y_offset;
>  p_dec->fmt_out.video.i_sar_num = p_dec->fmt_in.video.i_sar_num;
>  p_dec->fmt_out.video.i_sar_den = p_dec->fmt_in.video.i_sar_den;
>  p_dec->fmt_out.video.i_frame_rate = p_dec->fmt_in.video.i_frame_rate;
>  p_dec->fmt_out.video.i_frame_rate_base =
> p_dec->fmt_in.video.i_frame_rate_base;
>  // ...
>
>  *pp_block = NULL; // To avoid being fed the same packet again
>
>  p_pic = decoder_NewPicture( p_dec );
>  //p_pic = picture_NewFromFormat ()
>  if( !p_pic )
>   return NULL;
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: PIC: width=%d, height=%d",
> p_pic->format.i_width, p_pic->format.i_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: PIC: chroma=%x, refs=%d,
> planes=%d", p_pic->format.i_chroma, p_pic->i_refcount, p_pic->i_planes);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: PIC: xoff=%d, yoff=%d",
> p_pic->format.i_x_offset, p_pic->format.i_y_offset);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: PIC: viswidth=%d, visheight=%d",
> p_pic->format.i_visible_width, p_pic->format.i_visible_height);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: PIC: bitrate=%d, profile=%d,
> level=%d", p_dec->fmt_in.i_bitrate, p_dec->fmt_in.i_profile,
> p_dec->fmt_in.i_level);
>
>  // Time stamp management
>  if( p_block->i_pts > VLC_TS_INVALID )
>         p_sys->i_pts = p_block->i_pts;
>     else if( p_block->i_dts > VLC_TS_INVALID )
>         p_sys->i_pts = p_block->i_dts;
>  p_pic->date = p_sys->i_pts;
>
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: pts:%d (%d) dts:%d tlen:%d rate:%d
> bufsize:%d flags:%x",
>      p_block->i_pts, p_sys->i_pts, p_block->i_dts, p_block->i_length,
>      p_block->i_rate, p_block->i_buffer, p_block->i_flags);
>
>  // Decode the frame
>  sts = p_sys->pPipeline->RunDecodeFrame(p_dec, &p_pic, p_block);
>  msg_Dbg ( p_dec, "IMSDK decoder Frame: pPipeline->RunDecode:sts=%d", sts);
>  if( p_block )
>             block_Release( p_block );
>  if(MFX_ERR_NONE != sts)
>  {
>   decoder_DeletePicture(p_dec, p_pic);
>   return NULL;
>  }
>  else
>  {
>   // Successful decoding, return buffer
>   return p_pic;
>  }
> }
>
> //
> // CloseDecoder:
> //
> static void CloseDecoder( vlc_object_t *p_this )
> {
>     decoder_t  *p_dec = (decoder_t *)p_this;
>     decoder_sys_t *p_sys = p_dec->p_sys;
>  p_sys->pPipeline->Close();
>     delete p_sys->pPipeline;
>     free( p_sys );
>  fclose(fp);
>  msg_Dbg ( p_dec, "MSDK DEC END!");
> }
> Best,
>
>   On Wed, Aug 17, 2011 at 6:00 AM, Jean-Baptiste Kempf <jb at videolan.org>wrote:
>
>> On Tue, Aug 16, 2011 at 04:50:32PM -0700, yahui liu wrote :
>> > Does anyone have ideas or suggestions about this issue?
>>
>> Please share logs or code; or both.
>>
>> Best Regards,
>>
>> --
>> Jean-Baptiste Kempf
>> http://www.jbkempf.com/ - +33 672 704 734
>> Sent from my Electronic Device
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> http://mailman.videolan.org/listinfo/vlc-devel
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20110817/18dfd777/attachment.html>


More information about the vlc-devel mailing list