blob: 7d005ea62f43b45824687bdb978612883985ae5d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (C) 2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "GameClientStreams.h"
#include "GameClientStreamAudio.h"
#include "GameClientStreamSwFramebuffer.h"
#include "GameClientStreamVideo.h"
#include "cores/RetroPlayer/streams/IRetroPlayerStream.h"
#include "cores/RetroPlayer/streams/IStreamManager.h"
#include "cores/RetroPlayer/streams/RetroPlayerStreamTypes.h"
#include "games/addons/GameClient.h"
#include "games/addons/GameClientTranslator.h"
#include "utils/log.h"
#include <memory>
using namespace KODI;
using namespace GAME;
CGameClientStreams::CGameClientStreams(CGameClient& gameClient) : m_gameClient(gameClient)
{
}
void CGameClientStreams::Initialize(RETRO::IStreamManager& streamManager)
{
m_streamManager = &streamManager;
}
void CGameClientStreams::Deinitialize()
{
m_streamManager = nullptr;
}
IGameClientStream* CGameClientStreams::OpenStream(const game_stream_properties& properties)
{
if (m_streamManager == nullptr)
return nullptr;
RETRO::StreamType retroStreamType;
if (!CGameClientTranslator::TranslateStreamType(properties.type, retroStreamType))
{
CLog::Log(LOGERROR, "GAME: Invalid stream type: {}", static_cast<int>(properties.type));
return nullptr;
}
std::unique_ptr<IGameClientStream> gameStream = CreateStream(properties.type);
if (!gameStream)
{
CLog::Log(LOGERROR, "GAME: No stream implementation for type: {}",
static_cast<int>(properties.type));
return nullptr;
}
RETRO::StreamPtr retroStream = m_streamManager->CreateStream(retroStreamType);
if (!retroStream)
{
CLog::Log(LOGERROR, "GAME: Invalid RetroPlayer stream type: {}",
static_cast<int>(retroStreamType));
return nullptr;
}
if (!gameStream->OpenStream(retroStream.get(), properties))
{
CLog::Log(LOGERROR, "GAME: Failed to open audio stream");
return nullptr;
}
m_streams[gameStream.get()] = std::move(retroStream);
return gameStream.release();
}
void CGameClientStreams::CloseStream(IGameClientStream* stream)
{
if (stream != nullptr)
{
std::unique_ptr<IGameClientStream> streamHolder(stream);
streamHolder->CloseStream();
m_streamManager->CloseStream(std::move(m_streams[stream]));
m_streams.erase(stream);
}
}
std::unique_ptr<IGameClientStream> CGameClientStreams::CreateStream(
GAME_STREAM_TYPE streamType) const
{
std::unique_ptr<IGameClientStream> gameStream;
switch (streamType)
{
case GAME_STREAM_AUDIO:
{
gameStream.reset(new CGameClientStreamAudio(m_gameClient.GetSampleRate()));
break;
}
case GAME_STREAM_VIDEO:
{
gameStream.reset(new CGameClientStreamVideo);
break;
}
case GAME_STREAM_SW_FRAMEBUFFER:
{
gameStream.reset(new CGameClientStreamSwFramebuffer);
break;
}
default:
break;
}
return gameStream;
}
|