• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     std::lock_guard<std::mutex> lock(mutex_);
57     return codecListProxy_ == nullptr;
58 }
59 
FindDecoder(const Format & format)60 std::string CodecListClient::FindDecoder(const Format &format)
61 {
62     std::lock_guard<std::mutex> lock(mutex_);
63     CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, "", "Find decoder failed: codeclist service does not exist.");
64     return codecListProxy_->FindDecoder(format);
65 }
66 
FindEncoder(const Format & format)67 std::string CodecListClient::FindEncoder(const Format &format)
68 {
69     std::lock_guard<std::mutex> lock(mutex_);
70     CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, "", "Find encoder failed: codeclist service does not exist.");
71     return codecListProxy_->FindEncoder(format);
72 }
73 
GetCapability(CapabilityData & capabilityData,const std::string & mime,const bool isEncoder,const AVCodecCategory & category)74 int32_t CodecListClient::GetCapability(CapabilityData &capabilityData, const std::string &mime, const bool isEncoder,
75                                        const AVCodecCategory &category)
76 {
77     std::lock_guard<std::mutex> lock(mutex_);
78     CHECK_AND_RETURN_RET_LOG(codecListProxy_ != nullptr, AVCS_ERR_NO_MEMORY,
79                              "Get capability failed: codeclist service does not exist.");
80     return codecListProxy_->GetCapability(capabilityData, mime, isEncoder, category);
81 }
82 } // namespace MediaAVCodec
83 } // namespace OHOS