• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_SOUND_H
17 #define AUDIO_HAPTIC_SOUND_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "audio_haptic_manager.h"
23 
24 namespace OHOS {
25 namespace Media {
26 class AudioHapticSoundCallback {
27 public:
28     virtual ~AudioHapticSoundCallback() = default;
29 
30     virtual void OnEndOfStream() = 0;
31     virtual void OnError(int32_t errorCode) = 0;
32     virtual void OnFirstFrameWriting(uint64_t latency) = 0;
33     virtual void OnInterrupt(const AudioStandard::InterruptEvent &interruptEvent) = 0;
34 };
35 
36 class AudioHapticSound {
37 public:
38     virtual ~AudioHapticSound() = default;
39 
40     static std::shared_ptr<AudioHapticSound> CreateAudioHapticSound(const AudioLatencyMode &latencyMode,
41         const AudioSource& audioSource, const bool &muteAudio, const AudioStandard::StreamUsage &streamUsage,
42         const bool &parallelPlayFlag = false);
43 
44     virtual int32_t PrepareSound() = 0;
45     virtual int32_t StartSound(const int32_t &audioHapticSyncId = 0) = 0;
46     virtual int32_t StopSound() = 0;
47     virtual int32_t ReleaseSound() = 0;
48     virtual int32_t SetVolume(float volume) = 0;
49     virtual int32_t SetLoop(bool loop) = 0;
50     virtual int32_t GetAudioCurrentTime() = 0;
51     virtual int32_t SetAudioHapticSoundCallback(const std::shared_ptr<AudioHapticSoundCallback> &callback) = 0;
52 
53 private:
54     static std::mutex createAudioHapticSoundMutex_;
55 };
56 } // Media
57 } // OHOS
58 #endif // AUDIO_HAPTIC_SOUND_H
59