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 "recorder_listener_proxy.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, "RecorderListenerProxy"};
22 }
23
24 namespace OHOS {
25 namespace Media {
RecorderListenerProxy(const sptr<IRemoteObject> & impl)26 RecorderListenerProxy::RecorderListenerProxy(const sptr<IRemoteObject> &impl)
27 : IRemoteProxy<IStandardRecorderListener>(impl)
28 {
29 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
30 }
31
~RecorderListenerProxy()32 RecorderListenerProxy::~RecorderListenerProxy()
33 {
34 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
35 }
36
OnError(int32_t errorType,int32_t errorCode)37 void RecorderListenerProxy::OnError(int32_t errorType, int32_t errorCode)
38 {
39 MessageParcel data;
40 MessageParcel reply;
41 MessageOption option(MessageOption::TF_ASYNC);
42
43 bool token = data.WriteInterfaceToken(RecorderListenerProxy::GetDescriptor());
44 CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!");
45
46 data.WriteInt32(errorType);
47 data.WriteInt32(errorCode);
48 int error = Remote()->SendRequest(RecorderListenerMsg::ON_ERROR, data, reply, option);
49 CHECK_AND_RETURN_LOG(error == MSERR_OK, "on error failed, error: %{public}d", error);
50 }
51
OnInfo(int32_t type,int32_t extra)52 void RecorderListenerProxy::OnInfo(int32_t type, int32_t extra)
53 {
54 MessageParcel data;
55 MessageParcel reply;
56 MessageOption option(MessageOption::TF_ASYNC);
57
58 bool token = data.WriteInterfaceToken(RecorderListenerProxy::GetDescriptor());
59 CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!");
60
61 data.WriteInt32(static_cast<int>(type));
62 data.WriteInt32(static_cast<int>(extra));
63 int error = Remote()->SendRequest(RecorderListenerMsg::ON_INFO, data, reply, option);
64 CHECK_AND_RETURN_LOG(error == MSERR_OK, "on info failed, error: %{public}d", error);
65 }
66
OnAudioCaptureChange(const AudioRecorderChangeInfo & audioRecorderChangeInfo)67 void RecorderListenerProxy::OnAudioCaptureChange(const AudioRecorderChangeInfo &audioRecorderChangeInfo)
68 {
69 MessageParcel data;
70 MessageParcel reply;
71 MessageOption option(MessageOption::TF_ASYNC);
72
73 bool token = data.WriteInterfaceToken(RecorderListenerProxy::GetDescriptor());
74 CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!");
75
76 audioRecorderChangeInfo.Marshalling(data);
77 int error = Remote()->SendRequest(RecorderListenerMsg::ON_AUDIO_CAPTURE_CHANGE, data, reply, option);
78 CHECK_AND_RETURN_LOG(error == MSERR_OK, "on audio capture change failed, error: %{public}d", error);
79 }
80
OnPhotoAssertAvailable(const std::string & uri)81 void RecorderListenerProxy::OnPhotoAssertAvailable(const std::string &uri)
82 {
83 MessageParcel data;
84 MessageParcel reply;
85 MessageOption option(MessageOption::TF_ASYNC);
86
87 bool token = data.WriteInterfaceToken(RecorderListenerProxy::GetDescriptor());
88 CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!");
89
90 data.WriteString(uri);
91 int error = Remote()->SendRequest(RecorderListenerMsg::ON_PHOTO_ASSERT_AVAILABLE, data, reply, option);
92 CHECK_AND_RETURN_LOG(error == MSERR_OK, "on audio capture change failed, error: %{public}d", error);
93 }
94
RecorderListenerCallback(const sptr<IStandardRecorderListener> & listener)95 RecorderListenerCallback::RecorderListenerCallback(const sptr<IStandardRecorderListener> &listener)
96 : listener_(listener)
97 {
98 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
99 }
100
~RecorderListenerCallback()101 RecorderListenerCallback::~RecorderListenerCallback()
102 {
103 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
104 }
105
OnError(RecorderErrorType errorType,int32_t errorCode)106 void RecorderListenerCallback::OnError(RecorderErrorType errorType, int32_t errorCode)
107 {
108 if (listener_ != nullptr) {
109 listener_->OnError(errorType, errorCode);
110 }
111 }
112
OnInfo(int32_t type,int32_t extra)113 void RecorderListenerCallback::OnInfo(int32_t type, int32_t extra)
114 {
115 if (listener_ != nullptr) {
116 listener_->OnInfo(type, extra);
117 }
118 }
119
OnAudioCaptureChange(const AudioRecorderChangeInfo & audioRecorderChangeInfo)120 void RecorderListenerCallback::OnAudioCaptureChange(const AudioRecorderChangeInfo &audioRecorderChangeInfo)
121 {
122 if (listener_ != nullptr) {
123 listener_->OnAudioCaptureChange(audioRecorderChangeInfo);
124 }
125 }
126
OnPhotoAssertAvailable(const std::string & uri)127 void RecorderListenerCallback::OnPhotoAssertAvailable(const std::string &uri)
128 {
129 if (listener_ != nullptr) {
130 listener_->OnPhotoAssertAvailable(uri);
131 }
132 }
133 } // namespace Media
134 } // namespace OHOS
135