Exemplo n.º 1
0
CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec(CDVDStreamInfo &hint, bool allowpassthrough)
{
  CDVDAudioCodec* pCodec = NULL;
  CDVDCodecOptions options;

  // we don't use passthrough if "sync playback to display" is enabled
  if (allowpassthrough)
  {
    pCodec = OpenCodec(new CDVDAudioCodecPassthrough(), hint, options);
    if( pCodec ) return pCodec;
  }

#if defined(TARGET_DARWIN)
  if (hint.codec == AV_CODEC_ID_AC3 || hint.codec == AV_CODEC_ID_EAC3)
  {
    if (!hint.realtime && hint.filename != "dvd")
    {
      pCodec = OpenCodec(new CDVDAudioCodecAudioConverter(), hint, options);
      if( pCodec )
        return pCodec;
    }
  }
#endif

  pCodec = OpenCodec(new CDVDAudioCodecFFmpeg(), hint, options);
  if (pCodec)
    return pCodec;

  return nullptr;
}
Exemplo n.º 2
0
CDVDOverlayCodec* CDVDFactoryCodec::CreateOverlayCodec( CDVDStreamInfo &hint )
{
  CDVDOverlayCodec* pCodec = NULL;
  CDVDCodecOptions options;

  switch (hint.codec)
  {
    case AV_CODEC_ID_TEXT:
    case AV_CODEC_ID_SUBRIP:
      pCodec = OpenCodec(new CDVDOverlayCodecText(), hint, options);
      if( pCodec ) return pCodec;
      break;

    case AV_CODEC_ID_SSA:
      pCodec = OpenCodec(new CDVDOverlayCodecSSA(), hint, options);
      if( pCodec ) return pCodec;

      pCodec = OpenCodec(new CDVDOverlayCodecText(), hint, options);
      if( pCodec ) return pCodec;
      break;

    case AV_CODEC_ID_MOV_TEXT:
      pCodec = OpenCodec(new CDVDOverlayCodecTX3G(), hint, options);
      if( pCodec ) return pCodec;
      break;

    default:
      pCodec = OpenCodec(new CDVDOverlayCodecFFmpeg(), hint, options);
      if( pCodec ) return pCodec;
      break;
  }

  return NULL;
}
Exemplo n.º 3
0
CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec( CDVDStreamInfo &hint)
{
  CDVDAudioCodec* pCodec = NULL;
  CDVDCodecOptions options;

  // try passthrough first
  pCodec = OpenCodec( new CDVDAudioCodecPassthrough(), hint, options );
  if( pCodec ) return pCodec;

  pCodec = OpenCodec( new CDVDAudioCodecFFmpeg(), hint, options );
  if( pCodec ) return pCodec;

  return NULL;
}
Exemplo n.º 4
0
/***********************
* SetSize
*	Inicializa el tama�o de la imagen a codificar
************************/
int H263Encoder1996::SetSize(int width, int height)
{
	Log("-SetSize [%d,%d]\n",width,height);

	//Check size
	if (!(
		(width==128 && height==96)  ||
		(width==176 && height==144) ||
		(width==352 && height==288) ||
		(width==704 && height==576) ||
		(width==1408 && height==5711526)
		))
		//Error
		return Error("Size not supported for H263");

	// Set pixel format
	ctx->pix_fmt		= PIX_FMT_YUV420P;
	ctx->width 		= width;
	ctx->height 		= height;

	// Set picture data
	picture->linesize[0] = width;
	picture->linesize[1] = width/2;
	picture->linesize[2] = width/2;

	// Open codec
	return OpenCodec();
}
Exemplo n.º 5
0
RString MovieDecoder_FFMpeg::Open( RString sFile )
{
	MovieTexture_FFMpeg::RegisterProtocols();

	int ret = avcodec::av_open_input_file( &m_fctx, "rage://" + sFile, NULL, 0, NULL );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "AVCodec: Couldn't open \"%s\"", sFile.c_str()) );

	ret = avcodec::av_find_stream_info( m_fctx );
	if( ret < 0 )
		return RString( averr_ssprintf(ret, "AVCodec (%s): Couldn't find codec parameters", sFile.c_str()) );

	avcodec::AVStream *pStream = FindVideoStream( m_fctx );
	if( pStream == NULL )
		return "Couldn't find any video streams";
	m_pStream = pStream;

	if( m_pStream->codec->codec_id == avcodec::CODEC_ID_NONE )
		return ssprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag );

	RString sError = OpenCodec();
	if( !sError.empty() )
		return ssprintf( "AVCodec (%s): %s", sFile.c_str(), sError.c_str() );

	LOG->Trace( "Bitrate: %i", m_pStream->codec->bit_rate );
	LOG->Trace( "Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(m_pStream->codec->pix_fmt) );

	return RString();
}
Exemplo n.º 6
0
CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec(CDVDStreamInfo &hint, bool allowpassthrough)
{
  CDVDAudioCodec* pCodec = NULL;
  CDVDCodecOptions options;

  // we don't use passthrough if "sync playback to display" is enabled
  if (allowpassthrough)
  {
    pCodec = OpenCodec(new CDVDAudioCodecPassthrough(), hint, options);
    if (pCodec)
      return pCodec;
  }

  pCodec = OpenCodec(new CDVDAudioCodecFFmpeg(), hint, options);
  if (pCodec)
    return pCodec;

  return NULL;
}
Exemplo n.º 7
0
std::string MovieDecoder_FFMpeg::Open( std::string sFile )
{
	MovieTexture_FFMpeg::RegisterProtocols();
    
	m_fctx = avcodec::avformat_alloc_context();
	if( !m_fctx )
		return "AVCodec: Couldn't allocate context";
    
	RageFile *f = new RageFile;

	if( !f->Open(sFile, RageFile::READ) )
	{
		std::string errorMessage = f->GetError();
		std::string error = fmt::sprintf("MovieDecoder_FFMpeg: Error opening \"%s\": %s", sFile.c_str(), errorMessage.c_str() );
		delete f;
		return error;
	}

	m_buffer = (unsigned char *)avcodec::av_malloc(STEPMANIA_FFMPEG_BUFFER_SIZE);
	m_avioContext = avcodec::avio_alloc_context(m_buffer, STEPMANIA_FFMPEG_BUFFER_SIZE, 0, f, AVIORageFile_ReadPacket, nullptr, AVIORageFile_Seek);
	m_fctx->pb = m_avioContext;
	int ret = avcodec::avformat_open_input( &m_fctx, sFile.c_str(), nullptr, nullptr );
	if( ret < 0 )
		return std::string( averr_format(ret, "AVCodec: Couldn't open \"%s\"", sFile.c_str()) );

	ret = avcodec::avformat_find_stream_info( m_fctx, nullptr );
	if( ret < 0 )
		return std::string( averr_format(ret, "AVCodec (%s): Couldn't find codec parameters", sFile.c_str()) );

	int stream_idx = avcodec::av_find_best_stream( m_fctx, avcodec::AVMEDIA_TYPE_VIDEO, -1, -1, nullptr, 0 );
	if ( stream_idx < 0 ||
		static_cast<unsigned int>(stream_idx) >= m_fctx->nb_streams ||
		m_fctx->streams[stream_idx] == nullptr )
		return "Couldn't find any video streams";
	m_pStream = m_fctx->streams[stream_idx];

	if( m_pStream->codec->codec_id == avcodec::CODEC_ID_NONE )
		return fmt::sprintf( "Unsupported codec %08x", m_pStream->codec->codec_tag );

	std::string sError = OpenCodec();
	if( !sError.empty() )
		return fmt::sprintf( "AVCodec (%s): %s", sFile.c_str(), sError.c_str() );

	LOG->Trace( "Bitrate: %i", m_pStream->codec->bit_rate );
	char const* fmt_name= avcodec::av_get_pix_fmt_name(m_pStream->codec->pix_fmt);
	if(fmt_name == nullptr)
	{
		LOG->Trace("Codec pixel format: Unknown");
	}
	else
	{
		LOG->Trace("Codec pixel format: %s", fmt_name);
	}
	return std::string();
}
Exemplo n.º 8
0
CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec( CDVDStreamInfo &hint, bool passthrough /* = true */)
{
  CDVDAudioCodec* pCodec = NULL;
  CDVDCodecOptions options;

  if (passthrough)
  {
#if defined(TARGET_DARWIN_OSX) || defined(TARGET_DARWIN_IOS)
    switch(hint.codec)
    {
      case AV_CODEC_ID_AC3:
      case AV_CODEC_ID_DTS:
        pCodec = OpenCodec( new CDVDAudioCodecPassthroughFFmpeg(), hint, options );
        if( pCodec ) return pCodec;
        break;
      default:
        break;      
    }
#endif
    pCodec = OpenCodec( new CDVDAudioCodecPassthrough(), hint, options );
    if( pCodec ) return pCodec;
  }

  switch (hint.codec)
  {
  case AV_CODEC_ID_MP2:
  case AV_CODEC_ID_MP3:
    {
      pCodec = OpenCodec( new CDVDAudioCodecLibMad(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
  case AV_CODEC_ID_PCM_S32LE:
  case AV_CODEC_ID_PCM_S32BE:
  case AV_CODEC_ID_PCM_U32LE:
  case AV_CODEC_ID_PCM_U32BE:
  case AV_CODEC_ID_PCM_S24LE:
  case AV_CODEC_ID_PCM_S24BE:
  case AV_CODEC_ID_PCM_U24LE:
  case AV_CODEC_ID_PCM_U24BE:
  case AV_CODEC_ID_PCM_S24DAUD:
  case AV_CODEC_ID_PCM_S16LE:
  case AV_CODEC_ID_PCM_S16BE:
  case AV_CODEC_ID_PCM_U16LE:
  case AV_CODEC_ID_PCM_U16BE:
  case AV_CODEC_ID_PCM_S8:
  case AV_CODEC_ID_PCM_U8:
  case AV_CODEC_ID_PCM_ALAW:
  case AV_CODEC_ID_PCM_MULAW:
    {
      pCodec = OpenCodec( new CDVDAudioCodecPcm(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
#if 0
  //case AV_CODEC_ID_LPCM_S16BE:
  //case AV_CODEC_ID_LPCM_S20BE:
  case AV_CODEC_ID_LPCM_S24BE:
    {
      pCodec = OpenCodec( new CDVDAudioCodecLPcm(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
#endif
  default:
    {
      pCodec = NULL;
      break;
    }
  }

  pCodec = OpenCodec( new CDVDAudioCodecFFmpeg(), hint, options );
  if( pCodec ) return pCodec;

  return NULL;
}
Exemplo n.º 9
0
CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, unsigned int surfaces, const std::vector<ERenderFormat>& formats)
{
  CDVDVideoCodec* pCodec = NULL;
  CDVDCodecOptions options;

  if(formats.empty())
    options.m_formats.push_back(RENDER_FMT_YUV420P);
  else
    options.m_formats = formats;

  //when support for a hardware decoder is not compiled in
  //only print it if it's actually available on the platform
  CStdString hwSupport;
#if defined(TARGET_DARWIN_OSX)
  hwSupport += "VDADecoder:yes ";
#endif
#if defined(HAVE_VIDEOTOOLBOXDECODER) && defined(TARGET_DARWIN)
  hwSupport += "VideoToolBoxDecoder:yes ";
#elif defined(TARGET_DARWIN)
  hwSupport += "VideoToolBoxDecoder:no ";
#endif
#ifdef HAVE_LIBCRYSTALHD
  hwSupport += "CrystalHD:yes ";
#else
  hwSupport += "CrystalHD:no ";
#endif
#if defined(HAS_LIBAMCODEC)
  hwSupport += "AMCodec:yes ";
#else
  hwSupport += "AMCodec:no ";
#endif
#if defined(HAVE_LIBOPENMAX) && defined(TARGET_POSIX)
  hwSupport += "OpenMax:yes ";
#elif defined(TARGET_POSIX)
  hwSupport += "OpenMax:no ";
#endif
#if defined(HAS_LIBSTAGEFRIGHT)
  hwSupport += "libstagefright:yes ";
#elif defined(_LINUX)
  hwSupport += "libstagefright:no ";
#endif
#if defined(HAVE_LIBVDPAU) && defined(TARGET_POSIX)
  hwSupport += "VDPAU:yes ";
#elif defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
  hwSupport += "VDPAU:no ";
#endif
#if defined(TARGET_WINDOWS) && defined(HAS_DX)
  hwSupport += "DXVA:yes ";
#elif defined(TARGET_WINDOWS)
  hwSupport += "DXVA:no ";
#endif
#if defined(HAVE_LIBVA) && defined(TARGET_POSIX)
  hwSupport += "VAAPI:yes ";
#elif defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
  hwSupport += "VAAPI:no ";
#endif

  CLog::Log(LOGDEBUG, "CDVDFactoryCodec: compiled in hardware support: %s", hwSupport.c_str());
#if !defined(HAS_LIBAMCODEC)
  // dvd's have weird still-frames in it, which is not fully supported in ffmpeg
  if(hint.stills && (hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_MPEG1VIDEO))
  {
    if( (pCodec = OpenCodec(new CDVDVideoCodecLibMpeg2(), hint, options)) ) return pCodec;
  }
#endif

#if defined(TARGET_DARWIN_OSX)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usevda"))
  {
    if (hint.codec == AV_CODEC_ID_H264 && !hint.ptsinvalid)
    {
      if ( (pCodec = OpenCodec(new CDVDVideoCodecVDA(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAVE_VIDEOTOOLBOXDECODER)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usevideotoolbox"))
  {
    if (g_sysinfo.HasVideoToolBoxDecoder())
    {
      switch(hint.codec)
      {
        case AV_CODEC_ID_H264:
          if (hint.codec == AV_CODEC_ID_H264 && hint.ptsinvalid)
            break;
          if ( (pCodec = OpenCodec(new CDVDVideoCodecVideoToolBox(), hint, options)) ) return pCodec;
        break;
        default:
        break;
      }
    }
  }
#endif

#if defined(HAVE_LIBCRYSTALHD)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usechd"))
  {
    if (CCrystalHD::GetInstance()->DevicePresent())
    {
      switch(hint.codec)
      {
        case AV_CODEC_ID_VC1:
        case AV_CODEC_ID_WMV3:
        case AV_CODEC_ID_H264:
        case AV_CODEC_ID_MPEG2VIDEO:
          if (hint.codec == AV_CODEC_ID_H264 && hint.ptsinvalid)
            break;
          if (hint.codec == AV_CODEC_ID_MPEG2VIDEO && hint.width <= 720)
            break;
          if ( (pCodec = OpenCodec(new CDVDVideoCodecCrystalHD(), hint, options)) ) return pCodec;
        break;
        default:
        break;
      }
    }
  }
#endif

#if defined(HAS_LIBAMCODEC)
  if (!hint.software)
  {
    CLog::Log(LOGINFO, "Amlogic Video Decoder...");
    if ( (pCodec = OpenCodec(new CDVDVideoCodecAmlogic(), hint, options)) ) return pCodec;
  }
#endif

#if defined(HAVE_LIBOPENMAX)
  if (CSettings::Get().GetBool("videoplayer.useomx") && !hint.software )
  {
      if (hint.codec == AV_CODEC_ID_H264 || hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_VC1)
    {
      if ( (pCodec = OpenCodec(new CDVDVideoCodecOpenMax(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAS_LIBSTAGEFRIGHT)
  if (CSettings::Get().GetBool("videoplayer.usestagefright") && !hint.software )
  {
    switch(hint.codec)
    {
      case CODEC_ID_H264:
      case CODEC_ID_MPEG4:
      case CODEC_ID_MPEG2VIDEO:
      case CODEC_ID_VC1:
      case CODEC_ID_WMV3:
      case CODEC_ID_VP3:
      case CODEC_ID_VP6:
      case CODEC_ID_VP6F:
      case CODEC_ID_VP8:
        if ( (pCodec = OpenCodec(new CDVDVideoCodecStageFright(), hint, options)) ) return pCodec;
        break;
      default:
        break;
    }
  }
#endif

  // try to decide if we want to try halfres decoding
#if !defined(TARGET_POSIX) && !defined(TARGET_WINDOWS)
  float pixelrate = (float)hint.width*hint.height*hint.fpsrate/hint.fpsscale;
  if( pixelrate > 1400.0f*720.0f*30.0f )
  {
    CLog::Log(LOGINFO, "CDVDFactoryCodec - High video resolution detected %dx%d, trying half resolution decoding ", hint.width, hint.height);
    options.m_keys.push_back(CDVDCodecOption("lowres","1"));
  }
#endif

  CStdString value;
  value.Format("%d", surfaces);
  options.m_keys.push_back(CDVDCodecOption("surfaces", value));
  if( (pCodec = OpenCodec(new CDVDVideoCodecFFmpeg(), hint, options)) ) return pCodec;

  return NULL;
}
Exemplo n.º 10
0
CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, unsigned int surfaces)
{
  CDVDVideoCodec* pCodec = NULL;
  CDVDCodecOptions options;

  //when support for a hardware decoder is not compiled in
  //only print it if it's actually available on the platform
  CStdString hwSupport;
#if defined(HAVE_LIBVDADECODER) && defined(__APPLE__)
  hwSupport += "VDADecoder:yes ";
#elif defined(__APPLE__)
  hwSupport += "VDADecoder:no ";
#endif
#if defined(HAVE_VIDEOTOOLBOXDECODER) && defined(__APPLE__)
  hwSupport += "VideoToolBoxDecoder:yes ";
#elif defined(__APPLE__)
  hwSupport += "VideoToolBoxDecoder:no ";
#endif
#ifdef HAVE_LIBCRYSTALHD
  hwSupport += "CrystalHD:yes ";
#else
  hwSupport += "CrystalHD:no ";
#endif
#if defined(HAVE_LIBOPENMAX) && defined(_LINUX)
  hwSupport += "OpenMax:yes ";
#elif defined(_LINUX)
  hwSupport += "OpenMax:no ";
#endif
#if defined(HAVE_LIBVDPAU) && defined(_LINUX)
  hwSupport += "VDPAU:yes ";
#elif defined(_LINUX) && !defined(__APPLE__)
  hwSupport += "VDPAU:no ";
#endif
#if defined(_WIN32) && defined(HAS_DX)
  hwSupport += "DXVA:yes ";
#elif defined(_WIN32)
  hwSupport += "DXVA:no ";
#endif
#if defined(HAVE_LIBVA) && defined(_LINUX)
  hwSupport += "VAAPI:yes ";
#elif defined(_LINUX) && !defined(__APPLE__)
  hwSupport += "VAAPI:no ";
#endif
#if defined(HAVE_LIBGSTREAMER)
  hwSupport += "GStreamer:yes ";
#else
  hwSupport += "GStreamer:no ";
#endif

  CLog::Log(LOGDEBUG, "CDVDFactoryCodec: compiled in hardware support: %s", hwSupport.c_str());

#if defined(HAVE_LIBGSTREAMER)
  if (!hint.software)
  {
      CLog::Log(LOGINFO, "Trying GStreamer Video Decoder...");
      if ( (pCodec = OpenCodec(new CDVDVideoCodecGStreamer(), hint, options)) ) return pCodec;
  }
#endif

  // dvd's have weird still-frames in it, which is not fully supported in ffmpeg
  if(hint.stills && (hint.codec == CODEC_ID_MPEG2VIDEO || hint.codec == CODEC_ID_MPEG1VIDEO))
  {
    if( (pCodec = OpenCodec(new CDVDVideoCodecLibMpeg2(), hint, options)) ) return pCodec;
  }
#if defined(HAVE_LIBVDADECODER)
  if (!hint.software && g_guiSettings.GetBool("videoplayer.usevda"))
  {
    if (g_sysinfo.HasVDADecoder())
    {
      if (hint.codec == CODEC_ID_H264 && !hint.ptsinvalid)
      {
        CLog::Log(LOGINFO, "Trying Apple VDA Decoder...");
        if ( (pCodec = OpenCodec(new CDVDVideoCodecVDA(), hint, options)) ) return pCodec;
      }
    }
  }
#endif

#if defined(HAVE_VIDEOTOOLBOXDECODER)
  if (!hint.software && g_guiSettings.GetBool("videoplayer.usevideotoolbox"))
  {
    if (g_sysinfo.HasVideoToolBoxDecoder())
    {
      switch(hint.codec)
      {
        case CODEC_ID_H264:
          if (hint.codec == CODEC_ID_H264 && hint.ptsinvalid)
            break;
          CLog::Log(LOGINFO, "Apple VideoToolBox Decoder...");
          if ( (pCodec = OpenCodec(new CDVDVideoCodecVideoToolBox(), hint, options)) ) return pCodec;
        break;
        default:
        break;
      }
    }
  }
#endif

#if defined(HAVE_LIBCRYSTALHD)
  if (!hint.software && g_guiSettings.GetBool("videoplayer.usechd"))
  {
    if (CCrystalHD::GetInstance()->DevicePresent())
    {
      switch(hint.codec)
      {
        case CODEC_ID_VC1:
        case CODEC_ID_WMV3:
        case CODEC_ID_H264:
        case CODEC_ID_MPEG2VIDEO:
          if (hint.codec == CODEC_ID_H264 && hint.ptsinvalid)
            break;
          if (hint.codec == CODEC_ID_MPEG2VIDEO && hint.width <= 720)
            break;
          CLog::Log(LOGINFO, "Trying Broadcom Crystal HD Decoder...");
          if ( (pCodec = OpenCodec(new CDVDVideoCodecCrystalHD(), hint, options)) ) return pCodec;
        break;
        default:
        break;
      }
    }
  }
#endif

#if defined(HAVE_LIBOPENMAX)
  if (g_guiSettings.GetBool("videoplayer.useomx") && !hint.software )
  {
      if (hint.codec == CODEC_ID_H264 || hint.codec == CODEC_ID_MPEG2VIDEO || hint.codec == CODEC_ID_VC1)
    {
      CLog::Log(LOGINFO, "Trying OpenMax Decoder...");
      if ( (pCodec = OpenCodec(new CDVDVideoCodecOpenMax(), hint, options)) ) return pCodec;
    }
  }
#endif

  // try to decide if we want to try halfres decoding
#if !defined(_LINUX) && !defined(_WIN32)
  float pixelrate = (float)hint.width*hint.height*hint.fpsrate/hint.fpsscale;
  if( pixelrate > 1400.0f*720.0f*30.0f )
  {
    CLog::Log(LOGINFO, "CDVDFactoryCodec - High video resolution detected %dx%d, trying half resolution decoding ", hint.width, hint.height);
    options.push_back(CDVDCodecOption("lowres","1"));
  }
#endif

  CStdString value;
  value.Format("%d", surfaces);
  options.push_back(CDVDCodecOption("surfaces", value));
  if( (pCodec = OpenCodec(new CDVDVideoCodecFFmpeg(), hint, options)) ) return pCodec;

  return NULL;
}
Exemplo n.º 11
0
CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, const CRenderInfo &info)
{
  CDVDVideoCodec* pCodec = NULL;
  CDVDCodecOptions options;

  if(info.formats.empty())
    options.m_formats.push_back(RENDER_FMT_YUV420P);
  else
    options.m_formats = info.formats;

  options.m_opaque_pointer = info.opaque_pointer;

  //when support for a hardware decoder is not compiled in
  //only print it if it's actually available on the platform
  std::string hwSupport;
#if defined(TARGET_DARWIN_OSX)
  hwSupport += "VDADecoder:yes ";
#endif
#if defined(HAVE_VIDEOTOOLBOXDECODER) && defined(TARGET_DARWIN)
  hwSupport += "VideoToolBoxDecoder:yes ";
#elif defined(TARGET_DARWIN)
  hwSupport += "VideoToolBoxDecoder:no ";
#endif
#if defined(HAS_LIBAMCODEC)
  hwSupport += "AMCodec:yes ";
#else
  hwSupport += "AMCodec:no ";
#endif
#if defined(TARGET_ANDROID)
  hwSupport += "MediaCodec:yes ";
#else
  hwSupport += "MediaCodec:no ";
#endif
#if defined(HAVE_LIBOPENMAX)
  hwSupport += "OpenMax:yes ";
#elif defined(TARGET_POSIX)
  hwSupport += "OpenMax:no ";
#endif
#if defined(HAS_LIBSTAGEFRIGHT)
  hwSupport += "libstagefright:yes ";
#elif defined(_LINUX)
  hwSupport += "libstagefright:no ";
#endif
#if defined(HAVE_LIBVDPAU) && defined(TARGET_POSIX)
  hwSupport += "VDPAU:yes ";
#elif defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
  hwSupport += "VDPAU:no ";
#endif
#if defined(TARGET_WINDOWS) && defined(HAS_DX)
  hwSupport += "DXVA:yes ";
#elif defined(TARGET_WINDOWS)
  hwSupport += "DXVA:no ";
#endif
#if defined(HAVE_LIBVA) && defined(TARGET_POSIX)
  hwSupport += "VAAPI:yes ";
#elif defined(TARGET_POSIX) && !defined(TARGET_DARWIN)
  hwSupport += "VAAPI:no ";
#endif
#if defined(HAS_IMXVPU)
  hwSupport += "iMXVPU:yes ";
#else
  hwSupport += "iMXVPU:no ";
#endif
#if defined(HAS_MMAL)
  hwSupport += "MMAL:yes ";
#else
  hwSupport += "MMAL:no ";
#endif
  CLog::Log(LOGDEBUG, "CDVDFactoryCodec: compiled in hardware support: %s", hwSupport.c_str());

  if (hint.stills && (hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_MPEG1VIDEO))
  {
     // If dvd is an mpeg2 and hint.stills
     if ( (pCodec = OpenCodec(new CDVDVideoCodecLibMpeg2(), hint, options)) ) return pCodec;
  }

#if defined(HAS_LIBAMCODEC)
  // amcodec can handle dvd playback.
  if (!hint.software && CSettings::Get().GetBool("videoplayer.useamcodec"))
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_MPEG4:
      case AV_CODEC_ID_MSMPEG4V2:
      case AV_CODEC_ID_MSMPEG4V3:
        // Avoid h/w decoder for SD; Those files might use features
        // not supported and can easily be soft-decoded
        if (hint.width <= 800)
          break;
      default:
        if ( (pCodec = OpenCodec(new CDVDVideoCodecAmlogic(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAS_IMXVPU)
  if (!hint.software)
  {
    if ( (pCodec = OpenCodec(new CDVDVideoCodecIMX(), hint, options)) ) return pCodec;
  }
#endif

#if defined(TARGET_DARWIN_OSX)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usevda") && !g_advancedSettings.m_useFfmpegVda)
  {
    if (hint.codec == AV_CODEC_ID_H264 && !hint.ptsinvalid)
    {
      if ( (pCodec = OpenCodec(new CDVDVideoCodecVDA(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAVE_VIDEOTOOLBOXDECODER)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usevideotoolbox"))
  {
    if (g_sysinfo.HasVideoToolBoxDecoder())
    {
      switch(hint.codec)
      {
        case AV_CODEC_ID_H264:
          if (hint.codec == AV_CODEC_ID_H264 && hint.ptsinvalid)
            break;
          if ( (pCodec = OpenCodec(new CDVDVideoCodecVideoToolBox(), hint, options)) ) return pCodec;
          break;
        default:
          break;
      }
    }
  }
#endif

#if defined(TARGET_ANDROID)
  if (!hint.software && CSettings::Get().GetBool("videoplayer.usemediacodec"))
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_MPEG4:
      case AV_CODEC_ID_MSMPEG4V2:
      case AV_CODEC_ID_MSMPEG4V3:
        // Avoid h/w decoder for SD; Those files might use features
        // not supported and can easily be soft-decoded
        if (hint.width <= 800)
          break;
      default:
        CLog::Log(LOGINFO, "MediaCodec Video Decoder...");
        if ( (pCodec = OpenCodec(new CDVDVideoCodecAndroidMediaCodec(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAVE_LIBOPENMAX)
    if (CSettings::Get().GetBool("videoplayer.useomx") && !hint.software )
    {
      if (hint.codec == AV_CODEC_ID_H264 || hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_VC1)
      {
        if ( (pCodec = OpenCodec(new CDVDVideoCodecOpenMax(), hint, options)) ) return pCodec;
      }
    }
#endif

#if defined(HAS_MMAL)
    if (CSettings::Get().GetBool("videoplayer.usemmal") && !hint.software )
    {
      if (hint.codec == AV_CODEC_ID_H264 || hint.codec == AV_CODEC_ID_H263 || hint.codec == AV_CODEC_ID_MPEG4 ||
          hint.codec == AV_CODEC_ID_MPEG1VIDEO || hint.codec == AV_CODEC_ID_MPEG2VIDEO ||
          hint.codec == AV_CODEC_ID_VP6 || hint.codec == AV_CODEC_ID_VP6F || hint.codec == AV_CODEC_ID_VP6A || hint.codec == AV_CODEC_ID_VP8 ||
          hint.codec == AV_CODEC_ID_THEORA || hint.codec == AV_CODEC_ID_MJPEG || hint.codec == AV_CODEC_ID_MJPEGB || hint.codec == AV_CODEC_ID_VC1 || hint.codec == AV_CODEC_ID_WMV3)
      {
        if ( (pCodec = OpenCodec(new CMMALVideo(), hint, options)) ) return pCodec;
      }
    }
#endif

#if defined(HAS_LIBSTAGEFRIGHT)
    if (!hint.software && CSettings::Get().GetBool("videoplayer.usestagefright"))
    {
      switch(hint.codec)
      {
        case AV_CODEC_ID_MPEG4:
        case AV_CODEC_ID_MSMPEG4V2:
        case AV_CODEC_ID_MSMPEG4V3:
          // Avoid h/w decoder for SD; Those files might use features
          // not supported and can easily be soft-decoded
          if (hint.width <= 800)
            break;
        default:
          if ( (pCodec = OpenCodec(new CDVDVideoCodecStageFright(), hint, options)) ) return pCodec;
      }
    }
#endif


  // try to decide if we want to try halfres decoding
#if !defined(TARGET_POSIX) && !defined(TARGET_WINDOWS)
  float pixelrate = (float)hint.width*hint.height*hint.fpsrate/hint.fpsscale;
  if( pixelrate > 1400.0f*720.0f*30.0f )
  {
    CLog::Log(LOGINFO, "CDVDFactoryCodec - High video resolution detected %dx%d, trying half resolution decoding ", hint.width, hint.height);
    options.m_keys.push_back(CDVDCodecOption("lowres","1"));
  }
#endif

  std::string value = StringUtils::Format("%d", info.optimal_buffer_size);
  options.m_keys.push_back(CDVDCodecOption("surfaces", value));
  if( (pCodec = OpenCodec(new CDVDVideoCodecFFmpeg(), hint, options)) ) return pCodec;

  return NULL;
}
Exemplo n.º 12
0
CDVDAudioCodec* CDVDFactoryCodec::CreateAudioCodec( CDVDStreamInfo &hint)
{
  CDVDAudioCodec* pCodec = NULL;
  CDVDCodecOptions options;

  // try passthrough first
  pCodec = OpenCodec( new CDVDAudioCodecPassthrough(), hint, options );
  if( pCodec ) return pCodec;

  switch (hint.codec)
  {
  case AV_CODEC_ID_MP2:
  case AV_CODEC_ID_MP3:
    {
      pCodec = OpenCodec( new CDVDAudioCodecLibMad(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
  case AV_CODEC_ID_PCM_S32LE:
  case AV_CODEC_ID_PCM_S32BE:
  case AV_CODEC_ID_PCM_U32LE:
  case AV_CODEC_ID_PCM_U32BE:
  case AV_CODEC_ID_PCM_S24LE:
  case AV_CODEC_ID_PCM_S24BE:
  case AV_CODEC_ID_PCM_U24LE:
  case AV_CODEC_ID_PCM_U24BE:
  case AV_CODEC_ID_PCM_S24DAUD:
  case AV_CODEC_ID_PCM_S16LE:
  case AV_CODEC_ID_PCM_S16BE:
  case AV_CODEC_ID_PCM_U16LE:
  case AV_CODEC_ID_PCM_U16BE:
  case AV_CODEC_ID_PCM_S8:
  case AV_CODEC_ID_PCM_U8:
  case AV_CODEC_ID_PCM_ALAW:
  case AV_CODEC_ID_PCM_MULAW:
    {
      pCodec = OpenCodec( new CDVDAudioCodecPcm(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
#if 0
  //case AV_CODEC_ID_LPCM_S16BE:
  //case AV_CODEC_ID_LPCM_S20BE:
  case AV_CODEC_ID_LPCM_S24BE:
    {
      pCodec = OpenCodec( new CDVDAudioCodecLPcm(), hint, options );
      if( pCodec ) return pCodec;
      break;
    }
#endif
  default:
    {
      pCodec = NULL;
      break;
    }
  }

  pCodec = OpenCodec( new CDVDAudioCodecFFmpeg(), hint, options );
  if( pCodec ) return pCodec;

  return NULL;
}
Exemplo n.º 13
0
bool SimpleAudio::Decode(void *inbuf, int inbytes, uint8_t *outbuf, int *outbytes) {
#ifdef USE_FFMPEG
	if (!codecOpen_) {
		OpenCodec(inbytes);
	}

	AVPacket packet;
	av_init_packet(&packet);
	packet.data = static_cast<uint8_t *>(inbuf);
	packet.size = inbytes;

	int got_frame = 0;
	av_frame_unref(frame_);

	*outbytes = 0;
	srcPos = 0;
	int len = avcodec_decode_audio4(codecCtx_, frame_, &got_frame, &packet);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 12, 100)
	av_packet_unref(&packet);
#else
	av_free_packet(&packet);
#endif

	if (len < 0) {
		ERROR_LOG(ME, "Error decoding Audio frame (%i bytes): %i (%08x)", inbytes, len, len);
		return false;
	}
	
	// get bytes consumed in source
	srcPos = len;

	if (got_frame) {
		// Initializing the sample rate convert. We will use it to convert float output into int.
		int64_t wanted_channel_layout = AV_CH_LAYOUT_STEREO; // we want stereo output layout
		int64_t dec_channel_layout = frame_->channel_layout; // decoded channel layout

		if (!swrCtx_) {
			swrCtx_ = swr_alloc_set_opts(
				swrCtx_,
				wanted_channel_layout,
				AV_SAMPLE_FMT_S16,
				wanted_resample_freq,
				dec_channel_layout,
				codecCtx_->sample_fmt,
				codecCtx_->sample_rate,
				0,
				NULL);

			if (!swrCtx_ || swr_init(swrCtx_) < 0) {
				ERROR_LOG(ME, "swr_init: Failed to initialize the resampling context");
				avcodec_close(codecCtx_);
				codec_ = 0;
				return false;
			}
		}

		// convert audio to AV_SAMPLE_FMT_S16
		int swrRet = swr_convert(swrCtx_, &outbuf, frame_->nb_samples, (const u8 **)frame_->extended_data, frame_->nb_samples);
		if (swrRet < 0) {
			ERROR_LOG(ME, "swr_convert: Error while converting: %d", swrRet);
			return false;
		}
		// output samples per frame, we should *2 since we have two channels
		outSamples = swrRet * 2;

		// each sample occupies 2 bytes
		*outbytes = outSamples * 2;

		// Save outbuf into pcm audio, you can uncomment this line to save and check the decoded audio into pcm file.
		// SaveAudio("dump.pcm", outbuf, *outbytes);
	}
	return true;
#else
	// Zero bytes output. No need to memset.
	*outbytes = 0;
	return true;
#endif  // USE_FFMPEG
}
Exemplo n.º 14
0
void MovieDecoder_FFMpeg::Rewind()
{
	avcodec::av_seek_frame( m_fctx, -1, 0, 0 );
	OpenCodec();
}
Exemplo n.º 15
0
CDVDVideoCodec* CDVDFactoryCodec::CreateVideoCodec(CDVDStreamInfo &hint, const CRenderInfo &info)
{
  CDVDVideoCodec* pCodec = nullptr;
  CDVDCodecOptions options;

  if (info.formats.empty())
    options.m_formats.push_back(RENDER_FMT_YUV420P);
  else
    options.m_formats = info.formats;

  options.m_opaque_pointer = info.opaque_pointer;


  if ((hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_MPEG1VIDEO) && (hint.stills || hint.filename == "dvd"))
  {
     // If dvd is an mpeg2 and hint.stills
     if ( (pCodec = OpenCodec(new CDVDVideoCodecLibMpeg2(), hint, options)) ) return pCodec;
  }

#if defined(HAS_LIBAMCODEC)
  // amcodec can handle dvd playback.
  if (!hint.software && CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEAMCODEC))
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_MPEG4:
      case AV_CODEC_ID_MSMPEG4V2:
      case AV_CODEC_ID_MSMPEG4V3:
      case AV_CODEC_ID_MPEG1VIDEO:
      case AV_CODEC_ID_MPEG2VIDEO:
        // Avoid h/w decoder for SD; Those files might use features
        // not supported and can easily be soft-decoded
        if (hint.width <= 800)
          break;
      default:
        if ( (pCodec = OpenCodec(new CDVDVideoCodecAmlogic(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAS_IMXVPU)
  if (!hint.software)
  {
    if ( (pCodec = OpenCodec(new CDVDVideoCodecIMX(), hint, options)) ) return pCodec;
  }
#endif

#if defined(TARGET_DARWIN_OSX)
  if (!hint.software && CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEVDA))
  {
    if (hint.codec == AV_CODEC_ID_H264 && !hint.ptsinvalid)
    {
      if ( (pCodec = OpenCodec(new CDVDVideoCodecVDA(), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(TARGET_DARWIN_IOS)
  if (!hint.software)
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_H264:
      case AV_CODEC_ID_MPEG4:
        if (hint.codec == AV_CODEC_ID_H264 && hint.ptsinvalid)
          break;
        if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEVIDEOTOOLBOX))
          if ( (pCodec = OpenCodec(new CDVDVideoCodecVideoToolBox(), hint, options)) ) return pCodec;
        if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEAVF))
          if ( (pCodec = OpenCodec(new CDVDVideoCodecAVFoundation(), hint, options)) ) return pCodec;
        break;
      default:
        break;
    }
  }
#endif

#if defined(TARGET_ANDROID)
  if (!hint.software && CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEMEDIACODECSURFACE))
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_MPEG4:
      case AV_CODEC_ID_MSMPEG4V2:
      case AV_CODEC_ID_MSMPEG4V3:
        // Avoid h/w decoder for SD; Those files might use features
        // not supported and can easily be soft-decoded
        if (hint.width <= 800)
          break;
      default:
        CLog::Log(LOGINFO, "MediaCodec (Surface) Video Decoder...");
        if ( (pCodec = OpenCodec(new CDVDVideoCodecAndroidMediaCodec(true), hint, options)) ) return pCodec;
    }
  }
  if (!hint.software && CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEMEDIACODEC))
  {
    switch(hint.codec)
    {
      case AV_CODEC_ID_MPEG4:
      case AV_CODEC_ID_MSMPEG4V2:
      case AV_CODEC_ID_MSMPEG4V3:
        // Avoid h/w decoder for SD; Those files might use features
        // not supported and can easily be soft-decoded
        if (hint.width <= 800)
          break;
      default:
        CLog::Log(LOGINFO, "MediaCodec Video Decoder...");
        if ( (pCodec = OpenCodec(new CDVDVideoCodecAndroidMediaCodec(false), hint, options)) ) return pCodec;
    }
  }
#endif

#if defined(HAVE_LIBOPENMAX)
    if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEOMX) && !hint.software )
    {
      if (hint.codec == AV_CODEC_ID_H264 || hint.codec == AV_CODEC_ID_MPEG2VIDEO || hint.codec == AV_CODEC_ID_VC1)
      {
        if ( (pCodec = OpenCodec(new CDVDVideoCodecOpenMax(), hint, options)) ) return pCodec;
      }
    }
#endif

#if defined(HAS_MMAL)
    if (CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_USEMMAL) && !hint.software )
    {
      if (hint.codec == AV_CODEC_ID_H264 || hint.codec == AV_CODEC_ID_H263 || hint.codec == AV_CODEC_ID_MPEG4 ||
          hint.codec == AV_CODEC_ID_MPEG1VIDEO || hint.codec == AV_CODEC_ID_MPEG2VIDEO ||
          hint.codec == AV_CODEC_ID_VP6 || hint.codec == AV_CODEC_ID_VP6F || hint.codec == AV_CODEC_ID_VP6A || hint.codec == AV_CODEC_ID_VP8 ||
          hint.codec == AV_CODEC_ID_THEORA || hint.codec == AV_CODEC_ID_MJPEG || hint.codec == AV_CODEC_ID_MJPEGB || hint.codec == AV_CODEC_ID_VC1 || hint.codec == AV_CODEC_ID_WMV3)
      {
        if ( (pCodec = OpenCodec(new CMMALVideo(), hint, options)) ) return pCodec;
      }
    }
#endif

  std::string value = StringUtils::Format("%d", info.max_buffer_size);
  options.m_keys.push_back(CDVDCodecOption("surfaces", value));
  pCodec = OpenCodec(new CDVDVideoCodecFFmpeg(), hint, options);
  if (pCodec)
    return pCodec;

  return nullptr;
}