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 FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_SERVICE_ADAPTER_H
17 #define FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_SERVICE_ADAPTER_H
18 
19 #include <string>
20 #include <map>
21 #include <memory>
22 
23 #include "dynamic_loader.h"
24 #include "enhancement_thread_manager.h"
25 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
26 #include "media_enhance_constants_c_api.h"
27 #include "media_enhance_handles.h"
28 #include "media_enhance_client_c_api.h"
29 #include "media_enhance_bundle_c_api.h"
30 #endif
31 
32 namespace OHOS {
33 namespace Media {
34 #define EXPORT __attribute__ ((visibility ("default")))
35 
36 class EnhancementServiceAdapter {
37 public:
38     EXPORT EnhancementServiceAdapter();
39     EXPORT virtual ~EnhancementServiceAdapter();
40 
41 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
42     void InitEnhancementClient(MediaEnhance::MediaEnhance_TASK_TYPE taskType);
43     void DestroyEnhancementClient();
44     int32_t SetResultCallback();
45     int32_t LoadSA();
46     bool IsConnected(MediaEnhance::MediaEnhanceClientHandle* clientWrapper);
47     EXPORT MediaEnhance::MediaEnhanceBundleHandle* CreateBundle();
48     void DestroyBundle(MediaEnhance::MediaEnhanceBundleHandle* bundle);
49     int32_t GetInt(MediaEnhance::MediaEnhanceBundleHandle* bundle, const char* key);
50     int32_t FillTaskWithResultBuffer(MediaEnhance::MediaEnhanceBundleHandle* bundle,
51         CloudEnhancementThreadTask& task);
52     EXPORT void PutInt(MediaEnhance::MediaEnhanceBundleHandle* bundle, const char* key,
53         int32_t value);
54     void PutString(MediaEnhance::MediaEnhanceBundleHandle* bundle, const char* key,
55         const char* value);
56     void DeleteRawData(MediaEnhance::Raw_Data* rawData, uint32_t size);
57     void DeletePendingTasks(MediaEnhance::Pendding_Task* taskIdList, uint32_t size);
58     EXPORT int32_t AddTask(const std::string& taskId, MediaEnhance::MediaEnhanceBundleHandle* bundle);
59     EXPORT int32_t RemoveTask(const std::string &taskId);
60     EXPORT int32_t CancelTask(const std::string &taskId);
61     EXPORT int32_t CancelAllTasks();
62     EXPORT int32_t LoadEnhancementService();
63     EXPORT int32_t GetPendingTasks(std::vector<std::string> &taskIdList);
64 #endif
65 
66 private:
67 #ifdef ABILITY_CLOUD_ENHANCEMENT_SUPPORT
68     void ClientFuncInit();
69     void TaskFuncInit();
70     void BundleFuncInit();
71 #endif
72 
73     static std::mutex mtx_;
74     static std::shared_ptr<DynamicLoader> dynamicLoader_;
75 };
76 } // namespace Media
77 } // namespace OHOS
78 #endif  // FRAMEWORKS_SERVICES_MEDIA_CLOUD_ENHANCEMENT_INCLUDE_ENHANCEMENT_SERVICE_ADAPTER_H