1 /*
2  * Copyright (c) 2021-2021 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 #define HST_LOG_TAG "HstEngineFactory"
17 
18 #include "hst_engine_factory.h"
19 #include <memory>
20 #include "foundation/log.h"
21 #include "parameter.h"
22 #include "scene/player/standard/hiplayer_impl.h"
23 #include "scene/recorder/standard/hirecorder_impl.h"
24 
25 namespace OHOS {
26 namespace Media {
Score(Scene scene,const std::string & uri)27 int32_t HstEngineFactory::Score(Scene scene, const std::string& uri)
28 {
29     MEDIA_LOG_I("Score in");
30     if (scene == Scene::SCENE_PLAYBACK || scene == Scene::SCENE_RECORDER) {
31         char useHistreamer[10] = {0}; // 10 for system parameter usage
32         auto res = GetParameter("debug.media_service.histreamer", "0", useHistreamer, sizeof(useHistreamer));
33         if (res == 1 && useHistreamer[0] == '1') {
34             MEDIA_LOG_I("enable histreamer");
35             return MAX_SCORE;
36         }
37     }
38     return MIN_SCORE;
39 }
40 
41 #ifdef SUPPORT_PLAYER
CreatePlayerEngine(int32_t appUid,int32_t appPid,uint32_t appTokenId)42 std::unique_ptr<IPlayerEngine> HstEngineFactory::CreatePlayerEngine(int32_t appUid, int32_t appPid, uint32_t appTokenId)
43 {
44     (void)appTokenId;
45     MEDIA_LOG_I("CreatePlayerEngine enter.");
46     auto player = std::unique_ptr<HiPlayerImpl>(new (std::nothrow) HiPlayerImpl(appUid, appPid));
47     if (player && player->Init() == ErrorCode::SUCCESS) {
48         return player;
49     }
50     MEDIA_LOG_E("create player failed or player init failed");
51     return nullptr;
52 }
53 #endif
54 
55 #ifdef SUPPORT_RECORDER
CreateRecorderEngine(int32_t appUid,int32_t appPid,uint32_t appTokenId,uint64_t appFullTokenId)56 std::unique_ptr<IRecorderEngine> HstEngineFactory::CreateRecorderEngine(
57     int32_t appUid, int32_t appPid, uint32_t appTokenId, uint64_t appFullTokenId)
58 {
59     MEDIA_LOG_I("CreateRecorderEngine enter.");
60     auto recorder = std::unique_ptr<Record::HiRecorderImpl>(new (std::nothrow) Record::HiRecorderImpl(
61         appUid, appPid, appTokenId, appFullTokenId));
62     if (recorder && recorder->Init() == ErrorCode::SUCCESS) {
63         return recorder;
64     }
65     MEDIA_LOG_E("create recorder failed or recorder init failed");
66     return nullptr;
67 }
68 #endif
69 
70 #ifdef SUPPORT_METADATA
CreateAVMetadataHelperEngine()71 std::unique_ptr<IAVMetadataHelperEngine> HstEngineFactory::CreateAVMetadataHelperEngine()
72 {
73     MEDIA_LOG_W("CreateAVMetadataHelperEngine not supported now, return nullptr.");
74     return nullptr;
75 }
76 #endif
77 
78 #ifdef SUPPORT_CODEC
CreateAVCodecEngine()79 std::unique_ptr<IAVCodecEngine> HstEngineFactory::CreateAVCodecEngine()
80 {
81     MEDIA_LOG_W("CreateAVCodecEngine not supported now, return nullptr.");
82     return nullptr;
83 }
84 
CreateAVCodecListEngine()85 std::unique_ptr<IAVCodecListEngine> HstEngineFactory::CreateAVCodecListEngine()
86 {
87     MEDIA_LOG_W("CreateAVCodecListEngine not supported now, return nullptr.");
88     return nullptr;
89 }
90 #endif
91 
92 #ifdef SUPPORT_MUXER
CreateAVMuxerEngine()93 std::unique_ptr<IAVMuxerEngine> HstEngineFactory::CreateAVMuxerEngine()
94 {
95     MEDIA_LOG_W("CreateAVMuxerEngine not supported now, return nullptr.");
96     return nullptr;
97 }
98 #endif
99 }  // namespace Media
100 }  // namespace OHOS
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
106 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
107 #define HST_EXPORT __declspec(dllexport)
108 #else
109 #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
110 #define HST_EXPORT __attribute__((visibility("default")))
111 #else
112 #define HST_EXPORT
113 #endif
114 #endif
115 
CreateEngineFactory()116 HST_EXPORT OHOS::Media::IEngineFactory* CreateEngineFactory()
117 {
118     return new (std::nothrow) OHOS::Media::HstEngineFactory();
119 }
120 #undef HST_EXPORT
121 #ifdef __cplusplus
122 }
123 #endif