diff options
-rw-r--r-- | xbmc/cores/VideoPlayer/DVDFileInfo.cpp | 94 |
1 files changed, 38 insertions, 56 deletions
diff --git a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp index 450d2cd482..eb62cf24ea 100644 --- a/xbmc/cores/VideoPlayer/DVDFileInfo.cpp +++ b/xbmc/cores/VideoPlayer/DVDFileInfo.cpp @@ -111,29 +111,16 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f return {}; } - CDVDDemux* pDemuxer = NULL; - - try - { - pDemuxer = CDVDFactoryDemuxer::CreateDemuxer(pInputStream, true); - if (!pDemuxer) - { - CLog::LogF(LOGERROR, "Error creating demuxer"); - return {}; - } - } - catch (...) + std::unique_ptr<CDVDDemux> demuxer{CDVDFactoryDemuxer::CreateDemuxer(pInputStream, true)}; + if (!demuxer) { - CLog::LogF(LOGERROR, "Exception thrown when opening demuxer"); - if (pDemuxer) - delete pDemuxer; - + CLog::LogF(LOGERROR, "Error creating demuxer"); return {}; } int nVideoStream = -1; int64_t demuxerId = -1; - for (CDemuxStream* pStream : pDemuxer->GetStreams()) + for (CDemuxStream* pStream : demuxer->GetStreams()) { if (pStream) { @@ -144,7 +131,7 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f demuxerId = pStream->demuxerId; } else - pDemuxer->EnableStream(pStream->demuxerId, pStream->uniqueId, false); + demuxer->EnableStream(pStream->demuxerId, pStream->uniqueId, false); } } @@ -158,7 +145,7 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f pixFmts.push_back(AV_PIX_FMT_YUV420P); pProcessInfo->SetPixFormats(pixFmts); - CDVDStreamInfo hint(*pDemuxer->GetStream(demuxerId, nVideoStream), true); + CDVDStreamInfo hint(*demuxer->GetStream(demuxerId, nVideoStream), true); hint.codecOptions = CODEC_FORCE_SOFTWARE; std::unique_ptr<CDVDVideoCodec> pVideoCodec = @@ -166,25 +153,25 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f if (pVideoCodec) { - int nTotalLen = pDemuxer->GetStreamLength(); + int nTotalLen = demuxer->GetStreamLength(); - bool seekToChapter = chapterNumber > 0 && pDemuxer->GetChapterCount() > 0; + bool seekToChapter = chapterNumber > 0 && demuxer->GetChapterCount() > 0; int64_t nSeekTo = - seekToChapter ? pDemuxer->GetChapterPos(chapterNumber) * 1000 : nTotalLen / 3; + seekToChapter ? demuxer->GetChapterPos(chapterNumber) * 1000 : nTotalLen / 3; CLog::LogF(LOGDEBUG, "seeking to pos {}ms (total: {}ms) in {}", nSeekTo, nTotalLen, redactPath); - if (pDemuxer->SeekTime(static_cast<double>(nSeekTo), true)) + if (demuxer->SeekTime(static_cast<double>(nSeekTo), true)) { CDVDVideoCodec::VCReturn iDecoderState = CDVDVideoCodec::VC_NONE; VideoPicture picture = {}; // num streams * 160 frames, should get a valid frame, if not abort. - int abort_index = pDemuxer->GetNrOfStreams() * 160; + int abort_index = demuxer->GetNrOfStreams() * 160; do { - DemuxPacket* pPacket = pDemuxer->Read(); + DemuxPacket* pPacket = demuxer->Read(); packetsTried++; if (!pPacket) @@ -215,35 +202,33 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f if (iDecoderState == CDVDVideoCodec::VC_PICTURE && !(picture.iFlags & DVP_FLAG_DROPPED)) { + unsigned int nWidth = + std::min(picture.iDisplayWidth, + CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes); + double aspect = (double)picture.iDisplayWidth / (double)picture.iDisplayHeight; + if (hint.forced_aspect && hint.aspect != 0) + aspect = hint.aspect; + unsigned int nHeight = (unsigned int)((double)nWidth / aspect); + + result = CTexture::CreateTexture(nWidth, nHeight); + result->SetAlpha(false); + struct SwsContext* context = + sws_getContext(picture.iWidth, picture.iHeight, AV_PIX_FMT_YUV420P, nWidth, nHeight, + AV_PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL); + + if (context) { - unsigned int nWidth = - std::min(picture.iDisplayWidth, - CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_imageRes); - double aspect = (double)picture.iDisplayWidth / (double)picture.iDisplayHeight; - if (hint.forced_aspect && hint.aspect != 0) - aspect = hint.aspect; - unsigned int nHeight = (unsigned int)((double)nWidth / aspect); - - result = CTexture::CreateTexture(nWidth, nHeight); - result->SetAlpha(false); - struct SwsContext* context = - sws_getContext(picture.iWidth, picture.iHeight, AV_PIX_FMT_YUV420P, nWidth, nHeight, - AV_PIX_FMT_BGRA, SWS_FAST_BILINEAR, NULL, NULL, NULL); - - if (context) - { - uint8_t* planes[YuvImage::MAX_PLANES]; - int stride[YuvImage::MAX_PLANES]; - picture.videoBuffer->GetPlanes(planes); - picture.videoBuffer->GetStrides(stride); - uint8_t* src[4] = {planes[0], planes[1], planes[2], 0}; - int srcStride[] = {stride[0], stride[1], stride[2], 0}; - uint8_t* dst[] = {result->GetPixels(), 0, 0, 0}; - int dstStride[] = {static_cast<int>(result->GetPitch()), 0, 0, 0}; - result->SetOrientation(DegreeToOrientation(hint.orientation)); - sws_scale(context, src, srcStride, 0, picture.iHeight, dst, dstStride); - sws_freeContext(context); - } + uint8_t* planes[YuvImage::MAX_PLANES]; + int stride[YuvImage::MAX_PLANES]; + picture.videoBuffer->GetPlanes(planes); + picture.videoBuffer->GetStrides(stride); + uint8_t* src[4] = {planes[0], planes[1], planes[2], 0}; + int srcStride[] = {stride[0], stride[1], stride[2], 0}; + uint8_t* dst[] = {result->GetPixels(), 0, 0, 0}; + int dstStride[] = {static_cast<int>(result->GetPitch()), 0, 0, 0}; + result->SetOrientation(DegreeToOrientation(hint.orientation)); + sws_scale(context, src, srcStride, 0, picture.iHeight, dst, dstStride); + sws_freeContext(context); } } else @@ -254,9 +239,6 @@ std::unique_ptr<CTexture> CDVDFileInfo::ExtractThumbToTexture(const CFileItem& f } } - if (pDemuxer) - delete pDemuxer; - auto end = std::chrono::steady_clock::now(); auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); CLog::LogF(LOGDEBUG, "measured {} ms to extract thumb from file <{}> in {} packets. ", |