1 /*
2 * Copyright (C) 2024 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 "transcoder_listener_stub.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_PLAYER, "TransCoderListenerStub"};
22 }
23
24 namespace OHOS {
25 namespace Media {
TransCoderListenerStub()26 TransCoderListenerStub::TransCoderListenerStub()
27 {
28 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
29 }
30
~TransCoderListenerStub()31 TransCoderListenerStub::~TransCoderListenerStub()
32 {
33 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
34 }
35
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int TransCoderListenerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
37 MessageOption &option)
38 {
39 auto remoteDescriptor = data.ReadInterfaceToken();
40 CHECK_AND_RETURN_RET_LOG(TransCoderListenerStub::GetDescriptor() == remoteDescriptor, MSERR_INVALID_OPERATION,
41 "Invalid descriptor");
42
43 switch (code) {
44 case TransCoderListenerMsg::ON_ERROR: {
45 int32_t errorCode = data.ReadInt32();
46 std::string errorMsg = data.ReadString();
47 OnError(errorCode, errorMsg);
48 return MSERR_OK;
49 }
50 case TransCoderListenerMsg::ON_INFO: {
51 int type = data.ReadInt32();
52 int extra = data.ReadInt32();
53 OnInfo(type, extra);
54 return MSERR_OK;
55 }
56 default: {
57 MEDIA_LOGE("default case, need check TransCoderListenerStub");
58 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
59 }
60 }
61 }
62
OnError(int32_t errorCode,const std::string & errorMsg)63 void TransCoderListenerStub::OnError(int32_t errorCode, const std::string &errorMsg)
64 {
65 if (callback_ != nullptr) {
66 callback_->OnError(errorCode, errorMsg);
67 }
68
69 std::shared_ptr<MonitorClientObject> monitor = monitor_.lock();
70 CHECK_AND_RETURN(monitor != nullptr);
71 (void)monitor->DisableMonitor();
72 }
73
OnInfo(int32_t type,int32_t extra)74 void TransCoderListenerStub::OnInfo(int32_t type, int32_t extra)
75 {
76 CHECK_AND_RETURN(callback_ != nullptr);
77 callback_->OnInfo(type, extra);
78 }
79
SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> & callback)80 void TransCoderListenerStub::SetTransCoderCallback(const std::shared_ptr<TransCoderCallback> &callback)
81 {
82 callback_ = callback;
83 }
84
SetMonitor(const std::weak_ptr<MonitorClientObject> & monitor)85 void TransCoderListenerStub::SetMonitor(const std::weak_ptr<MonitorClientObject> &monitor)
86 {
87 MEDIA_LOGI("SetMonitor");
88 monitor_ = monitor;
89 }
90 } // namespace Media
91 } // namespace OHOS
92