Ring Daemon 16.0.0
Loading...
Searching...
No Matches
audio_common.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 The Android Open Source Project
3 * Copyright 2015-2025 Savoir-faire Linux Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19#include "../audio_format.h"
20#include "buf_manager.h"
21
22#include <SLES/OpenSLES.h>
23#include <SLES/OpenSLES_Android.h>
24
25namespace jami {
26namespace opensl {
27
28/*
29 * Sample Buffer Controls...
30 */
31#define RECORD_DEVICE_KICKSTART_BUF_COUNT 4
32#define PLAY_KICKSTART_BUFFER_COUNT 8
33#define DEVICE_SHADOW_BUFFER_QUEUE_LEN 4
34#define BUF_COUNT 16
35
38{
41 .formatType = SL_DATAFORMAT_PCM,
42 .numChannels = infos.nb_channels <= 1 ? 1u : 2u,
43 .sampleRate = infos.sample_rate * 1000,
44 .bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_16,
45 .containerSize = SL_PCMSAMPLEFORMAT_FIXED_16,
46 .channelMask = infos.nb_channels <= 1 ? SL_SPEAKER_FRONT_CENTER
48 .endianness = SL_BYTEORDER_LITTLEENDIAN,
50 };
51 else if (infos.sampleFormat == AV_SAMPLE_FMT_FLT)
53 .formatType = SL_ANDROID_DATAFORMAT_PCM_EX,
54 .numChannels = infos.nb_channels <= 1 ? 1u : 2u,
55 .sampleRate = infos.sample_rate * 1000,
56 .bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_32,
57 .containerSize = SL_PCMSAMPLEFORMAT_FIXED_32,
58 .channelMask = infos.nb_channels <= 1 ? SL_SPEAKER_FRONT_CENTER
60 .endianness = SL_BYTEORDER_LITTLEENDIAN,
62 };
63 else
64 throw std::runtime_error("Unsupported sample format");
65}
66
67#define SLASSERT(x) \
68 { \
69 if (SL_RESULT_SUCCESS != (x)) \
70 throw std::runtime_error("OpenSLES error " + std::to_string(x)); \
71 }
72
73/*
74 * Interface for player and recorder to communicate with engine
75 */
76#define ENGINE_SERVICE_MSG_KICKSTART_PLAYER 1
77#define ENGINE_SERVICE_MSG_RETRIEVE_DUMP_BUFS 2
78
79using EngineCallback = std::function<void()>;
80
81} // namespace opensl
82} // namespace jami
std::function< void()> EngineCallback
SLAndroidDataFormat_PCM_EX convertToSLSampleFormat(const jami::AudioFormat &infos)
void emitSignal(Args... args)
Definition ring_signal.h:64
Structure to hold sample rate and channel number associated with audio data.
AVSampleFormat sampleFormat