blob: e16b2c62b967ac8bd0734c2f18e03bb70925839e [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"
18#define LOG_NDEBUG 0
19#include <android-base/logging.h>
20
21#include "core-impl/Stream.h"
22
23using aidl::android::hardware::audio::common::SinkMetadata;
24using aidl::android::hardware::audio::common::SourceMetadata;
25using aidl::android::media::audio::common::AudioOffloadInfo;
26
27namespace aidl::android::hardware::audio::core {
28
29StreamIn::StreamIn(const SinkMetadata& sinkMetadata) : mMetadata(sinkMetadata) {}
30
31ndk::ScopedAStatus StreamIn::close() {
32 LOG(DEBUG) << __func__;
33 if (!mIsClosed) {
34 mIsClosed = true;
35 return ndk::ScopedAStatus::ok();
36 } else {
37 LOG(ERROR) << __func__ << ": stream was already closed";
38 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
39 }
40}
41
42ndk::ScopedAStatus StreamIn::updateMetadata(const SinkMetadata& in_sinkMetadata) {
43 LOG(DEBUG) << __func__;
44 if (!mIsClosed) {
45 mMetadata = in_sinkMetadata;
46 return ndk::ScopedAStatus::ok();
47 }
48 LOG(ERROR) << __func__ << ": stream was closed";
49 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
50}
51
52StreamOut::StreamOut(const SourceMetadata& sourceMetadata,
53 const std::optional<AudioOffloadInfo>& offloadInfo)
54 : mMetadata(sourceMetadata), mOffloadInfo(offloadInfo) {}
55
56ndk::ScopedAStatus StreamOut::close() {
57 LOG(DEBUG) << __func__;
58 if (!mIsClosed) {
59 mIsClosed = true;
60 return ndk::ScopedAStatus::ok();
61 }
62 LOG(ERROR) << __func__ << ": stream was already closed";
63 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
64}
65
66ndk::ScopedAStatus StreamOut::updateMetadata(const SourceMetadata& in_sourceMetadata) {
67 LOG(DEBUG) << __func__;
68 if (!mIsClosed) {
69 mMetadata = in_sourceMetadata;
70 return ndk::ScopedAStatus::ok();
71 }
72 LOG(ERROR) << __func__ << ": stream was closed";
73 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
74}
75
76} // namespace aidl::android::hardware::audio::core