1 /*
2  * Copyright (C) 2022 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 "recorder_profiles_client.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19 
20 namespace {
21     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER, "RecorderProfilesClient"};
22 }
23 
24 namespace OHOS {
25 namespace Media {
Create(const sptr<IStandardRecorderProfilesService> & ipcProxy)26 std::shared_ptr<RecorderProfilesClient> RecorderProfilesClient::Create(
27     const sptr<IStandardRecorderProfilesService> &ipcProxy)
28 {
29     CHECK_AND_RETURN_RET_LOG(ipcProxy != nullptr, nullptr, "ipcProxy is nullptr..");
30 
31     std::shared_ptr<RecorderProfilesClient> recorderProfiles = std::make_shared<RecorderProfilesClient>(ipcProxy);
32     CHECK_AND_RETURN_RET_LOG(recorderProfiles != nullptr, nullptr, "failed to new RecorderProfilesClient..");
33 
34     return recorderProfiles;
35 }
36 
RecorderProfilesClient(const sptr<IStandardRecorderProfilesService> & ipcProxy)37 RecorderProfilesClient::RecorderProfilesClient(const sptr<IStandardRecorderProfilesService> &ipcProxy)
38     : recorderProfilesProxy_(ipcProxy)
39 {
40     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
41 }
42 
~RecorderProfilesClient()43 RecorderProfilesClient::~RecorderProfilesClient()
44 {
45     std::lock_guard<std::mutex> lock(mutex_);
46     if (recorderProfilesProxy_ != nullptr) {
47         (void)recorderProfilesProxy_->DestroyStub();
48     }
49     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
50 }
51 
MediaServerDied()52 void RecorderProfilesClient::MediaServerDied()
53 {
54     std::lock_guard<std::mutex> lock(mutex_);
55     recorderProfilesProxy_ = nullptr;
56 }
57 
IsAudioRecorderConfigSupported(const RecorderProfilesData & profile)58 bool RecorderProfilesClient::IsAudioRecorderConfigSupported(const RecorderProfilesData &profile)
59 {
60     std::lock_guard<std::mutex> lock(mutex_);
61     CHECK_AND_RETURN_RET_LOG(recorderProfilesProxy_ != nullptr, false, "recorder_profiles service does not exist.");
62     return recorderProfilesProxy_->IsAudioRecorderConfigSupported(profile);
63 }
64 
HasVideoRecorderProfile(int32_t sourceId,int32_t qualityLevel)65 bool RecorderProfilesClient::HasVideoRecorderProfile(int32_t sourceId, int32_t qualityLevel)
66 {
67     std::lock_guard<std::mutex> lock(mutex_);
68     CHECK_AND_RETURN_RET_LOG(recorderProfilesProxy_ != nullptr, false, "recorder_profiles service does not exist.");
69     return recorderProfilesProxy_->HasVideoRecorderProfile(sourceId, qualityLevel);
70 }
71 
GetVideoRecorderProfileInfo(int32_t sourceId,int32_t qualityLevel)72 RecorderProfilesData RecorderProfilesClient::GetVideoRecorderProfileInfo(int32_t sourceId, int32_t qualityLevel)
73 {
74     std::lock_guard<std::mutex> lock(mutex_);
75     CHECK_AND_RETURN_RET_LOG(recorderProfilesProxy_ != nullptr, RecorderProfilesData(),
76         "recorder_profiles service does not exist.");
77     return recorderProfilesProxy_->GetVideoRecorderProfileInfo(sourceId, qualityLevel);
78 }
79 
GetAudioRecorderCapsInfo()80 std::vector<RecorderProfilesData> RecorderProfilesClient::GetAudioRecorderCapsInfo()
81 {
82     std::lock_guard<std::mutex> lock(mutex_);
83     CHECK_AND_RETURN_RET_LOG(recorderProfilesProxy_ != nullptr, std::vector<RecorderProfilesData>(),
84         "recorder_profiles service does not exist.");
85     return recorderProfilesProxy_->GetAudioRecorderCapsInfo();
86 }
87 
GetVideoRecorderCapsInfo()88 std::vector<RecorderProfilesData> RecorderProfilesClient::GetVideoRecorderCapsInfo()
89 {
90     std::lock_guard<std::mutex> lock(mutex_);
91     CHECK_AND_RETURN_RET_LOG(recorderProfilesProxy_ != nullptr, std::vector<RecorderProfilesData>(),
92         "recorder_profiles service does not exist.");
93     return recorderProfilesProxy_->GetVideoRecorderCapsInfo();
94 }
95 }  // namespace Media
96 }  // namespace OHOS
97