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 #ifndef MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASELOOKUP_H_ 17 #define MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASELOOKUP_H_ 18 19 #pragma once 20 21 #include <map> 22 #include <memory> 23 #include <mutex> 24 #include <set> 25 26 namespace android { 27 namespace media { 28 29 typedef int STREAMID; 30 typedef int PORTID; 31 32 // List of streamId and outputFlag state. 33 typedef std::map<STREAMID, bool> STREAMLIST; 34 // List of portId and streamId. 35 typedef std::map<PORTID, STREAMID> TRACKLIST; 36 typedef std::lock_guard<std::mutex> mutex_lock; 37 38 class UsecaseLookup { 39 public: UsecaseLookup()40 UsecaseLookup() { } ~UsecaseLookup()41 virtual ~UsecaseLookup() { } 42 43 // Required for testing. clear()44 void clear() { 45 m_streams.clear(); 46 m_tracks.clear(); 47 } 48 49 /** 50 * Add streamId and outputFlag to stream list. 51 */ 52 void addStream(STREAMID streamId, bool outputFlagGame = false); 53 54 /** 55 * Remove streamId from stream list. 56 */ 57 void removeStream(STREAMID streamId); 58 59 /** 60 * Add streamId and portId to track list. 61 */ 62 void addTrack(STREAMID streamId, PORTID portId); 63 64 /** 65 * Remove streamId and portId from track list. 66 */ 67 void removeTrack(STREAMID streamId, PORTID portId); 68 69 /** 70 * Check if stream list contains streamId with Game output flag. 71 */ 72 bool isGameStream(STREAMID streamId); 73 74 protected: 75 STREAMLIST m_streams; 76 TRACKLIST m_tracks; 77 std::mutex m_mutex; 78 }; 79 80 } // namespace media 81 } // namespace android 82 83 #endif // MEDIA_LIBAUDIOUSECASEVALIDATION_INCLUDE_MEDIA_USECASELOOKUP_H_ 84