Serenity Operating System
1/*
2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * 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 ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#pragma once
28
29#include <AudioServer/AudioClientEndpoint.h>
30#include <AudioServer/AudioServerEndpoint.h>
31#include <LibIPC/ServerConnection.h>
32
33namespace Audio {
34
35class Buffer;
36
37class ClientConnection : public IPC::ServerConnection<AudioClientEndpoint, AudioServerEndpoint>
38 , public AudioClientEndpoint {
39 C_OBJECT(ClientConnection)
40public:
41 ClientConnection();
42
43 virtual void handshake() override;
44 void enqueue(const Buffer&);
45 bool try_enqueue(const Buffer&);
46
47 bool get_muted();
48 void set_muted(bool);
49
50 int get_main_mix_volume();
51 void set_main_mix_volume(int);
52
53 int get_remaining_samples();
54 int get_played_samples();
55 int get_playing_buffer();
56
57 void set_paused(bool paused);
58 void clear_buffer(bool paused = false);
59
60 Function<void(i32 buffer_id)> on_finish_playing_buffer;
61 Function<void(bool muted)> on_muted_state_change;
62
63private:
64 virtual void handle(const Messages::AudioClient::FinishedPlayingBuffer&) override;
65 virtual void handle(const Messages::AudioClient::MutedStateChanged&) override;
66};
67
68}