|
|
if ( GetNextTimestamp ) | if ( GetNextTimestamp ) |
{ | { |
if (pkt.dts != int64_t(AV_NOPTS_VALUE)) | if (pkt.dts != int64_t(AV_NOPTS_VALUE)) |
pts = (float)pkt.dts / AV_TIME_BASE; |
pts = (float)pkt.dts * m_stream->time_base.num / m_stream->time_base.den; |
else | else |
pts = -1; | pts = -1; |
GetNextTimestamp = false; | GetNextTimestamp = false; |
|
|
* to give it a buffer to read from since it tries to read anyway. */ | * to give it a buffer to read from since it tries to read anyway. */ |
static uint8_t dummy[FF_INPUT_BUFFER_PADDING_SIZE] = { 0 }; | static uint8_t dummy[FF_INPUT_BUFFER_PADDING_SIZE] = { 0 }; |
int len = avcodec::avcodec_decode_video( | int len = avcodec::avcodec_decode_video( |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
m_stream->codec, |
|
#else |
&m_stream->codec, | &m_stream->codec, |
|
#endif |
&frame, &got_frame, | &frame, &got_frame, |
pkt.size? pkt.data:dummy, pkt.size ); | pkt.size? pkt.data:dummy, pkt.size ); |
CHECKPOINT; | CHECKPOINT; |
|
|
} | } |
| |
/* Length of this frame: */ | /* Length of this frame: */ |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
LastFrameDelay = (float)m_stream->codec->time_base.num / m_stream->codec->time_base.den; |
|
#else |
LastFrameDelay = (float)m_stream->codec.frame_rate_base / m_stream->codec.frame_rate; | LastFrameDelay = (float)m_stream->codec.frame_rate_base / m_stream->codec.frame_rate; |
|
#endif |
LastFrameDelay += frame.repeat_pict * (LastFrameDelay * 0.5f); | LastFrameDelay += frame.repeat_pict * (LastFrameDelay * 0.5f); |
| |
return 1; | return 1; |
|
|
pict.data[0] = (unsigned char *)m_img->pixels; | pict.data[0] = (unsigned char *)m_img->pixels; |
pict.linesize[0] = m_img->pitch; | pict.linesize[0] = m_img->pitch; |
| |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
avcodec::img_convert(&pict, AVPixelFormats[m_AVTexfmt].pf, |
|
(avcodec::AVPicture *) &decoder->frame, decoder->m_stream->codec->pix_fmt, |
|
decoder->m_stream->codec->width, decoder->m_stream->codec->height); |
|
#else |
avcodec::img_convert(&pict, AVPixelFormats[m_AVTexfmt].pf, | avcodec::img_convert(&pict, AVPixelFormats[m_AVTexfmt].pf, |
(avcodec::AVPicture *) &decoder->frame, decoder->m_stream->codec.pix_fmt, | (avcodec::AVPicture *) &decoder->frame, decoder->m_stream->codec.pix_fmt, |
decoder->m_stream->codec.width, decoder->m_stream->codec.height); | decoder->m_stream->codec.width, decoder->m_stream->codec.height); |
|
#endif |
| |
m_ImageWaiting = FRAME_WAITING; | m_ImageWaiting = FRAME_WAITING; |
} | } |
|
|
for( int stream = 0; stream < m_fctx->nb_streams; ++stream ) | for( int stream = 0; stream < m_fctx->nb_streams; ++stream ) |
{ | { |
avcodec::AVStream *enc = m_fctx->streams[stream]; | avcodec::AVStream *enc = m_fctx->streams[stream]; |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
if( enc->codec->codec_type == avcodec::CODEC_TYPE_VIDEO ) |
|
return enc; |
|
#else |
if( enc->codec.codec_type == avcodec::CODEC_TYPE_VIDEO ) | if( enc->codec.codec_type == avcodec::CODEC_TYPE_VIDEO ) |
return enc; | return enc; |
|
#endif |
} | } |
return NULL; | return NULL; |
} | } |
|
|
m_bThreaded = PREFSMAN->m_bThreadedMovieDecode; | m_bThreaded = PREFSMAN->m_bThreadedMovieDecode; |
| |
CreateDecoder(); | CreateDecoder(); |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
LOG->Trace("Bitrate: %i", decoder->m_stream->codec->bit_rate ); |
|
LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(decoder->m_stream->codec->pix_fmt) ); |
|
#else |
LOG->Trace("Bitrate: %i", decoder->m_stream->codec.bit_rate ); | LOG->Trace("Bitrate: %i", decoder->m_stream->codec.bit_rate ); |
LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(decoder->m_stream->codec.pix_fmt) ); | LOG->Trace("Codec pixel format: %s", avcodec::avcodec_get_pix_fmt_name(decoder->m_stream->codec.pix_fmt) ); |
|
#endif |
| |
/* Decode one frame, to guarantee that the texture is drawn when this function returns. */ | /* Decode one frame, to guarantee that the texture is drawn when this function returns. */ |
int ret = decoder->GetFrame(); | int ret = decoder->GetFrame(); |
|
|
if ( stream == NULL ) | if ( stream == NULL ) |
RageException::Throw( "AVCodec (%s): Couldn't find any video streams", GetID().filename.c_str() ); | RageException::Throw( "AVCodec (%s): Couldn't find any video streams", GetID().filename.c_str() ); |
| |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
if( stream->codec->codec_id == avcodec::CODEC_ID_NONE ) |
|
RageException::ThrowNonfatal( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), stream->codec->codec_tag ); |
|
|
|
avcodec::AVCodec *codec = avcodec::avcodec_find_decoder( stream->codec->codec_id ); |
|
if( codec == NULL ) |
|
RageException::Throw( "AVCodec (%s): Couldn't find decoder %i", GetID().filename.c_str(), stream->codec->codec_id ); |
|
|
|
LOG->Trace("Opening codec %s", codec->name ); |
|
ret = avcodec::avcodec_open( stream->codec, codec ); |
|
#else |
if( stream->codec.codec_id == avcodec::CODEC_ID_NONE ) | if( stream->codec.codec_id == avcodec::CODEC_ID_NONE ) |
RageException::ThrowNonfatal( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), stream->codec.codec_tag ); | RageException::ThrowNonfatal( "AVCodec (%s): Unsupported codec %08x", GetID().filename.c_str(), stream->codec.codec_tag ); |
| |
|
|
| |
LOG->Trace("Opening codec %s", codec->name ); | LOG->Trace("Opening codec %s", codec->name ); |
ret = avcodec::avcodec_open( &stream->codec, codec ); | ret = avcodec::avcodec_open( &stream->codec, codec ); |
|
#endif |
if ( ret < 0 ) | if ( ret < 0 ) |
RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", GetID().filename.c_str(), codec->name) ); | RageException::Throw( averr_ssprintf(ret, "AVCodec (%s): Couldn't open codec \"%s\"", GetID().filename.c_str(), codec->name) ); |
| |
|
|
{ | { |
if( decoder->m_stream ) | if( decoder->m_stream ) |
{ | { |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
avcodec::avcodec_close( decoder->m_stream->codec ); |
|
#else |
avcodec::avcodec_close( &decoder->m_stream->codec ); | avcodec::avcodec_close( &decoder->m_stream->codec ); |
|
#endif |
decoder->m_stream = NULL; | decoder->m_stream = NULL; |
} | } |
| |
|
|
/* Cap the max texture size to the hardware max. */ | /* Cap the max texture size to the hardware max. */ |
actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() ); | actualID.iMaxSize = min( actualID.iMaxSize, DISPLAY->GetMaxTextureSize() ); |
| |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
m_iSourceWidth = decoder->m_stream->codec->width; |
|
m_iSourceHeight = decoder->m_stream->codec->height; |
|
#else |
m_iSourceWidth = decoder->m_stream->codec.width; | m_iSourceWidth = decoder->m_stream->codec.width; |
m_iSourceHeight = decoder->m_stream->codec.height; | m_iSourceHeight = decoder->m_stream->codec.height; |
|
#endif |
| |
/* image size cannot exceed max size */ | /* image size cannot exceed max size */ |
m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize ); | m_iImageWidth = min( m_iSourceWidth, actualID.iMaxSize ); |
|
|
m_FrameSkipMode = true; | m_FrameSkipMode = true; |
} | } |
| |
|
#if (LIBAVCODEC_BUILD >= 4754) |
|
if( m_FrameSkipMode && decoder->m_stream->codec->frame_number % 2 ) |
|
#else |
if( m_FrameSkipMode && decoder->m_stream->codec.frame_number % 2 ) | if( m_FrameSkipMode && decoder->m_stream->codec.frame_number % 2 ) |
|
#endif |
return -1; /* skip */ | return -1; /* skip */ |
| |
return 0; | return 0; |