From 0ed08f64996f43bc46c6d1ee677cd23a79476c54 Mon Sep 17 00:00:00 2001 From: ace20022 Date: Fri, 4 Mar 2016 17:50:21 +0100 Subject: [videoplayer] Add InputStreamMultiSource to open/handle input streams from multiple sources (at once). --- Kodi.xcodeproj/project.pbxproj | 10 ++ project/VS2010Express/XBMC.vcxproj | 3 + project/VS2010Express/XBMC.vcxproj.filters | 9 ++ .../VideoPlayer/DVDInputStreams/CMakeLists.txt | 7 +- .../DVDInputStreams/DVDFactoryInputStream.cpp | 20 ++- .../DVDInputStreams/DVDFactoryInputStream.h | 3 +- .../VideoPlayer/DVDInputStreams/DVDInputStream.h | 3 +- .../DVDInputStreams/InputStreamMultiSource.cpp | 154 +++++++++++++++++++++ .../DVDInputStreams/InputStreamMultiSource.h | 55 ++++++++ .../DVDInputStreams/InputStreamMultiStreams.h | 42 ++++++ xbmc/cores/VideoPlayer/DVDInputStreams/Makefile | 1 + xbmc/cores/VideoPlayer/VideoPlayer.cpp | 2 +- 12 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.cpp create mode 100644 xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.h create mode 100644 xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiStreams.h diff --git a/Kodi.xcodeproj/project.pbxproj b/Kodi.xcodeproj/project.pbxproj index 32357d27b0..30ce85a0cc 100644 --- a/Kodi.xcodeproj/project.pbxproj +++ b/Kodi.xcodeproj/project.pbxproj @@ -632,6 +632,8 @@ 7CF80DCA19710DC2003B2B34 /* KeyboardLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CF80DC719710DC2003B2B34 /* KeyboardLayout.cpp */; }; 7CFC08381C5BA7D0000E5E73 /* DVDDemuxClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFC08361C5BA7D0000E5E73 /* DVDDemuxClient.cpp */; }; 7CFC08391C5BA7D0000E5E73 /* DVDDemuxClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CFC08361C5BA7D0000E5E73 /* DVDDemuxClient.cpp */; }; + 80204F121C91CD3600E8C88B /* InputStreamMultiSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 80204F0F1C91CD3600E8C88B /* InputStreamMultiSource.cpp */; }; + 80204F131C91CD3600E8C88B /* InputStreamMultiSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 80204F0F1C91CD3600E8C88B /* InputStreamMultiSource.cpp */; }; 815EE6350E17F1DC009FBE3C /* DVDInputStreamRTMP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 815EE6330E17F1DC009FBE3C /* DVDInputStreamRTMP.cpp */; }; 83E0B2490F7C95FF0091643F /* Atomics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 83E0B2480F7C95FF0091643F /* Atomics.cpp */; }; 880DBE4E0DC223FF00E26B71 /* MediaSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 880DBE4B0DC223FF00E26B71 /* MediaSource.cpp */; }; @@ -3258,6 +3260,9 @@ 7CF80DC819710DC2003B2B34 /* KeyboardLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardLayout.h; sourceTree = ""; }; 7CFC08361C5BA7D0000E5E73 /* DVDDemuxClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDDemuxClient.cpp; sourceTree = ""; }; 7CFC08371C5BA7D0000E5E73 /* DVDDemuxClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDDemuxClient.h; sourceTree = ""; }; + 80204F0F1C91CD3600E8C88B /* InputStreamMultiSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InputStreamMultiSource.cpp; sourceTree = ""; }; + 80204F101C91CD3600E8C88B /* InputStreamMultiSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputStreamMultiSource.h; sourceTree = ""; }; + 80204F111C91CD3600E8C88B /* InputStreamMultiStreams.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InputStreamMultiStreams.h; sourceTree = ""; }; 815EE6330E17F1DC009FBE3C /* DVDInputStreamRTMP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DVDInputStreamRTMP.cpp; sourceTree = ""; }; 815EE6340E17F1DC009FBE3C /* DVDInputStreamRTMP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DVDInputStreamRTMP.h; sourceTree = ""; }; 82F6F0EA16F269BB0081CC3C /* Buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Buffer.h; path = commons/Buffer.h; sourceTree = ""; }; @@ -7737,6 +7742,9 @@ 815EE6340E17F1DC009FBE3C /* DVDInputStreamRTMP.h */, E38E15740D25F9FA00618676 /* DVDStateSerializer.cpp */, E38E15750D25F9FA00618676 /* DVDStateSerializer.h */, + 80204F0F1C91CD3600E8C88B /* InputStreamMultiSource.cpp */, + 80204F101C91CD3600E8C88B /* InputStreamMultiSource.h */, + 80204F111C91CD3600E8C88B /* InputStreamMultiStreams.h */, ); path = DVDInputStreams; sourceTree = ""; @@ -9338,6 +9346,7 @@ E38E1F8F0D25F9FD00618676 /* DVDVideoPPFFmpeg.cpp in Sources */, E38E1F910D25F9FD00618676 /* DVDDemux.cpp in Sources */, 7C8E023A1BA35D0B0072E8B2 /* PlayerBuiltins.cpp in Sources */, + 80204F121C91CD3600E8C88B /* InputStreamMultiSource.cpp in Sources */, E38E1F940D25F9FD00618676 /* DVDDemuxUtils.cpp in Sources */, E38E1F970D25F9FD00618676 /* DVDDemuxSPU.cpp in Sources */, E38E1F980D25F9FD00618676 /* DVDFactoryInputStream.cpp in Sources */, @@ -10513,6 +10522,7 @@ F597B05C18A804E0005AADAE /* DVDVideoCodec.cpp in Sources */, E49911E4174E5D3700741B6D /* DVDInputStreamNavigator.cpp in Sources */, E49911E5174E5D3700741B6D /* DVDInputStreamPVRManager.cpp in Sources */, + 80204F131C91CD3600E8C88B /* InputStreamMultiSource.cpp in Sources */, E49911E6174E5D3700741B6D /* DVDInputStreamRTMP.cpp in Sources */, E49911E8174E5D3700741B6D /* DVDStateSerializer.cpp in Sources */, E49911E9174E5D3E00741B6D /* DVDSubtitleParserSSA.cpp in Sources */, diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index c2f6d9c1c0..bc8badca65 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -283,6 +283,7 @@ + @@ -1014,6 +1015,8 @@ + + diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index f873a8c641..6d5332ed91 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -3304,6 +3304,9 @@ addons\binary\interfaces\api1\Addon + + cores\VideoPlayer\DVDInputStreams + addons\binary\interfaces\api1\AudioDSP @@ -6341,6 +6344,9 @@ cores\Process + + cores\VideoPlayer\DVDInputStreams + addons\include @@ -6413,6 +6419,9 @@ addons\binary\interfaces\api1\AudioDSP + + cores\VideoPlayer\DVDInputStreams + cores\VideoPlayer\DVDDemuxers diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/CMakeLists.txt b/xbmc/cores/VideoPlayer/DVDInputStreams/CMakeLists.txt index 13bcb063d6..83d9fe9a1f 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/CMakeLists.txt +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/CMakeLists.txt @@ -8,7 +8,8 @@ set(SOURCES DVDFactoryInputStream.cpp DVDInputStreamRTMP.cpp DVDInputStreamStack.cpp DVDStateSerializer.cpp - InputStreamAddon.cpp) + InputStreamAddon.cpp + InputStreamMultiSource.cpp) set(HEADERS DVDFactoryInputStream.h DVDInputStream.h @@ -23,7 +24,9 @@ set(HEADERS DVDFactoryInputStream.h DVDStateSerializer.h DllDvdNav.h DllLibRTMP.h - InputStreamAddon.h) + InputStreamAddon.h + InputStreamMultiStreams.h + InputStreamMultiSource.h) if(BLURAY_FOUND) list(APPEND SOURCES DVDInputStreamBluray.cpp) diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp index fb4eeaafc8..d92211e163 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.cpp @@ -27,6 +27,7 @@ #include "DVDInputStreamPVRManager.h" #include "DVDInputStreamRTMP.h" #include "InputStreamAddon.h" +#include "InputStreamMultiSource.h" #ifdef HAVE_LIBBLURAY #include "DVDInputStreamBluray.h" #endif @@ -40,11 +41,23 @@ #include "utils/URIUtils.h" #include "addons/AddonManager.h" #include "addons/InputStream.h" +#include "Util.h" -CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem) +CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem, bool scanforextaudio) { std::string file = fileitem.GetPath(); + if (scanforextaudio) + { + // find any available external audio tracks + std::vector filenames; + filenames.push_back(file); + CUtil::ScanForExternalAudio(file, filenames); + if (filenames.size() >= 2) + { + return CreateInputStream(pPlayer, fileitem, filenames); + } + } ADDON::VECADDONS addons; ADDON::CAddonMgr::GetInstance().GetAddons(addons, ADDON::ADDON_INPUTSTREAM); @@ -136,3 +149,8 @@ CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer // our file interface handles all these types of streams return (new CDVDInputStreamFile(fileitem)); } + +CDVDInputStream* CDVDFactoryInputStream::CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem, const std::vector& filenames) +{ + return (new CInputStreamMultiSource(pPlayer, fileitem, filenames)); +} diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.h b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.h index f63c9ff51e..0c39e884a5 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.h +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDFactoryInputStream.h @@ -29,5 +29,6 @@ class IVideoPlayer; class CDVDFactoryInputStream { public: - static CDVDInputStream* CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem); + static CDVDInputStream* CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem, bool scanforextaudio = false); + static CDVDInputStream* CreateInputStream(IVideoPlayer* pPlayer, CFileItem fileitem, const std::vector& filenames); }; diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.h b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.h index db9a449288..90d103ae1d 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.h +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/DVDInputStream.h @@ -42,7 +42,8 @@ enum DVDStreamType DVDSTREAM_TYPE_MPLS = 10, DVDSTREAM_TYPE_BLURAY = 11, DVDSTREAM_TYPE_PVRMANAGER = 12, - DVDSTREAM_TYPE_ADDON = 13 + DVDSTREAM_TYPE_MULTIFILES = 13, + DVDSTREAM_TYPE_ADDON = 14 }; #define SEEK_POSSIBLE 0x10 // flag used to check if protocol allows seeks diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.cpp b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.cpp new file mode 100644 index 0000000000..d515c31105 --- /dev/null +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2005-2015 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "InputStreamMultiSource.h" +#include "DVDFactoryInputStream.h" +#include "filesystem/File.h" +#include "filesystem/IFile.h" +#include "settings/AdvancedSettings.h" +#include "utils/log.h" +#include "utils/StringUtils.h" +#include + +using namespace XFILE; + +CInputStreamMultiSource::CInputStreamMultiSource(IVideoPlayer* pPlayer, CFileItem& fileitem, const std::vector& filenames) : InputStreamMultiStreams(DVDSTREAM_TYPE_MULTIFILES, fileitem), + m_pPlayer(pPlayer), + m_filenames(filenames) +{ +} + +CInputStreamMultiSource::~CInputStreamMultiSource() +{ + Close(); +} + +void CInputStreamMultiSource::Abort() +{ + for (auto iter : m_InputStreams) + iter->Abort(); +} + +void CInputStreamMultiSource::Close() +{ + m_InputStreams.clear(); + CDVDInputStream::Close(); +} + +BitstreamStats CInputStreamMultiSource::GetBitstreamStats() const +{ + return m_stats; +} + +int CInputStreamMultiSource::GetBlockSize() +{ + return 0; +} + +bool CInputStreamMultiSource::GetCacheStatus(XFILE::SCacheStatus *status) +{ + return false; +} + +int64_t CInputStreamMultiSource::GetLength() +{ + int64_t length = 0; + for (auto iter : m_InputStreams) + { + length = std::max(length, iter->GetLength()); + } + + return length; +} + +bool CInputStreamMultiSource::IsEOF() +{ + if (m_InputStreams.empty()) + return true; + + for (auto iter : m_InputStreams) + { + if (!(iter->IsEOF())) + return false; + } + + return true; +} + +CDVDInputStream::ENextStream CInputStreamMultiSource::NextStream() +{ + bool eOF = IsEOF(); + if (m_InputStreams.empty() || eOF) + return NEXTSTREAM_NONE; + + + CDVDInputStream::ENextStream next; + for (auto iter : m_InputStreams) + { + next = iter->NextStream(); + if (next != NEXTSTREAM_NONE) + return next; + } + if (!eOF) + return NEXTSTREAM_RETRY; + + return NEXTSTREAM_NONE; +} + +bool CInputStreamMultiSource::Open() +{ + if (!m_pPlayer || m_filenames.empty()) + return false; + + for (unsigned int i = 0; i < m_filenames.size(); i++) + { + CFileItem fileitem = CFileItem(m_filenames[i], false); + InputStreamPtr inputstream(CDVDFactoryInputStream::CreateInputStream(m_pPlayer, fileitem)); + if (!inputstream) + { + CLog::Log(LOGERROR, "CDVDPlayer::OpenInputStream - unable to create input stream for file [%s]", m_filenames[i].c_str()); + continue; + } + + if (!inputstream->Open()) + { + CLog::Log(LOGERROR, "CDVDPlayer::OpenInputStream - error opening file [%s]", m_filenames[i].c_str()); + continue; + } + m_InputStreams.push_back(inputstream); + } + return !m_InputStreams.empty(); +} + +int CInputStreamMultiSource::Read(uint8_t* buf, int buf_size) +{ + return -1; +} + +int64_t CInputStreamMultiSource::Seek(int64_t offset, int whence) +{ + return -1; +} + +void CInputStreamMultiSource::SetReadRate(unsigned rate) +{ + for (auto iter : m_InputStreams) + iter->SetReadRate(rate); +} diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.h b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.h new file mode 100644 index 0000000000..2558632584 --- /dev/null +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiSource.h @@ -0,0 +1,55 @@ +#pragma once + +/* + * Copyright (C) 2005-2015 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "DVDInputStream.h" +#include "InputStreamMultiStreams.h" + +#include +#include + +class IVideoPlayer; + +class CInputStreamMultiSource : public InputStreamMultiStreams +{ + +public: + CInputStreamMultiSource(IVideoPlayer* pPlayer, CFileItem& fileitem, const std::vector& filenames); + virtual ~CInputStreamMultiSource(); + + virtual void Abort() override; + virtual void Close() override; + virtual BitstreamStats GetBitstreamStats() const ; + virtual int GetBlockSize(); + virtual bool GetCacheStatus(XFILE::SCacheStatus *status); + int64_t GetLength() override; + virtual bool IsEOF() override; + virtual CDVDInputStream::ENextStream NextStream() override; + virtual bool Open() override; + virtual bool Pause(double dTime)override { return false; }; + virtual int Read(uint8_t* buf, int buf_size) override; + virtual int64_t Seek(int64_t offset, int whence) override; + virtual void SetReadRate(unsigned rate) override; + +protected: + IVideoPlayer* m_pPlayer; + std::vector m_filenames; +}; diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiStreams.h b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiStreams.h new file mode 100644 index 0000000000..632c474c80 --- /dev/null +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/InputStreamMultiStreams.h @@ -0,0 +1,42 @@ +#pragma once + +/* + * Copyright (C) 2005-2015 Team XBMC + * http://xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, see + * . + * + */ + +#include "DVDInputStream.h" + +#include +#include + +typedef std::shared_ptr InputStreamPtr; +class IDVDPlayer; + +class InputStreamMultiStreams : public CDVDInputStream +{ + +public: + InputStreamMultiStreams(DVDStreamType type, CFileItem& fileitem) + : CDVDInputStream(type, fileitem) {} + + virtual ~InputStreamMultiStreams() {}; + +protected: + std::vector m_InputStreams; // input streams for current playing file +}; diff --git a/xbmc/cores/VideoPlayer/DVDInputStreams/Makefile b/xbmc/cores/VideoPlayer/DVDInputStreams/Makefile index f7c26593d1..1809e63613 100644 --- a/xbmc/cores/VideoPlayer/DVDInputStreams/Makefile +++ b/xbmc/cores/VideoPlayer/DVDInputStreams/Makefile @@ -12,6 +12,7 @@ SRCS= DVDFactoryInputStream.cpp \ DVDInputStreamPVRManager.cpp \ DVDInputStreamStack.cpp \ InputStreamAddon.cpp \ + InputStreamMultiSource.cpp\ DVDStateSerializer.cpp \ LIB= DVDInputStreams.a diff --git a/xbmc/cores/VideoPlayer/VideoPlayer.cpp b/xbmc/cores/VideoPlayer/VideoPlayer.cpp index 11f1b21161..853bd2e852 100644 --- a/xbmc/cores/VideoPlayer/VideoPlayer.cpp +++ b/xbmc/cores/VideoPlayer/VideoPlayer.cpp @@ -779,7 +779,7 @@ bool CVideoPlayer::OpenInputStream() m_item.SetPath(g_mediaManager.TranslateDevicePath("")); } - m_pInputStream = CDVDFactoryInputStream::CreateInputStream(this, m_item); + m_pInputStream = CDVDFactoryInputStream::CreateInputStream(this, m_item, true); if(m_pInputStream == NULL) { CLog::Log(LOGERROR, "CVideoPlayer::OpenInputStream - unable to create input stream for [%s]", m_item.GetPath().c_str()); -- cgit v1.2.3