Mikhail Naganov | 7cbf2f1 | 2016-10-27 20:05:35 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <memory.h> |
| 18 | #include <stdio.h> |
| 19 | |
| 20 | #include "Conversions.h" |
| 21 | |
| 22 | namespace android { |
| 23 | namespace hardware { |
| 24 | namespace audio { |
| 25 | namespace effect { |
| 26 | namespace V2_0 { |
| 27 | namespace implementation { |
| 28 | |
| 29 | void effectDescriptorFromHal( |
| 30 | const effect_descriptor_t& halDescriptor, EffectDescriptor* descriptor) { |
| 31 | uuidFromHal(halDescriptor.type, &descriptor->type); |
| 32 | uuidFromHal(halDescriptor.uuid, &descriptor->uuid); |
| 33 | descriptor->flags = EffectFlags(halDescriptor.flags); |
| 34 | descriptor->cpuLoad = halDescriptor.cpuLoad; |
| 35 | descriptor->memoryUsage = halDescriptor.memoryUsage; |
| 36 | memcpy(descriptor->name.data(), halDescriptor.name, descriptor->name.size()); |
| 37 | memcpy(descriptor->implementor.data(), |
| 38 | halDescriptor.implementor, descriptor->implementor.size()); |
| 39 | } |
| 40 | |
| 41 | void uuidFromHal(const effect_uuid_t& halUuid, Uuid* uuid) { |
| 42 | uuid->timeLow = halUuid.timeLow; |
| 43 | uuid->timeMid = halUuid.timeMid; |
| 44 | uuid->versionAndTimeHigh = halUuid.timeHiAndVersion; |
| 45 | uuid->variantAndClockSeqHigh = halUuid.clockSeq; |
| 46 | memcpy(uuid->node.data(), halUuid.node, uuid->node.size()); |
| 47 | } |
| 48 | |
| 49 | void uuidToHal(const Uuid& uuid, effect_uuid_t* halUuid) { |
| 50 | halUuid->timeLow = uuid.timeLow; |
| 51 | halUuid->timeMid = uuid.timeMid; |
| 52 | halUuid->timeHiAndVersion = uuid.versionAndTimeHigh; |
| 53 | halUuid->clockSeq = uuid.variantAndClockSeqHigh; |
| 54 | memcpy(halUuid->node, uuid.node.data(), uuid.node.size()); |
| 55 | } |
| 56 | |
| 57 | std::string uuidToString(const effect_uuid_t& halUuid) { |
| 58 | char str[64]; |
| 59 | snprintf(str, sizeof(str), "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x", |
| 60 | halUuid.timeLow, |
| 61 | halUuid.timeMid, |
| 62 | halUuid.timeHiAndVersion, |
| 63 | halUuid.clockSeq, |
| 64 | halUuid.node[0], |
| 65 | halUuid.node[1], |
| 66 | halUuid.node[2], |
| 67 | halUuid.node[3], |
| 68 | halUuid.node[4], |
| 69 | halUuid.node[5]); |
| 70 | return str; |
| 71 | } |
| 72 | |
| 73 | } // namespace implementation |
| 74 | } // namespace V2_0 |
| 75 | } // namespace effect |
| 76 | } // namespace audio |
| 77 | } // namespace hardware |
| 78 | } // namespace android |