1 /*
2 * Copyright (C) 2023 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 "codeclist_client.h"
17 #include "avcodec_log.h"
18 #include "avcodec_errors.h"
19
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "CodecListClient"};
22 }
23
24 namespace OHOS {
25 namespace MediaAVCodec {
26 using namespace Media;
Create(const sptr<IStandardCodecListService> & ipcProxy)27 std::shared_ptr<CodecListClient> CodecListClient::Create(const sptr<IStandardCodecListService> &ipcProxy)
28 {
29 CHECK_AND_RETURN_RET_LOG(ipcProxy != nullptr, nullptr, "Create codeclist client failed: ipcProxy is nullptr");
30 std::shared_ptr<CodecListClient> codecList = std::make_shared<CodecListClient>(ipcProxy);
31 return codecList;
32 }
33
CodecListClient(const sptr<IStandardCodecListService> & ipcProxy)34 CodecListClient::CodecListClient(const sptr<IStandardCodecListService> &ipcProxy) : codecListProxy_(ipcProxy)
35 {
36 AVCODEC_LOGD("Create CodecListClient instances successful");
37 }
38
~CodecListClient()39 CodecListClient::~CodecListClient()
40 {
41 std::lock_guard<std::mutex> lock(mutex_);
42 if (codecListProxy_ != nullptr) {
43 (void)codecListProxy_->DestroyStub();
44 }
45 AVCODEC_LOGD("Destroy codecListClient instances successful");
46 }
47
AVCodecServerDied()48 void CodecListClient::AVCodecServerDied()
49 {
50 std::lock_guard<std::mutex> lock(mutex_);
51 codecListProxy_ = nullptr;
52 }
53
IsServiceDied()54 bool CodecListClient::IsServiceDied()
55 {
56 return codecListProxy_ == nullptr;
57 }
58
FindDecoder(const Format & format)59 std::string CodecListClient::FindDecoder(const Format &format)
60 {
61 std::lock_guard<std::mutex> lock(mutex_);
62 CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, "", "Find decoder failed: codeclist service does not exist.");
63 return codecListProxy_->FindDecoder(format);
64 }
65
FindEncoder(const Format & format)66 std::string CodecListClient::FindEncoder(const Format &format)
67 {
68 std::lock_guard<std::mutex> lock(mutex_);
69 CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, "", "Find encoder failed: codeclist service does not exist.");
70 return codecListProxy_->FindEncoder(format);
71 }
72
GetCapability(CapabilityData & capabilityData,const std::string & mime,const bool isEncoder,const AVCodecCategory & category)73 int32_t CodecListClient::GetCapability(CapabilityData &capabilityData, const std::string &mime, const bool isEncoder,
74 const AVCodecCategory &category)
75 {
76 std::lock_guard<std::mutex> lock(mutex_);
77 CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, AVCS_ERR_NO_MEMORY,
78 "Get capability failed: codeclist service does not exist.");
79 return codecListProxy_->GetCapability(capabilityData, mime, isEncoder, category);
80 }
81 } // namespace MediaAVCodec
82 } // namespace OHOS