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 #define LOG_TAG "audio_proxy_client"
16 
17 #include "BusDeviceImpl.h"
18 
19 #include <utils/Log.h>
20 
21 #include "AudioProxyDevice.h"
22 #include "AudioProxyStreamOut.h"
23 #include "StreamOutImpl.h"
24 
25 using ::android::hardware::Void;
26 
27 namespace audio_proxy {
28 namespace CPP_VERSION {
29 
BusDeviceImpl(AudioProxyDevice * device)30 BusDeviceImpl::BusDeviceImpl(AudioProxyDevice* device) : mDevice(device) {}
31 BusDeviceImpl::~BusDeviceImpl() = default;
32 
openOutputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,hidl_bitfield<AudioOutputFlag> flags,const SourceMetadata & sourceMetadata,openOutputStream_cb _hidl_cb)33 Return<void> BusDeviceImpl::openOutputStream(
34     int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
35     hidl_bitfield<AudioOutputFlag> flags, const SourceMetadata& sourceMetadata,
36     openOutputStream_cb _hidl_cb) {
37   std::unique_ptr<AudioProxyStreamOut> stream;
38   AudioConfig suggestedConfig;
39 
40   Result res =
41       mDevice->openOutputStream(flags, config, &stream, &suggestedConfig);
42   ALOGE_IF(res != Result::OK, "Open output stream error.");
43 
44   // Still pass `suggestedConfig` back when `openOutputStream` returns error,
45   // so that audio service can re-open the stream with a new config.
46   _hidl_cb(res, stream ? new StreamOutImpl(std::move(stream)) : nullptr,
47            suggestedConfig);
48   return Void();
49 }
50 
51 }  // namespace CPP_VERSION
52 }  // namespace audio_proxy
53