• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_H
17 #define AUDIO_HAPTIC_MANAGER_H
18 
19 #include <mutex>
20 #include <string>
21 
22 #include "audio_info.h"
23 
24 #include "audio_haptic_player.h"
25 
26 namespace OHOS {
27 namespace Media {
28 struct AudioHapticFileDescriptor {
29     int32_t fd = -1;
30     int64_t length = 0;
31     int64_t offset = 0;
32 };
33 
34 class AudioHapticManager {
35 public:
36     virtual ~AudioHapticManager() = default;
37 
38     virtual int32_t RegisterSource(const std::string &audioUri, const std::string &hapticUri) = 0;
39 
40     virtual int32_t RegisterSourceFromFd(const AudioHapticFileDescriptor& audioFd,
41         const AudioHapticFileDescriptor& hapticFd);
42 
43     virtual int32_t RegisterSourceWithEffectId(const std::string &audioUri, const std::string &effectId) = 0;
44 
45     virtual int32_t UnregisterSource(const int32_t &sourceID) = 0;
46 
47     virtual int32_t SetAudioLatencyMode(const int32_t &sourceID, const AudioLatencyMode &latencyMode) = 0;
48 
49     virtual int32_t SetStreamUsage(const int32_t &sourceID, const AudioStandard::StreamUsage &streamUsage) = 0;
50 
51     virtual std::shared_ptr<AudioHapticPlayer> CreatePlayer(const int32_t &sourceID,
52         const AudioHapticPlayerOptions &audioHapticPlayerOptions) = 0;
53 };
54 
55 class __attribute__((visibility("default"))) AudioHapticManagerFactory {
56 public:
57     static std::shared_ptr<AudioHapticManager> CreateAudioHapticManager();
58 
59 private:
60     static std::shared_ptr<AudioHapticManager> audioHapticManager_;
61     static std::mutex audioHapticManagerMutex_;
62     AudioHapticManagerFactory() = default;
63     ~AudioHapticManagerFactory() = default;
64 };
65 } // Media
66 } // OHOS
67 #endif // AUDIO_HAPTIC_MANAGER_H
68