• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 V6_0 {
26 namespace implementation {
27 
28 using ::android::hardware::Void;
29 
StreamCommon(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,hidl_bitfield<AudioInputFlag> flags)30 StreamCommon::StreamCommon(int32_t ioHandle,
31                            const DeviceAddress& device,
32                            const AudioConfig& config,
33                            hidl_bitfield<AudioInputFlag> flags)
34         : m_ioHandle(ioHandle)
35         , m_device(device)
36         , m_config(config)
37         , m_flags(flags)
38 {}
39 
getFrameSize() const40 uint64_t StreamCommon::getFrameSize() const {
41     return util::countChannels(m_config.channelMask)
42            * util::getBytesPerSample(m_config.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.sampleRateHz;
55 }
56 
getSupportedSampleRates(AudioFormat format,IStream::getSupportedSampleRates_cb _hidl_cb) const57 void StreamCommon::getSupportedSampleRates(AudioFormat format,
58                                            IStream::getSupportedSampleRates_cb _hidl_cb) const {
59     if (m_config.format == format) {
60         _hidl_cb(Result::OK, {m_config.sampleRateHz});
61     } else {
62         _hidl_cb(Result::OK, {});
63     }
64 }
65 
setSampleRate(uint32_t sampleRateHz) const66 Result StreamCommon::setSampleRate(uint32_t sampleRateHz) const {
67     (void)sampleRateHz;
68     return FAILURE(Result::NOT_SUPPORTED);
69 }
70 
getChannelMask() const71 hidl_bitfield<AudioChannelMask> StreamCommon::getChannelMask() const {
72     return m_config.channelMask;
73 }
74 
getSupportedChannelMasks(AudioFormat format,IStream::getSupportedChannelMasks_cb _hidl_cb) const75 void StreamCommon::getSupportedChannelMasks(AudioFormat format,
76                                             IStream::getSupportedChannelMasks_cb _hidl_cb) const {
77     if (m_config.format == format) {
78         _hidl_cb(Result::OK, {m_config.channelMask});
79     } else {
80         _hidl_cb(Result::OK, {});
81     }
82 }
83 
setChannelMask(hidl_bitfield<AudioChannelMask> mask) const84 Result StreamCommon::setChannelMask(hidl_bitfield<AudioChannelMask> mask) const {
85     (void)mask;
86     return FAILURE(Result::NOT_SUPPORTED);
87 }
88 
getFormat() const89 AudioFormat StreamCommon::getFormat() const {
90     return m_config.format;
91 }
92 
getSupportedFormats(IStream::getSupportedFormats_cb _hidl_cb) const93 void StreamCommon::getSupportedFormats(IStream::getSupportedFormats_cb _hidl_cb) const {
94     _hidl_cb(Result::OK, {m_config.format});
95 }
96 
setFormat(AudioFormat format) const97 Result StreamCommon::setFormat(AudioFormat format) const {
98     (void)format;
99     return FAILURE(Result::NOT_SUPPORTED);
100 }
101 
getAudioProperties(IStream::getAudioProperties_cb _hidl_cb) const102 void StreamCommon::getAudioProperties(IStream::getAudioProperties_cb _hidl_cb) const {
103     _hidl_cb(m_config.sampleRateHz, m_config.channelMask, m_config.format);
104 }
105 
getDevices(IStream::getDevices_cb _hidl_cb) const106 void StreamCommon::getDevices(IStream::getDevices_cb _hidl_cb) const {
107     _hidl_cb(Result::OK, {m_device});
108 }
109 
setDevices(const hidl_vec<DeviceAddress> & devices) const110 Result StreamCommon::setDevices(const hidl_vec<DeviceAddress>& devices) const {
111     (void)devices;
112     return FAILURE(Result::NOT_SUPPORTED);
113 }
114 
115 }  // namespace implementation
116 }  // namespace V6_0
117 }  // namespace audio
118 }  // namespace hardware
119 }  // namespace android
120