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 "bluetooth_a2dp_a2dpCodecInfo.h"
17 #include "bluetooth_log.h"
18 
19 namespace OHOS {
20 namespace Bluetooth {
Marshalling(Parcel & parcel) const21 bool BluetoothA2dpCodecInfo::Marshalling(Parcel &parcel) const
22 {
23     if (!parcel.WriteUint8(codecPriority)) {
24         return false;
25     }
26     if (!parcel.WriteUint8(codecType)) {
27         return false;
28     }
29     if (!parcel.WriteUint32(sampleRate)) {
30         return false;
31     }
32     if (!parcel.WriteUint8(bitsPerSample)) {
33         return false;
34     }
35     if (!parcel.WriteUint8(channelMode)) {
36         return false;
37     }
38     if (!parcel.WriteUint64(codecSpecific1)) {
39         return false;
40     }
41     if (!parcel.WriteUint64(codecSpecific2)) {
42         return false;
43     }
44     if (!parcel.WriteUint64(codecSpecific3)) {
45         return false;
46     }
47     if (!parcel.WriteUint64(codecSpecific4)) {
48         return false;
49     }
50     return true;
51 }
52 
WriteToParcel(Parcel & parcel)53 bool BluetoothA2dpCodecInfo::WriteToParcel(Parcel &parcel)
54 {
55     return Marshalling(parcel);
56 }
57 
Unmarshalling(Parcel & parcel)58 BluetoothA2dpCodecInfo *BluetoothA2dpCodecInfo::Unmarshalling(Parcel &parcel)
59 {
60     BluetoothA2dpCodecInfo *codecData = new BluetoothA2dpCodecInfo();
61     if (codecData != nullptr && !codecData->ReadFromParcel(parcel)) {
62         delete codecData;
63         codecData = nullptr;
64     }
65     return codecData;
66 }
67 
ReadFromParcel(Parcel & parcel)68 bool BluetoothA2dpCodecInfo::ReadFromParcel(Parcel &parcel)
69 {
70     if (!parcel.ReadUint8(codecPriority)) {
71         return false;
72     }
73     if (!parcel.ReadUint8(codecType)) {
74         return false;
75     }
76     if (!parcel.ReadUint32(sampleRate)) {
77         return false;
78     }
79     if (!parcel.ReadUint8(bitsPerSample)) {
80         return false;
81     }
82     if (!parcel.ReadUint8(channelMode)) {
83         return false;
84     }
85     if (!parcel.ReadUint64(codecSpecific1)) {
86         return false;
87     }
88     if (!parcel.ReadUint64(codecSpecific2)) {
89         return false;
90     }
91     if (!parcel.ReadUint64(codecSpecific3)) {
92         return false;
93     }
94     if (!parcel.ReadUint64(codecSpecific4)) {
95         return false;
96     }
97     return true;
98 }
99 
Marshalling(Parcel & parcel) const100 bool BluetoothA2dpOffloadCodecInfo::Marshalling(Parcel &parcel) const
101 {
102     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(mediaPacketHeader), false, "write mediaPacketHeader failed.");
103     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(mPt), false, "write mPt failed.");
104     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint32(ssrc), false, "write ssrc failed.");
105     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(boundaryFlag), false, "write boundaryFlag failed.");
106     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(broadcastFlag), false, "write broadcastFlag failed.");
107     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint32(codecType), false, "write codecType failed.");
108     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(maxLatency), false, "write maxLatency failed.");
109     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(scmsTEnable), false, "write scmsTEnable failed.");
110     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint32(sampleRate), false, "write sampleRate failed.");
111     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint32(encodedAudioBitrate), false, "write encodedAudioBitrate failed.");
112     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(bitsPerSample), false, "write bitsPerSample failed.");
113     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(chMode), false, "write chMode failed.");
114     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(aclHdl), false, "write aclHdl failed.");
115     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(l2cRcid), false, "write l2cRcid failed.");
116     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint16(mtu), false, "write mtu failed.");
117     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific0), false, "write codecSpecific0 failed.");
118     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific1), false, "write codecSpecific1 failed.");
119     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific2), false, "write codecSpecific2 failed.");
120     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific3), false, "write codecSpecific3 failed.");
121     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific4), false, "write codecSpecific4 failed.");
122     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific5), false, "write codecSpecific5 failed.");
123     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific6), false, "write codecSpecific6 failed.");
124     CHECK_AND_RETURN_LOG_RET(parcel.WriteUint8(codecSpecific7), false, "write codecSpecific7 failed.");
125     return true;
126 }
127 
WriteToParcel(Parcel & parcel)128 bool BluetoothA2dpOffloadCodecInfo::WriteToParcel(Parcel &parcel)
129 {
130     return Marshalling(parcel);
131 }
132 
Unmarshalling(Parcel & parcel)133 BluetoothA2dpOffloadCodecInfo *BluetoothA2dpOffloadCodecInfo::Unmarshalling(Parcel &parcel)
134 {
135     BluetoothA2dpOffloadCodecInfo *offloadCodecData = new BluetoothA2dpOffloadCodecInfo();
136     if (offloadCodecData != nullptr && !offloadCodecData->ReadFromParcel(parcel)) {
137         delete offloadCodecData;
138         offloadCodecData = nullptr;
139     }
140     return offloadCodecData;
141 }
142 
ReadFromParcel(Parcel & parcel)143 bool BluetoothA2dpOffloadCodecInfo::ReadFromParcel(Parcel &parcel)
144 {
145     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(mediaPacketHeader), false, "read mediaPacketHeader failed.");
146     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(mPt), false, "read mPt failed.");
147     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint32(ssrc), false, "read ssrc failed.");
148     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(boundaryFlag), false, "read boundaryFlag failed.");
149     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(broadcastFlag), false, "read broadcastFlag failed.");
150     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint32(codecType), false, "read codecType failed.");
151     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(maxLatency), false, "read maxLatency failed.");
152     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(scmsTEnable), false, "read scmsTEnable failed.");
153     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint32(sampleRate), false, "read sampleRate failed.");
154     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint32(encodedAudioBitrate), false, "read encodedAudioBitrate failed.");
155     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(bitsPerSample), false, "read bitsPerSample failed.");
156     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(chMode), false, "read chMode failed.");
157     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(aclHdl), false, "read aclHdl failed.");
158     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(l2cRcid), false, "read l2cRcid failed.");
159     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint16(mtu), false, "read mtu failed.");
160     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific0), false, "read codecSpecific0 failed.");
161     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific1), false, "read codecSpecific1 failed.");
162     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific2), false, "read codecSpecific2 failed.");
163     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific3), false, "read codecSpecific3 failed.");
164     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific4), false, "read codecSpecific4 failed.");
165     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific5), false, "read codecSpecific5 failed.");
166     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific6), false, "read codecSpecific6 failed.");
167     CHECK_AND_RETURN_LOG_RET(parcel.ReadUint8(codecSpecific7), false, "read codecSpecific7 failed.");
168     return true;
169 }
170 }  // namespace Bluetooth
171 }  // namespace OHOS
172