blob: ab3e45136417c51101a8fc913abe950c062fe8f4 [file] [log] [blame]
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001/*
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 Naganovdf5adfd2021-11-11 22:09:22 +000018#include <android-base/logging.h>
19
20#include "core-impl/Stream.h"
21
22using aidl::android::hardware::audio::common::SinkMetadata;
23using aidl::android::hardware::audio::common::SourceMetadata;
24using aidl::android::media::audio::common::AudioOffloadInfo;
25
26namespace aidl::android::hardware::audio::core {
27
Mikhail Naganov6a4872d2022-06-15 21:39:04 +000028StreamIn::StreamIn(const SinkMetadata& sinkMetadata) : mMetadata(sinkMetadata) {
29 LOG(DEBUG) << __func__;
30}
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000031
32ndk::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
43ndk::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
53StreamOut::StreamOut(const SourceMetadata& sourceMetadata,
54 const std::optional<AudioOffloadInfo>& offloadInfo)
Mikhail Naganov6a4872d2022-06-15 21:39:04 +000055 : mMetadata(sourceMetadata), mOffloadInfo(offloadInfo) {
56 LOG(DEBUG) << __func__;
57}
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000058
59ndk::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
69ndk::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