• 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 #ifndef LOG_TAG
16 #define LOG_TAG "IpcOfflineStreamStub"
17 #endif
18 
19 #include "ipc_offline_stream_stub.h"
20 #include "audio_service_log.h"
21 #include "audio_errors.h"
22 
23 namespace OHOS {
24 namespace AudioStandard {
IpcOfflineStreamStub()25 IpcOfflineStreamStub::IpcOfflineStreamStub()
26 {
27     handlerMap_ = {
28         {CREATE_OFFLINE_EFFECT_CHAIN, [this](MessageParcel &data, MessageParcel &reply) {
29             return HandleCreateOfflineEffectChain(data, reply);
30         }},
31         {CONFIGURE_OFFLINE_EFFECT_CHAIN, [this](MessageParcel &data, MessageParcel &reply) {
32             return HandleConfigureOfflineEffectChain(data, reply);
33         }},
34         {PROCESS_OFFLINE_EFFECT_CHAIN, [this](MessageParcel &data, MessageParcel &reply) {
35             return HandleProcessOfflineEffectChain(data, reply);
36         }},
37         {PREPARE_OFFLINE_EFFECT_CHAIN, [this](MessageParcel &data, MessageParcel &reply) {
38             return HandlePrepareOfflineEffectChain(data, reply);
39         }},
40         {RELEASE_OFFLINE_EFFECT_CHAIN, [this](MessageParcel &data, MessageParcel &reply) {
41             return HandleReleaseOfflineEffectChain(data, reply);
42         }}
43     };
44 }
45 
CheckInterfaceToken(MessageParcel & data)46 bool IpcOfflineStreamStub::CheckInterfaceToken(MessageParcel &data)
47 {
48     static auto localDescriptor = IpcOfflineStream::GetDescriptor();
49     auto remoteDescriptor = data.ReadInterfaceToken();
50     if (remoteDescriptor != localDescriptor) {
51         AUDIO_ERR_LOG("CheckInterFfaceToken failed.");
52         return false;
53     }
54     return true;
55 }
56 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)57 int32_t IpcOfflineStreamStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
58     MessageOption &option)
59 {
60     CHECK_AND_RETURN_RET(CheckInterfaceToken(data), AUDIO_ERR);
61     auto it = handlerMap_.find(code);
62     if (it != handlerMap_.end()) {
63         return it->second(data, reply);
64     }
65     AUDIO_WARNING_LOG("OnRemoteRequest unsupported request code:%{public}d.", code);
66     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
67 }
68 
HandleCreateOfflineEffectChain(MessageParcel & data,MessageParcel & reply)69 int32_t IpcOfflineStreamStub::HandleCreateOfflineEffectChain(MessageParcel &data, MessageParcel &reply)
70 {
71 #ifdef FEATURE_OFFLINE_EFFECT
72     std::string chainName = data.ReadString();
73     int32_t ret = CreateOfflineEffectChain(chainName);
74     reply.WriteInt32(ret);
75     return AUDIO_OK;
76 #endif
77     return ERR_NOT_SUPPORTED;
78 }
79 
HandleConfigureOfflineEffectChain(MessageParcel & data,MessageParcel & reply)80 int32_t IpcOfflineStreamStub::HandleConfigureOfflineEffectChain(MessageParcel &data, MessageParcel &reply)
81 {
82 #ifdef FEATURE_OFFLINE_EFFECT
83     AudioStreamInfo inInfo;
84     AudioStreamInfo outInfo;
85     inInfo.Unmarshalling(data);
86     outInfo.Unmarshalling(data);
87     int32_t ret = ConfigureOfflineEffectChain(inInfo, outInfo);
88     reply.WriteInt32(ret);
89     return AUDIO_OK;
90 #endif
91     return ERR_NOT_SUPPORTED;
92 }
93 
HandlePrepareOfflineEffectChain(MessageParcel & data,MessageParcel & reply)94 int32_t IpcOfflineStreamStub::HandlePrepareOfflineEffectChain(MessageParcel &data, MessageParcel &reply)
95 {
96 #ifdef FEATURE_OFFLINE_EFFECT
97     (void)data;
98     std::shared_ptr<AudioSharedMemory> inBuf = nullptr;
99     std::shared_ptr<AudioSharedMemory> outBuf = nullptr;
100     int32_t ret = PrepareOfflineEffectChain(inBuf, outBuf);
101     AudioSharedMemory::WriteToParcel(inBuf, reply);
102     AudioSharedMemory::WriteToParcel(outBuf, reply);
103     reply.WriteInt32(ret);
104     return AUDIO_OK;
105 #endif
106     return ERR_NOT_SUPPORTED;
107 }
108 
HandleProcessOfflineEffectChain(MessageParcel & data,MessageParcel & reply)109 int32_t IpcOfflineStreamStub::HandleProcessOfflineEffectChain(MessageParcel &data, MessageParcel &reply)
110 {
111 #ifdef FEATURE_OFFLINE_EFFECT
112     uint32_t inSize;
113     uint32_t outSize;
114     inSize = data.ReadUint32();
115     outSize = data.ReadUint32();
116     int32_t ret = ProcessOfflineEffectChain(inSize, outSize);
117     return ret;
118 #endif
119     return ERR_NOT_SUPPORTED;
120 }
121 
HandleReleaseOfflineEffectChain(MessageParcel & data,MessageParcel & reply)122 int32_t IpcOfflineStreamStub::HandleReleaseOfflineEffectChain(MessageParcel &data, MessageParcel &reply)
123 {
124 #ifdef FEATURE_OFFLINE_EFFECT
125     ReleaseOfflineEffectChain();
126     return SUCCESS;
127 #endif
128     return ERR_NOT_SUPPORTED;
129 }
130 } // namespace AudioStandard
131 } // namespace OHOS
132