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 "StreamProviderImpl.h"
16 
17 #include <android-base/logging.h>
18 
19 #include "AudioProxyDevice.h"
20 #include "AudioProxyStreamOut.h"
21 #include "OutputStreamImpl.h"
22 
23 using aidl::device::google::atv::audio_proxy::AudioConfig;
24 using aidl::device::google::atv::audio_proxy::IOutputStream;
25 
26 namespace audio_proxy {
27 
StreamProviderImpl(AudioProxyDevice * device)28 StreamProviderImpl::StreamProviderImpl(AudioProxyDevice* device)
29     : mDevice(device) {}
30 StreamProviderImpl::~StreamProviderImpl() = default;
31 
openOutputStream(const std::string & address,const AudioConfig & config,int32_t flags,std::shared_ptr<IOutputStream> * outputStream)32 ndk::ScopedAStatus StreamProviderImpl::openOutputStream(
33     const std::string& address, const AudioConfig& config, int32_t flags,
34     std::shared_ptr<IOutputStream>* outputStream) {
35   *outputStream = nullptr;
36 
37   std::unique_ptr<AudioProxyStreamOut> stream =
38       mDevice->openOutputStream(address, config, flags);
39   if (stream) {
40     *outputStream =
41         ndk::SharedRefBase::make<OutputStreamImpl>(std::move(stream));
42   } else {
43     LOG(WARNING) << "Failed to open output stream.";
44   }
45 
46   // Returns OK as this is a recoverable failure. The caller can open a new
47   // output stream with different config and flags.
48   return ndk::ScopedAStatus::ok();
49 }
50 
51 }  // namespace audio_proxy