2016-10-31 10:39:47 -07: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-10-31 10:39:47 -07: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
|
|
|
#define LOG_TAG "StreamInHAL"
|
|
|
|
|
|
|
|
|
|
#include "core/default/StreamIn.h"
|
|
|
|
|
#include "core/default/Conversions.h"
|
|
|
|
|
#include "core/default/Util.h"
|
2019-05-20 15:04:49 -07:00
|
|
|
#include "common/all-versions/HidlSupport.h"
|
2017-12-18 10:05:35 -08:00
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
//#define LOG_NDEBUG 0
|
2017-01-31 17:24:48 -08:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_AUDIO
|
2016-10-31 10:39:47 -07:00
|
|
|
|
2020-12-10 17:25:40 -08:00
|
|
|
#include <HidlUtils.h>
|
2016-11-30 13:45:34 -08:00
|
|
|
#include <android/log.h>
|
2016-12-22 09:21:34 -08:00
|
|
|
#include <hardware/audio.h>
|
2017-01-31 17:24:48 -08:00
|
|
|
#include <utils/Trace.h>
|
2019-05-20 15:04:49 -07:00
|
|
|
#include <cmath>
|
2020-12-10 17:25:40 -08:00
|
|
|
#include <memory>
|
2016-10-31 10:39:47 -07:00
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
namespace hardware {
|
|
|
|
|
namespace audio {
|
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 {
|
2016-10-31 10:39:47 -07:00
|
|
|
namespace implementation {
|
|
|
|
|
|
2020-12-10 17:25:40 -08:00
|
|
|
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
|
|
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class ReadThread : public Thread {
|
2017-05-05 14:02:55 -07:00
|
|
|
public:
|
2016-12-22 09:21:34 -08:00
|
|
|
// ReadThread's lifespan never exceeds StreamIn's lifespan.
|
2017-12-14 18:50:12 -08:00
|
|
|
ReadThread(std::atomic<bool>* stop, audio_stream_in_t* stream, StreamIn::CommandMQ* commandMQ,
|
|
|
|
|
StreamIn::DataMQ* dataMQ, StreamIn::StatusMQ* statusMQ, EventFlag* efGroup)
|
2017-05-05 14:02:55 -07:00
|
|
|
: Thread(false /*canCallJava*/),
|
|
|
|
|
mStop(stop),
|
|
|
|
|
mStream(stream),
|
|
|
|
|
mCommandMQ(commandMQ),
|
|
|
|
|
mDataMQ(dataMQ),
|
|
|
|
|
mStatusMQ(statusMQ),
|
|
|
|
|
mEfGroup(efGroup),
|
|
|
|
|
mBuffer(nullptr) {}
|
2017-03-31 19:34:04 -07:00
|
|
|
bool init() {
|
2017-05-05 14:02:55 -07:00
|
|
|
mBuffer.reset(new (std::nothrow) uint8_t[mDataMQ->getQuantumCount()]);
|
2017-03-31 19:34:04 -07:00
|
|
|
return mBuffer != nullptr;
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
|
|
|
|
virtual ~ReadThread() {}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
private:
|
2016-12-22 09:21:34 -08:00
|
|
|
std::atomic<bool>* mStop;
|
|
|
|
|
audio_stream_in_t* mStream;
|
2017-01-31 13:56:02 -08:00
|
|
|
StreamIn::CommandMQ* mCommandMQ;
|
2016-12-22 09:21:34 -08:00
|
|
|
StreamIn::DataMQ* mDataMQ;
|
|
|
|
|
StreamIn::StatusMQ* mStatusMQ;
|
|
|
|
|
EventFlag* mEfGroup;
|
|
|
|
|
std::unique_ptr<uint8_t[]> mBuffer;
|
2017-01-31 13:56:02 -08:00
|
|
|
IStreamIn::ReadParameters mParameters;
|
|
|
|
|
IStreamIn::ReadStatus mStatus;
|
2016-12-22 09:21:34 -08:00
|
|
|
|
|
|
|
|
bool threadLoop() override;
|
2017-01-31 13:56:02 -08:00
|
|
|
|
|
|
|
|
void doGetCapturePosition();
|
|
|
|
|
void doRead();
|
2016-12-22 09:21:34 -08:00
|
|
|
};
|
|
|
|
|
|
2017-01-31 13:56:02 -08:00
|
|
|
void ReadThread::doRead() {
|
|
|
|
|
size_t availableToWrite = mDataMQ->availableToWrite();
|
|
|
|
|
size_t requestedToRead = mParameters.params.read;
|
|
|
|
|
if (requestedToRead > availableToWrite) {
|
2017-05-05 14:02:55 -07:00
|
|
|
ALOGW(
|
|
|
|
|
"truncating read data from %d to %d due to insufficient data queue "
|
|
|
|
|
"space",
|
|
|
|
|
(int32_t)requestedToRead, (int32_t)availableToWrite);
|
2017-01-31 13:56:02 -08:00
|
|
|
requestedToRead = availableToWrite;
|
|
|
|
|
}
|
|
|
|
|
ssize_t readResult = mStream->read(mStream, &mBuffer[0], requestedToRead);
|
|
|
|
|
mStatus.retval = Result::OK;
|
|
|
|
|
if (readResult >= 0) {
|
|
|
|
|
mStatus.reply.read = readResult;
|
|
|
|
|
if (!mDataMQ->write(&mBuffer[0], readResult)) {
|
|
|
|
|
ALOGW("data message queue write failed");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
mStatus.retval = Stream::analyzeStatus("read", readResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReadThread::doGetCapturePosition() {
|
|
|
|
|
mStatus.retval = StreamIn::getCapturePositionImpl(
|
2017-12-14 18:50:12 -08:00
|
|
|
mStream, &mStatus.reply.capturePosition.frames, &mStatus.reply.capturePosition.time);
|
2017-01-31 13:56:02 -08:00
|
|
|
}
|
|
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
bool ReadThread::threadLoop() {
|
2017-05-05 14:02:55 -07:00
|
|
|
// This implementation doesn't return control back to the Thread until it
|
|
|
|
|
// decides to stop,
|
2016-12-22 09:21:34 -08:00
|
|
|
// as the Thread uses mutexes, and this can lead to priority inversion.
|
2017-05-05 14:02:55 -07:00
|
|
|
while (!std::atomic_load_explicit(mStop, std::memory_order_acquire)) {
|
2016-12-22 09:21:34 -08:00
|
|
|
uint32_t efState = 0;
|
2017-12-14 18:50:12 -08:00
|
|
|
mEfGroup->wait(static_cast<uint32_t>(MessageQueueFlagBits::NOT_FULL), &efState);
|
|
|
|
|
if (!(efState & static_cast<uint32_t>(MessageQueueFlagBits::NOT_FULL))) {
|
2016-12-22 09:21:34 -08:00
|
|
|
continue; // Nothing to do.
|
|
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
if (!mCommandMQ->read(&mParameters)) {
|
|
|
|
|
continue; // Nothing to do.
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
mStatus.replyTo = mParameters.command;
|
|
|
|
|
switch (mParameters.command) {
|
|
|
|
|
case IStreamIn::ReadCommand::READ:
|
|
|
|
|
doRead();
|
|
|
|
|
break;
|
|
|
|
|
case IStreamIn::ReadCommand::GET_CAPTURE_POSITION:
|
|
|
|
|
doGetCapturePosition();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-12-14 18:50:12 -08:00
|
|
|
ALOGE("Unknown read thread command code %d", mParameters.command);
|
2017-01-31 13:56:02 -08:00
|
|
|
mStatus.retval = Result::NOT_SUPPORTED;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!mStatusMQ->write(&mStatus)) {
|
2016-12-22 09:21:34 -08:00
|
|
|
ALOGW("status message queue write failed");
|
|
|
|
|
}
|
|
|
|
|
mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_EMPTY));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2017-03-29 09:31:18 -07:00
|
|
|
StreamIn::StreamIn(const sp<Device>& device, audio_stream_in_t* stream)
|
2019-11-14 13:57:15 -08:00
|
|
|
: mDevice(device),
|
2017-05-05 14:02:55 -07:00
|
|
|
mStream(stream),
|
2020-12-10 17:25:40 -08:00
|
|
|
mStreamCommon(new Stream(true /*isInput*/, &stream->common)),
|
2017-05-05 14:02:55 -07:00
|
|
|
mStreamMmap(new StreamMmap<audio_stream_in_t>(stream)),
|
|
|
|
|
mEfGroup(nullptr),
|
|
|
|
|
mStopReadThread(false) {}
|
2016-10-31 10:39:47 -07:00
|
|
|
|
|
|
|
|
StreamIn::~StreamIn() {
|
2017-01-31 17:24:48 -08:00
|
|
|
ATRACE_CALL();
|
2016-12-22 09:21:34 -08:00
|
|
|
close();
|
2017-01-31 17:24:48 -08:00
|
|
|
if (mReadThread.get()) {
|
|
|
|
|
ATRACE_NAME("mReadThread->join");
|
|
|
|
|
status_t status = mReadThread->join();
|
|
|
|
|
ALOGE_IF(status, "read thread exit error: %s", strerror(-status));
|
|
|
|
|
}
|
|
|
|
|
if (mEfGroup) {
|
|
|
|
|
status_t status = EventFlag::deleteEventFlag(&mEfGroup);
|
2017-12-14 18:50:12 -08:00
|
|
|
ALOGE_IF(status, "read MQ event flag deletion error: %s", strerror(-status));
|
2017-01-31 17:24:48 -08:00
|
|
|
}
|
2019-11-14 13:57:15 -08:00
|
|
|
#if MAJOR_VERSION <= 5
|
2017-03-29 09:31:18 -07:00
|
|
|
mDevice->closeInputStream(mStream);
|
2019-11-14 13:57:15 -08:00
|
|
|
#endif
|
2016-10-31 10:39:47 -07:00
|
|
|
mStream = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// Methods from ::android::hardware::audio::CPP_VERSION::IStream follow.
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint64_t> StreamIn::getFrameSize() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return audio_stream_in_frame_size(mStream);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint64_t> StreamIn::getFrameCount() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getFrameCount();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint64_t> StreamIn::getBufferSize() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getBufferSize();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 17:25:40 -08:00
|
|
|
#if MAJOR_VERSION <= 6
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint32_t> StreamIn::getSampleRate() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getSampleRate();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
#if MAJOR_VERSION == 2
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<void> StreamIn::getSupportedChannelMasks(getSupportedChannelMasks_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedChannelMasks(_hidl_cb);
|
|
|
|
|
}
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamIn::getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getSupportedSampleRates(_hidl_cb);
|
|
|
|
|
}
|
2018-03-01 15:08:07 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
Return<void> StreamIn::getSupportedChannelMasks(AudioFormat format,
|
|
|
|
|
getSupportedChannelMasks_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedChannelMasks(format, _hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
Return<void> StreamIn::getSupportedSampleRates(AudioFormat format,
|
|
|
|
|
getSupportedSampleRates_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedSampleRates(format, _hidl_cb);
|
|
|
|
|
}
|
2016-10-31 10:39:47 -07:00
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::setSampleRate(uint32_t sampleRateHz) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->setSampleRate(sampleRateHz);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<AudioChannelBitfield> StreamIn::getChannelMask() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getChannelMask();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<Result> StreamIn::setChannelMask(AudioChannelBitfield mask) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->setChannelMask(mask);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<AudioFormat> StreamIn::getFormat() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getFormat();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamIn::getSupportedFormats(getSupportedFormats_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getSupportedFormats(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::setFormat(AudioFormat format) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->setFormat(format);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 17:25:40 -08:00
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
Return<void> StreamIn::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedProfiles(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::setAudioProperties(const AudioConfigBase& config) {
|
|
|
|
|
return mStreamCommon->setAudioProperties(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // MAJOR_VERSION <= 6
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamIn::getAudioProperties(getAudioProperties_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getAudioProperties(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::addEffect(uint64_t effectId) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->addEffect(effectId);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::removeEffect(uint64_t effectId) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->removeEffect(effectId);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::standby() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->standby();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<Result> StreamIn::setHwAvSync(uint32_t hwAvSync) {
|
|
|
|
|
return mStreamCommon->setHwAvSync(hwAvSync);
|
2016-10-31 10:39:47 -07: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
|
|
|
#if MAJOR_VERSION == 2
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<Result> StreamIn::setConnectedState(const DeviceAddress& address, bool connected) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->setConnectedState(address, connected);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<AudioDevice> StreamIn::getDevice() {
|
|
|
|
|
return mStreamCommon->getDevice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::setDevice(const DeviceAddress& address) {
|
|
|
|
|
return mStreamCommon->setDevice(address);
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamIn::getParameters(const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getParameters(keys, _hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<Result> StreamIn::setParameters(const hidl_vec<ParameterValue>& parameters) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->setParameters(parameters);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamIn::debugDump(const hidl_handle& fd) {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->debugDump(fd);
|
|
|
|
|
}
|
2018-11-10 07:20:17 -08:00
|
|
|
#elif MAJOR_VERSION >= 4
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<void> StreamIn::getDevices(getDevices_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getDevices(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::setDevices(const hidl_vec<DeviceAddress>& devices) {
|
|
|
|
|
return mStreamCommon->setDevices(devices);
|
|
|
|
|
}
|
|
|
|
|
Return<void> StreamIn::getParameters(const hidl_vec<ParameterValue>& context,
|
|
|
|
|
const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getParameters(context, keys, _hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::setParameters(const hidl_vec<ParameterValue>& context,
|
|
|
|
|
const hidl_vec<ParameterValue>& parameters) {
|
|
|
|
|
return mStreamCommon->setParameters(context, parameters);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2016-10-31 10:39:47 -07:00
|
|
|
|
2016-12-15 19:15:45 -08:00
|
|
|
Return<Result> StreamIn::start() {
|
|
|
|
|
return mStreamMmap->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::stop() {
|
|
|
|
|
return mStreamMmap->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamIn::createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) {
|
|
|
|
|
return mStreamMmap->createMmapBuffer(minSizeFrames, audio_stream_in_frame_size(mStream),
|
|
|
|
|
_hidl_cb);
|
2016-12-15 19:15:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<void> StreamIn::getMmapPosition(getMmapPosition_cb _hidl_cb) {
|
|
|
|
|
return mStreamMmap->getMmapPosition(_hidl_cb);
|
|
|
|
|
}
|
2016-10-31 10:39:47 -07:00
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::close() {
|
2019-11-14 13:57:15 -08:00
|
|
|
if (mStopReadThread.load(std::memory_order_relaxed)) { // only this thread writes
|
|
|
|
|
return Result::INVALID_STATE;
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
2019-11-14 13:57:15 -08:00
|
|
|
mStopReadThread.store(true, std::memory_order_release);
|
2016-12-22 09:21:34 -08:00
|
|
|
if (mEfGroup) {
|
2017-01-31 17:24:48 -08:00
|
|
|
mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_FULL));
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
2019-11-14 13:57:15 -08:00
|
|
|
#if MAJOR_VERSION >= 6
|
|
|
|
|
mDevice->closeInputStream(mStream);
|
|
|
|
|
#endif
|
2016-12-22 09:21:34 -08:00
|
|
|
return Result::OK;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
// Methods from ::android::hardware::audio::CPP_VERSION::IStreamIn follow.
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamIn::getAudioSource(getAudioSource_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
int halSource;
|
2017-12-14 18:50:12 -08:00
|
|
|
Result retval = mStreamCommon->getParam(AudioParameter::keyInputSource, &halSource);
|
2020-12-10 17:25:40 -08:00
|
|
|
AudioSource source = {};
|
2016-10-31 10:39:47 -07:00
|
|
|
if (retval == Result::OK) {
|
2020-12-10 17:25:40 -08:00
|
|
|
retval = Stream::analyzeStatus(
|
|
|
|
|
"get_audio_source",
|
|
|
|
|
HidlUtils::audioSourceFromHal(static_cast<audio_source_t>(halSource), &source));
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
_hidl_cb(retval, source);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamIn::setGain(float gain) {
|
2017-05-08 17:08:11 -07:00
|
|
|
if (!isGainNormalized(gain)) {
|
|
|
|
|
ALOGW("Can not set a stream input gain (%f) outside [0,1]", gain);
|
|
|
|
|
return Result::INVALID_ARGUMENTS;
|
|
|
|
|
}
|
2016-12-15 19:15:45 -08:00
|
|
|
return Stream::analyzeStatus("set_gain", mStream->set_gain(mStream, gain));
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamIn::prepareForReading(uint32_t frameSize, uint32_t framesCount,
|
2017-05-05 14:02:55 -07:00
|
|
|
prepareForReading_cb _hidl_cb) {
|
2016-12-22 09:21:34 -08:00
|
|
|
status_t status;
|
2020-12-10 17:25:40 -08:00
|
|
|
#if MAJOR_VERSION <= 6
|
2017-05-05 14:02:55 -07:00
|
|
|
ThreadInfo threadInfo = {0, 0};
|
2020-12-10 17:25:40 -08:00
|
|
|
#else
|
|
|
|
|
int32_t threadInfo = 0;
|
|
|
|
|
#endif
|
2017-05-02 18:31:24 -07:00
|
|
|
|
|
|
|
|
// Wrap the _hidl_cb to return an error
|
2017-11-20 15:36:52 -08:00
|
|
|
auto sendError = [&threadInfo, &_hidl_cb](Result result) {
|
2017-12-14 18:50:12 -08:00
|
|
|
_hidl_cb(result, CommandMQ::Descriptor(), DataMQ::Descriptor(), StatusMQ::Descriptor(),
|
|
|
|
|
threadInfo);
|
2017-05-02 18:31:24 -07:00
|
|
|
};
|
|
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
// Create message queues.
|
|
|
|
|
if (mDataMQ) {
|
|
|
|
|
ALOGE("the client attempts to call prepareForReading twice");
|
2017-05-02 18:31:24 -07:00
|
|
|
sendError(Result::INVALID_STATE);
|
2016-12-22 09:21:34 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
std::unique_ptr<CommandMQ> tempCommandMQ(new CommandMQ(1));
|
2017-05-02 18:34:59 -07:00
|
|
|
|
|
|
|
|
// Check frameSize and framesCount
|
|
|
|
|
if (frameSize == 0 || framesCount == 0) {
|
2017-12-14 18:50:12 -08:00
|
|
|
ALOGE("Null frameSize (%u) or framesCount (%u)", frameSize, framesCount);
|
2017-05-02 18:34:59 -07:00
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
2017-10-05 18:47:02 -07:00
|
|
|
|
|
|
|
|
if (frameSize > Stream::MAX_BUFFER_SIZE / framesCount) {
|
|
|
|
|
ALOGE("Buffer too big: %u*%u bytes > MAX_BUFFER_SIZE (%u)", frameSize, framesCount,
|
|
|
|
|
Stream::MAX_BUFFER_SIZE);
|
2017-05-02 18:31:24 -07:00
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2017-03-31 19:36:29 -07:00
|
|
|
return Void();
|
|
|
|
|
}
|
2017-12-14 18:50:12 -08:00
|
|
|
std::unique_ptr<DataMQ> tempDataMQ(new DataMQ(frameSize * framesCount, true /* EventFlag */));
|
2017-03-31 19:36:29 -07:00
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
std::unique_ptr<StatusMQ> tempStatusMQ(new StatusMQ(1));
|
2017-12-14 18:50:12 -08:00
|
|
|
if (!tempCommandMQ->isValid() || !tempDataMQ->isValid() || !tempStatusMQ->isValid()) {
|
2017-01-31 13:56:02 -08:00
|
|
|
ALOGE_IF(!tempCommandMQ->isValid(), "command MQ is invalid");
|
2016-12-22 09:21:34 -08:00
|
|
|
ALOGE_IF(!tempDataMQ->isValid(), "data MQ is invalid");
|
|
|
|
|
ALOGE_IF(!tempStatusMQ->isValid(), "status MQ is invalid");
|
2017-05-02 18:31:24 -07:00
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2016-12-22 09:21:34 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
2017-03-31 19:36:55 -07:00
|
|
|
EventFlag* tempRawEfGroup{};
|
2017-12-14 18:50:12 -08:00
|
|
|
status = EventFlag::createEventFlag(tempDataMQ->getEventFlagWord(), &tempRawEfGroup);
|
2017-05-05 14:02:55 -07:00
|
|
|
std::unique_ptr<EventFlag, void (*)(EventFlag*)> tempElfGroup(
|
|
|
|
|
tempRawEfGroup, [](auto* ef) { EventFlag::deleteEventFlag(&ef); });
|
2017-03-31 19:36:55 -07:00
|
|
|
if (status != OK || !tempElfGroup) {
|
2016-12-22 09:21:34 -08:00
|
|
|
ALOGE("failed creating event flag for data MQ: %s", strerror(-status));
|
2017-05-02 18:31:24 -07:00
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2016-12-22 09:21:34 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create and launch the thread.
|
2017-12-14 18:50:12 -08:00
|
|
|
auto tempReadThread =
|
|
|
|
|
std::make_unique<ReadThread>(&mStopReadThread, mStream, tempCommandMQ.get(),
|
|
|
|
|
tempDataMQ.get(), tempStatusMQ.get(), tempElfGroup.get());
|
2017-03-31 19:34:04 -07:00
|
|
|
if (!tempReadThread->init()) {
|
2017-05-02 18:31:24 -07:00
|
|
|
ALOGW("failed to start reader thread: %s", strerror(-status));
|
|
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2017-03-31 19:34:04 -07:00
|
|
|
return Void();
|
|
|
|
|
}
|
2017-04-19 09:32:21 -07:00
|
|
|
status = tempReadThread->run("reader", PRIORITY_URGENT_AUDIO);
|
2016-12-22 09:21:34 -08:00
|
|
|
if (status != OK) {
|
|
|
|
|
ALOGW("failed to start reader thread: %s", strerror(-status));
|
2017-05-02 18:31:24 -07:00
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2016-12-22 09:21:34 -08:00
|
|
|
return Void();
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
2016-12-22 09:21:34 -08:00
|
|
|
|
2017-01-31 13:56:02 -08:00
|
|
|
mCommandMQ = std::move(tempCommandMQ);
|
2016-12-22 09:21:34 -08:00
|
|
|
mDataMQ = std::move(tempDataMQ);
|
|
|
|
|
mStatusMQ = std::move(tempStatusMQ);
|
2017-03-31 19:34:04 -07:00
|
|
|
mReadThread = tempReadThread.release();
|
2017-03-31 19:36:55 -07:00
|
|
|
mEfGroup = tempElfGroup.release();
|
2020-12-10 17:25:40 -08:00
|
|
|
#if MAJOR_VERSION <= 6
|
2017-02-07 10:49:18 -08:00
|
|
|
threadInfo.pid = getpid();
|
|
|
|
|
threadInfo.tid = mReadThread->getTid();
|
2020-12-10 17:25:40 -08:00
|
|
|
#else
|
|
|
|
|
threadInfo = mReadThread->getTid();
|
|
|
|
|
#endif
|
2017-12-14 18:50:12 -08:00
|
|
|
_hidl_cb(Result::OK, *mCommandMQ->getDesc(), *mDataMQ->getDesc(), *mStatusMQ->getDesc(),
|
|
|
|
|
threadInfo);
|
2016-10-31 10:39:47 -07:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint32_t> StreamIn::getInputFramesLost() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStream->get_input_frames_lost(mStream);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-31 13:56:02 -08:00
|
|
|
// static
|
2017-12-14 18:50:12 -08:00
|
|
|
Result StreamIn::getCapturePositionImpl(audio_stream_in_t* stream, uint64_t* frames,
|
|
|
|
|
uint64_t* time) {
|
2017-05-19 16:46:28 -07:00
|
|
|
// HAL may have a stub function, always returning ENOSYS, don't
|
|
|
|
|
// spam the log in this case.
|
|
|
|
|
static const std::vector<int> ignoredErrors{ENOSYS};
|
2016-10-31 10:39:47 -07:00
|
|
|
Result retval(Result::NOT_SUPPORTED);
|
2017-11-28 15:53:09 +11:00
|
|
|
if (stream->get_capture_position == NULL) return retval;
|
2017-01-31 13:56:02 -08:00
|
|
|
int64_t halFrames, halTime;
|
2017-05-19 16:46:28 -07:00
|
|
|
retval = Stream::analyzeStatus("get_capture_position",
|
|
|
|
|
stream->get_capture_position(stream, &halFrames, &halTime),
|
|
|
|
|
ignoredErrors);
|
2017-01-31 13:56:02 -08:00
|
|
|
if (retval == Result::OK) {
|
|
|
|
|
*frames = halFrames;
|
|
|
|
|
*time = halTime;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
return retval;
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamIn::getCapturePosition(getCapturePosition_cb _hidl_cb) {
|
2017-01-31 13:56:02 -08:00
|
|
|
uint64_t frames = 0, time = 0;
|
|
|
|
|
Result retval = getCapturePositionImpl(mStream, &frames, &time);
|
2016-10-31 10:39:47 -07:00
|
|
|
_hidl_cb(retval, frames, time);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<void> StreamIn::debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) {
|
|
|
|
|
return mStreamCommon->debug(fd, options);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-10 07:20:17 -08:00
|
|
|
#if MAJOR_VERSION >= 4
|
2020-11-20 18:42:21 +01:00
|
|
|
|
|
|
|
|
record_track_metadata StreamIn::convertRecordTrackMetadata(
|
|
|
|
|
const RecordTrackMetadata& trackMetadata) {
|
|
|
|
|
record_track_metadata halTrackMetadata = {.gain = trackMetadata.gain};
|
|
|
|
|
(void)HidlUtils::audioSourceToHal(trackMetadata.source, &halTrackMetadata.source);
|
|
|
|
|
#if MAJOR_VERSION >= 5
|
|
|
|
|
if (trackMetadata.destination.getDiscriminator() ==
|
|
|
|
|
RecordTrackMetadata::Destination::hidl_discriminator::device) {
|
|
|
|
|
(void)deviceAddressToHal(trackMetadata.destination.device(), &halTrackMetadata.dest_device,
|
|
|
|
|
halTrackMetadata.dest_device_address);
|
2018-03-28 11:32:08 -07:00
|
|
|
}
|
2020-11-20 18:42:21 +01:00
|
|
|
#endif
|
|
|
|
|
return halTrackMetadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StreamIn::doUpdateSinkMetadata(const SinkMetadata& sinkMetadata) {
|
2018-03-28 11:32:08 -07:00
|
|
|
std::vector<record_track_metadata> halTracks;
|
|
|
|
|
halTracks.reserve(sinkMetadata.tracks.size());
|
|
|
|
|
for (auto& metadata : sinkMetadata.tracks) {
|
2020-11-20 18:42:21 +01:00
|
|
|
halTracks.push_back(convertRecordTrackMetadata(metadata));
|
2018-03-28 11:32:08 -07:00
|
|
|
}
|
|
|
|
|
const sink_metadata_t halMetadata = {
|
2018-11-12 12:33:16 -08:00
|
|
|
.track_count = halTracks.size(),
|
|
|
|
|
.tracks = halTracks.data(),
|
2018-03-28 11:32:08 -07:00
|
|
|
};
|
|
|
|
|
mStream->update_sink_metadata(mStream, &halMetadata);
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if MAJOR_VERSION >= 7
|
|
|
|
|
record_track_metadata_v7 StreamIn::convertRecordTrackMetadataV7(
|
|
|
|
|
const RecordTrackMetadata& trackMetadata) {
|
|
|
|
|
record_track_metadata_v7 halTrackMetadata;
|
|
|
|
|
halTrackMetadata.base = convertRecordTrackMetadata(trackMetadata);
|
|
|
|
|
(void)HidlUtils::audioChannelMaskToHal(trackMetadata.channelMask,
|
|
|
|
|
&halTrackMetadata.channel_mask);
|
|
|
|
|
std::string halTags;
|
|
|
|
|
for (const auto& tag : trackMetadata.tags) {
|
|
|
|
|
if (&tag != &trackMetadata.tags[0]) {
|
|
|
|
|
halTags += HidlUtils::sAudioTagSeparator;
|
|
|
|
|
}
|
|
|
|
|
halTags += tag.c_str();
|
|
|
|
|
}
|
|
|
|
|
strncpy(halTrackMetadata.tags, halTags.c_str(), AUDIO_ATTRIBUTES_TAGS_MAX_SIZE);
|
|
|
|
|
return halTrackMetadata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StreamIn::doUpdateSinkMetadataV7(const SinkMetadata& sinkMetadata) {
|
|
|
|
|
std::vector<record_track_metadata_v7> halTracks;
|
|
|
|
|
halTracks.reserve(sinkMetadata.tracks.size());
|
|
|
|
|
for (auto& metadata : sinkMetadata.tracks) {
|
|
|
|
|
halTracks.push_back(convertRecordTrackMetadataV7(metadata));
|
|
|
|
|
}
|
|
|
|
|
const sink_metadata_v7_t halMetadata = {
|
|
|
|
|
.track_count = halTracks.size(),
|
|
|
|
|
.tracks = halTracks.data(),
|
|
|
|
|
};
|
|
|
|
|
mStream->update_sink_metadata_v7(mStream, &halMetadata);
|
|
|
|
|
}
|
|
|
|
|
#endif // MAJOR_VERSION >= 7
|
|
|
|
|
|
|
|
|
|
Return<void> StreamIn::updateSinkMetadata(const SinkMetadata& sinkMetadata) {
|
|
|
|
|
#if MAJOR_VERSION < 7
|
|
|
|
|
if (mStream->update_sink_metadata == nullptr) {
|
|
|
|
|
return Void(); // not supported by the HAL
|
|
|
|
|
}
|
|
|
|
|
doUpdateSinkMetadata(sinkMetadata);
|
|
|
|
|
#else
|
|
|
|
|
if (mDevice->version() < AUDIO_DEVICE_API_VERSION_3_2) {
|
|
|
|
|
if (mStream->update_sink_metadata == nullptr) {
|
|
|
|
|
return Void(); // not supported by the HAL
|
|
|
|
|
}
|
|
|
|
|
doUpdateSinkMetadata(sinkMetadata);
|
|
|
|
|
} else {
|
|
|
|
|
if (mStream->update_sink_metadata_v7 == nullptr) {
|
|
|
|
|
return Void(); // not supported by the HAL
|
|
|
|
|
}
|
|
|
|
|
doUpdateSinkMetadataV7(sinkMetadata);
|
|
|
|
|
}
|
|
|
|
|
#endif // MAJOR_VERSION < 7
|
2018-03-28 11:32:08 -07:00
|
|
|
return Void();
|
2018-03-01 15:08:07 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<void> StreamIn::getActiveMicrophones(getActiveMicrophones_cb _hidl_cb) {
|
2018-03-19 18:22:29 -07:00
|
|
|
Result retval = Result::NOT_SUPPORTED;
|
|
|
|
|
size_t actual_mics = AUDIO_MICROPHONE_MAX_COUNT;
|
|
|
|
|
audio_microphone_characteristic_t mic_array[AUDIO_MICROPHONE_MAX_COUNT];
|
|
|
|
|
|
|
|
|
|
hidl_vec<MicrophoneInfo> microphones;
|
|
|
|
|
if (mStream->get_active_microphones != NULL &&
|
|
|
|
|
mStream->get_active_microphones(mStream, &mic_array[0], &actual_mics) == 0) {
|
|
|
|
|
microphones.resize(actual_mics);
|
|
|
|
|
for (size_t i = 0; i < actual_mics; ++i) {
|
|
|
|
|
halToMicrophoneCharacteristics(µphones[i], mic_array[i]);
|
|
|
|
|
}
|
|
|
|
|
retval = Result::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_hidl_cb(retval, microphones);
|
2018-03-01 15:08:07 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-12-12 10:08:11 -08:00
|
|
|
#if MAJOR_VERSION >= 5
|
|
|
|
|
Return<Result> StreamIn::setMicrophoneDirection(MicrophoneDirection direction) {
|
|
|
|
|
if (mStream->set_microphone_direction == nullptr) {
|
|
|
|
|
return Result::NOT_SUPPORTED;
|
|
|
|
|
}
|
2019-05-20 15:04:49 -07:00
|
|
|
if (!common::utils::isValidHidlEnum(direction)) {
|
|
|
|
|
ALOGE("%s: Invalid direction %d", __func__, direction);
|
|
|
|
|
return Result::INVALID_ARGUMENTS;
|
|
|
|
|
}
|
2018-12-12 10:08:11 -08:00
|
|
|
return Stream::analyzeStatus(
|
|
|
|
|
"set_microphone_direction",
|
|
|
|
|
mStream->set_microphone_direction(
|
|
|
|
|
mStream, static_cast<audio_microphone_direction_t>(direction)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamIn::setMicrophoneFieldDimension(float zoom) {
|
|
|
|
|
if (mStream->set_microphone_field_dimension == nullptr) {
|
|
|
|
|
return Result::NOT_SUPPORTED;
|
|
|
|
|
}
|
2019-05-20 15:04:49 -07:00
|
|
|
if (std::isnan(zoom) || zoom < -1 || zoom > 1) {
|
|
|
|
|
ALOGE("%s: Invalid zoom %f", __func__, zoom);
|
|
|
|
|
return Result::INVALID_ARGUMENTS;
|
|
|
|
|
}
|
2018-12-12 10:08:11 -08:00
|
|
|
return Stream::analyzeStatus("set_microphone_field_dimension",
|
|
|
|
|
mStream->set_microphone_field_dimension(mStream, zoom));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-05-05 14:02:55 -07: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
|
2016-10-31 10:39:47 -07:00
|
|
|
} // namespace audio
|
|
|
|
|
} // namespace hardware
|
|
|
|
|
} // namespace android
|