void CDVDOverlayCodecFFmpeg::Flush() { FreeSubtitle(m_Subtitle); m_SubtitleIndex = -1; avcodec_flush_buffers(m_pCodecContext); }
int CDVDOverlayCodecFFmpeg::Decode(BYTE* data, int size, double pts, double duration) { if (!m_pCodecContext) return 1; int gotsub = 0, len = 0; FreeSubtitle(m_Subtitle); try { len = m_dllAvCodec.avcodec_decode_subtitle(m_pCodecContext, &m_Subtitle, &gotsub, data, size); } catch (win32_exception e) { e.writelog("avcodec_decode_subtitle"); return OC_ERROR; } if (len < 0) { CLog::Log(LOGERROR, "%s - avcodec_decode_subtitle returned failure", __FUNCTION__); return OC_ERROR; } if (len != size) CLog::Log(LOGWARNING, "%s - avcodec_decode_subtitle didn't consume the full packet", __FUNCTION__); if (!gotsub) return OC_BUFFER; m_SubtitleIndex = 0; return OC_OVERLAY; }
void CDVDOverlayCodecFFmpeg::Dispose() { if (m_pCodecContext) { if (m_pCodecContext->codec) avcodec_close(m_pCodecContext); av_free(m_pCodecContext); m_pCodecContext = NULL; } FreeSubtitle(m_Subtitle); }
int CDVDOverlayCodecFFmpeg::Decode(DemuxPacket *pPacket) { if (!m_pCodecContext || !pPacket) return 1; int gotsub = 0, len = 0; FreeSubtitle(m_Subtitle); AVPacket avpkt; av_init_packet(&avpkt); avpkt.data = pPacket->pData; avpkt.size = pPacket->iSize; avpkt.pts = pPacket->pts == DVD_NOPTS_VALUE ? AV_NOPTS_VALUE : (int64_t)pPacket->pts; avpkt.dts = pPacket->dts == DVD_NOPTS_VALUE ? AV_NOPTS_VALUE : (int64_t)pPacket->dts; len = avcodec_decode_subtitle2(m_pCodecContext, &m_Subtitle, &gotsub, &avpkt); if (len < 0) { CLog::Log(LOGERROR, "%s - avcodec_decode_subtitle returned failure", __FUNCTION__); Flush(); return OC_ERROR; } if (len != avpkt.size) CLog::Log(LOGWARNING, "%s - avcodec_decode_subtitle didn't consume the full packet", __FUNCTION__); if (!gotsub) return OC_BUFFER; double pts_offset = 0.0; if (m_pCodecContext->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE && m_Subtitle.format == 0) { // for pgs subtitles the packet pts of the end_segments are wrong // instead use the subtitle pts to calc the offset here // see http://git.videolan.org/?p=ffmpeg.git;a=commit;h=2939e258f9d1fff89b3b68536beb931b54611585 if (m_Subtitle.pts != AV_NOPTS_VALUE && pPacket->pts != DVD_NOPTS_VALUE) { pts_offset = m_Subtitle.pts - pPacket->pts ; } } m_StartTime = DVD_MSEC_TO_TIME(m_Subtitle.start_display_time); m_StopTime = DVD_MSEC_TO_TIME(m_Subtitle.end_display_time); //adapt start and stop time to our packet pts bool dummy = false; CDVDOverlayCodec::GetAbsoluteTimes(m_StartTime, m_StopTime, pPacket, dummy, pts_offset); m_SubtitleIndex = 0; return OC_OVERLAY; }
void CDVDOverlayCodecFFmpeg::Dispose() { if (m_pCodecContext) { if (m_pCodecContext->codec) m_dllAvCodec.avcodec_close(m_pCodecContext); m_dllAvUtil.av_free(m_pCodecContext); m_pCodecContext = NULL; } FreeSubtitle(m_Subtitle); m_dllAvCodec.Unload(); m_dllAvUtil.Unload(); }
void CDVDOverlayCodecFFmpeg::Flush() { FreeSubtitle(m_Subtitle); m_SubtitleIndex = -1; try { m_dllAvCodec.avcodec_flush_buffers(m_pCodecContext); } catch (win32_exception e) { e.writelog(__FUNCTION__); } }