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_VIBRATOR_IMPL_H 17 #define AUDIO_HAPTIC_VIBRATOR_IMPL_H 18 19 #include "audio_haptic_vibrator.h" 20 21 #include <cstdint> 22 #include <string> 23 24 #ifdef SUPPORT_VIBRATOR 25 #include "vibrator_agent.h" 26 #endif 27 28 namespace OHOS { 29 namespace Media { 30 31 class AudioHapticVibratorImpl : public AudioHapticVibrator { 32 public: 33 explicit AudioHapticVibratorImpl(AudioHapticPlayer &audioHapticPlayer); 34 ~AudioHapticVibratorImpl(); 35 36 int32_t PreLoad(const HapticSource &hapticSource, const AudioStandard::StreamUsage &streamUsage) override; 37 int32_t SetHapticIntensity(float intensity) override; 38 int32_t Release() override; 39 void ResetStopState() override; 40 int32_t StartVibrate(const AudioLatencyMode &latencyMode) override; 41 int32_t StopVibrate() override; 42 int32_t GetDelayTime() override; 43 void SetIsSupportEffectId(bool isSupport); 44 45 private: 46 int32_t StartVibrateForSoundPool(); 47 int32_t StartVibrateForAVPlayer(); 48 49 AudioHapticPlayer &audioHapticPlayer_; 50 51 #ifdef SUPPORT_VIBRATOR 52 VibratorUsage vibratorUsage_ = VibratorUsage::USAGE_UNKNOWN; 53 std::shared_ptr<VibratorFileDescription> vibratorFD_ = nullptr; 54 std::shared_ptr<VibratorPackage> vibratorPkg_ = nullptr; 55 std::condition_variable vibrateCV_; 56 float vibrateIntensity_ = 1.0f; 57 bool isSupportEffectId_ = false; 58 HapticSource hapticSource_; 59 #endif 60 std::mutex vibrateMutex_; 61 AudioStandard::StreamUsage streamUsage_ = AudioStandard::StreamUsage::STREAM_USAGE_UNKNOWN; 62 bool isStopped_ = false; 63 }; 64 } // namespace Media 65 } // namespace OHOS 66 #endif // AUDIO_HAPTIC_VIBRATOR_IMPL_H 67