Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 "Camera3-OutStrmIntf" |
| 18 | #define ATRACE_TAG ATRACE_TAG_CAMERA |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | //#define LOG_NNDEBUG 0 // Per-frame verbose logging |
| 21 | |
| 22 | |
| 23 | #include "Camera3OutputStreamInterface.h" |
| 24 | |
| 25 | namespace android { |
| 26 | |
| 27 | namespace camera3 { |
| 28 | |
| 29 | status_t StreamSet::add( |
| 30 | int streamId, sp<camera3::Camera3OutputStreamInterface> stream) { |
| 31 | if (stream == nullptr) { |
| 32 | ALOGE("%s: cannot add null stream", __FUNCTION__); |
| 33 | return BAD_VALUE; |
| 34 | } |
| 35 | std::lock_guard<std::mutex> lock(mLock); |
| 36 | return mData.add(streamId, stream); |
| 37 | } |
| 38 | |
| 39 | ssize_t StreamSet::remove(int streamId) { |
| 40 | std::lock_guard<std::mutex> lock(mLock); |
| 41 | return mData.removeItem(streamId); |
| 42 | } |
| 43 | |
| 44 | sp<camera3::Camera3OutputStreamInterface> StreamSet::get(int streamId) { |
| 45 | std::lock_guard<std::mutex> lock(mLock); |
| 46 | ssize_t idx = mData.indexOfKey(streamId); |
| 47 | if (idx == NAME_NOT_FOUND) { |
| 48 | return nullptr; |
| 49 | } |
| 50 | return mData.editValueAt(idx); |
| 51 | } |
| 52 | |
| 53 | sp<camera3::Camera3OutputStreamInterface> StreamSet::operator[] (size_t index) { |
| 54 | std::lock_guard<std::mutex> lock(mLock); |
| 55 | return mData.editValueAt(index); |
| 56 | } |
| 57 | |
| 58 | size_t StreamSet::size() const { |
| 59 | std::lock_guard<std::mutex> lock(mLock); |
| 60 | return mData.size(); |
| 61 | } |
| 62 | |
| 63 | void StreamSet::clear() { |
| 64 | std::lock_guard<std::mutex> lock(mLock); |
| 65 | return mData.clear(); |
| 66 | } |
| 67 | |
| 68 | std::vector<int> StreamSet::getStreamIds() { |
| 69 | std::lock_guard<std::mutex> lock(mLock); |
| 70 | std::vector<int> streamIds(mData.size()); |
| 71 | for (size_t i = 0; i < mData.size(); i++) { |
| 72 | streamIds[i] = mData.keyAt(i); |
| 73 | } |
| 74 | return streamIds; |
| 75 | } |
| 76 | |
| 77 | StreamSet::StreamSet(const StreamSet& other) { |
| 78 | std::lock_guard<std::mutex> lock(other.mLock); |
| 79 | mData = other.mData; |
| 80 | } |
| 81 | |
| 82 | } // namespace camera3 |
| 83 | |
| 84 | } // namespace android |