2016-11-16 16:30:17 -08:00
|
|
|
/*
|
Audio HAL: Factorize V2 and V4 like libaudiohal
Use the same technique developed for the simpler libaudiohal to
factorize the audio HAL impl.
Generated with script:
set -euo pipefail
cd hardware/interfaces/audio
# Make 2.0 and 4.0 files mostly identical by removing all 2.0, V4.0...
# and replacing it by CPP_VERSION and FILE_VERSION
# This allow both implementation to be mostly identical, except for code difference
# Also remove IncludeGuard.h as it will be included from compiler flag
# Also update license to 2018
find -name *.cpp -o -name *h |
grep -v -e service.cpp |
xargs sed -Ei \
-e 's/(#.*)V[42]_0_(.*_H_?)$/\1\2/' \
-e 's/(LOG_TAG.*)[24]_0/\1/' \
-e '/#ifndef AUDIO_HAL_VERSION/,/#endif/d' \
-e '/^#.*def.*AUDIO_HAL_VERSION\b/d' \
-e's/V[42]_0/CPP_VERSION/' \
-e 's/(#include ).(android.*)[24].0(.*).$/\1PATH(\2FILE_VERSION\3)/' \
-e 's|(#include) .(.*)[24].0/(default/.*).$|\1 "\2\3"|' \
-e 's/\bAUDIO_HAL_VERSION\b/CPP_VERSION/' \
-e '/IncludeGuard.h/d' \
-e 's/(Copyright .C. 201)./\18/'
# set MAJOR_VERSION instead of having a different macro for each version
# this allow to do preprocessor arithmetic (eg: MAJOR_VERSION >= 4)
for v in 2 4; do
find -ipath '*/'$v'.0/*/Android.bp' |
xargs sed -i -e '/cflags:/,/^$/d' -e '/vndk/{:a;/}/!{N;ba};d}' -e '$i\
cflags: [\
"-DMAJOR_VERSION='$v'",\
"-DMINOR_VERSION=0",\
"-include common/all-versions/VersionMacro.h",\
]'; done
# replace# ifdef VERSION_X by #if MAJOR_VERSION == X
find -path *all-versions/*.h |
xargs sed -Ei -e 's/def.*AUDIO_HAL_VERSION_([24])_0.*/ MAJOR_VERSION == \1/' \
-e 'T;s/ +/ /'
# copy all-versions impl in each version impl
find -path '*/[24].0/*.[hc]*' |
grep -ve all-versions -e test |
xargs -P99 -n4 sed -i -Ee '/include <.*all-versions.default/!b' \
-e 's#.*<#find -path */#' -e 's/>$/|xargs tail -n +16/' -e e
# remove all-versions impl
rm -r {core,effect}/all-versions/
# merge version impl into a single all-version
for dir in core/*.0/vts/functional/*.0/ ;do
dest=$(echo $dir | sed 's#/..0/#/all-versions/#')
mkdir -p $dest
mv -T $dir $dest
done
find -mindepth 3 -path '*/2.0/*' -a \( -name '*cpp' -o -name '*h' \) |
grep -v 'all-versions' |
sed -E 'h;s/2/4/g;H;s/4.0/all-versions/;s/4.0//;H;g;s/\n/ /g;'|
xargs -P99 -L1 sh -c '
set -euo pipefail
mkdir -p $(dirname $2);
diff --old-group-format="#if MAJOR_VERSION == 2
%<#endif
" \
--new-group-format="#if MAJOR_VERSION == 4
%>#endif
" $0 $1 > $2 || true;
rm $0 $1'
# merge the X.0 Android.bp & OWNERS in the all-versions
for dir in common effect core; do
for sub in default vts/functional; do
test -f $dir/2.0/$sub/Android.bp || continue
awk 1 $dir/*.0/$sub/Android.bp >> $dir/all-versions/$sub/Android.bp
# delete licenses except for the first one and add whitelines
sed -i -e '/^}$/{N;/^}\n$/!s/\n/&\n/}' $dir/all-versions/$sub/Android.bp
sed -i -e '1,17b;/^\/\//,/^$/{d}' $dir/all-versions/$sub/Android.bp
done
for sub in default vts; do
test -d $dir/2.0/$sub || continue
test -f $dir/2.0/$sub/OWNERS &&
awk 1 $dir/*.0/$sub/OWNERS | sort -u > $dir/all-versions/$sub/OWNERS ||
true
rm -r $dir/*.0/$sub
done
done
# delete all-versions-impl dependencies
find -name 'Android.bp' | xargs sed -i -e '/all-versions-impl/d'
# cleanup unused files
rm common/all-versions/default/include/common/all-versions/default/HidlUtils*
rm common/all-versions/util/include/common/all-versions/IncludeGuard.h
find -depth -type d -empty -delete
# Clamp consecutive number of empty lines to 2
find -name *.cpp -o -name *h | xargs sed -Ei ':a;/^\n*$/{N;ba};s/\n\n+/\n\n/'
# transform #endif\n#if to #elif
find -name *.cpp -o -name *h | xargs sed -i '/^#endif/{N;s/.*\n#if/#elif/}'
# remove leftover include guard in cpp
find -name *.cpp |xargs sed -Ei '/^#.*_H_?$/d'
# apply clang-format
find -name *cpp -o -name *h |
xargs ../../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang-format --style file -i
# clang format breaks PATH(a/b) to PATH(a / b), remove the space surrounding /
find -name *cpp -o -name *h | xargs sed -i "/#include PATH/s# / #/#g"
Test: compile
Bug: 118203066
Change-Id: I3692a444307afc5f71064fe0b9e6b8af3c9ff1dd
Signed-off-by: Kevin Rocard <krocard@google.com>
2018-11-14 16:22:07 -08:00
|
|
|
* Copyright (C) 2018 The Android Open Source Project
|
2016-11-16 16:30:17 -08:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
Audio HAL: Factorize V2 and V4 like libaudiohal
Use the same technique developed for the simpler libaudiohal to
factorize the audio HAL impl.
Generated with script:
set -euo pipefail
cd hardware/interfaces/audio
# Make 2.0 and 4.0 files mostly identical by removing all 2.0, V4.0...
# and replacing it by CPP_VERSION and FILE_VERSION
# This allow both implementation to be mostly identical, except for code difference
# Also remove IncludeGuard.h as it will be included from compiler flag
# Also update license to 2018
find -name *.cpp -o -name *h |
grep -v -e service.cpp |
xargs sed -Ei \
-e 's/(#.*)V[42]_0_(.*_H_?)$/\1\2/' \
-e 's/(LOG_TAG.*)[24]_0/\1/' \
-e '/#ifndef AUDIO_HAL_VERSION/,/#endif/d' \
-e '/^#.*def.*AUDIO_HAL_VERSION\b/d' \
-e's/V[42]_0/CPP_VERSION/' \
-e 's/(#include ).(android.*)[24].0(.*).$/\1PATH(\2FILE_VERSION\3)/' \
-e 's|(#include) .(.*)[24].0/(default/.*).$|\1 "\2\3"|' \
-e 's/\bAUDIO_HAL_VERSION\b/CPP_VERSION/' \
-e '/IncludeGuard.h/d' \
-e 's/(Copyright .C. 201)./\18/'
# set MAJOR_VERSION instead of having a different macro for each version
# this allow to do preprocessor arithmetic (eg: MAJOR_VERSION >= 4)
for v in 2 4; do
find -ipath '*/'$v'.0/*/Android.bp' |
xargs sed -i -e '/cflags:/,/^$/d' -e '/vndk/{:a;/}/!{N;ba};d}' -e '$i\
cflags: [\
"-DMAJOR_VERSION='$v'",\
"-DMINOR_VERSION=0",\
"-include common/all-versions/VersionMacro.h",\
]'; done
# replace# ifdef VERSION_X by #if MAJOR_VERSION == X
find -path *all-versions/*.h |
xargs sed -Ei -e 's/def.*AUDIO_HAL_VERSION_([24])_0.*/ MAJOR_VERSION == \1/' \
-e 'T;s/ +/ /'
# copy all-versions impl in each version impl
find -path '*/[24].0/*.[hc]*' |
grep -ve all-versions -e test |
xargs -P99 -n4 sed -i -Ee '/include <.*all-versions.default/!b' \
-e 's#.*<#find -path */#' -e 's/>$/|xargs tail -n +16/' -e e
# remove all-versions impl
rm -r {core,effect}/all-versions/
# merge version impl into a single all-version
for dir in core/*.0/vts/functional/*.0/ ;do
dest=$(echo $dir | sed 's#/..0/#/all-versions/#')
mkdir -p $dest
mv -T $dir $dest
done
find -mindepth 3 -path '*/2.0/*' -a \( -name '*cpp' -o -name '*h' \) |
grep -v 'all-versions' |
sed -E 'h;s/2/4/g;H;s/4.0/all-versions/;s/4.0//;H;g;s/\n/ /g;'|
xargs -P99 -L1 sh -c '
set -euo pipefail
mkdir -p $(dirname $2);
diff --old-group-format="#if MAJOR_VERSION == 2
%<#endif
" \
--new-group-format="#if MAJOR_VERSION == 4
%>#endif
" $0 $1 > $2 || true;
rm $0 $1'
# merge the X.0 Android.bp & OWNERS in the all-versions
for dir in common effect core; do
for sub in default vts/functional; do
test -f $dir/2.0/$sub/Android.bp || continue
awk 1 $dir/*.0/$sub/Android.bp >> $dir/all-versions/$sub/Android.bp
# delete licenses except for the first one and add whitelines
sed -i -e '/^}$/{N;/^}\n$/!s/\n/&\n/}' $dir/all-versions/$sub/Android.bp
sed -i -e '1,17b;/^\/\//,/^$/{d}' $dir/all-versions/$sub/Android.bp
done
for sub in default vts; do
test -d $dir/2.0/$sub || continue
test -f $dir/2.0/$sub/OWNERS &&
awk 1 $dir/*.0/$sub/OWNERS | sort -u > $dir/all-versions/$sub/OWNERS ||
true
rm -r $dir/*.0/$sub
done
done
# delete all-versions-impl dependencies
find -name 'Android.bp' | xargs sed -i -e '/all-versions-impl/d'
# cleanup unused files
rm common/all-versions/default/include/common/all-versions/default/HidlUtils*
rm common/all-versions/util/include/common/all-versions/IncludeGuard.h
find -depth -type d -empty -delete
# Clamp consecutive number of empty lines to 2
find -name *.cpp -o -name *h | xargs sed -Ei ':a;/^\n*$/{N;ba};s/\n\n+/\n\n/'
# transform #endif\n#if to #elif
find -name *.cpp -o -name *h | xargs sed -i '/^#endif/{N;s/.*\n#if/#elif/}'
# remove leftover include guard in cpp
find -name *.cpp |xargs sed -Ei '/^#.*_H_?$/d'
# apply clang-format
find -name *cpp -o -name *h |
xargs ../../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang-format --style file -i
# clang format breaks PATH(a/b) to PATH(a / b), remove the space surrounding /
find -name *cpp -o -name *h | xargs sed -i "/#include PATH/s# / #/#g"
Test: compile
Bug: 118203066
Change-Id: I3692a444307afc5f71064fe0b9e6b8af3c9ff1dd
Signed-off-by: Kevin Rocard <krocard@google.com>
2018-11-14 16:22:07 -08:00
|
|
|
#include "HidlUtils.h"
|
2016-11-16 16:30:17 -08:00
|
|
|
|
2018-02-26 18:45:07 -08:00
|
|
|
#include <common/all-versions/VersionUtils.h>
|
2017-12-14 18:39:39 -08:00
|
|
|
#include <string.h>
|
2016-11-16 16:30:17 -08:00
|
|
|
|
2018-11-13 10:41:53 -08:00
|
|
|
using ::android::hardware::audio::common::utils::EnumBitfield;
|
2018-02-26 18:45:07 -08:00
|
|
|
|
2016-11-16 16:30:17 -08:00
|
|
|
namespace android {
|
2017-12-14 18:39:39 -08:00
|
|
|
namespace hardware {
|
|
|
|
|
namespace audio {
|
|
|
|
|
namespace common {
|
Audio HAL: Factorize V2 and V4 like libaudiohal
Use the same technique developed for the simpler libaudiohal to
factorize the audio HAL impl.
Generated with script:
set -euo pipefail
cd hardware/interfaces/audio
# Make 2.0 and 4.0 files mostly identical by removing all 2.0, V4.0...
# and replacing it by CPP_VERSION and FILE_VERSION
# This allow both implementation to be mostly identical, except for code difference
# Also remove IncludeGuard.h as it will be included from compiler flag
# Also update license to 2018
find -name *.cpp -o -name *h |
grep -v -e service.cpp |
xargs sed -Ei \
-e 's/(#.*)V[42]_0_(.*_H_?)$/\1\2/' \
-e 's/(LOG_TAG.*)[24]_0/\1/' \
-e '/#ifndef AUDIO_HAL_VERSION/,/#endif/d' \
-e '/^#.*def.*AUDIO_HAL_VERSION\b/d' \
-e's/V[42]_0/CPP_VERSION/' \
-e 's/(#include ).(android.*)[24].0(.*).$/\1PATH(\2FILE_VERSION\3)/' \
-e 's|(#include) .(.*)[24].0/(default/.*).$|\1 "\2\3"|' \
-e 's/\bAUDIO_HAL_VERSION\b/CPP_VERSION/' \
-e '/IncludeGuard.h/d' \
-e 's/(Copyright .C. 201)./\18/'
# set MAJOR_VERSION instead of having a different macro for each version
# this allow to do preprocessor arithmetic (eg: MAJOR_VERSION >= 4)
for v in 2 4; do
find -ipath '*/'$v'.0/*/Android.bp' |
xargs sed -i -e '/cflags:/,/^$/d' -e '/vndk/{:a;/}/!{N;ba};d}' -e '$i\
cflags: [\
"-DMAJOR_VERSION='$v'",\
"-DMINOR_VERSION=0",\
"-include common/all-versions/VersionMacro.h",\
]'; done
# replace# ifdef VERSION_X by #if MAJOR_VERSION == X
find -path *all-versions/*.h |
xargs sed -Ei -e 's/def.*AUDIO_HAL_VERSION_([24])_0.*/ MAJOR_VERSION == \1/' \
-e 'T;s/ +/ /'
# copy all-versions impl in each version impl
find -path '*/[24].0/*.[hc]*' |
grep -ve all-versions -e test |
xargs -P99 -n4 sed -i -Ee '/include <.*all-versions.default/!b' \
-e 's#.*<#find -path */#' -e 's/>$/|xargs tail -n +16/' -e e
# remove all-versions impl
rm -r {core,effect}/all-versions/
# merge version impl into a single all-version
for dir in core/*.0/vts/functional/*.0/ ;do
dest=$(echo $dir | sed 's#/..0/#/all-versions/#')
mkdir -p $dest
mv -T $dir $dest
done
find -mindepth 3 -path '*/2.0/*' -a \( -name '*cpp' -o -name '*h' \) |
grep -v 'all-versions' |
sed -E 'h;s/2/4/g;H;s/4.0/all-versions/;s/4.0//;H;g;s/\n/ /g;'|
xargs -P99 -L1 sh -c '
set -euo pipefail
mkdir -p $(dirname $2);
diff --old-group-format="#if MAJOR_VERSION == 2
%<#endif
" \
--new-group-format="#if MAJOR_VERSION == 4
%>#endif
" $0 $1 > $2 || true;
rm $0 $1'
# merge the X.0 Android.bp & OWNERS in the all-versions
for dir in common effect core; do
for sub in default vts/functional; do
test -f $dir/2.0/$sub/Android.bp || continue
awk 1 $dir/*.0/$sub/Android.bp >> $dir/all-versions/$sub/Android.bp
# delete licenses except for the first one and add whitelines
sed -i -e '/^}$/{N;/^}\n$/!s/\n/&\n/}' $dir/all-versions/$sub/Android.bp
sed -i -e '1,17b;/^\/\//,/^$/{d}' $dir/all-versions/$sub/Android.bp
done
for sub in default vts; do
test -d $dir/2.0/$sub || continue
test -f $dir/2.0/$sub/OWNERS &&
awk 1 $dir/*.0/$sub/OWNERS | sort -u > $dir/all-versions/$sub/OWNERS ||
true
rm -r $dir/*.0/$sub
done
done
# delete all-versions-impl dependencies
find -name 'Android.bp' | xargs sed -i -e '/all-versions-impl/d'
# cleanup unused files
rm common/all-versions/default/include/common/all-versions/default/HidlUtils*
rm common/all-versions/util/include/common/all-versions/IncludeGuard.h
find -depth -type d -empty -delete
# Clamp consecutive number of empty lines to 2
find -name *.cpp -o -name *h | xargs sed -Ei ':a;/^\n*$/{N;ba};s/\n\n+/\n\n/'
# transform #endif\n#if to #elif
find -name *.cpp -o -name *h | xargs sed -i '/^#endif/{N;s/.*\n#if/#elif/}'
# remove leftover include guard in cpp
find -name *.cpp |xargs sed -Ei '/^#.*_H_?$/d'
# apply clang-format
find -name *cpp -o -name *h |
xargs ../../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang-format --style file -i
# clang format breaks PATH(a/b) to PATH(a / b), remove the space surrounding /
find -name *cpp -o -name *h | xargs sed -i "/#include PATH/s# / #/#g"
Test: compile
Bug: 118203066
Change-Id: I3692a444307afc5f71064fe0b9e6b8af3c9ff1dd
Signed-off-by: Kevin Rocard <krocard@google.com>
2018-11-14 16:22:07 -08:00
|
|
|
namespace CPP_VERSION {
|
2018-12-11 16:36:53 -08:00
|
|
|
namespace implementation {
|
|
|
|
|
|
2020-02-14 15:39:55 -08:00
|
|
|
status_t HidlUtils::audioConfigFromHal(const audio_config_t& halConfig, AudioConfig* config) {
|
2016-11-16 16:30:17 -08:00
|
|
|
config->sampleRateHz = halConfig.sample_rate;
|
2018-11-13 10:41:53 -08:00
|
|
|
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
|
2016-11-16 16:30:17 -08:00
|
|
|
config->format = AudioFormat(halConfig.format);
|
2020-02-14 15:39:55 -08:00
|
|
|
status_t status = audioOffloadInfoFromHal(halConfig.offload_info, &config->offloadInfo);
|
2016-11-16 16:30:17 -08:00
|
|
|
config->frameCount = halConfig.frame_count;
|
2020-02-14 15:39:55 -08:00
|
|
|
return status;
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::audioConfigToHal(const AudioConfig& config, audio_config_t* halConfig) {
|
|
|
|
|
memset(halConfig, 0, sizeof(audio_config_t));
|
|
|
|
|
halConfig->sample_rate = config.sampleRateHz;
|
|
|
|
|
halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
|
|
|
|
|
halConfig->format = static_cast<audio_format_t>(config.format);
|
|
|
|
|
audioOffloadInfoToHal(config.offloadInfo, &halConfig->offload_info);
|
|
|
|
|
halConfig->frame_count = config.frameCount;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioGainConfigFromHal(const struct audio_gain_config& halConfig,
|
|
|
|
|
AudioGainConfig* config) {
|
2016-11-16 16:30:17 -08:00
|
|
|
config->index = halConfig.index;
|
2018-11-13 10:41:53 -08:00
|
|
|
config->mode = EnumBitfield<AudioGainMode>(halConfig.mode);
|
|
|
|
|
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
|
2016-11-16 16:30:17 -08:00
|
|
|
for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
|
|
|
|
|
config->values[i] = halConfig.values[i];
|
|
|
|
|
}
|
|
|
|
|
config->rampDurationMs = halConfig.ramp_duration_ms;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioGainConfigToHal(const AudioGainConfig& config,
|
|
|
|
|
struct audio_gain_config* halConfig) {
|
2016-11-16 16:30:17 -08:00
|
|
|
halConfig->index = config.index;
|
|
|
|
|
halConfig->mode = static_cast<audio_gain_mode_t>(config.mode);
|
|
|
|
|
halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
|
|
|
|
|
memset(halConfig->values, 0, sizeof(halConfig->values));
|
|
|
|
|
for (size_t i = 0; i < sizeof(audio_channel_mask_t) * 8; ++i) {
|
|
|
|
|
halConfig->values[i] = config.values[i];
|
|
|
|
|
}
|
|
|
|
|
halConfig->ramp_duration_ms = config.rampDurationMs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::audioGainFromHal(const struct audio_gain& halGain, AudioGain* gain) {
|
2018-11-13 10:41:53 -08:00
|
|
|
gain->mode = EnumBitfield<AudioGainMode>(halGain.mode);
|
|
|
|
|
gain->channelMask = EnumBitfield<AudioChannelMask>(halGain.channel_mask);
|
2016-11-16 16:30:17 -08:00
|
|
|
gain->minValue = halGain.min_value;
|
|
|
|
|
gain->maxValue = halGain.max_value;
|
|
|
|
|
gain->defaultValue = halGain.default_value;
|
|
|
|
|
gain->stepValue = halGain.step_value;
|
|
|
|
|
gain->minRampMs = halGain.min_ramp_ms;
|
|
|
|
|
gain->maxRampMs = halGain.max_ramp_ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::audioGainToHal(const AudioGain& gain, struct audio_gain* halGain) {
|
|
|
|
|
halGain->mode = static_cast<audio_gain_mode_t>(gain.mode);
|
|
|
|
|
halGain->channel_mask = static_cast<audio_channel_mask_t>(gain.channelMask);
|
|
|
|
|
halGain->min_value = gain.minValue;
|
|
|
|
|
halGain->max_value = gain.maxValue;
|
|
|
|
|
halGain->default_value = gain.defaultValue;
|
|
|
|
|
halGain->step_value = gain.stepValue;
|
|
|
|
|
halGain->min_ramp_ms = gain.minRampMs;
|
|
|
|
|
halGain->max_ramp_ms = gain.maxRampMs;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 18:43:39 -08:00
|
|
|
AudioUsage HidlUtils::audioUsageFromHal(const audio_usage_t halUsage) {
|
|
|
|
|
switch (halUsage) {
|
|
|
|
|
case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_REQUEST:
|
|
|
|
|
case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_INSTANT:
|
|
|
|
|
case AUDIO_USAGE_NOTIFICATION_COMMUNICATION_DELAYED:
|
|
|
|
|
case AUDIO_USAGE_NOTIFICATION_EVENT:
|
|
|
|
|
return AudioUsage::NOTIFICATION;
|
|
|
|
|
default:
|
|
|
|
|
return static_cast<AudioUsage>(halUsage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
audio_usage_t HidlUtils::audioUsageToHal(const AudioUsage usage) {
|
|
|
|
|
return static_cast<audio_usage_t>(usage);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 15:39:55 -08:00
|
|
|
status_t HidlUtils::audioOffloadInfoFromHal(const audio_offload_info_t& halOffload,
|
|
|
|
|
AudioOffloadInfo* offload) {
|
2016-11-16 16:30:17 -08:00
|
|
|
offload->sampleRateHz = halOffload.sample_rate;
|
2018-11-13 10:41:53 -08:00
|
|
|
offload->channelMask = EnumBitfield<AudioChannelMask>(halOffload.channel_mask);
|
2016-12-16 17:18:08 -08:00
|
|
|
offload->format = AudioFormat(halOffload.format);
|
2016-11-16 16:30:17 -08:00
|
|
|
offload->streamType = AudioStreamType(halOffload.stream_type);
|
|
|
|
|
offload->bitRatePerSecond = halOffload.bit_rate;
|
|
|
|
|
offload->durationMicroseconds = halOffload.duration_us;
|
|
|
|
|
offload->hasVideo = halOffload.has_video;
|
|
|
|
|
offload->isStreaming = halOffload.is_streaming;
|
2017-04-06 18:27:34 -07:00
|
|
|
offload->bitWidth = halOffload.bit_width;
|
|
|
|
|
offload->bufferSize = halOffload.offload_buffer_size;
|
2018-02-23 18:43:39 -08:00
|
|
|
offload->usage = audioUsageFromHal(halOffload.usage);
|
2020-02-14 15:39:55 -08:00
|
|
|
#if MAJOR_VERSION >= 6
|
|
|
|
|
if (halOffload.version >= AUDIO_OFFLOAD_INFO_VERSION_0_2) {
|
|
|
|
|
offload->encapsulationMode =
|
|
|
|
|
static_cast<AudioEncapsulationMode>(halOffload.encapsulation_mode);
|
|
|
|
|
offload->contentId = halOffload.content_id;
|
|
|
|
|
offload->syncId = halOffload.sync_id;
|
|
|
|
|
} else {
|
|
|
|
|
offload->encapsulationMode = AudioEncapsulationMode::NONE;
|
|
|
|
|
offload->contentId = 0;
|
|
|
|
|
offload->syncId = 0;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
// nonzero values here are not compatible with HAL versions below 6.
|
|
|
|
|
if (halOffload.version >= AUDIO_OFFLOAD_INFO_VERSION_0_2 &&
|
|
|
|
|
(halOffload.encapsulation_mode != AUDIO_ENCAPSULATION_MODE_NONE ||
|
|
|
|
|
halOffload.content_id != 0 || halOffload.sync_id != 0)) {
|
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return OK;
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioOffloadInfoToHal(const AudioOffloadInfo& offload,
|
|
|
|
|
audio_offload_info_t* halOffload) {
|
2016-11-16 16:30:17 -08:00
|
|
|
*halOffload = AUDIO_INFO_INITIALIZER;
|
|
|
|
|
halOffload->sample_rate = offload.sampleRateHz;
|
|
|
|
|
halOffload->channel_mask = static_cast<audio_channel_mask_t>(offload.channelMask);
|
2016-12-16 17:18:08 -08:00
|
|
|
halOffload->format = static_cast<audio_format_t>(offload.format);
|
2016-11-16 16:30:17 -08:00
|
|
|
halOffload->stream_type = static_cast<audio_stream_type_t>(offload.streamType);
|
|
|
|
|
halOffload->bit_rate = offload.bitRatePerSecond;
|
|
|
|
|
halOffload->duration_us = offload.durationMicroseconds;
|
|
|
|
|
halOffload->has_video = offload.hasVideo;
|
|
|
|
|
halOffload->is_streaming = offload.isStreaming;
|
Audio HAL: extensions for new SoC features
Extended audio offload structure: added support to add bit_width,
offload buffer size and usage info.
Add support for direct PCM audio stream. Direct PCM stream
is used when pcm data required post processing in DSP. Direct PCM
stream is used for both track offload and PCM offload.
Add audio proxy source device.
Add support for additional audio formats: EVRC, QCELP, WMA, WMA,
AAC_ADIF, AMR, MP2, FLAC, ALAC, APE, DSD, LDAC.
Extend audio channel mask.
Test: make
Change-Id: I02d2f1fff6fa467688c1bad158ae18b5fa8c0f5b
2016-11-21 18:33:52 -08:00
|
|
|
halOffload->bit_width = offload.bitWidth;
|
|
|
|
|
halOffload->offload_buffer_size = offload.bufferSize;
|
2018-02-23 18:43:39 -08:00
|
|
|
halOffload->usage = audioUsageToHal(offload.usage);
|
2020-02-14 15:39:55 -08:00
|
|
|
#if MAJOR_VERSION >= 6
|
|
|
|
|
halOffload->encapsulation_mode =
|
|
|
|
|
static_cast<audio_encapsulation_mode_t>(offload.encapsulationMode);
|
|
|
|
|
halOffload->content_id = offload.contentId;
|
|
|
|
|
halOffload->sync_id = offload.syncId;
|
|
|
|
|
#else
|
|
|
|
|
// offload doesn't contain encapsulationMode, contentId, syncId, so this is OK.
|
|
|
|
|
#endif
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioPortConfigFromHal(const struct audio_port_config& halConfig,
|
|
|
|
|
AudioPortConfig* config) {
|
2016-11-16 16:30:17 -08:00
|
|
|
config->id = halConfig.id;
|
|
|
|
|
config->role = AudioPortRole(halConfig.role);
|
|
|
|
|
config->type = AudioPortType(halConfig.type);
|
2018-11-13 10:41:53 -08:00
|
|
|
config->configMask = EnumBitfield<AudioPortConfigMask>(halConfig.config_mask);
|
2016-11-16 16:30:17 -08:00
|
|
|
config->sampleRateHz = halConfig.sample_rate;
|
2018-11-13 10:41:53 -08:00
|
|
|
config->channelMask = EnumBitfield<AudioChannelMask>(halConfig.channel_mask);
|
2016-11-16 16:30:17 -08:00
|
|
|
config->format = AudioFormat(halConfig.format);
|
|
|
|
|
audioGainConfigFromHal(halConfig.gain, &config->gain);
|
|
|
|
|
switch (halConfig.type) {
|
2017-12-14 18:50:12 -08:00
|
|
|
case AUDIO_PORT_TYPE_NONE:
|
|
|
|
|
break;
|
2016-11-16 16:30:17 -08:00
|
|
|
case AUDIO_PORT_TYPE_DEVICE: {
|
|
|
|
|
config->ext.device.hwModule = halConfig.ext.device.hw_module;
|
|
|
|
|
config->ext.device.type = AudioDevice(halConfig.ext.device.type);
|
2017-12-14 18:50:12 -08:00
|
|
|
memcpy(config->ext.device.address.data(), halConfig.ext.device.address,
|
|
|
|
|
AUDIO_DEVICE_MAX_ADDRESS_LEN);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AUDIO_PORT_TYPE_MIX: {
|
|
|
|
|
config->ext.mix.hwModule = halConfig.ext.mix.hw_module;
|
|
|
|
|
config->ext.mix.ioHandle = halConfig.ext.mix.handle;
|
|
|
|
|
if (halConfig.role == AUDIO_PORT_ROLE_SOURCE) {
|
|
|
|
|
config->ext.mix.useCase.stream = AudioStreamType(halConfig.ext.mix.usecase.stream);
|
2018-07-09 14:28:57 -07:00
|
|
|
} else if (halConfig.role == AUDIO_PORT_ROLE_SINK) {
|
|
|
|
|
config->ext.mix.useCase.source = AudioSource(halConfig.ext.mix.usecase.source);
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AUDIO_PORT_TYPE_SESSION: {
|
|
|
|
|
config->ext.session.session = halConfig.ext.session.session;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioPortConfigToHal(const AudioPortConfig& config,
|
|
|
|
|
struct audio_port_config* halConfig) {
|
2016-11-16 16:30:17 -08:00
|
|
|
memset(halConfig, 0, sizeof(audio_port_config));
|
|
|
|
|
halConfig->id = config.id;
|
|
|
|
|
halConfig->role = static_cast<audio_port_role_t>(config.role);
|
|
|
|
|
halConfig->type = static_cast<audio_port_type_t>(config.type);
|
|
|
|
|
halConfig->config_mask = static_cast<unsigned int>(config.configMask);
|
|
|
|
|
halConfig->sample_rate = config.sampleRateHz;
|
|
|
|
|
halConfig->channel_mask = static_cast<audio_channel_mask_t>(config.channelMask);
|
|
|
|
|
halConfig->format = static_cast<audio_format_t>(config.format);
|
|
|
|
|
audioGainConfigToHal(config.gain, &halConfig->gain);
|
|
|
|
|
switch (config.type) {
|
2017-12-14 18:50:12 -08:00
|
|
|
case AudioPortType::NONE:
|
|
|
|
|
break;
|
2016-11-16 16:30:17 -08:00
|
|
|
case AudioPortType::DEVICE: {
|
|
|
|
|
halConfig->ext.device.hw_module = config.ext.device.hwModule;
|
|
|
|
|
halConfig->ext.device.type = static_cast<audio_devices_t>(config.ext.device.type);
|
2017-12-14 18:50:12 -08:00
|
|
|
memcpy(halConfig->ext.device.address, config.ext.device.address.data(),
|
|
|
|
|
AUDIO_DEVICE_MAX_ADDRESS_LEN);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AudioPortType::MIX: {
|
|
|
|
|
halConfig->ext.mix.hw_module = config.ext.mix.hwModule;
|
|
|
|
|
halConfig->ext.mix.handle = config.ext.mix.ioHandle;
|
|
|
|
|
if (config.role == AudioPortRole::SOURCE) {
|
|
|
|
|
halConfig->ext.mix.usecase.stream =
|
2017-12-14 18:50:12 -08:00
|
|
|
static_cast<audio_stream_type_t>(config.ext.mix.useCase.stream);
|
2018-07-09 14:28:57 -07:00
|
|
|
} else if (config.role == AudioPortRole::SINK) {
|
|
|
|
|
halConfig->ext.mix.usecase.source =
|
|
|
|
|
static_cast<audio_source_t>(config.ext.mix.useCase.source);
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AudioPortType::SESSION: {
|
|
|
|
|
halConfig->ext.session.session =
|
2017-12-14 18:50:12 -08:00
|
|
|
static_cast<audio_session_t>(config.ext.session.session);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
void HidlUtils::audioPortConfigsFromHal(unsigned int numHalConfigs,
|
|
|
|
|
const struct audio_port_config* halConfigs,
|
|
|
|
|
hidl_vec<AudioPortConfig>* configs) {
|
2016-11-16 16:30:17 -08:00
|
|
|
configs->resize(numHalConfigs);
|
|
|
|
|
for (unsigned int i = 0; i < numHalConfigs; ++i) {
|
|
|
|
|
audioPortConfigFromHal(halConfigs[i], &(*configs)[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<audio_port_config[]> HidlUtils::audioPortConfigsToHal(
|
2017-12-14 18:50:12 -08:00
|
|
|
const hidl_vec<AudioPortConfig>& configs) {
|
2016-11-16 16:30:17 -08:00
|
|
|
std::unique_ptr<audio_port_config[]> halConfigs(new audio_port_config[configs.size()]);
|
|
|
|
|
for (size_t i = 0; i < configs.size(); ++i) {
|
|
|
|
|
audioPortConfigToHal(configs[i], &halConfigs[i]);
|
|
|
|
|
}
|
|
|
|
|
return halConfigs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::audioPortFromHal(const struct audio_port& halPort, AudioPort* port) {
|
|
|
|
|
port->id = halPort.id;
|
|
|
|
|
port->role = AudioPortRole(halPort.role);
|
|
|
|
|
port->type = AudioPortType(halPort.type);
|
|
|
|
|
port->name.setToExternal(halPort.name, strlen(halPort.name));
|
|
|
|
|
port->sampleRates.resize(halPort.num_sample_rates);
|
|
|
|
|
for (size_t i = 0; i < halPort.num_sample_rates; ++i) {
|
|
|
|
|
port->sampleRates[i] = halPort.sample_rates[i];
|
|
|
|
|
}
|
|
|
|
|
port->channelMasks.resize(halPort.num_channel_masks);
|
|
|
|
|
for (size_t i = 0; i < halPort.num_channel_masks; ++i) {
|
2018-11-13 10:41:53 -08:00
|
|
|
port->channelMasks[i] = EnumBitfield<AudioChannelMask>(halPort.channel_masks[i]);
|
2016-11-16 16:30:17 -08:00
|
|
|
}
|
|
|
|
|
port->formats.resize(halPort.num_formats);
|
|
|
|
|
for (size_t i = 0; i < halPort.num_formats; ++i) {
|
|
|
|
|
port->formats[i] = AudioFormat(halPort.formats[i]);
|
|
|
|
|
}
|
|
|
|
|
port->gains.resize(halPort.num_gains);
|
|
|
|
|
for (size_t i = 0; i < halPort.num_gains; ++i) {
|
|
|
|
|
audioGainFromHal(halPort.gains[i], &port->gains[i]);
|
|
|
|
|
}
|
|
|
|
|
audioPortConfigFromHal(halPort.active_config, &port->activeConfig);
|
|
|
|
|
switch (halPort.type) {
|
2017-12-14 18:50:12 -08:00
|
|
|
case AUDIO_PORT_TYPE_NONE:
|
|
|
|
|
break;
|
2016-11-16 16:30:17 -08:00
|
|
|
case AUDIO_PORT_TYPE_DEVICE: {
|
|
|
|
|
port->ext.device.hwModule = halPort.ext.device.hw_module;
|
|
|
|
|
port->ext.device.type = AudioDevice(halPort.ext.device.type);
|
2017-12-14 18:50:12 -08:00
|
|
|
memcpy(port->ext.device.address.data(), halPort.ext.device.address,
|
|
|
|
|
AUDIO_DEVICE_MAX_ADDRESS_LEN);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AUDIO_PORT_TYPE_MIX: {
|
|
|
|
|
port->ext.mix.hwModule = halPort.ext.mix.hw_module;
|
|
|
|
|
port->ext.mix.ioHandle = halPort.ext.mix.handle;
|
|
|
|
|
port->ext.mix.latencyClass = AudioMixLatencyClass(halPort.ext.mix.latency_class);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AUDIO_PORT_TYPE_SESSION: {
|
|
|
|
|
port->ext.session.session = halPort.ext.session.session;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::audioPortToHal(const AudioPort& port, struct audio_port* halPort) {
|
|
|
|
|
memset(halPort, 0, sizeof(audio_port));
|
|
|
|
|
halPort->id = port.id;
|
|
|
|
|
halPort->role = static_cast<audio_port_role_t>(port.role);
|
|
|
|
|
halPort->type = static_cast<audio_port_type_t>(port.type);
|
2018-02-27 10:56:32 -08:00
|
|
|
strncpy(halPort->name, port.name.c_str(), AUDIO_PORT_MAX_NAME_LEN);
|
|
|
|
|
halPort->name[AUDIO_PORT_MAX_NAME_LEN - 1] = '\0';
|
2016-11-16 16:30:17 -08:00
|
|
|
halPort->num_sample_rates =
|
2017-12-14 18:50:12 -08:00
|
|
|
std::min(port.sampleRates.size(), static_cast<size_t>(AUDIO_PORT_MAX_SAMPLING_RATES));
|
2016-11-16 16:30:17 -08:00
|
|
|
for (size_t i = 0; i < halPort->num_sample_rates; ++i) {
|
|
|
|
|
halPort->sample_rates[i] = port.sampleRates[i];
|
|
|
|
|
}
|
|
|
|
|
halPort->num_channel_masks =
|
2017-12-14 18:50:12 -08:00
|
|
|
std::min(port.channelMasks.size(), static_cast<size_t>(AUDIO_PORT_MAX_CHANNEL_MASKS));
|
2016-11-16 16:30:17 -08:00
|
|
|
for (size_t i = 0; i < halPort->num_channel_masks; ++i) {
|
|
|
|
|
halPort->channel_masks[i] = static_cast<audio_channel_mask_t>(port.channelMasks[i]);
|
|
|
|
|
}
|
|
|
|
|
halPort->num_formats =
|
2017-12-14 18:50:12 -08:00
|
|
|
std::min(port.formats.size(), static_cast<size_t>(AUDIO_PORT_MAX_FORMATS));
|
2016-11-16 16:30:17 -08:00
|
|
|
for (size_t i = 0; i < halPort->num_formats; ++i) {
|
|
|
|
|
halPort->formats[i] = static_cast<audio_format_t>(port.formats[i]);
|
|
|
|
|
}
|
|
|
|
|
halPort->num_gains = std::min(port.gains.size(), static_cast<size_t>(AUDIO_PORT_MAX_GAINS));
|
|
|
|
|
for (size_t i = 0; i < halPort->num_gains; ++i) {
|
|
|
|
|
audioGainToHal(port.gains[i], &halPort->gains[i]);
|
|
|
|
|
}
|
|
|
|
|
audioPortConfigToHal(port.activeConfig, &halPort->active_config);
|
|
|
|
|
switch (port.type) {
|
2017-12-14 18:50:12 -08:00
|
|
|
case AudioPortType::NONE:
|
|
|
|
|
break;
|
2016-11-16 16:30:17 -08:00
|
|
|
case AudioPortType::DEVICE: {
|
|
|
|
|
halPort->ext.device.hw_module = port.ext.device.hwModule;
|
|
|
|
|
halPort->ext.device.type = static_cast<audio_devices_t>(port.ext.device.type);
|
2017-12-14 18:50:12 -08:00
|
|
|
memcpy(halPort->ext.device.address, port.ext.device.address.data(),
|
|
|
|
|
AUDIO_DEVICE_MAX_ADDRESS_LEN);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AudioPortType::MIX: {
|
|
|
|
|
halPort->ext.mix.hw_module = port.ext.mix.hwModule;
|
|
|
|
|
halPort->ext.mix.handle = port.ext.mix.ioHandle;
|
|
|
|
|
halPort->ext.mix.latency_class =
|
2017-12-14 18:50:12 -08:00
|
|
|
static_cast<audio_mix_latency_class_t>(port.ext.mix.latencyClass);
|
2016-11-16 16:30:17 -08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case AudioPortType::SESSION: {
|
|
|
|
|
halPort->ext.session.session = static_cast<audio_session_t>(port.ext.session.session);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::uuidFromHal(const audio_uuid_t& halUuid, Uuid* uuid) {
|
|
|
|
|
uuid->timeLow = halUuid.timeLow;
|
|
|
|
|
uuid->timeMid = halUuid.timeMid;
|
|
|
|
|
uuid->versionAndTimeHigh = halUuid.timeHiAndVersion;
|
|
|
|
|
uuid->variantAndClockSeqHigh = halUuid.clockSeq;
|
|
|
|
|
memcpy(uuid->node.data(), halUuid.node, uuid->node.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HidlUtils::uuidToHal(const Uuid& uuid, audio_uuid_t* halUuid) {
|
|
|
|
|
halUuid->timeLow = uuid.timeLow;
|
|
|
|
|
halUuid->timeMid = uuid.timeMid;
|
|
|
|
|
halUuid->timeHiAndVersion = uuid.versionAndTimeHigh;
|
|
|
|
|
halUuid->clockSeq = uuid.variantAndClockSeqHigh;
|
|
|
|
|
memcpy(halUuid->node, uuid.node.data(), uuid.node.size());
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-11 16:36:53 -08:00
|
|
|
} // namespace implementation
|
Audio HAL: Factorize V2 and V4 like libaudiohal
Use the same technique developed for the simpler libaudiohal to
factorize the audio HAL impl.
Generated with script:
set -euo pipefail
cd hardware/interfaces/audio
# Make 2.0 and 4.0 files mostly identical by removing all 2.0, V4.0...
# and replacing it by CPP_VERSION and FILE_VERSION
# This allow both implementation to be mostly identical, except for code difference
# Also remove IncludeGuard.h as it will be included from compiler flag
# Also update license to 2018
find -name *.cpp -o -name *h |
grep -v -e service.cpp |
xargs sed -Ei \
-e 's/(#.*)V[42]_0_(.*_H_?)$/\1\2/' \
-e 's/(LOG_TAG.*)[24]_0/\1/' \
-e '/#ifndef AUDIO_HAL_VERSION/,/#endif/d' \
-e '/^#.*def.*AUDIO_HAL_VERSION\b/d' \
-e's/V[42]_0/CPP_VERSION/' \
-e 's/(#include ).(android.*)[24].0(.*).$/\1PATH(\2FILE_VERSION\3)/' \
-e 's|(#include) .(.*)[24].0/(default/.*).$|\1 "\2\3"|' \
-e 's/\bAUDIO_HAL_VERSION\b/CPP_VERSION/' \
-e '/IncludeGuard.h/d' \
-e 's/(Copyright .C. 201)./\18/'
# set MAJOR_VERSION instead of having a different macro for each version
# this allow to do preprocessor arithmetic (eg: MAJOR_VERSION >= 4)
for v in 2 4; do
find -ipath '*/'$v'.0/*/Android.bp' |
xargs sed -i -e '/cflags:/,/^$/d' -e '/vndk/{:a;/}/!{N;ba};d}' -e '$i\
cflags: [\
"-DMAJOR_VERSION='$v'",\
"-DMINOR_VERSION=0",\
"-include common/all-versions/VersionMacro.h",\
]'; done
# replace# ifdef VERSION_X by #if MAJOR_VERSION == X
find -path *all-versions/*.h |
xargs sed -Ei -e 's/def.*AUDIO_HAL_VERSION_([24])_0.*/ MAJOR_VERSION == \1/' \
-e 'T;s/ +/ /'
# copy all-versions impl in each version impl
find -path '*/[24].0/*.[hc]*' |
grep -ve all-versions -e test |
xargs -P99 -n4 sed -i -Ee '/include <.*all-versions.default/!b' \
-e 's#.*<#find -path */#' -e 's/>$/|xargs tail -n +16/' -e e
# remove all-versions impl
rm -r {core,effect}/all-versions/
# merge version impl into a single all-version
for dir in core/*.0/vts/functional/*.0/ ;do
dest=$(echo $dir | sed 's#/..0/#/all-versions/#')
mkdir -p $dest
mv -T $dir $dest
done
find -mindepth 3 -path '*/2.0/*' -a \( -name '*cpp' -o -name '*h' \) |
grep -v 'all-versions' |
sed -E 'h;s/2/4/g;H;s/4.0/all-versions/;s/4.0//;H;g;s/\n/ /g;'|
xargs -P99 -L1 sh -c '
set -euo pipefail
mkdir -p $(dirname $2);
diff --old-group-format="#if MAJOR_VERSION == 2
%<#endif
" \
--new-group-format="#if MAJOR_VERSION == 4
%>#endif
" $0 $1 > $2 || true;
rm $0 $1'
# merge the X.0 Android.bp & OWNERS in the all-versions
for dir in common effect core; do
for sub in default vts/functional; do
test -f $dir/2.0/$sub/Android.bp || continue
awk 1 $dir/*.0/$sub/Android.bp >> $dir/all-versions/$sub/Android.bp
# delete licenses except for the first one and add whitelines
sed -i -e '/^}$/{N;/^}\n$/!s/\n/&\n/}' $dir/all-versions/$sub/Android.bp
sed -i -e '1,17b;/^\/\//,/^$/{d}' $dir/all-versions/$sub/Android.bp
done
for sub in default vts; do
test -d $dir/2.0/$sub || continue
test -f $dir/2.0/$sub/OWNERS &&
awk 1 $dir/*.0/$sub/OWNERS | sort -u > $dir/all-versions/$sub/OWNERS ||
true
rm -r $dir/*.0/$sub
done
done
# delete all-versions-impl dependencies
find -name 'Android.bp' | xargs sed -i -e '/all-versions-impl/d'
# cleanup unused files
rm common/all-versions/default/include/common/all-versions/default/HidlUtils*
rm common/all-versions/util/include/common/all-versions/IncludeGuard.h
find -depth -type d -empty -delete
# Clamp consecutive number of empty lines to 2
find -name *.cpp -o -name *h | xargs sed -Ei ':a;/^\n*$/{N;ba};s/\n\n+/\n\n/'
# transform #endif\n#if to #elif
find -name *.cpp -o -name *h | xargs sed -i '/^#endif/{N;s/.*\n#if/#elif/}'
# remove leftover include guard in cpp
find -name *.cpp |xargs sed -Ei '/^#.*_H_?$/d'
# apply clang-format
find -name *cpp -o -name *h |
xargs ../../../prebuilts/clang/host/linux-x86/clang-stable/bin/clang-format --style file -i
# clang format breaks PATH(a/b) to PATH(a / b), remove the space surrounding /
find -name *cpp -o -name *h | xargs sed -i "/#include PATH/s# / #/#g"
Test: compile
Bug: 118203066
Change-Id: I3692a444307afc5f71064fe0b9e6b8af3c9ff1dd
Signed-off-by: Kevin Rocard <krocard@google.com>
2018-11-14 16:22:07 -08:00
|
|
|
} // namespace CPP_VERSION
|
2017-12-14 18:39:39 -08:00
|
|
|
} // namespace common
|
|
|
|
|
} // namespace audio
|
|
|
|
|
} // namespace hardware
|
2016-11-16 16:30:17 -08:00
|
|
|
} // namespace android
|