1 /*
2  * Copyright (C) 2023 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 "codec_service_proxy.h"
17 #include "avcodec_errors.h"
18 #include "avcodec_parcel.h"
19 #include "avsharedmemory_ipc.h"
20 #include "buffer_client_producer.h"
21 
22 namespace OHOS {
23 namespace MediaAVCodec {
24 using namespace Media;
CodecServiceProxy(const sptr<IRemoteObject> & impl)25 CodecServiceProxy::CodecServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IStandardCodecService>(impl)
26 {
27     AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
28 }
29 
~CodecServiceProxy()30 CodecServiceProxy::~CodecServiceProxy()
31 {
32     AVCODEC_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
33 }
34 
SetListenerObject(const sptr<IRemoteObject> & object)35 int32_t CodecServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
36 {
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option;
40 
41     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
42     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
43 
44     bool parcelRet = data.WriteRemoteObject(object);
45     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
46     int32_t ret =
47         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_LISTENER_OBJ), data, reply, option);
48     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
49 
50     return reply.ReadInt32();
51 }
52 
SetListener(const sptr<CodecListenerStub> & listener)53 void CodecServiceProxy::SetListener(const sptr<CodecListenerStub> &listener)
54 {
55     listener_ = listener;
56 }
57 
InitLabel(const uint64_t uid)58 void CodecServiceProxy::InitLabel(const uint64_t uid)
59 {
60     tag_ = "ServiceProxy[";
61     tag_ += std::to_string(uid) + "]";
62     auto &label = const_cast<OHOS::HiviewDFX::HiLogLabel &>(LABEL);
63     label.tag = tag_.c_str();
64 }
65 
Init(AVCodecType type,bool isMimeType,const std::string & name,Meta & callerInfo)66 int32_t CodecServiceProxy::Init(AVCodecType type, bool isMimeType, const std::string &name, Meta &callerInfo)
67 {
68     MessageParcel data;
69     MessageParcel reply;
70     MessageOption option;
71 
72     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
73     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
74 
75     bool parcelRet = callerInfo.ToParcel(data);
76     parcelRet = parcelRet && data.WriteInt32(static_cast<int32_t>(type));
77     parcelRet = parcelRet && data.WriteBool(isMimeType);
78     parcelRet = parcelRet && data.WriteString(name);
79     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
80     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::INIT), data, reply, option);
81     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
82 
83     return reply.ReadInt32();
84 }
85 
Configure(const Format & format)86 int32_t CodecServiceProxy::Configure(const Format &format)
87 {
88     MessageParcel data;
89     MessageParcel reply;
90     MessageOption option;
91 
92     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
93     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
94 
95     bool parcelRet = AVCodecParcel::Marshalling(data, format);
96     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
97     int32_t ret =
98         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::CONFIGURE), data, reply, option);
99     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
100 
101     return reply.ReadInt32();
102 }
103 
Prepare()104 int32_t CodecServiceProxy::Prepare()
105 {
106     MessageParcel data;
107     MessageParcel reply;
108     MessageOption option;
109 
110     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
111     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
112 
113     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::PREPARE), data, reply, option);
114     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
115 
116     return reply.ReadInt32();
117 }
118 
SetCustomBuffer(std::shared_ptr<AVBuffer> buffer)119 int32_t CodecServiceProxy::SetCustomBuffer(std::shared_ptr<AVBuffer> buffer)
120 {
121     MessageParcel data;
122     MessageParcel reply;
123     MessageOption option;
124 
125     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
126     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
127 
128     bool parcelRet = buffer->WriteToMessageParcel(data);
129     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
130 
131     int32_t ret =
132         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_CUSTOM_BUFFER), data, reply, option);
133     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
134 
135     return reply.ReadInt32();
136 }
137 
Start()138 int32_t CodecServiceProxy::Start()
139 {
140     MessageParcel data;
141     MessageParcel reply;
142     MessageOption option;
143 
144     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
145     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
146 
147     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::START), data, reply, option);
148     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
149 
150     return reply.ReadInt32();
151 }
152 
Stop()153 int32_t CodecServiceProxy::Stop()
154 {
155     MessageParcel data;
156     MessageParcel reply;
157     MessageOption option;
158 
159     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
160     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
161 
162     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::STOP), data, reply, option);
163     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
164 
165     static_cast<CodecListenerStub *>(listener_.GetRefPtr())->ClearListenerCache();
166     return reply.ReadInt32();
167 }
168 
Flush()169 int32_t CodecServiceProxy::Flush()
170 {
171     MessageParcel data;
172     MessageParcel reply;
173     MessageOption option;
174 
175     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
176     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
177 
178     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::FLUSH), data, reply, option);
179     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
180     static_cast<CodecListenerStub *>(listener_.GetRefPtr())->FlushListenerCache();
181     return reply.ReadInt32();
182 }
183 
NotifyEos()184 int32_t CodecServiceProxy::NotifyEos()
185 {
186     MessageParcel data;
187     MessageParcel reply;
188     MessageOption option;
189 
190     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
191     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
192 
193     int32_t ret =
194         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::NOTIFY_EOS), data, reply, option);
195     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
196 
197     return reply.ReadInt32();
198 }
199 
Reset()200 int32_t CodecServiceProxy::Reset()
201 {
202     MessageParcel data;
203     MessageParcel reply;
204     MessageOption option;
205 
206     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
207     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
208 
209     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RESET), data, reply, option);
210     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
211     static_cast<CodecListenerStub *>(listener_.GetRefPtr())->ClearListenerCache();
212     return reply.ReadInt32();
213 }
214 
Release()215 int32_t CodecServiceProxy::Release()
216 {
217     MessageParcel data;
218     MessageParcel reply;
219     MessageOption option;
220 
221     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
222     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
223 
224     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RELEASE), data, reply, option);
225     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
226 
227     return reply.ReadInt32();
228 }
229 
CreateInputSurface()230 sptr<OHOS::Surface> CodecServiceProxy::CreateInputSurface()
231 {
232     MessageParcel data;
233     MessageParcel reply;
234     MessageOption option;
235 
236     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
237     CHECK_AND_RETURN_RET_LOG(token, nullptr, "Write descriptor failed!");
238 
239     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::CREATE_INPUT_SURFACE), data,
240                                         reply, option);
241     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, nullptr, "Send request failed");
242 
243     if (reply.ReadInt32() != AVCS_ERR_OK) {
244         return nullptr;
245     }
246     sptr<IRemoteObject> object = reply.ReadRemoteObject();
247     CHECK_AND_RETURN_RET_LOG(object != nullptr, nullptr, "Read surface object failed");
248 
249     sptr<IBufferProducer> producer(new BufferClientProducer(object));
250     CHECK_AND_RETURN_RET_LOG(producer != nullptr, nullptr, "Convert object to producer failed");
251 
252     return OHOS::Surface::CreateSurfaceAsProducer(producer);
253 }
254 
SetOutputSurface(sptr<OHOS::Surface> surface)255 int32_t CodecServiceProxy::SetOutputSurface(sptr<OHOS::Surface> surface)
256 {
257     MessageParcel data;
258     MessageParcel reply;
259     MessageOption option;
260 
261     CHECK_AND_RETURN_RET_LOG(surface != nullptr, AVCS_ERR_NO_MEMORY, "Surface is nullptr");
262     sptr<IBufferProducer> producer = surface->GetProducer();
263     CHECK_AND_RETURN_RET_LOG(producer != nullptr, AVCS_ERR_NO_MEMORY, "Producer is nullptr");
264 
265     sptr<IRemoteObject> object = producer->AsObject();
266     CHECK_AND_RETURN_RET_LOG(object != nullptr, AVCS_ERR_NO_MEMORY, "Object is nullptr");
267 
268     const std::string surfaceFormat = "SURFACE_FORMAT";
269     std::string format = surface->GetUserData(surfaceFormat);
270     AVCODEC_LOGD("Surface format is %{public}s!", format.c_str());
271 
272     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
273     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
274 
275     bool parcelRet = data.WriteRemoteObject(object);
276     parcelRet = parcelRet && data.WriteString(format);
277     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
278 
279     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_OUTPUT_SURFACE), data,
280                                         reply, option);
281     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
282 
283     return reply.ReadInt32();
284 }
285 
QueueInputBuffer(uint32_t index,AVCodecBufferInfo info,AVCodecBufferFlag flag)286 int32_t CodecServiceProxy::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
287 {
288     MessageParcel data;
289     MessageParcel reply;
290     MessageOption option;
291 
292     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
293     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
294 
295     data.WriteUint32(index);
296 
297     auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
298     bool parcelRet = listenerStub->WriteInputMemoryToParcel(index, info, flag, data);
299     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
300 
301     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
302                                         reply, option);
303     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
304 
305     return reply.ReadInt32();
306 }
307 
QueueInputBuffer(uint32_t index)308 int32_t CodecServiceProxy::QueueInputBuffer(uint32_t index)
309 {
310     MessageParcel data;
311     MessageParcel reply;
312     MessageOption option;
313 
314     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
315     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
316 
317     data.WriteUint32(index);
318 
319     auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
320     bool parcelRet = listenerStub->WriteInputBufferToParcel(index, data);
321     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
322 
323     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
324                                         reply, option);
325     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
326 
327     return reply.ReadInt32();
328 }
329 
QueueInputParameter(uint32_t index)330 int32_t CodecServiceProxy::QueueInputParameter(uint32_t index)
331 {
332     MessageParcel data;
333     MessageParcel reply;
334     MessageOption option;
335 
336     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
337     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
338 
339     data.WriteUint32(index);
340 
341     auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
342     bool parcelRet = listenerStub->WriteInputParameterToParcel(index, data);
343     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
344 
345     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
346                                         reply, option);
347     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
348 
349     return reply.ReadInt32();
350 }
351 
GetOutputFormat(Format & format)352 int32_t CodecServiceProxy::GetOutputFormat(Format &format)
353 {
354     MessageParcel data;
355     MessageParcel reply;
356     MessageOption option;
357 
358     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
359     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
360 
361     int32_t ret =
362         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::GET_OUTPUT_FORMAT), data, reply, option);
363     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
364 
365     (void)AVCodecParcel::Unmarshalling(reply, format);
366     return AVCS_ERR_OK;
367 }
368 
ReleaseOutputBuffer(uint32_t index,bool render)369 int32_t CodecServiceProxy::ReleaseOutputBuffer(uint32_t index, bool render)
370 {
371     MessageParcel data;
372     MessageParcel reply;
373     MessageOption option;
374 
375     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
376     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
377 
378     auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
379     bool parcelRet = data.WriteUint32(index);
380     parcelRet = parcelRet && data.WriteBool(render);
381     parcelRet = parcelRet && listenerStub->WriteOutputBufferToParcel(index, data);
382     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
383 
384     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RELEASE_OUTPUT_BUFFER), data,
385                                         reply, option);
386     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
387 
388     return reply.ReadInt32();
389 }
390 
RenderOutputBufferAtTime(uint32_t index,int64_t renderTimestampNs)391 int32_t CodecServiceProxy::RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs)
392 {
393     MessageParcel data;
394     MessageParcel reply;
395     MessageOption option;
396 
397     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
398     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
399 
400     bool parcelRet = data.WriteUint32(index);
401     parcelRet = parcelRet && data.WriteInt64(renderTimestampNs);
402     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
403 
404     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RENDER_OUTPUT_BUFFER_AT_TIME),
405                                         data, reply, option);
406     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
407 
408     return reply.ReadInt32();
409 }
410 
SetParameter(const Format & format)411 int32_t CodecServiceProxy::SetParameter(const Format &format)
412 {
413     MessageParcel data;
414     MessageParcel reply;
415     MessageOption option;
416 
417     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
418     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
419 
420     bool parcelRet = AVCodecParcel::Marshalling(data, format);
421     CHECK_AND_RETURN_RET_LOG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
422 
423     int32_t ret =
424         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_PARAMETER), data, reply, option);
425     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
426 
427     return reply.ReadInt32();
428 }
429 
GetInputFormat(Format & format)430 int32_t CodecServiceProxy::GetInputFormat(Format &format)
431 {
432     MessageParcel data;
433     MessageParcel reply;
434     MessageOption option;
435 
436     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
437     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
438 
439     int32_t ret =
440         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::GET_INPUT_FORMAT), data, reply, option);
441     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
442 
443     (void)AVCodecParcel::Unmarshalling(reply, format);
444     return AVCS_ERR_OK;
445 }
446 
DestroyStub()447 int32_t CodecServiceProxy::DestroyStub()
448 {
449     MessageParcel data;
450     MessageParcel reply;
451     MessageOption option;
452 
453     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
454     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
455 
456     int32_t ret =
457         Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::DESTROY_STUB), data, reply, option);
458     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
459 
460     static_cast<CodecListenerStub *>(listener_.GetRefPtr())->ClearListenerCache();
461     return reply.ReadInt32();
462 }
463 
464 #ifdef SUPPORT_DRM
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)465 int32_t CodecServiceProxy::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
466                                             const bool svpFlag)
467 {
468     MessageParcel data;
469     MessageParcel reply;
470     MessageOption option;
471 
472     bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
473     CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
474 
475     CHECK_AND_RETURN_RET_LOG(keySession != nullptr, AVCS_ERR_INVALID_VAL, "keySession nullptr failed!");
476     sptr<IRemoteObject> object = keySession->AsObject();
477     CHECK_AND_RETURN_RET_LOG(object != nullptr, AVCS_ERR_INVALID_VAL, "keySessionProxy object is null");
478     bool status = data.WriteRemoteObject(object);
479     CHECK_AND_RETURN_RET_LOG(status, AVCS_ERR_INVALID_OPERATION, "SetDecryptConfig WriteRemoteObject failed");
480     data.WriteBool(svpFlag);
481 
482     int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_DECRYPT_CONFIG), data,
483                                         reply, option);
484     CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
485 
486     return reply.ReadInt32();
487 }
488 #endif
489 } // namespace MediaAVCodec
490 } // namespace OHOS
491