[WASAPI] set stream audio category
[xbmc.git] / xbmc / cores / RetroPlayer / process / RPProcessInfo.cpp
blob76fe7a137b4747c7bb94374d597db48920a28d03
1 /*
2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "RPProcessInfo.h"
11 #include "ServiceBroker.h"
12 #include "cores/DataCacheCore.h"
13 #include "cores/RetroPlayer/buffers/RenderBufferManager.h"
14 #include "cores/RetroPlayer/rendering/RenderContext.h"
15 #include "settings/DisplaySettings.h"
16 #include "settings/MediaSettings.h"
17 #include "utils/log.h"
18 #include "windowing/GraphicContext.h"
19 #include "windowing/WinSystem.h"
21 #include <mutex>
23 extern "C"
25 #include <libavutil/pixdesc.h>
28 #include <utility>
30 using namespace KODI;
31 using namespace RETRO;
33 CreateRPProcessControl CRPProcessInfo::m_processControl = nullptr;
34 std::vector<std::unique_ptr<IRendererFactory>> CRPProcessInfo::m_rendererFactories;
35 CCriticalSection CRPProcessInfo::m_createSection;
37 CRPProcessInfo::CRPProcessInfo(std::string platformName)
38 : m_platformName(std::move(platformName)),
39 m_renderBufferManager(new CRenderBufferManager),
40 m_renderContext(new CRenderContext(CServiceBroker::GetRenderSystem(),
41 CServiceBroker::GetWinSystem(),
42 CServiceBroker::GetWinSystem()->GetGfxContext(),
43 CDisplaySettings::GetInstance(),
44 CMediaSettings::GetInstance(),
45 CServiceBroker::GetGameServices(),
46 CServiceBroker::GetGUI()))
48 for (auto& rendererFactory : m_rendererFactories)
50 RenderBufferPoolVector bufferPools = rendererFactory->CreateBufferPools(*m_renderContext);
51 if (!bufferPools.empty())
52 m_renderBufferManager->RegisterPools(rendererFactory.get(), std::move(bufferPools));
55 // Initialize default scaling method
56 for (auto scalingMethod : GetScalingMethods())
58 if (HasScalingMethod(scalingMethod))
60 m_defaultScalingMethod = scalingMethod;
61 break;
66 CRPProcessInfo::~CRPProcessInfo() = default;
68 std::unique_ptr<CRPProcessInfo> CRPProcessInfo::CreateInstance()
70 std::unique_ptr<CRPProcessInfo> processInfo;
72 std::unique_lock<CCriticalSection> lock(m_createSection);
74 if (m_processControl != nullptr)
76 processInfo = m_processControl();
78 if (processInfo)
79 CLog::Log(LOGINFO, "RetroPlayer[PROCESS]: Created process info for {}",
80 processInfo->GetPlatformName());
81 else
82 CLog::Log(LOGERROR, "RetroPlayer[PROCESS]: Failed to create process info");
84 else
86 CLog::Log(LOGERROR, "RetroPlayer[PROCESS]: No process control registered");
89 return processInfo;
92 void CRPProcessInfo::RegisterProcessControl(const CreateRPProcessControl& createFunc)
94 m_processControl = createFunc;
97 void CRPProcessInfo::RegisterRendererFactory(IRendererFactory* factory)
99 std::unique_lock<CCriticalSection> lock(m_createSection);
101 CLog::Log(LOGINFO, "RetroPlayer[RENDER]: Registering renderer factory for {}",
102 factory->RenderSystemName());
104 m_rendererFactories.emplace_back(factory);
107 std::string CRPProcessInfo::GetRenderSystemName(IRenderBufferPool* renderBufferPool) const
109 return m_renderBufferManager->GetRenderSystemName(renderBufferPool);
112 CRPBaseRenderer* CRPProcessInfo::CreateRenderer(IRenderBufferPool* renderBufferPool,
113 const CRenderSettings& renderSettings)
115 std::unique_lock<CCriticalSection> lock(m_createSection);
117 for (auto& rendererFactory : m_rendererFactories)
119 RenderBufferPoolVector bufferPools = m_renderBufferManager->GetPools(rendererFactory.get());
120 for (auto& bufferPool : bufferPools)
122 if (bufferPool.get() == renderBufferPool)
123 return rendererFactory->CreateRenderer(renderSettings, *m_renderContext,
124 std::move(bufferPool));
128 CLog::Log(LOGERROR, "RetroPlayer[RENDER]: Failed to find a suitable renderer factory");
130 return nullptr;
133 void CRPProcessInfo::SetDataCache(CDataCacheCore* cache)
135 m_dataCache = cache;
139 void CRPProcessInfo::ResetInfo()
141 if (m_dataCache != nullptr)
143 m_dataCache->Reset();
147 bool CRPProcessInfo::HasScalingMethod(SCALINGMETHOD scalingMethod) const
149 return m_renderBufferManager->HasScalingMethod(scalingMethod);
152 std::vector<SCALINGMETHOD> CRPProcessInfo::GetScalingMethods()
154 return {
155 SCALINGMETHOD::NEAREST,
156 SCALINGMETHOD::LINEAR,
160 //******************************************************************************
161 // video codec
162 //******************************************************************************
163 void CRPProcessInfo::SetVideoPixelFormat(AVPixelFormat pixFormat)
165 const char* videoPixelFormat = av_get_pix_fmt_name(pixFormat);
167 if (m_dataCache != nullptr)
168 m_dataCache->SetVideoPixelFormat(videoPixelFormat != nullptr ? videoPixelFormat : "");
171 void CRPProcessInfo::SetVideoDimensions(int width, int height)
173 if (m_dataCache != nullptr)
174 m_dataCache->SetVideoDimensions(width, height);
177 void CRPProcessInfo::SetVideoFps(float fps)
179 if (m_dataCache != nullptr)
180 m_dataCache->SetVideoFps(fps);
183 //******************************************************************************
184 // player audio info
185 //******************************************************************************
186 void CRPProcessInfo::SetAudioChannels(const std::string& channels)
188 if (m_dataCache != nullptr)
189 m_dataCache->SetAudioChannels(channels);
192 void CRPProcessInfo::SetAudioSampleRate(int sampleRate)
194 if (m_dataCache != nullptr)
195 m_dataCache->SetAudioSampleRate(sampleRate);
198 void CRPProcessInfo::SetAudioBitsPerSample(int bitsPerSample)
200 if (m_dataCache != nullptr)
201 m_dataCache->SetAudioBitsPerSample(bitsPerSample);
204 //******************************************************************************
205 // player states
206 //******************************************************************************
207 void CRPProcessInfo::SetSpeed(float speed)
209 if (m_dataCache != nullptr)
210 m_dataCache->SetSpeed(1.0f, speed);
213 void CRPProcessInfo::SetPlayTimes(time_t start, int64_t current, int64_t min, int64_t max)
215 if (m_dataCache != nullptr)
216 m_dataCache->SetPlayTimes(start, current, min, max);