1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef PLAYBACK_CAPTURER_MANAGER_H 17 #define PLAYBACK_CAPTURER_MANAGER_H 18 19 #include <cstdio> 20 #include <cstdint> 21 #include <cstddef> 22 #include <unordered_set> 23 #include <memory> 24 #include <mutex> 25 #include <string> 26 #include <vector> 27 28 #include "audio_info.h" 29 #include "playback_capturer_adapter.h" 30 31 namespace OHOS { 32 namespace AudioStandard { 33 class ICapturerFilterListener { 34 public: 35 virtual ~ICapturerFilterListener() = default; 36 37 // This will be called when a filter is first enabled or changed. 38 virtual int32_t OnCapturerFilterChange(uint32_t sessionId, const AudioPlaybackCaptureConfig &newConfig) = 0; 39 40 // This will be called when a filter released. 41 virtual int32_t OnCapturerFilterRemove(uint32_t sessionId) = 0; 42 }; 43 44 class PlaybackCapturerManager { 45 public: 46 PlaybackCapturerManager(); 47 ~PlaybackCapturerManager(); 48 static PlaybackCapturerManager *GetInstance(); 49 void SetSupportStreamUsage(std::vector<int32_t> usage); 50 bool IsStreamSupportInnerCapturer(int32_t streamUsage); 51 bool IsPrivacySupportInnerCapturer(int32_t privacyType); 52 void SetCaptureSilentState(bool state); 53 bool IsCaptureSilently(); 54 bool GetInnerCapturerState(); 55 void SetInnerCapturerState(bool state); 56 57 // add for new playback-capturer 58 std::vector<StreamUsage> GetDefaultUsages(); 59 bool RegisterCapturerFilterListener(ICapturerFilterListener *listener); 60 int32_t SetPlaybackCapturerFilterInfo(uint32_t sessionId, const AudioPlaybackCaptureConfig &config); 61 int32_t RemovePlaybackCapturerFilterInfo(uint32_t sessionId); 62 private: 63 std::mutex setMutex_; 64 std::unordered_set<int32_t> supportStreamUsageSet_; 65 std::vector<StreamUsage> defaultUsages_ = { STREAM_USAGE_MEDIA, STREAM_USAGE_MUSIC, STREAM_USAGE_MOVIE, 66 STREAM_USAGE_GAME, STREAM_USAGE_AUDIOBOOK }; 67 bool isCaptureSilently_ = false; 68 bool isInnerCapturerRunning_ = false; 69 ICapturerFilterListener *listener_ = nullptr; 70 }; 71 72 } // namespace AudioStandard 73 } // namespace OHOS 74 #endif // PLAYBACK_CAPTURER_MANAGER_H 75