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 "avcodeclist_server.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 #include "engine_factory_repo.h"
20
21 namespace {
22 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "AVCodecListServer"};
23 }
24
25 namespace OHOS {
26 namespace Media {
Create()27 std::shared_ptr<IAVCodecListService> AVCodecListServer::Create()
28 {
29 std::shared_ptr<AVCodecListServer> server = std::make_shared<AVCodecListServer>();
30 int32_t ret = server->Init();
31 if (ret != MSERR_OK) {
32 MEDIA_LOGE("failed to init AVCodecListServer");
33 return nullptr;
34 }
35 return server;
36 }
37
AVCodecListServer()38 AVCodecListServer::AVCodecListServer()
39 {
40 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
41 }
42
~AVCodecListServer()43 AVCodecListServer::~AVCodecListServer()
44 {
45 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
46 }
47
Init()48 int32_t AVCodecListServer::Init()
49 {
50 auto engineFactory = EngineFactoryRepo::Instance().GetEngineFactory(IEngineFactory::Scene::SCENE_AVCODECLIST);
51 CHECK_AND_RETURN_RET_LOG(engineFactory != nullptr, MSERR_CREATE_REC_ENGINE_FAILED, "failed to get factory");
52 codecListEngine_ = engineFactory->CreateAVCodecListEngine();
53 CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, MSERR_CREATE_REC_ENGINE_FAILED,
54 "Failed to create codec list engine");
55 return MSERR_OK;
56 }
57
FindVideoDecoder(const Format & format)58 std::string AVCodecListServer::FindVideoDecoder(const Format &format)
59 {
60 std::lock_guard<std::mutex> lock(mutex_);
61 CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, "", "engine is nullptr");
62
63 return codecListEngine_->FindVideoDecoder(format);
64 }
65
FindVideoEncoder(const Format & format)66 std::string AVCodecListServer::FindVideoEncoder(const Format &format)
67 {
68 std::lock_guard<std::mutex> lock(mutex_);
69 CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, "", "engine is nullptr");
70
71 return codecListEngine_->FindVideoEncoder(format);
72 }
73
FindAudioDecoder(const Format & format)74 std::string AVCodecListServer::FindAudioDecoder(const Format &format)
75 {
76 std::lock_guard<std::mutex> lock(mutex_);
77 CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, "", "engine is nullptr");
78
79 return codecListEngine_->FindAudioDecoder(format);
80 }
81
FindAudioEncoder(const Format & format)82 std::string AVCodecListServer::FindAudioEncoder(const Format &format)
83 {
84 std::lock_guard<std::mutex> lock(mutex_);
85 CHECK_AND_RETURN_RET_LOG(codecListEngine_ != nullptr, "", "engine is nullptr");
86
87 return codecListEngine_->FindAudioEncoder(format);
88 }
89
GetCodecCapabilityInfos()90 std::vector<CapabilityData> AVCodecListServer::GetCodecCapabilityInfos()
91 {
92 std::lock_guard<std::mutex> lock(mutex_);
93 return codecListEngine_->GetCodecCapabilityInfos();
94 }
95 } // namespace Media
96 } // namespace OHOS
97