Audaspace 1.6.0
A high level audio library.
Loading...
Searching...
No Matches
OpenCloseDevice.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright 2009-2024 Jörg Müller
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 ******************************************************************************/
16
17#pragma once
18
24
25#include <chrono>
26#include <condition_variable>
27#include <thread>
28
30
32
36class AUD_PLUGIN_API OpenCloseDevice : public SoftwareDevice
37{
38private:
42 bool m_device_opened{false};
43
47 bool m_playing{false};
48
52 bool m_delayed_close_running{false};
53
57 std::thread m_delayed_close_thread;
58
62 std::mutex m_delayed_close_mutex;
63
67 std::condition_variable m_immediate_close_condition;
68
72 std::chrono::milliseconds m_device_close_delay{10000};
73
77 std::chrono::time_point<std::chrono::steady_clock> m_playback_stopped_time;
78
82 void closeAfterDelay();
83
87 AUD_LOCAL virtual void start() = 0;
88
92 AUD_LOCAL virtual void stop() = 0;
93
97 AUD_LOCAL virtual void open() = 0;
98
102 AUD_LOCAL virtual void close() = 0;
103
104 // delete copy constructor and operator=
105 OpenCloseDevice(const OpenCloseDevice&) = delete;
106 OpenCloseDevice& operator=(const OpenCloseDevice&) = delete;
107
108protected:
109 OpenCloseDevice() = default;
110
111 void closeNow();
112
113 virtual void playing(bool playing);
114};
115
#define AUD_NAMESPACE_END
Closes the audaspace namespace aud.
Definition Audaspace.h:119
#define AUD_LOCAL
Used for hiding symbols from export in the shared library.
Definition Audaspace.h:80
#define AUD_NAMESPACE_BEGIN
Opens the audaspace namespace aud.
Definition Audaspace.h:116
#define AUD_PLUGIN_API
Used for exporting symbols in the shared library.
Definition Audaspace.h:94
The SoftwareDevice class.
virtual void playing(bool playing)
This function tells the device, to start or pause playback.
SoftwareDevice()
Empty default constructor.