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 "microphone_descriptor.h"
17 #include "audio_system_manager.h"
18 #include "audio_service_log.h"
19
20 namespace OHOS {
21 namespace AudioStandard {
22
MicrophoneDescriptor(int32_t id,DeviceType type,int32_t groupId,int32_t sensitivity)23 MicrophoneDescriptor::MicrophoneDescriptor(int32_t id, DeviceType type, int32_t groupId, int32_t sensitivity)
24 : micId_(id), deviceType_(type), groupId_(groupId), sensitivity_(sensitivity)
25 {
26 position_ = {};
27 orientation_ = {};
28 }
29
MicrophoneDescriptor(int32_t id,DeviceType type)30 MicrophoneDescriptor::MicrophoneDescriptor(int32_t id, DeviceType type) : micId_(id), deviceType_(type)
31 {
32 sensitivity_ = 0;
33 groupId_ = 0;
34 position_ = {};
35 orientation_ = {};
36 }
37
MicrophoneDescriptor()38 MicrophoneDescriptor::MicrophoneDescriptor()
39 : MicrophoneDescriptor(0, DEVICE_TYPE_NONE)
40 {}
41
MicrophoneDescriptor(const MicrophoneDescriptor & micDescriptor)42 MicrophoneDescriptor::MicrophoneDescriptor(const MicrophoneDescriptor &micDescriptor)
43 {
44 micId_ = micDescriptor.micId_;
45 deviceType_ = micDescriptor.deviceType_;
46 groupId_ = micDescriptor.groupId_;
47 sensitivity_ = micDescriptor.sensitivity_;
48 position_ = micDescriptor.position_;
49 orientation_ = micDescriptor.orientation_;
50 }
51
MicrophoneDescriptor(const sptr<MicrophoneDescriptor> & micDescriptor)52 MicrophoneDescriptor::MicrophoneDescriptor(const sptr<MicrophoneDescriptor> &micDescriptor)
53 {
54 micId_ = micDescriptor->micId_;
55 deviceType_ = micDescriptor->deviceType_;
56 groupId_ = micDescriptor->groupId_;
57 sensitivity_ = micDescriptor->sensitivity_;
58 position_ = micDescriptor->position_;
59 orientation_ = micDescriptor->orientation_;
60 }
61
~MicrophoneDescriptor()62 MicrophoneDescriptor::~MicrophoneDescriptor()
63 {}
64
Marshalling(Parcel & parcel) const65 bool MicrophoneDescriptor::Marshalling(Parcel &parcel) const
66 {
67 parcel.WriteInt32(micId_);
68 parcel.WriteInt32(deviceType_);
69 parcel.WriteInt32(groupId_);
70 parcel.WriteInt32(sensitivity_);
71 parcel.WriteFloat(position_.x);
72 parcel.WriteFloat(position_.y);
73 parcel.WriteFloat(position_.z);
74 parcel.WriteFloat(orientation_.x);
75 parcel.WriteFloat(orientation_.y);
76 parcel.WriteFloat(orientation_.z);
77 return true;
78 }
79
Unmarshalling(Parcel & in)80 sptr<MicrophoneDescriptor> MicrophoneDescriptor::Unmarshalling(Parcel &in)
81 {
82 sptr<MicrophoneDescriptor> microphoneDescriptor = new(std::nothrow) MicrophoneDescriptor();
83 CHECK_AND_RETURN_RET(microphoneDescriptor != nullptr, nullptr);
84
85 microphoneDescriptor->micId_ = in.ReadInt32();
86 microphoneDescriptor->deviceType_ = static_cast<DeviceType>(in.ReadInt32());
87 microphoneDescriptor->groupId_ = in.ReadInt32();
88 microphoneDescriptor->sensitivity_ = in.ReadInt32();
89 microphoneDescriptor->position_.x = in.ReadFloat();
90 microphoneDescriptor->position_.y = in.ReadFloat();
91 microphoneDescriptor->position_.z = in.ReadFloat();
92 microphoneDescriptor->orientation_.x = in.ReadFloat();
93 microphoneDescriptor->orientation_.y = in.ReadFloat();
94 microphoneDescriptor->orientation_.z = in.ReadFloat();
95
96 return microphoneDescriptor;
97 }
98
SetMicPositionInfo(const Vector3D & pos)99 void MicrophoneDescriptor::SetMicPositionInfo(const Vector3D &pos)
100 {
101 position_ = pos;
102 }
103
SetMicOrientationInfo(const Vector3D & orientation)104 void MicrophoneDescriptor::SetMicOrientationInfo(const Vector3D &orientation)
105 {
106 orientation_ = orientation;
107 }
108 } // namespace AudioStandard
109 } // namespace OHOS
110