• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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_PLAYER, "TransCoderListenerProxy"};
22 }
23 
24 namespace OHOS {
25 namespace Media {
TransCoderListenerProxy(const sptr<IRemoteObject> & impl)26 TransCoderListenerProxy::TransCoderListenerProxy(const sptr<IRemoteObject> &impl)
27     : IRemoteProxy<IStandardTransCoderListener>(impl)
28 {
29     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
30 }
31 
~TransCoderListenerProxy()32 TransCoderListenerProxy::~TransCoderListenerProxy()
33 {
34     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
35 }
36 
OnError(int32_t errorCode,const std::string & errorMsg)37 void TransCoderListenerProxy::OnError(int32_t errorCode, const std::string &errorMsg)
38 {
39     MessageParcel data;
40     MessageParcel reply;
41     MessageOption option(MessageOption::TF_ASYNC);
42 
43     bool token = data.WriteInterfaceToken(TransCoderListenerProxy::GetDescriptor());
44     CHECK_AND_RETURN_LOG(token, "Failed to write descriptor!");
45 
46     data.WriteInt32(errorCode);
47     data.WriteString(errorMsg);
48     int error = Remote()->SendRequest(TransCoderListenerMsg::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 TransCoderListenerProxy::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(TransCoderListenerProxy::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(TransCoderListenerMsg::ON_INFO, data, reply, option);
64     CHECK_AND_RETURN_LOG(error == MSERR_OK, "on info failed, error: %{public}d", error);
65 }
66 
TransCoderListenerCallback(const sptr<IStandardTransCoderListener> & listener)67 TransCoderListenerCallback::TransCoderListenerCallback(const sptr<IStandardTransCoderListener> &listener)
68     : listener_(listener)
69 {
70     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
71 }
72 
~TransCoderListenerCallback()73 TransCoderListenerCallback::~TransCoderListenerCallback()
74 {
75     MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
76 }
77 
OnError(int32_t errorCode,const std::string & errorMsg)78 void TransCoderListenerCallback::OnError(int32_t errorCode, const std::string &errorMsg)
79 {
80     CHECK_AND_RETURN(listener_ != nullptr);
81     listener_->OnError(errorCode, errorMsg);
82 }
83 
OnInfo(int32_t type,int32_t extra)84 void TransCoderListenerCallback::OnInfo(int32_t type, int32_t extra)
85 {
86     CHECK_AND_RETURN(listener_ != nullptr);
87     listener_->OnInfo(type, extra);
88 }
89 } // namespace Media
90 } // namespace OHOS
91