Eric Laurent | 3be0f00 | 2022-12-15 16:08:30 +0100 | [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 | */ |
Chris Waddell | ca0dd18 | 2022-11-25 17:15:30 +0000 | [diff] [blame] | 16 | #define LOG_TAG "UsecaseLookup" |
| 17 | // #define LOG_NDEBUG 0 |
| 18 | |
| 19 | #include "media/UsecaseLookup.h" |
| 20 | |
| 21 | #include <utils/Log.h> |
| 22 | |
| 23 | namespace android { |
| 24 | namespace media { |
| 25 | |
| 26 | /** |
| 27 | * Add streamId and outputFlags to stream list. |
| 28 | */ |
| 29 | void UsecaseLookup::addStream(STREAMID streamId, bool outputFlagGame) { |
| 30 | ALOGV("%s streamId: %d outputFlagGame: %d", __func__, streamId, outputFlagGame); |
| 31 | |
| 32 | mutex_lock lock(m_mutex); |
| 33 | m_streams[streamId] = outputFlagGame; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Remove streamId from stream list. |
| 38 | */ |
| 39 | void UsecaseLookup::removeStream(STREAMID streamId) { |
| 40 | ALOGV("%s streamId: %d ", __func__, streamId); |
| 41 | |
| 42 | mutex_lock lock(m_mutex); |
| 43 | m_streams.erase(streamId); |
| 44 | |
| 45 | // Shouldn't happen but it might. |
| 46 | for (auto it = m_tracks.begin(); it != m_tracks.end();) { |
| 47 | if (it->second == streamId) { |
| 48 | it = m_tracks.erase(it); |
| 49 | } else { |
| 50 | it++; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Add streamId and portId to track list. |
| 57 | */ |
| 58 | void UsecaseLookup::addTrack(STREAMID streamId, PORTID portId) { |
| 59 | ALOGV("%s streamId: %d portId: %d", __func__, streamId, portId); |
| 60 | |
| 61 | mutex_lock lock(m_mutex); |
| 62 | |
| 63 | if (m_tracks.find(portId) == m_tracks.end()) { |
| 64 | m_tracks[portId] = streamId; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Remove streamId and portId from track list. |
| 70 | */ |
| 71 | void UsecaseLookup::removeTrack(STREAMID streamId, PORTID portId) { |
| 72 | ALOGV("%s streamId: %d portId: %d", __func__, streamId, portId); |
| 73 | |
| 74 | mutex_lock lock(m_mutex); |
| 75 | auto it = m_tracks.find(portId); |
| 76 | |
| 77 | if (it != m_tracks.end() && it->second == streamId) { |
| 78 | m_tracks.erase(portId); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Check if stream list contains streamId with Game outputFlag. |
| 84 | */ |
| 85 | bool UsecaseLookup::isGameStream(STREAMID streamId) { |
| 86 | ALOGV("%s streamId: %d ", __func__, streamId); |
| 87 | mutex_lock lock(m_mutex); |
| 88 | auto it = m_streams.find(streamId); |
| 89 | |
| 90 | return (it != m_streams.end()) ? it->second : false; |
| 91 | } |
| 92 | |
| 93 | } // namespace media |
| 94 | } // namespace android |