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 AUDIO_HAPTIC_MANAGER_IMPL_H 17 #define AUDIO_HAPTIC_MANAGER_IMPL_H 18 19 #include "audio_haptic_manager.h" 20 #include "audio_haptic_player.h" 21 22 namespace OHOS { 23 namespace Media { 24 struct AudioHapticPlayerInfo { 25 std::string audioUri_; 26 HapticSource hapticSource_; 27 AudioLatencyMode latencyMode_; 28 AudioStandard::StreamUsage streamUsage_; 29 AudioHapticPlayerInfoAudioHapticPlayerInfo30 AudioHapticPlayerInfo() {}; AudioHapticPlayerInfoAudioHapticPlayerInfo31 AudioHapticPlayerInfo(const std::string &audioUri, const HapticSource &hapticSource, 32 const AudioLatencyMode &latencyMode, const AudioStandard::StreamUsage &streamUsage) 33 : audioUri_(audioUri), 34 hapticSource_(hapticSource), 35 latencyMode_(latencyMode), 36 streamUsage_(streamUsage) {}; 37 }; 38 39 class AudioHapticManagerImpl : public AudioHapticManager { 40 public: 41 AudioHapticManagerImpl(); 42 ~AudioHapticManagerImpl(); 43 44 int32_t RegisterSource(const std::string &audioUri, const std::string &hapticUri) override; 45 46 int32_t RegisterSourceWithEffectId(const std::string &audioUri, const std::string &effectId) override; 47 48 int32_t UnregisterSource(const int32_t &sourceID) override; 49 50 int32_t SetAudioLatencyMode(const int32_t &sourceId, const AudioLatencyMode &latencyMode) override; 51 52 int32_t SetStreamUsage(const int32_t &sourceID, const AudioStandard::StreamUsage &streamUsage) override; 53 54 std::shared_ptr<AudioHapticPlayer> CreatePlayer(const int32_t &sourceID, 55 const AudioHapticPlayerOptions &audioHapticPlayerOptions) override; 56 57 private: 58 bool CheckAudioLatencyMode(const int32_t &sourceId, const AudioLatencyMode &latencyMode); 59 bool CheckAudioStreamUsage(const AudioStandard::StreamUsage &streamUsage); 60 61 std::unordered_map<int32_t, std::shared_ptr<AudioHapticPlayerInfo>> audioHapticPlayerMap_; 62 int32_t curPlayerIndex_; 63 int32_t curPlayerCount_; 64 65 std::mutex audioHapticManagerMutex_; 66 }; 67 } // namespace Media 68 } // namespace OHOS 69 #endif // AUDIO_HAPTIC_MANAGER_IMPL_H 70