From 707f7af29ab55d75957cf62fc731797881c018ce Mon Sep 17 00:00:00 2001 From: initramfs Date: Thu, 4 Aug 2016 19:51:15 +0800 Subject: [PATCH] fix(video): fix invalid VideoSource ID allocation This commit fixes the an invalid ID allocation by VideoSource, before this commit all VideoSources receives the same ID causing VideoFrame to believe all frames belong to the same video source. Additionally, this commit addresses issues with deprecated pixel formats and silences libswscale warnings. --- src/video/videoframe.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/video/videosource.h | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/video/videoframe.cpp b/src/video/videoframe.cpp index 978dd8596..01e7d0a3e 100644 --- a/src/video/videoframe.cpp +++ b/src/video/videoframe.cpp @@ -97,6 +97,46 @@ VideoFrame::VideoFrame(IDType sourceID, AVFrame* sourceFrame, QRect dimensions, sourceFrameKey(getFrameKey(dimensions.size(), pixFmt, sourceFrame->linesize[0])), freeSourceFrame(freeSourceFrame) { + + // We override the pixel format in the case a deprecated one is used + switch(pixFmt) + { + case AV_PIX_FMT_YUVJ420P: + { + pixFmt = AV_PIX_FMT_YUV420P; + sourceFrame->color_range = AVCOL_RANGE_MPEG; + break; + } + + case AV_PIX_FMT_YUVJ411P: + { + pixFmt = AV_PIX_FMT_YUV411P; + sourceFrame->color_range = AVCOL_RANGE_MPEG; + break; + } + + case AV_PIX_FMT_YUVJ422P: + { + pixFmt = AV_PIX_FMT_YUV422P; + sourceFrame->color_range = AVCOL_RANGE_MPEG; + break; + } + + case AV_PIX_FMT_YUVJ444P: + { + pixFmt = AV_PIX_FMT_YUV444P; + sourceFrame->color_range = AVCOL_RANGE_MPEG; + break; + } + + case AV_PIX_FMT_YUVJ440P: + { + pixFmt = AV_PIX_FMT_YUV440P; + sourceFrame->color_range = AVCOL_RANGE_MPEG; + break; + } + } + frameBuffer[sourceFrameKey] = sourceFrame; } diff --git a/src/video/videosource.h b/src/video/videosource.h index c3aff9d2a..ca053ba64 100644 --- a/src/video/videosource.h +++ b/src/video/videosource.h @@ -38,7 +38,7 @@ public: using AtomicIDType = std::atomic_uint_fast64_t; public: - VideoSource() : id(sourceIDs.fetch_add(std::memory_order_relaxed)){} + VideoSource() : id(sourceIDs++){} virtual ~VideoSource() = default; /**