~aleteoryx/muditaos

ref: f1fc9df1527237c0449585bcaa620851583a271e muditaos/module-audio/Audio/Endpoint.cpp -rw-r--r-- 2.0 KiB
f1fc9df1 — Marcin Smoczyński [EGD-4977] Reduce audio lag during voice call 5 years ago
                                                                                
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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "Endpoint.hpp"

#include <cassert> // assert

using namespace audio;

Endpoint::Endpoint(const Capabilities &caps) : _caps(caps)
{}

const Endpoint::Capabilities &Endpoint::getCapabilities() const noexcept
{
    return _caps;
}

void Endpoint::connectStream(Stream &stream)
{
    assert(_stream == nullptr);
    _stream = &stream;
}

void Endpoint::disconnectStream()
{
    assert(_stream != nullptr);
    _stream = nullptr;
}

bool Endpoint::isConnected() const noexcept
{
    return _stream != nullptr;
}

Sink::Sink(const Capabilities &caps) : Endpoint(caps)
{}

Source::Source(const Capabilities &caps) : Endpoint(caps)
{}

IOProxy::IOProxy(const Capabilities &sourceCaps, const Capabilities &sinkCaps) : Source(sourceCaps), Sink(sinkCaps)
{}

StreamConnection::StreamConnection(Source *source, Sink *sink, Stream *stream)
    : _sink(sink), _source(source), _stream(stream)
{
    assert(_sink != nullptr);
    assert(_source != nullptr);
    assert(_stream != nullptr);

    _sink->connectStream(*_stream);
    _source->connectStream(*_stream);
}

StreamConnection::~StreamConnection()
{
    destroy();
}

void StreamConnection::destroy()
{
    disable();
    _sink->disconnectStream();
    _source->disconnectStream();
}

void StreamConnection::enable()
{
    if (enabled) {
        return;
    }

    _stream->reset();
    _sink->enableOutput();
    _source->enableInput();

    enabled = true;
}

void StreamConnection::disable()
{
    if (!enabled) {
        return;
    }

    _source->disableInput();
    _sink->disableOutput();
    _stream->reset();

    enabled = false;
}

bool StreamConnection::isEnabled() const noexcept
{
    return enabled;
}

Source *StreamConnection::getSource() const noexcept
{
    return _source;
}

Sink *StreamConnection::getSink() const noexcept
{
    return _sink;
}

Stream *StreamConnection::getStream() const noexcept
{
    return _stream;
}