• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 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 <memory>
18 
19 // clang-format off
20 #include PATH(android/hardware/audio/FILE_VERSION/types.h)
21 #include PATH(android/hardware/audio/common/FILE_VERSION/types.h)
22 // clang-format on
23 
24 #include "public/audio_proxy.h"
25 
26 namespace audio_proxy {
27 namespace CPP_VERSION {
28 
29 using ::android::hardware::hidl_bitfield;
30 using ::android::hardware::hidl_string;
31 using ::android::hardware::hidl_vec;
32 
33 using namespace ::android::hardware::audio::common::CPP_VERSION;
34 using namespace ::android::hardware::audio::CPP_VERSION;
35 
36 // C++ friendly wrapper of audio_proxy_stream_out. It handles type conversion
37 // between C type and hidl type.
38 class AudioProxyStreamOut final {
39  public:
40   AudioProxyStreamOut(audio_proxy_stream_out_t* stream,
41                       audio_proxy_device_t* device);
42   ~AudioProxyStreamOut();
43 
44   size_t getBufferSize() const;
45   uint64_t getFrameCount() const;
46 
47   hidl_vec<uint32_t> getSupportedSampleRates(AudioFormat format) const;
48   uint32_t getSampleRate() const;
49   Result setSampleRate(uint32_t rate);
50 
51   hidl_vec<hidl_bitfield<AudioChannelMask>> getSupportedChannelMasks(
52       AudioFormat format) const;
53   hidl_bitfield<AudioChannelMask> getChannelMask() const;
54   Result setChannelMask(hidl_bitfield<AudioChannelMask> mask);
55 
56   hidl_vec<AudioFormat> getSupportedFormats() const;
57   AudioFormat getFormat() const;
58   Result setFormat(AudioFormat format);
59 
60   Result standby();
61 
62   Result setParameters(const hidl_vec<ParameterValue>& context,
63                        const hidl_vec<ParameterValue>& parameters);
64   hidl_vec<ParameterValue> getParameters(
65       const hidl_vec<ParameterValue>& context,
66       const hidl_vec<hidl_string>& keys) const;
67 
68   uint32_t getLatency() const;
69   ssize_t write(const void* buffer, size_t bytes);
70   Result getRenderPosition(uint32_t* dsp_frames) const;
71   Result getNextWriteTimestamp(int64_t* timestamp) const;
72   Result getPresentationPosition(uint64_t* frames, TimeSpec* timestamp) const;
73 
74   Result pause();
75   Result resume();
76 
77   bool supportsDrain() const;
78   Result drain(AudioDrain type);
79 
80   Result flush();
81 
82   Result setVolume(float left, float right);
83 
84  private:
85   audio_proxy_stream_out_t* const mStream;
86   audio_proxy_device_t* const mDevice;
87 };
88 
89 }  // namespace CPP_VERSION
90 }  // namespace audio_proxy
91