~aleteoryx/muditaos

ref: 2b754af627a1d4d93fdbf28c79eab64db5ea72cd muditaos/module-bsp/board/rt1051/bsp/audio/RT1051BluetoothAudio.cpp -rw-r--r-- 3.2 KiB
2b754af6 — Piotr Leniec [DW-31] Add a condition that prohibits checks to be run on draft PRs 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051BluetoothAudio.hpp"

namespace bsp
{
    RT1051BluetoothAudio::RT1051BluetoothAudio(AudioDevice::audioCallback_t callback) : AudioDevice(callback)
    {
        isInitialized = true;
        LOG_INFO("Device created!");
    }
    AudioDevice::RetCode RT1051BluetoothAudio::Start(const AudioDevice::Format &format)
    {
        LOG_INFO("Start");
        Init();
        if ((format.flags & static_cast<uint32_t>(AudioDevice::Flags::OutputMono)) != 0u) {
            OutStart();
        }
        else if ((format.flags & static_cast<uint32_t>(AudioDevice::Flags::OutputStereo)) != 0u) {
            OutStart();
        }
        return AudioDevice::RetCode::Success;
    }
    AudioDevice::RetCode RT1051BluetoothAudio::Stop()
    {
        return AudioDevice::RetCode::Success;
    }
    AudioDevice::RetCode RT1051BluetoothAudio::OutputVolumeCtrl(float vol)
    {
        return AudioDevice::RetCode::Success;
    }
    AudioDevice::RetCode RT1051BluetoothAudio::InputGainCtrl(float gain)
    {
        return AudioDevice::RetCode::Success;
    }
    AudioDevice::RetCode RT1051BluetoothAudio::OutputPathCtrl(AudioDevice::OutputPath outputPath)
    {
        return AudioDevice::RetCode::Success;
    }
    AudioDevice::RetCode RT1051BluetoothAudio::InputPathCtrl(AudioDevice::InputPath inputPath)
    {
        return AudioDevice::RetCode::Success;
    }
    bool RT1051BluetoothAudio::IsFormatSupported(const AudioDevice::Format &format)
    {
        return true;
    }
    void outBluetoothAudioWorkerTask(void *pvp)
    {
        auto *inst    = static_cast<RT1051BluetoothAudio *>(pvp);
        auto dataSize = inst->metadata.samplesPerFrame;
        auto fatalError = false;

        if (inst->sourceQueue == nullptr) {
            LOG_FATAL("sourceQueue nullptr");
            fatalError = true;
        }

        while (!fatalError) {
            auto framesFetched = inst->GetAudioCallback()(nullptr, inst->audioData.data.data(), dataSize);
            if (framesFetched == 0) {
                break;
            }
            else if (framesFetched < inst->audioData.data.size()) {
                std::fill(inst->audioData.data.begin() + framesFetched, inst->audioData.data.end(), 0);
            }

            if (inst->sourceQueue != nullptr) {
                xQueueSend(inst->sourceQueue, inst->audioData.data.data(), 2);
            }
            else {
                LOG_ERROR("Queue nullptr");
                vTaskDelay(2);
            }
        }

        inst->OutStop();
        inst->outWorkerThread = nullptr;
        vTaskDelete(nullptr);
    }

    void RT1051BluetoothAudio::OutStart()
    {
        if (xTaskCreate(outBluetoothAudioWorkerTask,
                        "outbluetoothaudio",
                        stackSize,
                        this,
                        tskIDLE_PRIORITY,
                        &outWorkerThread) != pdPASS) {
            LOG_ERROR("Error during creating  output bluetooth audio task");
        }
    }
    void RT1051BluetoothAudio::OutStop()
    {}

    void RT1051BluetoothAudio::Init()
    {}

    RT1051BluetoothAudio::~RT1051BluetoothAudio()
    {
        Stop();
    }
} // namespace bsp