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 #ifdef SUPPORT_DRM
21 #include "imedia_key_session_service.h"
22 #endif
23
24 namespace {
25 const OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_FRAMEWORK, "CodecServiceProxy"};
26 }
27
28 namespace OHOS {
29 namespace MediaAVCodec {
30 using namespace Media;
CodecServiceProxy(const sptr<IRemoteObject> & impl)31 CodecServiceProxy::CodecServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<IStandardCodecService>(impl)
32 {
33 AVCODEC_LOGD_WITH_TAG("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
34 }
35
~CodecServiceProxy()36 CodecServiceProxy::~CodecServiceProxy()
37 {
38 AVCODEC_LOGD_WITH_TAG("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
39 }
40
SetListenerObject(const sptr<IRemoteObject> & object)41 int32_t CodecServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
42 {
43 MessageParcel data;
44 MessageParcel reply;
45 MessageOption option;
46
47 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
48 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
49
50 bool parcelRet = data.WriteRemoteObject(object);
51 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
52 int32_t ret =
53 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_LISTENER_OBJ), data, reply, option);
54 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
55
56 return reply.ReadInt32();
57 }
58
SetListener(const sptr<CodecListenerStub> & listener)59 void CodecServiceProxy::SetListener(const sptr<CodecListenerStub> &listener)
60 {
61 listener_ = listener;
62 }
63
Init(AVCodecType type,bool isMimeType,const std::string & name,Meta & callerInfo)64 int32_t CodecServiceProxy::Init(AVCodecType type, bool isMimeType, const std::string &name, Meta &callerInfo)
65 {
66 MessageParcel data;
67 MessageParcel reply;
68 MessageOption option;
69
70 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
71 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
72
73 bool parcelRet = callerInfo.ToParcel(data);
74 parcelRet = parcelRet && data.WriteInt32(static_cast<int32_t>(type));
75 parcelRet = parcelRet && data.WriteBool(isMimeType);
76 parcelRet = parcelRet && data.WriteString(name);
77 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
78 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::INIT), data, reply, option);
79 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
80 ret = reply.ReadInt32();
81 parcelRet = callerInfo.FromParcel(reply);
82 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Read parcel failed");
83 return ret;
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_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
94
95 bool parcelRet = AVCodecParcel::Marshalling(data, format);
96 CHECK_AND_RETURN_RET_LOG_WITH_TAG(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_WITH_TAG(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_WITH_TAG(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_WITH_TAG(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_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
127
128 bool parcelRet = buffer->WriteToMessageParcel(data);
129 CHECK_AND_RETURN_RET_LOG_WITH_TAG(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_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
134
135 return reply.ReadInt32();
136 }
137
NotifyMemoryExchange(const bool exchangeFlag)138 int32_t CodecServiceProxy::NotifyMemoryExchange(const bool exchangeFlag)
139 {
140 MessageParcel data;
141 MessageParcel reply;
142 MessageOption option;
143
144 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
145 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
146
147 bool res = data.WriteBool(exchangeFlag);
148 CHECK_AND_RETURN_RET_LOG_WITH_TAG(res, AVCS_ERR_INVALID_OPERATION, "Write bool failed!");
149
150 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::NOTIFY_MEMORY_EXCHANGE),
151 data, reply, option);
152 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
153
154 return reply.ReadInt32();
155 }
156
Start()157 int32_t CodecServiceProxy::Start()
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 MessageOption option;
162
163 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
164 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
165
166 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::START), data, reply, option);
167 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
168
169 return reply.ReadInt32();
170 }
171
Stop()172 int32_t CodecServiceProxy::Stop()
173 {
174 MessageParcel data;
175 MessageParcel reply;
176 MessageOption option;
177
178 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
179 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
180
181 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::STOP), data, reply, option);
182 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
183
184 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
185 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
186 listenerStub->ClearListenerCache();
187 return reply.ReadInt32();
188 }
189
Flush()190 int32_t CodecServiceProxy::Flush()
191 {
192 MessageParcel data;
193 MessageParcel reply;
194 MessageOption option;
195
196 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
197 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
198
199 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::FLUSH), data, reply, option);
200 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
201 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
202 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
203 listenerStub->FlushListenerCache();
204 return reply.ReadInt32();
205 }
206
NotifyEos()207 int32_t CodecServiceProxy::NotifyEos()
208 {
209 MessageParcel data;
210 MessageParcel reply;
211 MessageOption option;
212
213 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
214 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
215
216 int32_t ret =
217 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::NOTIFY_EOS), data, reply, option);
218 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
219
220 return reply.ReadInt32();
221 }
222
Reset()223 int32_t CodecServiceProxy::Reset()
224 {
225 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listener_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
226 MessageParcel data;
227 MessageParcel reply;
228 MessageOption option;
229
230 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
231 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
232
233 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RESET), data, reply, option);
234 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
235 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
236 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
237 listenerStub->ClearListenerCache();
238 return reply.ReadInt32();
239 }
240
Release()241 int32_t CodecServiceProxy::Release()
242 {
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option;
246
247 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
248 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
249
250 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RELEASE), data, reply, option);
251 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
252
253 return reply.ReadInt32();
254 }
255
GetChannelId(int32_t & channelId)256 int32_t CodecServiceProxy::GetChannelId(int32_t &channelId)
257 {
258 MessageParcel data;
259 MessageParcel reply;
260 MessageOption option;
261
262 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
263 CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "LowPowerPlayer Write descriptor failed!");
264 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::GET_CHANNEL_ID),
265 data, reply, option);
266 CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "LowPowerPlayer Send request failed");
267 channelId = reply.ReadInt32();
268 return AVCS_ERR_OK;
269 }
270
CreateInputSurface()271 sptr<OHOS::Surface> CodecServiceProxy::CreateInputSurface()
272 {
273 MessageParcel data;
274 MessageParcel reply;
275 MessageOption option;
276
277 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
278 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, nullptr, "Write descriptor failed!");
279
280 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::CREATE_INPUT_SURFACE), data,
281 reply, option);
282 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, nullptr, "Send request failed");
283
284 if (reply.ReadInt32() != AVCS_ERR_OK) {
285 return nullptr;
286 }
287 sptr<IRemoteObject> object = reply.ReadRemoteObject();
288 CHECK_AND_RETURN_RET_LOG_WITH_TAG(object != nullptr, nullptr, "Read surface object failed");
289
290 sptr<IBufferProducer> producer = iface_cast<IBufferProducer>(object);
291 CHECK_AND_RETURN_RET_LOG_WITH_TAG(producer != nullptr, nullptr, "Convert object to producer failed");
292
293 return OHOS::Surface::CreateSurfaceAsProducer(producer);
294 }
295
SetOutputSurface(sptr<OHOS::Surface> surface)296 int32_t CodecServiceProxy::SetOutputSurface(sptr<OHOS::Surface> surface)
297 {
298 MessageParcel data;
299 MessageParcel reply;
300 MessageOption option;
301
302 CHECK_AND_RETURN_RET_LOG_WITH_TAG(surface != nullptr, AVCS_ERR_NO_MEMORY, "Surface is nullptr");
303 sptr<IBufferProducer> producer = surface->GetProducer();
304 CHECK_AND_RETURN_RET_LOG_WITH_TAG(producer != nullptr, AVCS_ERR_NO_MEMORY, "Producer is nullptr");
305
306 sptr<IRemoteObject> object = producer->AsObject();
307 CHECK_AND_RETURN_RET_LOG_WITH_TAG(object != nullptr, AVCS_ERR_NO_MEMORY, "Object is nullptr");
308
309 const std::string surfaceFormat = "SURFACE_FORMAT";
310 std::string format = surface->GetUserData(surfaceFormat);
311 AVCODEC_LOGD_WITH_TAG("Surface format is %{public}s!", format.c_str());
312
313 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
314 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
315
316 bool parcelRet = data.WriteRemoteObject(object);
317 parcelRet = parcelRet && data.WriteString(format);
318 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
319
320 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_OUTPUT_SURFACE), data,
321 reply, option);
322 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
323
324 return reply.ReadInt32();
325 }
326
SetLowPowerPlayerMode(bool isLpp)327 int32_t CodecServiceProxy::SetLowPowerPlayerMode(bool isLpp)
328 {
329 MessageParcel data;
330 MessageParcel reply;
331 MessageOption option;
332
333 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
334 CHECK_AND_RETURN_RET_LOG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
335
336 data.WriteBool(isLpp);
337 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_LPP_MODE), data,
338 reply, option);
339 CHECK_AND_RETURN_RET_LOG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
340
341 return reply.ReadInt32();
342 }
343
QueueInputBuffer(uint32_t index,AVCodecBufferInfo info,AVCodecBufferFlag flag)344 int32_t CodecServiceProxy::QueueInputBuffer(uint32_t index, AVCodecBufferInfo info, AVCodecBufferFlag flag)
345 {
346 MessageParcel data;
347 MessageParcel reply;
348 MessageOption option;
349
350 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
351 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
352
353 data.WriteUint32(index);
354
355 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
356 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
357 bool parcelRet = listenerStub->WriteInputBufferToParcel(index, data);
358 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
359
360 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
361 reply, option);
362 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
363
364 return reply.ReadInt32();
365 }
366
QueueInputBuffer(uint32_t index)367 int32_t CodecServiceProxy::QueueInputBuffer(uint32_t index)
368 {
369 MessageParcel data;
370 MessageParcel reply;
371 MessageOption option;
372
373 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
374 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
375
376 data.WriteUint32(index);
377
378 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
379 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
380 bool parcelRet = listenerStub->WriteInputBufferToParcel(index, data);
381 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
382
383 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
384 reply, option);
385 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
386
387 return reply.ReadInt32();
388 }
389
QueueInputParameter(uint32_t index)390 int32_t CodecServiceProxy::QueueInputParameter(uint32_t index)
391 {
392 MessageParcel data;
393 MessageParcel reply;
394 MessageOption option;
395
396 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
397 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
398
399 data.WriteUint32(index);
400
401 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
402 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
403 bool parcelRet = listenerStub->WriteInputBufferToParcel(index, data);
404 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
405
406 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::QUEUE_INPUT_BUFFER), data,
407 reply, option);
408 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
409
410 return reply.ReadInt32();
411 }
412
GetOutputFormat(Format & format)413 int32_t CodecServiceProxy::GetOutputFormat(Format &format)
414 {
415 MessageParcel data;
416 MessageParcel reply;
417 MessageOption option;
418
419 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
420 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
421
422 int32_t ret =
423 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::GET_OUTPUT_FORMAT), data, reply, option);
424 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
425
426 (void)AVCodecParcel::Unmarshalling(reply, format);
427 return AVCS_ERR_OK;
428 }
429
ReleaseOutputBuffer(uint32_t index,bool render)430 int32_t CodecServiceProxy::ReleaseOutputBuffer(uint32_t index, bool render)
431 {
432 MessageParcel data;
433 MessageParcel reply;
434 MessageOption option;
435
436 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
437 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
438
439 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
440 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
441 bool parcelRet = data.WriteUint32(index);
442 parcelRet = parcelRet && data.WriteBool(render);
443 parcelRet = parcelRet && listenerStub->WriteOutputBufferToParcel(index, data);
444 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_STATE, "Write parcel failed");
445
446 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RELEASE_OUTPUT_BUFFER), data,
447 reply, option);
448 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
449
450 return reply.ReadInt32();
451 }
452
RenderOutputBufferAtTime(uint32_t index,int64_t renderTimestampNs)453 int32_t CodecServiceProxy::RenderOutputBufferAtTime(uint32_t index, int64_t renderTimestampNs)
454 {
455 MessageParcel data;
456 MessageParcel reply;
457 MessageOption option;
458
459 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
460 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
461
462 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
463 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
464 bool parcelRet = data.WriteUint32(index);
465 parcelRet = parcelRet && data.WriteInt64(renderTimestampNs);
466 parcelRet = parcelRet && listenerStub->WriteOutputBufferToParcel(index, data);
467 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
468
469 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::RENDER_OUTPUT_BUFFER_AT_TIME),
470 data, reply, option);
471 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
472
473 return reply.ReadInt32();
474 }
475
SetParameter(const Format & format)476 int32_t CodecServiceProxy::SetParameter(const Format &format)
477 {
478 MessageParcel data;
479 MessageParcel reply;
480 MessageOption option;
481
482 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
483 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
484
485 bool parcelRet = AVCodecParcel::Marshalling(data, format);
486 CHECK_AND_RETURN_RET_LOG_WITH_TAG(parcelRet, AVCS_ERR_INVALID_OPERATION, "Write parcel failed");
487
488 int32_t ret =
489 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_PARAMETER), data, reply, option);
490 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
491
492 return reply.ReadInt32();
493 }
494
GetInputFormat(Format & format)495 int32_t CodecServiceProxy::GetInputFormat(Format &format)
496 {
497 MessageParcel data;
498 MessageParcel reply;
499 MessageOption option;
500
501 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
502 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
503
504 int32_t ret =
505 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::GET_INPUT_FORMAT), data, reply, option);
506 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
507
508 (void)AVCodecParcel::Unmarshalling(reply, format);
509 return AVCS_ERR_OK;
510 }
511
DestroyStub()512 int32_t CodecServiceProxy::DestroyStub()
513 {
514 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listener_ != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
515 MessageParcel data;
516 MessageParcel reply;
517 MessageOption option;
518
519 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
520 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
521
522 int32_t ret =
523 Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::DESTROY_STUB), data, reply, option);
524 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
525
526 auto listenerStub = static_cast<CodecListenerStub *>(listener_.GetRefPtr());
527 CHECK_AND_RETURN_RET_LOG_WITH_TAG(listenerStub != nullptr, AVCS_ERR_INVALID_OPERATION, "Listener is nullptr");
528 listenerStub->ClearListenerCache();
529 return reply.ReadInt32();
530 }
531
532 #ifdef SUPPORT_DRM
SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> & keySession,const bool svpFlag)533 int32_t CodecServiceProxy::SetDecryptConfig(const sptr<DrmStandard::IMediaKeySessionService> &keySession,
534 const bool svpFlag)
535 {
536 MessageParcel data;
537 MessageParcel reply;
538 MessageOption option;
539
540 bool token = data.WriteInterfaceToken(CodecServiceProxy::GetDescriptor());
541 CHECK_AND_RETURN_RET_LOG_WITH_TAG(token, AVCS_ERR_INVALID_OPERATION, "Write descriptor failed!");
542
543 CHECK_AND_RETURN_RET_LOG_WITH_TAG(keySession != nullptr, AVCS_ERR_INVALID_VAL, "keySession nullptr failed!");
544 sptr<IRemoteObject> object = keySession->AsObject();
545 CHECK_AND_RETURN_RET_LOG_WITH_TAG(object != nullptr, AVCS_ERR_INVALID_VAL, "keySessionProxy object is null");
546 bool status = data.WriteRemoteObject(object);
547 CHECK_AND_RETURN_RET_LOG_WITH_TAG(status, AVCS_ERR_INVALID_OPERATION, "SetDecryptConfig WriteRemoteObject failed");
548 data.WriteBool(svpFlag);
549
550 int32_t ret = Remote()->SendRequest(static_cast<uint32_t>(CodecServiceInterfaceCode::SET_DECRYPT_CONFIG), data,
551 reply, option);
552 CHECK_AND_RETURN_RET_LOG_WITH_TAG(ret == AVCS_ERR_OK, AVCS_ERR_INVALID_OPERATION, "Send request failed");
553
554 return reply.ReadInt32();
555 }
556 #endif
557 } // namespace MediaAVCodec
558 } // namespace OHOS
559