• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "BusOutputStream.h"
16 
17 #include <android-base/logging.h>
18 #include <system/audio.h>
19 
20 namespace audio_proxy::service {
21 
BusOutputStream(const std::string & address,const AidlAudioConfig & config,int32_t flags)22 BusOutputStream::BusOutputStream(const std::string& address,
23                                  const AidlAudioConfig& config, int32_t flags)
24     : mAddress(address), mConfig(config), mFlags(flags) {}
25 BusOutputStream::~BusOutputStream() = default;
26 
getAddress() const27 const std::string& BusOutputStream::getAddress() const { return mAddress; }
getConfig() const28 const AidlAudioConfig& BusOutputStream::getConfig() const { return mConfig; }
getFlags() const29 int32_t BusOutputStream::getFlags() const { return mFlags; }
30 
getFrameSize() const31 int BusOutputStream::getFrameSize() const {
32   audio_format_t format = static_cast<audio_format_t>(mConfig.format);
33 
34   if (!audio_has_proportional_frames(format)) {
35     return sizeof(int8_t);
36   }
37 
38   size_t channelSampleSize = audio_bytes_per_sample(format);
39   return audio_channel_count_from_out_mask(
40              static_cast<audio_channel_mask_t>(mConfig.channelMask)) *
41          channelSampleSize;
42 }
43 
prepareForWriting(uint32_t frameSize,uint32_t frameCount)44 bool BusOutputStream::prepareForWriting(uint32_t frameSize,
45                                         uint32_t frameCount) {
46   DCHECK_EQ(mWritingFrameSize, 0);
47   DCHECK_EQ(mWritingFrameCount, 0);
48 
49   if (!prepareForWritingImpl(frameSize, frameCount)) {
50     return false;
51   }
52 
53   mWritingFrameSize = frameSize;
54   mWritingFrameCount = frameCount;
55   return true;
56 }
57 
getWritingFrameSize() const58 uint32_t BusOutputStream::getWritingFrameSize() const {
59   return mWritingFrameSize;
60 }
61 
getWritingFrameCount() const62 uint32_t BusOutputStream::getWritingFrameCount() const {
63   return mWritingFrameCount;
64 }
65 
66 }  // namespace audio_proxy::service