~aleteoryx/muditaos

ref: f7f5bc377ad45f735777096c9edddeeae453b671 muditaos/module-services/service-cellular/CallAudio.cpp -rw-r--r-- 1.1 KiB
f7f5bc37 — Adam Dobrowolski [EGD-8208] Added stop audio route on async response 4 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
// 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>

struct CallRingAudio::CallMeta
{
    sys::Async<AudioStartPlaybackRequest, AudioStartPlaybackResponse> p;
};

CallRingAudio::CallRingAudio(sys::Service &s) : owner(s), meta(new CallRingAudio::CallMeta)
{}

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

void CallRingAudio::play()
{
    started = true;
    const auto file = AudioServiceAPI::GetSound(&owner, audio::PlaybackType::CallRingtone);
    meta->p         = owner.async_call<AudioStartPlaybackRequest, AudioStartPlaybackResponse>(
        service::name::audio, file, audio::PlaybackType::CallRingtone);
}

void CallRingAudio::stop()
{
    if ( not started ) {
        return;
    }
    owner.sync(meta->p);
    AudioServiceAPI::Stop(&owner, meta->p.getResult().token);
}