• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
33             sizeof(useHistreamer));
34         if (res == 1 && useHistreamer[0] == '1') {
35             MEDIA_LOG_I("enable histreamer");
36             return MAX_SCORE;
37         }
38     }
39     return MIN_SCORE;
40 }
41 
CreatePlayerEngine(int32_t appUid,int32_t appPid)42 std::unique_ptr<IPlayerEngine> HstEngineFactory::CreatePlayerEngine(int32_t appUid, int32_t appPid)
43 {
44     MEDIA_LOG_I("CreatePlayerEngine enter.");
45     auto player = std::unique_ptr<HiPlayerImpl>(new (std::nothrow) HiPlayerImpl(appUid, appPid));
46     if (player && player->Init() == ErrorCode::SUCCESS) {
47         return player;
48     } else {
49         MEDIA_LOG_E("create player failed or player init failed");
50     }
51     return nullptr;
52 }
53 
CreateRecorderEngine(int32_t appUid,int32_t appPid,uint32_t appTokenId)54 std::unique_ptr<IRecorderEngine> HstEngineFactory::CreateRecorderEngine(
55     int32_t appUid, int32_t appPid, uint32_t appTokenId)
56 {
57 #ifdef RECORDER_SUPPORT
58     MEDIA_LOG_I("CreateRecorderEngine enter.");
59     auto recorder = std::unique_ptr<Record::HiRecorderImpl>(new (std::nothrow) Record::HiRecorderImpl(
60             appUid, appPid, appTokenId));
61     if (recorder && recorder->Init() == ErrorCode::SUCCESS) {
62         return recorder;
63     } else {
64         MEDIA_LOG_E("create recorder failed or player init failed");
65     }
66 #else
67     (void)appUid;
68     (void)appPid;
69     (void)appTokenId;
70     MEDIA_LOG_W("CreateRecorderEngine not supported now, return nullptr.");
71 #endif
72     return nullptr;
73 }
74 
CreateAVMetadataHelperEngine()75 std::unique_ptr<IAVMetadataHelperEngine> HstEngineFactory::CreateAVMetadataHelperEngine()
76 {
77     MEDIA_LOG_W("CreateAVMetadataHelperEngine not supported now, return nullptr.");
78     return nullptr;
79 }
80 
CreateAVCodecEngine()81 std::unique_ptr<IAVCodecEngine> HstEngineFactory::CreateAVCodecEngine()
82 {
83     MEDIA_LOG_W("CreateAVCodecEngine not supported now, return nullptr.");
84     return nullptr;
85 }
86 
CreateAVCodecListEngine()87 std::unique_ptr<IAVCodecListEngine> HstEngineFactory::CreateAVCodecListEngine()
88 {
89     MEDIA_LOG_W("CreateAVCodecListEngine not supported now, return nullptr.");
90     return nullptr;
91 }
92 }  // namespace Media
93 }  // namespace OHOS
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
99 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
100 #define HST_EXPORT __declspec(dllexport)
101 #else
102 #if defined(__GNUC__) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
103 #define HST_EXPORT __attribute__((visibility("default")))
104 #else
105 #define HST_EXPORT
106 #endif
107 #endif
108 
CreateEngineFactory()109 HST_EXPORT OHOS::Media::IEngineFactory* CreateEngineFactory()
110 {
111     return new (std::nothrow) OHOS::Media::HstEngineFactory();
112 }
113 #undef HST_EXPORT
114 #ifdef __cplusplus
115 }
116 #endif