• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_service_stub.h"
17 #include <unistd.h>
18 #include "avsharedmemory_ipc.h"
19 #include "media_errors.h"
20 #include "media_log.h"
21 #include "media_server_manager.h"
22 
23 namespace {
24     constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER, "RecorderProfilesServiceStub"};
25 }
26 
27 namespace OHOS {
28 namespace Media {
Create()29 sptr<RecorderProfilesServiceStub> RecorderProfilesServiceStub::Create()
30 {
31     sptr<RecorderProfilesServiceStub> meidaProfileStub = new(std::nothrow) RecorderProfilesServiceStub();
32     CHECK_AND_RETURN_RET_LOG(meidaProfileStub != nullptr, nullptr, "failed to new RecorderProfilesServiceStub");
33     int32_t ret = meidaProfileStub->Init();
34     CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to mediaprofile stub init");
35     return meidaProfileStub;
36 }
37 
RecorderProfilesServiceStub()38 RecorderProfilesServiceStub::RecorderProfilesServiceStub()
39 {
40     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
41 }
42 
~RecorderProfilesServiceStub()43 RecorderProfilesServiceStub::~RecorderProfilesServiceStub()
44 {
45     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
46 }
47 
Init()48 int32_t RecorderProfilesServiceStub::Init()
49 {
50     mediaProfileServer_ = RecorderProfilesServer::Create();
51     CHECK_AND_RETURN_RET_LOG(
52         mediaProfileServer_ != nullptr, MSERR_NO_MEMORY, "failed to create RecorderProfilesServer");
53     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_IS_AUDIO_RECORDER_SUPPORT)]
54         = &RecorderProfilesServiceStub::IsAudioRecorderConfigSupported;
55     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_HAS_VIDEO_RECORD_PROFILE)]
56         = &RecorderProfilesServiceStub::HasVideoRecorderProfile;
57     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_GET_AUDIO_RECORDER_CAPS)]
58         = &RecorderProfilesServiceStub::GetAudioRecorderCapsInfo;
59     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_GET_VIDEO_RECORDER_CAPS)]
60         = &RecorderProfilesServiceStub::GetVideoRecorderCapsInfo;
61     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_GET_VIDEO_RECORDER_PROFILE)]
62         = &RecorderProfilesServiceStub::GetVideoRecorderProfileInfo;
63     mediaProfileFuncs_[static_cast<int>(RecorderProfilesServiceMsg::RECORDER_PROFILES_DESTROY)]
64         = &RecorderProfilesServiceStub::DestroyStub;
65     return MSERR_OK;
66 }
67 
DestroyStub()68 int32_t RecorderProfilesServiceStub::DestroyStub()
69 {
70     mediaProfileServer_ = nullptr;
71     MediaServerManager::GetInstance().DestroyStubObject(MediaServerManager::RECORDERPROFILES, AsObject());
72     return MSERR_OK;
73 }
74 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)75 int RecorderProfilesServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
76     MessageOption &option)
77 {
78     MEDIA_LOGI("Stub: OnRemoteRequest of code: %{public}u is received", code);
79 
80     auto remoteDescriptor = data.ReadInterfaceToken();
81     if (RecorderProfilesServiceStub::GetDescriptor() != remoteDescriptor) {
82         MEDIA_LOGE("Invalid descriptor");
83         return MSERR_INVALID_OPERATION;
84     }
85 
86     auto itFunc = mediaProfileFuncs_.find(code);
87     if (itFunc != mediaProfileFuncs_.end()) {
88         auto memberFunc = itFunc->second;
89         if (memberFunc != nullptr) {
90             std::lock_guard<std::mutex> lock(mutex_);
91             int32_t ret = (this->*memberFunc)(data, reply);
92             if (ret != MSERR_OK) {
93                 MEDIA_LOGE("calling memberFunc is failed.");
94             }
95             return MSERR_OK;
96         }
97     }
98     MEDIA_LOGW("RecorderProfilesServiceStub: no member func supporting, applying default process");
99 
100     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
101 }
102 
IsAudioRecorderConfigSupported(const RecorderProfilesData & profile)103 bool RecorderProfilesServiceStub::IsAudioRecorderConfigSupported(const RecorderProfilesData &profile)
104 {
105     CHECK_AND_RETURN_RET_LOG(mediaProfileServer_ != nullptr, false, "recorder_profiles server is nullptr");
106     return mediaProfileServer_->IsAudioRecorderConfigSupported(profile);
107 }
108 
HasVideoRecorderProfile(int32_t sourceId,int32_t qualityLevel)109 bool RecorderProfilesServiceStub::HasVideoRecorderProfile(int32_t sourceId, int32_t qualityLevel)
110 {
111     CHECK_AND_RETURN_RET_LOG(mediaProfileServer_ != nullptr, false, "recorder_profiles server is nullptr");
112     return mediaProfileServer_->HasVideoRecorderProfile(sourceId, qualityLevel);
113 }
114 
GetVideoRecorderProfileInfo(int32_t sourceId,int32_t qualityLevel)115 RecorderProfilesData RecorderProfilesServiceStub::GetVideoRecorderProfileInfo(int32_t sourceId, int32_t qualityLevel)
116 {
117     RecorderProfilesData data;
118     CHECK_AND_RETURN_RET_LOG(mediaProfileServer_ != nullptr, data, "recorder_profiles server is nullptr");
119     return mediaProfileServer_->GetVideoRecorderProfileInfo(sourceId, qualityLevel);
120 }
121 
GetAudioRecorderCapsInfo()122 std::vector<RecorderProfilesData> RecorderProfilesServiceStub::GetAudioRecorderCapsInfo()
123 {
124     CHECK_AND_RETURN_RET_LOG(
125         mediaProfileServer_ != nullptr, std::vector<RecorderProfilesData>(), "recorder_profiles server is nullptr");
126     return mediaProfileServer_->GetAudioRecorderCapsInfo();
127 }
128 
GetVideoRecorderCapsInfo()129 std::vector<RecorderProfilesData> RecorderProfilesServiceStub::GetVideoRecorderCapsInfo()
130 {
131     CHECK_AND_RETURN_RET_LOG(
132         mediaProfileServer_ != nullptr, std::vector<RecorderProfilesData>(), "recorder_profiles server is nullptr");
133     return mediaProfileServer_->GetVideoRecorderCapsInfo();
134 }
135 
IsAudioRecorderConfigSupported(MessageParcel & data,MessageParcel & reply)136 int32_t RecorderProfilesServiceStub::IsAudioRecorderConfigSupported(MessageParcel &data, MessageParcel &reply)
137 {
138     RecorderProfilesData profile;
139     (void)RecorderProfilesParcel::Unmarshalling(data, profile);
140     reply.WriteBool(IsAudioRecorderConfigSupported(profile));
141     return MSERR_OK;
142 }
143 
HasVideoRecorderProfile(MessageParcel & data,MessageParcel & reply)144 int32_t RecorderProfilesServiceStub::HasVideoRecorderProfile(MessageParcel &data, MessageParcel &reply)
145 {
146     int32_t sourceId = data.ReadInt32();
147     int32_t qualityLevel = data.ReadInt32();
148     reply.WriteBool(HasVideoRecorderProfile(sourceId, qualityLevel));
149     return MSERR_OK;
150 }
151 
GetVideoRecorderProfileInfo(MessageParcel & data,MessageParcel & reply)152 int32_t RecorderProfilesServiceStub::GetVideoRecorderProfileInfo(MessageParcel &data, MessageParcel &reply)
153 {
154     int32_t sourceId = data.ReadInt32();
155     int32_t qualityLevel = data.ReadInt32();
156     RecorderProfilesData capabilityData = GetVideoRecorderProfileInfo(sourceId, qualityLevel);
157     (void)RecorderProfilesParcel::Marshalling(reply, capabilityData);
158     return MSERR_OK;
159 }
160 
GetAudioRecorderCapsInfo(MessageParcel & data,MessageParcel & reply)161 int32_t RecorderProfilesServiceStub::GetAudioRecorderCapsInfo(MessageParcel &data, MessageParcel &reply)
162 {
163     std::string configFile = data.ReadString();
164     std::vector<RecorderProfilesData> capabilityDataArray = GetAudioRecorderCapsInfo();
165     (void)RecorderProfilesParcel::Marshalling(reply, capabilityDataArray);
166     return MSERR_OK;
167 }
168 
GetVideoRecorderCapsInfo(MessageParcel & data,MessageParcel & reply)169 int32_t RecorderProfilesServiceStub::GetVideoRecorderCapsInfo(MessageParcel &data, MessageParcel &reply)
170 {
171     std::string configFile = data.ReadString();
172     std::vector<RecorderProfilesData> capabilityDataArray = GetVideoRecorderCapsInfo();
173     (void)RecorderProfilesParcel::Marshalling(reply, capabilityDataArray);
174     return MSERR_OK;
175 }
176 
DestroyStub(MessageParcel & data,MessageParcel & reply)177 int32_t RecorderProfilesServiceStub::DestroyStub(MessageParcel &data, MessageParcel &reply)
178 {
179     (void)data;
180     reply.WriteInt32(DestroyStub());
181     return MSERR_OK;
182 }
183 }  // namespace Media
184 }  // namespace OHOS
185