• 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 #pragma once
16 
17 #include <inttypes.h>
18 
19 #include "AidlTypes.h"
20 
21 namespace audio_proxy::service {
22 
23 // Interface for audio playback. It has similar APIs to the AIDL IOutputStream.
24 class BusOutputStream {
25  public:
26   BusOutputStream(const std::string& address, const AidlAudioConfig& config,
27                   int32_t flags);
28   virtual ~BusOutputStream();
29 
30   const std::string& getAddress() const;
31   const AidlAudioConfig& getConfig() const;
32   int32_t getFlags() const;
33   int getFrameSize() const;
34 
35   bool prepareForWriting(uint32_t frameSize, uint32_t frameCount);
36   uint32_t getWritingFrameSize() const;
37   uint32_t getWritingFrameCount() const;
38 
39   virtual bool standby() = 0;
40   virtual bool pause() = 0;
41   virtual bool resume() = 0;
42   virtual bool drain(AidlAudioDrain drain) = 0;
43   virtual bool flush() = 0;
44   virtual bool close() = 0;
45   virtual bool setVolume(float left, float right) = 0;
46 
47   virtual size_t availableToWrite() = 0;
48   virtual AidlWriteStatus writeRingBuffer(const uint8_t* firstMem,
49                                           size_t firstLength,
50                                           const uint8_t* secondMem,
51                                           size_t secondLength) = 0;
52 
53  protected:
54   virtual bool prepareForWritingImpl(uint32_t frameSize,
55                                      uint32_t frameCount) = 0;
56 
57   const std::string mAddress;
58   const AidlAudioConfig mConfig;
59   const int32_t mFlags;
60 
61   uint32_t mWritingFrameSize = 0;
62   uint32_t mWritingFrameCount = 0;
63 };
64 
65 }  // namespace audio_proxy::service