• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "audio_renderer_write_callback_stub.h"
17 #include "audio_log.h"
18 
19 namespace OHOS {
20 namespace AudioStandard {
AudioRendererWriteCallbackStub()21 AudioRendererWriteCallbackStub::AudioRendererWriteCallbackStub()
22 {
23 }
24 
~AudioRendererWriteCallbackStub()25 AudioRendererWriteCallbackStub::~AudioRendererWriteCallbackStub()
26 {
27 }
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int AudioRendererWriteCallbackStub::OnRemoteRequest(
30     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
31 {
32     AUDIO_DEBUG_LOG("AudioRendererWriteCallbackStub::OnRemoteRequest");
33     if (data.ReadInterfaceToken() != GetDescriptor()) {
34         AUDIO_ERR_LOG("AudioRendererWriteCallbackStub: ReadInterfaceToken failed");
35         return -1;
36     }
37     switch (code) {
38         case ON_WRITE_DATA: {
39             size_t length = static_cast<size_t>(data.ReadInt64());
40             OnWriteData(length);
41             reply.WriteInt32(AUDIO_OK);
42             break;
43         }
44         default: {
45             reply.WriteInt32(AUDIO_INVALID_PARAM);
46             break;
47         }
48     }
49     return AUDIO_OK;
50 }
51 
OnWriteData(size_t length)52 void AudioRendererWriteCallbackStub::OnWriteData(size_t length)
53 {
54     AUDIO_DEBUG_LOG("AudioRendererWriteCallbackStub::OnWriteData");
55     std::shared_ptr<AudioRendererWriteCallback> cb = callback_.lock();
56     if (cb != nullptr) {
57         AUDIO_DEBUG_LOG("AudioRendererWriteCallbackStub::OnWriteData CALLBACK NOT NULL");
58         cb->OnWriteData(length);
59     } else {
60         AUDIO_DEBUG_LOG("AudioRendererWriteCallbackStub::OnWriteData CALLBACK NULL");
61     }
62 }
63 
SetOnRendererWriteCallback(const std::weak_ptr<AudioRendererWriteCallback> & callback)64 void AudioRendererWriteCallbackStub::SetOnRendererWriteCallback(
65     const std::weak_ptr<AudioRendererWriteCallback> &callback)
66 {
67     AUDIO_DEBUG_LOG("AudioRendererWriteCallbackStub::SetOnRendererWriteCallback");
68     callback_ = callback;
69 }
70 } // namespace AudioStandard
71 } // namespace OHOS