Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "AHAL_Stream" |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 18 | #include <android-base/logging.h> |
| 19 | |
| 20 | #include "core-impl/Stream.h" |
| 21 | |
| 22 | using aidl::android::hardware::audio::common::SinkMetadata; |
| 23 | using aidl::android::hardware::audio::common::SourceMetadata; |
| 24 | using aidl::android::media::audio::common::AudioOffloadInfo; |
| 25 | |
| 26 | namespace aidl::android::hardware::audio::core { |
| 27 | |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 28 | StreamIn::StreamIn(const SinkMetadata& sinkMetadata) : mMetadata(sinkMetadata) { |
| 29 | LOG(DEBUG) << __func__; |
| 30 | } |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 31 | |
| 32 | ndk::ScopedAStatus StreamIn::close() { |
| 33 | LOG(DEBUG) << __func__; |
| 34 | if (!mIsClosed) { |
| 35 | mIsClosed = true; |
| 36 | return ndk::ScopedAStatus::ok(); |
| 37 | } else { |
| 38 | LOG(ERROR) << __func__ << ": stream was already closed"; |
| 39 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | ndk::ScopedAStatus StreamIn::updateMetadata(const SinkMetadata& in_sinkMetadata) { |
| 44 | LOG(DEBUG) << __func__; |
| 45 | if (!mIsClosed) { |
| 46 | mMetadata = in_sinkMetadata; |
| 47 | return ndk::ScopedAStatus::ok(); |
| 48 | } |
| 49 | LOG(ERROR) << __func__ << ": stream was closed"; |
| 50 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 51 | } |
| 52 | |
| 53 | StreamOut::StreamOut(const SourceMetadata& sourceMetadata, |
| 54 | const std::optional<AudioOffloadInfo>& offloadInfo) |
Mikhail Naganov | 6a4872d | 2022-06-15 21:39:04 +0000 | [diff] [blame] | 55 | : mMetadata(sourceMetadata), mOffloadInfo(offloadInfo) { |
| 56 | LOG(DEBUG) << __func__; |
| 57 | } |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 58 | |
| 59 | ndk::ScopedAStatus StreamOut::close() { |
| 60 | LOG(DEBUG) << __func__; |
| 61 | if (!mIsClosed) { |
| 62 | mIsClosed = true; |
| 63 | return ndk::ScopedAStatus::ok(); |
| 64 | } |
| 65 | LOG(ERROR) << __func__ << ": stream was already closed"; |
| 66 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 67 | } |
| 68 | |
| 69 | ndk::ScopedAStatus StreamOut::updateMetadata(const SourceMetadata& in_sourceMetadata) { |
| 70 | LOG(DEBUG) << __func__; |
| 71 | if (!mIsClosed) { |
| 72 | mMetadata = in_sourceMetadata; |
| 73 | return ndk::ScopedAStatus::ok(); |
| 74 | } |
| 75 | LOG(ERROR) << __func__ << ": stream was closed"; |
| 76 | return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE); |
| 77 | } |
| 78 | |
| 79 | } // namespace aidl::android::hardware::audio::core |