Line |
Branch |
Exec |
Source |
1 |
|
|
/* GATE PROJECT LICENSE: |
2 |
|
|
+----------------------------------------------------------------------------+ |
3 |
|
|
| Copyright(c) 2018-2025, Stefan Meislinger | |
4 |
|
|
| All rights reserved. | |
5 |
|
|
| | |
6 |
|
|
| Redistribution and use in source and binary forms, with or without | |
7 |
|
|
| modification, are permitted provided that the following conditions are met:| |
8 |
|
|
| | |
9 |
|
|
| 1. Redistributions of source code must retain the above copyright notice, | |
10 |
|
|
| this list of conditions and the following disclaimer. | |
11 |
|
|
| 2. Redistributions in binary form must reproduce the above copyright | |
12 |
|
|
| notice, this list of conditions and the following disclaimer in the | |
13 |
|
|
| documentation and/or other materials provided with the distribution. | |
14 |
|
|
| | |
15 |
|
|
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| |
16 |
|
|
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 |
|
|
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 |
|
|
| ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
19 |
|
|
| LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 |
|
|
| CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 |
|
|
| SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 |
|
|
| INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 |
|
|
| CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 |
|
|
| ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
25 |
|
|
| THE POSSIBILITY OF SUCH DAMAGE. | |
26 |
|
|
+----------------------------------------------------------------------------+ |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
#include "gate/tech/mediaplayers.hpp" |
30 |
|
|
#include "gate/exceptions.hpp" |
31 |
|
|
|
32 |
|
|
namespace gate |
33 |
|
|
{ |
34 |
|
|
namespace tech |
35 |
|
|
{ |
36 |
|
|
struct GATE_API_LOCAL MediaPlayer_cb_param |
37 |
|
|
{ |
38 |
|
|
MediaPlayer::CallbackDelegate const* cb; |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
✗ |
static gate_bool_t MediaPlayer_cb1(gate_mediaplayer_id_t id, gate_string_t const* name, void* cb_param) |
42 |
|
|
{ |
43 |
|
✗ |
MediaPlayer_cb_param* ptrCallback = static_cast<MediaPlayer_cb_param*>(cb_param); |
44 |
|
✗ |
if (ptrCallback) |
45 |
|
|
{ |
46 |
|
|
try |
47 |
|
|
{ |
48 |
|
✗ |
String strName(*name); |
49 |
|
✗ |
ptrCallback->cb->invoke(id, strName); |
50 |
|
|
} |
51 |
|
✗ |
catch (...) |
52 |
|
|
{ |
53 |
|
✗ |
return false; |
54 |
|
|
} |
55 |
|
|
} |
56 |
|
✗ |
return true; |
57 |
|
|
} |
58 |
|
|
|
59 |
|
✗ |
void MediaPlayer::enumDevices(CallbackDelegate const& callback) |
60 |
|
|
{ |
61 |
|
|
MediaPlayer_cb_param param; |
62 |
|
✗ |
param.cb = &callback; |
63 |
|
✗ |
result_t result = gate_mediaplayer_enum(&MediaPlayer_cb1, ¶m, GATE_MEDIAPLAYER_FORMAT_AUDIOFILE); |
64 |
|
✗ |
GATEXX_RAISE_EXCEPTION(result, "Failed to enumerate media player devices", 0); |
65 |
|
✗ |
} |
66 |
|
|
|
67 |
|
✗ |
static gate_bool_t MediaPlayer_cb2(gate_mediaplayer_id_t id, gate_string_t const* name, void* cb_param) |
68 |
|
|
{ |
69 |
|
✗ |
Map<MediaPlayer::DeviceId, String>* ptrMap = static_cast<Map<MediaPlayer::DeviceId, String>*>(cb_param); |
70 |
|
✗ |
if (ptrMap) |
71 |
|
|
{ |
72 |
|
|
try |
73 |
|
|
{ |
74 |
|
✗ |
String strName(*name); |
75 |
|
✗ |
ptrMap->add(id, strName); |
76 |
|
|
} |
77 |
|
✗ |
catch (...) |
78 |
|
|
{ |
79 |
|
✗ |
return false; |
80 |
|
|
} |
81 |
|
|
} |
82 |
|
✗ |
return true; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
✗ |
MediaPlayer::DeviceMap MediaPlayer::enumDevices() |
86 |
|
|
{ |
87 |
|
✗ |
DeviceMap ret; |
88 |
|
✗ |
result_t result = gate_mediaplayer_enum(&MediaPlayer_cb2, &ret, GATE_MEDIAPLAYER_FORMAT_AUDIOFILE); |
89 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
90 |
|
✗ |
return ret; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
|
94 |
|
✗ |
MediaPlayer::MediaPlayer(DeviceId playerId) |
95 |
|
|
{ |
96 |
|
✗ |
result_t result = gate_mediaplayer_open(playerId, &this->impl); |
97 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
98 |
|
✗ |
} |
99 |
|
✗ |
MediaPlayer::~MediaPlayer() |
100 |
|
|
{ |
101 |
|
✗ |
gate_mediaplayer_close(&this->impl); |
102 |
|
✗ |
} |
103 |
|
|
|
104 |
|
✗ |
void MediaPlayer::loadFile(String const& filePath) |
105 |
|
|
{ |
106 |
|
✗ |
result_t result = gate_mediaplayer_load_file(&this->impl, filePath.c_impl()); |
107 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
108 |
|
✗ |
} |
109 |
|
✗ |
MediaPlayer::Status MediaPlayer::getStatus() |
110 |
|
|
{ |
111 |
|
|
Status ret; |
112 |
|
✗ |
result_t result = gate_mediaplayer_status(&this->impl, &ret); |
113 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
114 |
|
✗ |
return ret; |
115 |
|
|
} |
116 |
|
✗ |
void MediaPlayer::play() |
117 |
|
|
{ |
118 |
|
✗ |
result_t result = gate_mediaplayer_play(&this->impl); |
119 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
120 |
|
✗ |
} |
121 |
|
✗ |
void MediaPlayer::stop() |
122 |
|
|
{ |
123 |
|
✗ |
result_t result = gate_mediaplayer_stop(&this->impl); |
124 |
|
✗ |
GATEXX_CHECK_EXCEPTION(result); |
125 |
|
✗ |
} |
126 |
|
✗ |
gate_mediaplayer_device_t* MediaPlayer::c_impl() |
127 |
|
|
{ |
128 |
|
✗ |
return &this->impl; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
|
132 |
|
|
} // end of namespace tech |
133 |
|
|
} // end of namespace gate |
134 |
|
|
|