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
19 #include "AudioUtil.h"
20
21 namespace audio_proxy::service {
22
BusOutputStream(const std::string & address,const AidlAudioConfig & config,int32_t flags)23 BusOutputStream::BusOutputStream(const std::string& address,
24 const AidlAudioConfig& config, int32_t flags)
25 : mAddress(address), mConfig(config), mFlags(flags) {}
26 BusOutputStream::~BusOutputStream() = default;
27
getAddress() const28 const std::string& BusOutputStream::getAddress() const { return mAddress; }
getConfig() const29 const AidlAudioConfig& BusOutputStream::getConfig() const { return mConfig; }
getFlags() const30 int32_t BusOutputStream::getFlags() const { return mFlags; }
31
getFrameSize() const32 int BusOutputStream::getFrameSize() const { return computeFrameSize(mConfig); }
33
prepareForWriting(uint32_t frameSize,uint32_t frameCount)34 bool BusOutputStream::prepareForWriting(uint32_t frameSize,
35 uint32_t frameCount) {
36 DCHECK_EQ(mWritingFrameSize, 0);
37 DCHECK_EQ(mWritingFrameCount, 0);
38
39 if (!prepareForWritingImpl(frameSize, frameCount)) {
40 return false;
41 }
42
43 mWritingFrameSize = frameSize;
44 mWritingFrameCount = frameCount;
45 return true;
46 }
47
getWritingFrameSize() const48 uint32_t BusOutputStream::getWritingFrameSize() const {
49 return mWritingFrameSize;
50 }
51
getWritingFrameCount() const52 uint32_t BusOutputStream::getWritingFrameCount() const {
53 return mWritingFrameCount;
54 }
55
56 } // namespace audio_proxy::service