From 5f2316bdcc751de483d4a52eee31c1c1786469a9 Mon Sep 17 00:00:00 2001 From: popcornmix Date: Fri, 11 Nov 2016 15:53:53 +0000 Subject: [PATCH] stereoscopicmanager: fixups for rbp --- .../VideoPlayer/DVDCodecs/DVDCodecUtils.cpp | 61 +++++++++++++++++++ .../VideoPlayer/DVDCodecs/DVDCodecUtils.h | 4 ++ .../VideoPlayer/DVDCodecs/Video/MMALCodec.cpp | 9 ++- .../VideoPlayer/DVDCodecs/Video/MMALCodec.h | 1 + .../cores/VideoPlayer/DVDDemuxers/Makefile.in | 2 +- xbmc/cores/omxplayer/OMXPlayerVideo.cpp | 5 ++ xbmc/cores/omxplayer/OMXPlayerVideo.h | 1 + xbmc/cores/omxplayer/OMXVideo.cpp | 2 +- xbmc/guilib/StereoscopicsManager.cpp | 3 + 9 files changed, 84 insertions(+), 4 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.cpp index ac4e063460a39..0d88acfb85333 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.cpp @@ -24,6 +24,7 @@ #include "utils/log.h" #include "cores/FFmpeg.h" #include "Util.h" +#include #ifdef TARGET_WINDOWS #pragma comment(lib, "avcodec.lib") @@ -37,6 +38,7 @@ extern "C" { #include "libswscale/swscale.h" +#include "libavutil/intreadwrite.h" } // allocate a new picture (AV_PIX_FMT_YUV420P) @@ -402,6 +404,65 @@ double CDVDCodecUtils::NormalizeFrameduration(double frameduration, bool *match) } } +bool CDVDCodecUtils::IsH264AnnexB(std::string format, AVStream *avstream) +{ + assert(avstream->codec->codec_id == AV_CODEC_ID_H264 || avstream->codec->codec_id == AV_CODEC_ID_H264_MVC); + if (avstream->codec->extradata_size < 4) + return true; + if (avstream->codec->extradata[0] == 1) + return false; + if (format == "avi") + { + BYTE *src = avstream->codec->extradata; + unsigned startcode = AV_RB32(src); + if (startcode == 0x00000001 || (startcode & 0xffffff00) == 0x00000100) + return true; + if (avstream->codec->codec_tag == MKTAG('A', 'V', 'C', '1') || avstream->codec->codec_tag == MKTAG('a', 'v', 'c', '1')) + return false; + } + return true; +} + +bool CDVDCodecUtils::ProcessH264MVCExtradata(uint8_t *data, int data_size, uint8_t **mvc_data, int *mvc_data_size) +{ + uint8_t* extradata = data; + int extradata_size = data_size; + + if (extradata_size > 4 && *(char *)extradata == 1) + { + // Find "mvcC" atom + uint32_t state = -1; + int i = 0; + for (; i < extradata_size; i++) + { + state = (state << 8) | extradata[i]; + if (state == MKBETAG('m', 'v', 'c', 'C')) + break; + } + if (i >= 8 && i < extradata_size) + { + // Update pointers to the start of the mvcC atom + extradata = extradata + i - 7; + extradata_size = extradata_size - i + 7; + // verify size atom and actual size + if (extradata_size >= 14 && (AV_RB32(extradata) + 4) <= extradata_size) + { + extradata += 8; + extradata_size -= 8; + if (*(char *)extradata == 1) + { + if (mvc_data) + *mvc_data = extradata; + if (mvc_data_size) + *mvc_data_size = extradata_size; + return true; + } + } + } + } + return false; +} + struct EFormatMap { AVPixelFormat pix_fmt; ERenderFormat format; diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.h b/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.h index 361c966236603..8ec50bbf79e9e 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/DVDCodecUtils.h @@ -28,6 +28,7 @@ extern "C" { } struct YV12Image; +class AVStream; class CDVDCodecUtils { @@ -46,6 +47,9 @@ class CDVDCodecUtils static double NormalizeFrameduration(double frameduration, bool *match = NULL); + static bool IsH264AnnexB(std::string format, AVStream *avstream); + static bool ProcessH264MVCExtradata(uint8_t *extradata, int extradata_size, uint8_t **mvc_extradata = nullptr, int *mvc_extradata_size = nullptr); + static ERenderFormat EFormatFromPixfmt(int fmt); static AVPixelFormat PixfmtFromEFormat(ERenderFormat format); }; diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.cpp index 68459e35bc2cd..dca8723730801 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.cpp @@ -362,6 +362,11 @@ bool CMMALVideo::SendCodecConfigData() return true; } +bool CMMALVideo::SupportsExtention() +{ + return CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_SUPPORTMVC); +} + bool CMMALVideo::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) { CSingleLock lock(m_sharedSection); @@ -408,12 +413,12 @@ bool CMMALVideo::Open(CDVDStreamInfo &hints, CDVDCodecOptions &options) m_codingType = MMAL_ENCODING_H264; m_pFormatName = "mmal-h264"; if ((hints.codec_tag == MKTAG('M', 'V', 'C', '1') || hints.codec_tag == MKTAG('A', 'M', 'V', 'C')) && - CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_SUPPORTMVC)) + SupportsExtention()) { m_codingType = MMAL_ENCODING_MVC; m_pFormatName= "mmal-mvc"; if (hints.stereo_mode == "mono") - hints.stereo_mode = "mvc_lr"; + hints.stereo_mode = "block_lr"; } break; case AV_CODEC_ID_H263: diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.h b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.h index baff1f031149d..1e49f09574c2a 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.h +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/MMALCodec.h @@ -104,6 +104,7 @@ class CMMALVideo : public CDVDVideoCodec virtual bool GetCodecStats(double &pts, int &droppedPics); virtual void SetCodecControl(int flags); virtual void SetSpeed(int iSpeed); + virtual bool SupportsExtention(); // MMAL decoder callback routines. void dec_output_port_cb(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer); diff --git a/xbmc/cores/VideoPlayer/DVDDemuxers/Makefile.in b/xbmc/cores/VideoPlayer/DVDDemuxers/Makefile.in index 0359426b85683..7d19ec3c56fde 100644 --- a/xbmc/cores/VideoPlayer/DVDDemuxers/Makefile.in +++ b/xbmc/cores/VideoPlayer/DVDDemuxers/Makefile.in @@ -11,7 +11,7 @@ SRCS += DVDDemuxVobsub.cpp SRCS += DVDDemuxCC.cpp SRCS += DVDFactoryDemuxer.cpp SRCS += DemuxStreamSSIF.cpp -SRCS += DVDDemuxMVC.cpp +SRCS += DemuxMVC.cpp LIB = DVDDemuxers.a diff --git a/xbmc/cores/omxplayer/OMXPlayerVideo.cpp b/xbmc/cores/omxplayer/OMXPlayerVideo.cpp index f6fb241dfec92..58ad6672e3351 100644 --- a/xbmc/cores/omxplayer/OMXPlayerVideo.cpp +++ b/xbmc/cores/omxplayer/OMXPlayerVideo.cpp @@ -111,6 +111,11 @@ OMXPlayerVideo::~OMXPlayerVideo() CloseStream(false); } +bool OMXPlayerVideo::SupportsExtention() const +{ + return CSettings::GetInstance().GetBool(CSettings::SETTING_VIDEOPLAYER_SUPPORTMVC); +} + bool OMXPlayerVideo::OpenStream(CDVDStreamInfo &hints) { m_hints = hints; diff --git a/xbmc/cores/omxplayer/OMXPlayerVideo.h b/xbmc/cores/omxplayer/OMXPlayerVideo.h index b5050081c360d..c880fa6bbb128 100644 --- a/xbmc/cores/omxplayer/OMXPlayerVideo.h +++ b/xbmc/cores/omxplayer/OMXPlayerVideo.h @@ -96,6 +96,7 @@ class OMXPlayerVideo : public CThread, public IDVDStreamPlayerVideo void WaitForBuffers() { m_messageQueue.WaitUntilEmpty(); } int GetLevel() const { return m_messageQueue.GetLevel(); } bool IsStalled() const { return m_stalled; } + bool SupportsExtention() const; bool IsEOS(); void CloseStream(bool bWaitForBuffers); void Output(double pts, bool bDropPacket); diff --git a/xbmc/cores/omxplayer/OMXVideo.cpp b/xbmc/cores/omxplayer/OMXVideo.cpp index 536332c43e22c..39bc0530cecd5 100644 --- a/xbmc/cores/omxplayer/OMXVideo.cpp +++ b/xbmc/cores/omxplayer/OMXVideo.cpp @@ -441,7 +441,7 @@ bool COMXVideo::Open(CDVDStreamInfo &hints, OMXClock *clock, bool hdmi_clock_syn m_codingType = OMX_VIDEO_CodingMVC; m_video_codec_name = "omx-mvc"; if (hints.stereo_mode == "mono") - hints.stereo_mode = "mvc_lr"; + hints.stereo_mode = "block_lr"; } break; case AV_CODEC_ID_MPEG4: diff --git a/xbmc/guilib/StereoscopicsManager.cpp b/xbmc/guilib/StereoscopicsManager.cpp index 6aaa82f4d883b..cc929b599125a 100644 --- a/xbmc/guilib/StereoscopicsManager.cpp +++ b/xbmc/guilib/StereoscopicsManager.cpp @@ -70,10 +70,13 @@ static const struct StereoModeMap VideoModeToGuiModeMap[] = { "anaglyph_cyan_red", RENDER_STEREO_MODE_ANAGLYPH_RED_CYAN }, { "anaglyph_green_magenta", RENDER_STEREO_MODE_ANAGLYPH_GREEN_MAGENTA }, { "anaglyph_yellow_blue", RENDER_STEREO_MODE_ANAGLYPH_YELLOW_BLUE }, +#ifndef TARGET_RASPBERRY_PI { "block_lr", RENDER_STEREO_MODE_HARDWAREBASED }, { "block_rl", RENDER_STEREO_MODE_HARDWAREBASED }, +#else { "block_lr", RENDER_STEREO_MODE_SPLIT_HORIZONTAL }, // fallback { "block_rl", RENDER_STEREO_MODE_SPLIT_HORIZONTAL }, // fallback +#endif {} };