1 /*
2 * Copyright (C) 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 #include "i_engine_factory.h"
17 #include "avcodec_engine_gst_impl.h"
18 #include "avcodeclist_engine_gst_impl.h"
19 #include "avmetadatahelper_engine_gst_impl.h"
20 #include "gst_loader.h"
21 #include "media_errors.h"
22 #include "media_log.h"
23 #include "nocopyable.h"
24 #include "player_engine_gst_impl.h"
25 #include "recorder_engine_gst_impl.h"
26
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "GstEngineFactory"};
29 }
30
31 namespace OHOS {
32 namespace Media {
33 class GstEngineFactory : public IEngineFactory, public NoCopyable {
34 public:
35 GstEngineFactory() = default;
36 ~GstEngineFactory() = default;
37
38 int32_t Score(Scene scene, const std::string &uri) override;
39 std::unique_ptr<IPlayerEngine> CreatePlayerEngine() override;
40 std::unique_ptr<IRecorderEngine> CreateRecorderEngine() override;
41 std::unique_ptr<IAVMetadataHelperEngine> CreateAVMetadataHelperEngine() override;
42 std::unique_ptr<IAVCodecEngine> CreateAVCodecEngine() override;
43 std::unique_ptr<IAVCodecListEngine> CreateAVCodecListEngine() override;
44 };
45
Score(Scene scene,const std::string & uri)46 int32_t GstEngineFactory::Score(Scene scene, const std::string &uri)
47 {
48 (void)uri;
49 (void)scene;
50 return MIN_SCORE + 1;
51 }
52
CreatePlayerEngine()53 std::unique_ptr<IPlayerEngine> GstEngineFactory::CreatePlayerEngine()
54 {
55 GstLoader::Instance().UpdateLogLevel();
56 return std::make_unique<PlayerEngineGstImpl>();
57 }
58
CreateAVMetadataHelperEngine()59 std::unique_ptr<IAVMetadataHelperEngine> GstEngineFactory::CreateAVMetadataHelperEngine()
60 {
61 GstLoader::Instance().UpdateLogLevel();
62 return std::make_unique<AVMetadataHelperEngineGstImpl>();
63 }
64
CreateRecorderEngine()65 std::unique_ptr<IRecorderEngine> GstEngineFactory::CreateRecorderEngine()
66 {
67 GstLoader::Instance().UpdateLogLevel();
68 auto engine = std::make_unique<RecorderEngineGstImpl>();
69 int32_t ret = engine->Init();
70 if (ret != MSERR_OK) {
71 MEDIA_LOGE("recorder engine init failed, ret = %{public}d", ret);
72 return nullptr;
73 }
74 return engine;
75 }
76
CreateAVCodecEngine()77 std::unique_ptr<IAVCodecEngine> GstEngineFactory::CreateAVCodecEngine()
78 {
79 GstLoader::Instance().UpdateLogLevel();
80 return std::make_unique<AVCodecEngineGstImpl>();
81 }
82
CreateAVCodecListEngine()83 std::unique_ptr<IAVCodecListEngine> GstEngineFactory::CreateAVCodecListEngine()
84 {
85 GstLoader::Instance().UpdateLogLevel();
86 return std::make_unique<AVCodecListEngineGstImpl>();
87 }
88 } // namespace Media
89 } // namespace OHOS
90
91 #ifdef __cplusplus
92 extern "C" {
93 #endif
94
CreateEngineFactory()95 __attribute__((visibility("default"))) OHOS::Media::IEngineFactory *CreateEngineFactory()
96 {
97 int32_t ret = OHOS::Media::GstLoader::Instance().SetUp();
98 if (ret != OHOS::Media::MSERR_OK) {
99 MEDIA_LOGE("Gst Engine setup failed, ret = %{public}d", ret);
100 return nullptr;
101 }
102 return new (std::nothrow) OHOS::Media::GstEngineFactory();
103 }
104
105 #ifdef __cplusplus
106 }
107 #endif