~aleteoryx/muditaos

ref: 3cc3f50f7b9364ffac38349238cd6d9aa243dc23 muditaos/module-services/service-cellular/call/api/CallAudio.cpp -rw-r--r-- 1.6 KiB
3cc3f50f — Maciej Gibowicz [BH-1809][BH-1835] Add date format setting 2 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CallAudio.hpp"
#include "Service/Message.hpp"
#include "log/log.hpp"
#include <limits>
#include <service-audio/AudioMessage.hpp>
#include "service-audio/AudioServiceName.hpp"
#include <service-audio/AudioServiceAPI.hpp>
#include <Timers/TimerFactory.hpp>
#include <gsl/util>

struct Audio::CallMeta
{
    sys::Async<AudioStartPlaybackRequest, AudioStartPlaybackResponse> async;
};

Audio::Audio(sys::Service *s) : owner(s), meta(new Audio::CallMeta)
{}

Audio::~Audio()
{
    delete meta;
}

void Audio::play()
{
    if (not started) {
        started         = true;
        const auto file = AudioServiceAPI::GetSound(owner, audio::PlaybackType::CallRingtone);
        meta->async     = owner->async_call<AudioStartPlaybackRequest, AudioStartPlaybackResponse>(
            service::name::audio, file, audio::PlaybackType::CallRingtone);
    }
}

void Audio::stop()
{
    auto _ = gsl::finally([this] { AudioServiceAPI::StopAll(owner); });

    if (not started) {
        return;
    }
    started = false;
    owner->sync(meta->async);
}

void Audio::muteCall()
{
    AudioServiceAPI::SendEvent(owner, audio::EventType::CallMute);
}

void Audio::unmuteCall()
{
    AudioServiceAPI::SendEvent(owner, audio::EventType::CallUnmute);
}

void Audio::setLoudspeakerOn()
{
    AudioServiceAPI::SendEvent(owner, audio::EventType::CallLoudspeakerOn);
}

void Audio::setLoudspeakerOff()
{
    AudioServiceAPI::SendEvent(owner, audio::EventType::CallLoudspeakerOff);
}

void Audio::routingStart()
{
    AudioServiceAPI::RoutingStart(owner);
}