1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <log/log.h>
18 #include "stream_common.h"
19 #include "util.h"
20 #include "debug.h"
21
22 namespace android {
23 namespace hardware {
24 namespace audio {
25 namespace CPP_VERSION {
26 namespace implementation {
27
28 using ::android::hardware::Void;
29
StreamCommon(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,hidl_vec<AudioInOutFlag> flags)30 StreamCommon::StreamCommon(int32_t ioHandle,
31 const DeviceAddress& device,
32 const AudioConfig& config,
33 hidl_vec<AudioInOutFlag> flags)
34 : m_ioHandle(ioHandle)
35 , m_device(device)
36 , m_config(config)
37 , m_flags(std::move(flags))
38 {}
39
getFrameSize() const40 uint64_t StreamCommon::getFrameSize() const {
41 return util::countChannels(m_config.base.channelMask)
42 * util::getBytesPerSample(m_config.base.format);
43 }
44
getFrameCount() const45 uint64_t StreamCommon::getFrameCount() const {
46 return m_config.frameCount;
47 }
48
getBufferSize() const49 uint64_t StreamCommon::getBufferSize() const {
50 return getFrameSize() * getFrameCount();
51 }
52
getSampleRate() const53 uint32_t StreamCommon::getSampleRate() const {
54 return m_config.base.sampleRateHz;
55 }
56
getSupportedProfiles(const IStream::getSupportedProfiles_cb & _hidl_cb) const57 void StreamCommon::getSupportedProfiles(const IStream::getSupportedProfiles_cb &_hidl_cb) const {
58 AudioProfile profile;
59
60 profile.format = m_config.base.format;
61 profile.sampleRates = { m_config.base.sampleRateHz };
62 profile.channelMasks = { m_config.base.channelMask };
63
64 _hidl_cb(Result::OK, {profile});
65 }
66
getFormat() const67 AudioFormat StreamCommon::getFormat() const {
68 return m_config.base.format;
69 }
70
setFormat(AudioFormat format) const71 Result StreamCommon::setFormat(AudioFormat format) const {
72 (void)format;
73 return FAILURE(Result::NOT_SUPPORTED);
74 }
75
getAudioProperties(const IStream::getAudioProperties_cb & _hidl_cb) const76 void StreamCommon::getAudioProperties(const IStream::getAudioProperties_cb &_hidl_cb) const {
77 _hidl_cb(Result::OK, m_config.base);
78 }
79
getDevices(const IStream::getDevices_cb & _hidl_cb) const80 void StreamCommon::getDevices(const IStream::getDevices_cb &_hidl_cb) const {
81 _hidl_cb(Result::OK, {m_device});
82 }
83
setDevices(const hidl_vec<DeviceAddress> & devices) const84 Result StreamCommon::setDevices(const hidl_vec<DeviceAddress>& devices) const {
85 (void)devices;
86 return FAILURE(Result::NOT_SUPPORTED);
87 }
88
89 } // namespace implementation
90 } // namespace CPP_VERSION
91 } // namespace audio
92 } // namespace hardware
93 } // namespace android
94