GCC Code Coverage Report


Directory: src/gate/
File: src/gate/tech/cxx_mediaplayers.cpp
Date: 2026-03-20 22:56:14
Exec Total Coverage
Lines: 0 50 0.0%
Functions: 0 11 0.0%
Branches: 0 40 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, 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 GATE_CALL 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 ExceptionInfo xcptStatus;
47 GATEXX_TRY_CATCHINFO(xcptStatus, {
48 String strName(*name);
49 ptrCallback->cb->invoke(id, strName);
50 });
51 return xcptStatus.succeeded();
52 }
53 return true;
54 }
55
56 void MediaPlayer::enumDevices(CallbackDelegate const& callback)
57 {
58 MediaPlayer_cb_param param;
59 param.cb = &callback;
60 result_t result = gate_mediaplayer_enum(&MediaPlayer_cb1, &param, GATE_MEDIAPLAYER_FORMAT_AUDIOFILE);
61 GATEXX_RAISE_EXCEPTION(result, "Failed to enumerate media player devices", 0);
62 }
63
64 static gate_bool_t GATE_CALL MediaPlayer_cb2(gate_mediaplayer_id_t id, gate_string_t const* name, void* cb_param)
65 {
66 Map<MediaPlayer::DeviceId, String>* ptrMap = static_cast<Map<MediaPlayer::DeviceId, String>*>(cb_param);
67 if (ptrMap)
68 {
69 String strName(*name);
70 VoidResult result = ptrMap->tryAdd(id, strName);
71 if (result.hasError())
72 {
73 return false;
74 }
75 }
76 return true;
77 }
78
79 MediaPlayer::DeviceMap MediaPlayer::enumDevices()
80 {
81 DeviceMap ret;
82 result_t result = gate_mediaplayer_enum(&MediaPlayer_cb2, &ret, GATE_MEDIAPLAYER_FORMAT_AUDIOFILE);
83 GATEXX_CHECK_EXCEPTION(result);
84 return ret;
85 }
86
87
88 MediaPlayer::MediaPlayer(DeviceId playerId)
89 {
90 result_t result = gate_mediaplayer_open(playerId, &this->impl);
91 GATEXX_CHECK_EXCEPTION(result);
92 }
93 MediaPlayer::~MediaPlayer()
94 {
95 gate_mediaplayer_close(&this->impl);
96 }
97
98 void MediaPlayer::loadFile(String const& filePath)
99 {
100 result_t result = gate_mediaplayer_load_file(&this->impl, filePath.c_impl());
101 GATEXX_CHECK_EXCEPTION(result);
102 }
103 MediaPlayer::Status MediaPlayer::getStatus()
104 {
105 Status ret;
106 result_t result = gate_mediaplayer_status(&this->impl, &ret);
107 GATEXX_CHECK_EXCEPTION(result);
108 return ret;
109 }
110 void MediaPlayer::play()
111 {
112 result_t result = gate_mediaplayer_play(&this->impl);
113 GATEXX_CHECK_EXCEPTION(result);
114 }
115 void MediaPlayer::stop()
116 {
117 result_t result = gate_mediaplayer_stop(&this->impl);
118 GATEXX_CHECK_EXCEPTION(result);
119 }
120 gate_mediaplayer_device_t* MediaPlayer::c_impl()
121 {
122 return &this->impl;
123 }
124
125
126 } // end of namespace tech
127 } // end of namespace gate
128