~aleteoryx/muditaos

ref: 3d13f10839e218b65dc247f03a15fb5dfa87bc8b muditaos/module-bluetooth/Bluetooth/interface/profiles/A2DP/A2DPImpl.hpp -rw-r--r-- 2.5 KiB
3d13f108 — Bartosz [MOS-668] Modify USB notifications logging 3 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include "A2DP.hpp"
#include <Bluetooth/Device.hpp>
#include <Bluetooth/Error.hpp>
#include <log/log.hpp>
#include <Audio/AudioCommon.hpp>
#include <audio/BluetoothAudioDevice.hpp>

#include "MediaContext.hpp"

#include <memory>

extern "C"
{
#include <btstack.h>
#include <btstack_defines.h>
}

namespace bluetooth
{
    class AVRCP;
    class A2DP::A2DPImpl
    {

        static constexpr int NUM_CHANNELS           = 2;
        static constexpr int BYTES_PER_AUDIO_SAMPLE = (2 * NUM_CHANNELS);
        static constexpr int AUDIO_TIMEOUT_MS       = 10;
        static constexpr int TABLE_SIZE_441HZ       = 100;
        static constexpr int SDP_BUFFER_LENGTH      = 150;
        static constexpr int MEDIA_CAP_SIZE         = 4;

        static std::array<uint8_t, SDP_BUFFER_LENGTH> sdpSourceServiceBuffer;
        static btstack_packet_callback_registration_t hciEventCallbackRegistration;
        static std::array<uint8_t, MEDIA_CAP_SIZE> mediaSbcCodecCapabilities;
        static const sys::Service *ownerService;
        static QueueHandle_t sourceQueue;
        static QueueHandle_t sinkQueue;
        static DeviceMetadata_t metadata;

        static void startTimer(MediaContext *context);
        static void stopTimer(MediaContext *context);
        static void audioTimeoutHandler(btstack_timer_source_t *timer);
        static void sourcePacketHandler(uint8_t packetType, uint16_t channel, uint8_t *packet, uint16_t size);
        static void hciPacketHandler(uint8_t packetType, uint16_t channel, uint8_t *packet, uint16_t size);
        static void sendMediaPacket();
        static void sendAudioEvent(audio::EventType event, audio::Event::DeviceState state);
        static bool isConnected;
        static std::shared_ptr<BluetoothAudioDevice> audioDevice;
        static Devicei device;
        static constexpr uint32_t a2dpSdpRecordHandle            = 0x10001;
        static constexpr uint32_t avrcpServiceSdpRecordHandle    = 0x10002;
        static constexpr uint32_t avrcpControllerSdpRecordHandle = 0x10003;

      public:
        auto init() -> Error::Code;
        void deInit();
        void connect();
        void disconnect();
        void start();
        void stop();
        void setDevice(const Devicei &dev);
        void setOwnerService(const sys::Service *service);
        void setAudioDevice(std::shared_ptr<bluetooth::BluetoothAudioDevice> audioDevice);
    };
} // namespace bluetooth