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 "StreamOutHAL"
|
|
|
|
|
|
|
|
|
|
#include "core/default/StreamOut.h"
|
|
|
|
|
#include "core/default/Util.h"
|
2017-12-18 10:05:35 -08:00
|
|
|
|
2016-12-16 17:18:08 -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-02-12 13:05:44 -08:00
|
|
|
#include <string.h>
|
|
|
|
|
|
2017-03-31 19:34:04 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2020-12-10 17:25:40 -08:00
|
|
|
#include <HidlUtils.h>
|
2016-11-30 13:45:34 -08:00
|
|
|
#include <android/log.h>
|
2021-04-30 15:29:47 -07:00
|
|
|
#include <audio_utils/Metadata.h>
|
2016-12-22 09:21:34 -08:00
|
|
|
#include <hardware/audio.h>
|
2021-01-15 19:05:04 +00:00
|
|
|
#include <util/CoreUtils.h>
|
2017-01-31 17:24:48 -08:00
|
|
|
#include <utils/Trace.h>
|
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 {
|
|
|
|
|
|
2022-01-15 01:15:12 +00:00
|
|
|
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
|
|
|
|
|
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
|
|
|
|
|
namespace util {
|
|
|
|
|
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
|
|
|
|
|
}
|
2020-12-10 17:25:40 -08:00
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
class WriteThread : public Thread {
|
2017-05-05 14:02:55 -07:00
|
|
|
public:
|
2016-12-22 09:21:34 -08:00
|
|
|
// WriteThread's lifespan never exceeds StreamOut's lifespan.
|
2017-05-05 14:02:55 -07:00
|
|
|
WriteThread(std::atomic<bool>* stop, audio_stream_out_t* stream,
|
|
|
|
|
StreamOut::CommandMQ* commandMQ, StreamOut::DataMQ* dataMQ,
|
|
|
|
|
StreamOut::StatusMQ* statusMQ, EventFlag* efGroup)
|
|
|
|
|
: 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 ~WriteThread() {}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
private:
|
2016-12-22 09:21:34 -08:00
|
|
|
std::atomic<bool>* mStop;
|
|
|
|
|
audio_stream_out_t* mStream;
|
2017-01-31 13:56:02 -08:00
|
|
|
StreamOut::CommandMQ* mCommandMQ;
|
2016-12-22 09:21:34 -08:00
|
|
|
StreamOut::DataMQ* mDataMQ;
|
|
|
|
|
StreamOut::StatusMQ* mStatusMQ;
|
|
|
|
|
EventFlag* mEfGroup;
|
|
|
|
|
std::unique_ptr<uint8_t[]> mBuffer;
|
2017-01-31 13:56:02 -08:00
|
|
|
IStreamOut::WriteStatus mStatus;
|
2016-12-22 09:21:34 -08:00
|
|
|
|
|
|
|
|
bool threadLoop() override;
|
2017-01-31 13:56:02 -08:00
|
|
|
|
|
|
|
|
void doGetLatency();
|
|
|
|
|
void doGetPresentationPosition();
|
|
|
|
|
void doWrite();
|
2016-12-22 09:21:34 -08:00
|
|
|
};
|
|
|
|
|
|
2017-01-31 13:56:02 -08:00
|
|
|
void WriteThread::doWrite() {
|
|
|
|
|
const size_t availToRead = mDataMQ->availableToRead();
|
|
|
|
|
mStatus.retval = Result::OK;
|
|
|
|
|
mStatus.reply.written = 0;
|
|
|
|
|
if (mDataMQ->read(&mBuffer[0], availToRead)) {
|
|
|
|
|
ssize_t writeResult = mStream->write(mStream, &mBuffer[0], availToRead);
|
|
|
|
|
if (writeResult >= 0) {
|
|
|
|
|
mStatus.reply.written = writeResult;
|
|
|
|
|
} else {
|
|
|
|
|
mStatus.retval = Stream::analyzeStatus("write", writeResult);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WriteThread::doGetPresentationPosition() {
|
2017-12-14 18:50:12 -08:00
|
|
|
mStatus.retval =
|
|
|
|
|
StreamOut::getPresentationPositionImpl(mStream, &mStatus.reply.presentationPosition.frames,
|
|
|
|
|
&mStatus.reply.presentationPosition.timeStamp);
|
2017-01-31 13:56:02 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WriteThread::doGetLatency() {
|
|
|
|
|
mStatus.retval = Result::OK;
|
|
|
|
|
mStatus.reply.latencyMs = mStream->get_latency(mStream);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 09:21:34 -08:00
|
|
|
bool WriteThread::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_EMPTY), &efState);
|
|
|
|
|
if (!(efState & static_cast<uint32_t>(MessageQueueFlagBits::NOT_EMPTY))) {
|
2016-12-22 09:21:34 -08:00
|
|
|
continue; // Nothing to do.
|
|
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
if (!mCommandMQ->read(&mStatus.replyTo)) {
|
|
|
|
|
continue; // Nothing to do.
|
|
|
|
|
}
|
|
|
|
|
switch (mStatus.replyTo) {
|
|
|
|
|
case IStreamOut::WriteCommand::WRITE:
|
|
|
|
|
doWrite();
|
|
|
|
|
break;
|
|
|
|
|
case IStreamOut::WriteCommand::GET_PRESENTATION_POSITION:
|
|
|
|
|
doGetPresentationPosition();
|
|
|
|
|
break;
|
|
|
|
|
case IStreamOut::WriteCommand::GET_LATENCY:
|
|
|
|
|
doGetLatency();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ALOGE("Unknown write thread command code %d", mStatus.replyTo);
|
|
|
|
|
mStatus.retval = Result::NOT_SUPPORTED;
|
|
|
|
|
break;
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
2017-01-31 13:56:02 -08:00
|
|
|
if (!mStatusMQ->write(&mStatus)) {
|
|
|
|
|
ALOGE("status message queue write failed");
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
|
|
|
|
mEfGroup->wake(static_cast<uint32_t>(MessageQueueFlagBits::NOT_FULL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2017-03-29 09:31:18 -07:00
|
|
|
StreamOut::StreamOut(const sp<Device>& device, audio_stream_out_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(false /*isInput*/, &stream->common)),
|
2017-05-05 14:02:55 -07:00
|
|
|
mStreamMmap(new StreamMmap<audio_stream_out_t>(stream)),
|
|
|
|
|
mEfGroup(nullptr),
|
|
|
|
|
mStopWriteThread(false) {}
|
2016-10-31 10:39:47 -07:00
|
|
|
|
|
|
|
|
StreamOut::~StreamOut() {
|
2017-01-31 17:24:48 -08:00
|
|
|
ATRACE_CALL();
|
2019-11-14 13:57:15 -08:00
|
|
|
(void)close();
|
2017-01-31 17:24:48 -08:00
|
|
|
if (mWriteThread.get()) {
|
|
|
|
|
ATRACE_NAME("mWriteThread->join");
|
|
|
|
|
status_t status = mWriteThread->join();
|
|
|
|
|
ALOGE_IF(status, "write 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, "write MQ event flag deletion error: %s", strerror(-status));
|
2017-01-31 17:24:48 -08:00
|
|
|
}
|
2021-01-12 14:54:10 -08:00
|
|
|
mCallback = nullptr;
|
2019-11-14 13:57:15 -08:00
|
|
|
#if MAJOR_VERSION <= 5
|
2017-03-29 09:31:18 -07:00
|
|
|
mDevice->closeOutputStream(mStream);
|
2017-12-21 13:14:27 -08:00
|
|
|
// Closing the output stream in the HAL waits for the callback to finish,
|
|
|
|
|
// and joins the callback thread. Thus is it guaranteed that the callback
|
|
|
|
|
// thread will not be accessing our object anymore.
|
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> StreamOut::getFrameSize() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return audio_stream_out_frame_size(mStream);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint64_t> StreamOut::getFrameCount() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getFrameCount();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint64_t> StreamOut::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> StreamOut::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> StreamOut::getSupportedChannelMasks(getSupportedChannelMasks_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedChannelMasks(_hidl_cb);
|
|
|
|
|
}
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::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> StreamOut::getSupportedChannelMasks(AudioFormat format,
|
|
|
|
|
getSupportedChannelMasks_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedChannelMasks(format, _hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
Return<void> StreamOut::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> StreamOut::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> StreamOut::getChannelMask() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getChannelMask();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<Result> StreamOut::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> StreamOut::getFormat() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->getFormat();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamOut::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> StreamOut::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> StreamOut::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getSupportedProfiles(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 02:16:53 +00:00
|
|
|
Return<Result> StreamOut::setAudioProperties(const AudioConfigBaseOptional& config) {
|
2020-12-10 17:25:40 -08:00
|
|
|
return mStreamCommon->setAudioProperties(config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // MAJOR_VERSION <= 6
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamOut::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> StreamOut::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> StreamOut::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> StreamOut::standby() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStreamCommon->standby();
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<Result> StreamOut::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> StreamOut::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> StreamOut::getDevice() {
|
|
|
|
|
return mStreamCommon->getDevice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamOut::setDevice(const DeviceAddress& address) {
|
|
|
|
|
return mStreamCommon->setDevice(address);
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<void> StreamOut::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> StreamOut::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> StreamOut::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> StreamOut::getDevices(getDevices_cb _hidl_cb) {
|
|
|
|
|
return mStreamCommon->getDevices(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamOut::setDevices(const hidl_vec<DeviceAddress>& devices) {
|
|
|
|
|
return mStreamCommon->setDevices(devices);
|
|
|
|
|
}
|
|
|
|
|
Return<void> StreamOut::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> StreamOut::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
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::close() {
|
2019-11-14 13:57:15 -08:00
|
|
|
if (mStopWriteThread.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
|
|
|
mStopWriteThread.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_EMPTY));
|
2016-12-22 09:21:34 -08:00
|
|
|
}
|
2019-11-14 13:57:15 -08:00
|
|
|
#if MAJOR_VERSION >= 6
|
|
|
|
|
mDevice->closeOutputStream(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::IStreamOut follow.
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<uint32_t> StreamOut::getLatency() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStream->get_latency(mStream);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::setVolume(float left, float right) {
|
2017-05-08 17:08:11 -07:00
|
|
|
if (mStream->set_volume == NULL) {
|
|
|
|
|
return Result::NOT_SUPPORTED;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
2022-01-15 01:15:12 +00:00
|
|
|
if (!util::isGainNormalized(left)) {
|
2017-12-14 18:50:12 -08:00
|
|
|
ALOGW("Can not set a stream output volume {%f, %f} outside [0,1]", left, right);
|
2017-05-08 17:08:11 -07:00
|
|
|
return Result::INVALID_ARGUMENTS;
|
|
|
|
|
}
|
2019-12-11 15:50:51 -08:00
|
|
|
return Stream::analyzeStatus("set_volume", mStream->set_volume(mStream, left, right),
|
|
|
|
|
{ENOSYS} /*ignore*/);
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::prepareForWriting(uint32_t frameSize, uint32_t framesCount,
|
2017-05-05 14:02:55 -07:00
|
|
|
prepareForWriting_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 prepareForWriting 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-03-31 19:36:29 -07:00
|
|
|
|
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:34:59 -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 tempWriteThread =
|
2021-04-13 20:14:16 +00:00
|
|
|
sp<WriteThread>::make(&mStopWriteThread, mStream, tempCommandMQ.get(), tempDataMQ.get(),
|
|
|
|
|
tempStatusMQ.get(), tempElfGroup.get());
|
2017-03-31 19:34:04 -07:00
|
|
|
if (!tempWriteThread->init()) {
|
2017-05-02 18:31:24 -07:00
|
|
|
ALOGW("failed to start writer thread: %s", strerror(-status));
|
|
|
|
|
sendError(Result::INVALID_ARGUMENTS);
|
2017-03-31 19:34:04 -07:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
status = tempWriteThread->run("writer", PRIORITY_URGENT_AUDIO);
|
2016-12-22 09:21:34 -08:00
|
|
|
if (status != OK) {
|
|
|
|
|
ALOGW("failed to start writer 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);
|
2021-04-13 20:14:16 +00:00
|
|
|
mWriteThread = tempWriteThread;
|
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 = mWriteThread->getTid();
|
2020-12-10 17:25:40 -08:00
|
|
|
#else
|
|
|
|
|
threadInfo = mWriteThread->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<void> StreamOut::getRenderPosition(getRenderPosition_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
uint32_t halDspFrames;
|
2017-12-14 18:50:12 -08:00
|
|
|
Result retval = Stream::analyzeStatus("get_render_position",
|
2019-12-11 15:50:51 -08:00
|
|
|
mStream->get_render_position(mStream, &halDspFrames),
|
|
|
|
|
{ENOSYS} /*ignore*/);
|
2016-10-31 10:39:47 -07:00
|
|
|
_hidl_cb(retval, halDspFrames);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::getNextWriteTimestamp(getNextWriteTimestamp_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
Result retval(Result::NOT_SUPPORTED);
|
|
|
|
|
int64_t timestampUs = 0;
|
|
|
|
|
if (mStream->get_next_write_timestamp != NULL) {
|
2017-12-14 18:50:12 -08:00
|
|
|
retval = Stream::analyzeStatus("get_next_write_timestamp",
|
2019-12-11 15:50:51 -08:00
|
|
|
mStream->get_next_write_timestamp(mStream, ×tampUs),
|
|
|
|
|
{ENOSYS} /*ignore*/);
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
_hidl_cb(retval, timestampUs);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::setCallback(const sp<IStreamOutCallback>& callback) {
|
2016-10-31 10:39:47 -07:00
|
|
|
if (mStream->set_callback == NULL) return Result::NOT_SUPPORTED;
|
2017-12-21 13:14:27 -08:00
|
|
|
// Safe to pass 'this' because it is guaranteed that the callback thread
|
|
|
|
|
// is joined prior to exit from StreamOut's destructor.
|
2016-10-31 10:39:47 -07:00
|
|
|
int result = mStream->set_callback(mStream, StreamOut::asyncCallback, this);
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
mCallback = callback;
|
|
|
|
|
}
|
2019-12-11 15:50:51 -08:00
|
|
|
return Stream::analyzeStatus("set_callback", result, {ENOSYS} /*ignore*/);
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::clearCallback() {
|
2016-11-16 16:30:17 -08:00
|
|
|
if (mStream->set_callback == NULL) return Result::NOT_SUPPORTED;
|
2021-01-12 14:54:10 -08:00
|
|
|
mCallback = nullptr;
|
2016-11-16 16:30:17 -08:00
|
|
|
return Result::OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 10:39:47 -07:00
|
|
|
// static
|
2017-12-14 18:50:12 -08:00
|
|
|
int StreamOut::asyncCallback(stream_callback_event_t event, void*, void* cookie) {
|
2017-12-21 13:14:27 -08:00
|
|
|
// It is guaranteed that the callback thread is joined prior
|
|
|
|
|
// to exiting from StreamOut's destructor. Must *not* use sp<StreamOut>
|
|
|
|
|
// here because it can make this code the last owner of StreamOut,
|
|
|
|
|
// and an attempt to run the destructor on the callback thread
|
|
|
|
|
// will cause a deadlock in the legacy HAL code.
|
2017-12-14 18:50:12 -08:00
|
|
|
StreamOut* self = reinterpret_cast<StreamOut*>(cookie);
|
2017-12-21 13:14:27 -08:00
|
|
|
// It's correct to hold an sp<> to callback because the reference
|
|
|
|
|
// in the StreamOut instance can be cleared in the meantime. There is
|
|
|
|
|
// no difference on which thread to run IStreamOutCallback's destructor.
|
2021-01-12 14:54:10 -08:00
|
|
|
sp<IStreamOutCallback> callback = self->mCallback.load();
|
2017-12-21 13:14:27 -08:00
|
|
|
if (callback.get() == nullptr) return 0;
|
2016-10-31 10:39:47 -07:00
|
|
|
ALOGV("asyncCallback() event %d", event);
|
2020-03-19 20:39:12 +00:00
|
|
|
Return<void> result;
|
2016-10-31 10:39:47 -07:00
|
|
|
switch (event) {
|
|
|
|
|
case STREAM_CBK_EVENT_WRITE_READY:
|
2020-03-19 20:39:12 +00:00
|
|
|
result = callback->onWriteReady();
|
2016-10-31 10:39:47 -07:00
|
|
|
break;
|
|
|
|
|
case STREAM_CBK_EVENT_DRAIN_READY:
|
2020-03-19 20:39:12 +00:00
|
|
|
result = callback->onDrainReady();
|
2016-10-31 10:39:47 -07:00
|
|
|
break;
|
|
|
|
|
case STREAM_CBK_EVENT_ERROR:
|
2020-03-19 20:39:12 +00:00
|
|
|
result = callback->onError();
|
2016-10-31 10:39:47 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ALOGW("asyncCallback() unknown event %d", event);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-03-19 20:39:12 +00:00
|
|
|
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
|
2016-10-31 10:39:47 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::supportsPauseAndResume(supportsPauseAndResume_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
_hidl_cb(mStream->pause != NULL, mStream->resume != NULL);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::pause() {
|
2019-12-11 15:50:51 -08:00
|
|
|
return mStream->pause != NULL
|
|
|
|
|
? Stream::analyzeStatus("pause", mStream->pause(mStream), {ENOSYS} /*ignore*/)
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::resume() {
|
2019-12-11 15:50:51 -08:00
|
|
|
return mStream->resume != NULL
|
|
|
|
|
? Stream::analyzeStatus("resume", mStream->resume(mStream), {ENOSYS} /*ignore*/)
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<bool> StreamOut::supportsDrain() {
|
2016-10-31 10:39:47 -07:00
|
|
|
return mStream->drain != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::drain(AudioDrain type) {
|
2020-10-19 21:27:14 +00:00
|
|
|
audio_drain_type_t halDrainType =
|
|
|
|
|
type == AudioDrain::EARLY_NOTIFY ? AUDIO_DRAIN_EARLY_NOTIFY : AUDIO_DRAIN_ALL;
|
2017-05-05 14:02:55 -07:00
|
|
|
return mStream->drain != NULL
|
2020-10-19 21:27:14 +00:00
|
|
|
? Stream::analyzeStatus("drain", mStream->drain(mStream, halDrainType),
|
|
|
|
|
{ENOSYS} /*ignore*/)
|
2019-12-11 15:50:51 -08:00
|
|
|
: Result::NOT_SUPPORTED;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-05-05 14:02:55 -07:00
|
|
|
Return<Result> StreamOut::flush() {
|
2019-12-11 15:50:51 -08:00
|
|
|
return mStream->flush != NULL
|
|
|
|
|
? Stream::analyzeStatus("flush", mStream->flush(mStream), {ENOSYS} /*ignore*/)
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2016-10-31 10:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-12 09:28:52 -08:00
|
|
|
// static
|
2017-12-14 18:50:12 -08:00
|
|
|
Result StreamOut::getPresentationPositionImpl(audio_stream_out_t* stream, uint64_t* frames,
|
2017-05-05 14:02:55 -07:00
|
|
|
TimeSpec* timeStamp) {
|
2017-05-19 16:46:28 -07:00
|
|
|
// Don't logspam on EINVAL--it's normal for get_presentation_position
|
|
|
|
|
// to return it sometimes. EAGAIN may be returned by A2DP audio HAL
|
|
|
|
|
// implementation. ENODATA can also be reported while the writer is
|
|
|
|
|
// continuously querying it, but the stream has been stopped.
|
2019-12-11 15:50:51 -08:00
|
|
|
static const std::vector<int> ignoredErrors{EINVAL, EAGAIN, ENODATA, ENOSYS};
|
2016-10-31 10:39:47 -07:00
|
|
|
Result retval(Result::NOT_SUPPORTED);
|
2017-01-12 09:28:52 -08:00
|
|
|
if (stream->get_presentation_position == NULL) return retval;
|
|
|
|
|
struct timespec halTimeStamp;
|
2017-05-19 16:46:28 -07:00
|
|
|
retval = Stream::analyzeStatus("get_presentation_position",
|
|
|
|
|
stream->get_presentation_position(stream, frames, &halTimeStamp),
|
|
|
|
|
ignoredErrors);
|
2017-01-12 09:28:52 -08:00
|
|
|
if (retval == Result::OK) {
|
|
|
|
|
timeStamp->tvSec = halTimeStamp.tv_sec;
|
|
|
|
|
timeStamp->tvNSec = halTimeStamp.tv_nsec;
|
|
|
|
|
}
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::getPresentationPosition(getPresentationPosition_cb _hidl_cb) {
|
2016-10-31 10:39:47 -07:00
|
|
|
uint64_t frames = 0;
|
2017-05-05 14:02:55 -07:00
|
|
|
TimeSpec timeStamp = {0, 0};
|
2017-01-12 09:28:52 -08:00
|
|
|
Result retval = getPresentationPositionImpl(mStream, &frames, &timeStamp);
|
2016-10-31 10:39:47 -07:00
|
|
|
_hidl_cb(retval, frames, timeStamp);
|
|
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 19:15:45 -08:00
|
|
|
Return<Result> StreamOut::start() {
|
|
|
|
|
return mStreamMmap->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamOut::stop() {
|
|
|
|
|
return mStreamMmap->stop();
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-14 18:50:12 -08:00
|
|
|
Return<void> StreamOut::createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) {
|
|
|
|
|
return mStreamMmap->createMmapBuffer(minSizeFrames, audio_stream_out_frame_size(mStream),
|
|
|
|
|
_hidl_cb);
|
2016-12-15 19:15:45 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<void> StreamOut::getMmapPosition(getMmapPosition_cb _hidl_cb) {
|
|
|
|
|
return mStreamMmap->getMmapPosition(_hidl_cb);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<void> StreamOut::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
|
2021-01-07 18:29:59 -08:00
|
|
|
Result StreamOut::doUpdateSourceMetadata(const SourceMetadata& sourceMetadata) {
|
2020-12-10 17:25:40 -08:00
|
|
|
std::vector<playback_track_metadata_t> halTracks;
|
2021-01-07 18:29:59 -08:00
|
|
|
#if MAJOR_VERSION <= 6
|
2021-01-15 19:05:04 +00:00
|
|
|
(void)CoreUtils::sourceMetadataToHal(sourceMetadata, &halTracks);
|
2021-01-07 18:29:59 -08:00
|
|
|
#else
|
|
|
|
|
// Validate whether a conversion to V7 is possible. This is needed
|
|
|
|
|
// to have a consistent behavior of the HAL regardless of the API
|
|
|
|
|
// version of the legacy HAL (and also to be consistent with openOutputStream).
|
|
|
|
|
std::vector<playback_track_metadata_v7> halTracksV7;
|
2021-01-15 19:05:04 +00:00
|
|
|
if (status_t status = CoreUtils::sourceMetadataToHalV7(
|
|
|
|
|
sourceMetadata, false /*ignoreNonVendorTags*/, &halTracksV7);
|
|
|
|
|
status == NO_ERROR) {
|
2021-01-07 18:29:59 -08:00
|
|
|
halTracks.reserve(halTracksV7.size());
|
|
|
|
|
for (auto metadata_v7 : halTracksV7) {
|
|
|
|
|
halTracks.push_back(std::move(metadata_v7.base));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-12-17 15:01:54 -08:00
|
|
|
return Stream::analyzeStatus("sourceMetadataToHal", status);
|
2018-03-28 11:32:08 -07:00
|
|
|
}
|
2021-01-07 18:29:59 -08:00
|
|
|
#endif // MAJOR_VERSION <= 6
|
2018-03-28 11:32:08 -07:00
|
|
|
const source_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_source_metadata(mStream, &halMetadata);
|
2020-12-17 15:01:54 -08:00
|
|
|
return Result::OK;
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if MAJOR_VERSION >= 7
|
2020-12-17 15:01:54 -08:00
|
|
|
Result StreamOut::doUpdateSourceMetadataV7(const SourceMetadata& sourceMetadata) {
|
2020-11-20 18:42:21 +01:00
|
|
|
std::vector<playback_track_metadata_v7> halTracks;
|
2021-01-15 19:05:04 +00:00
|
|
|
if (status_t status = CoreUtils::sourceMetadataToHalV7(
|
|
|
|
|
sourceMetadata, false /*ignoreNonVendorTags*/, &halTracks);
|
|
|
|
|
status != NO_ERROR) {
|
2020-12-17 15:01:54 -08:00
|
|
|
return Stream::analyzeStatus("sourceMetadataToHal", status);
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
|
|
|
|
const source_metadata_v7_t halMetadata = {
|
|
|
|
|
.track_count = halTracks.size(),
|
|
|
|
|
.tracks = halTracks.data(),
|
|
|
|
|
};
|
|
|
|
|
mStream->update_source_metadata_v7(mStream, &halMetadata);
|
2020-12-17 15:01:54 -08:00
|
|
|
return Result::OK;
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
|
|
|
|
#endif // MAJOR_VERSION >= 7
|
|
|
|
|
|
2020-12-17 15:01:54 -08:00
|
|
|
#if MAJOR_VERSION <= 6
|
2020-11-20 18:42:21 +01:00
|
|
|
Return<void> StreamOut::updateSourceMetadata(const SourceMetadata& sourceMetadata) {
|
|
|
|
|
if (mStream->update_source_metadata == nullptr) {
|
|
|
|
|
return Void(); // not supported by the HAL
|
|
|
|
|
}
|
2021-01-07 18:29:59 -08:00
|
|
|
(void)doUpdateSourceMetadata(sourceMetadata);
|
2020-12-17 15:01:54 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
#elif MAJOR_VERSION >= 7
|
|
|
|
|
Return<Result> StreamOut::updateSourceMetadata(const SourceMetadata& sourceMetadata) {
|
2020-11-20 18:42:21 +01:00
|
|
|
if (mDevice->version() < AUDIO_DEVICE_API_VERSION_3_2) {
|
|
|
|
|
if (mStream->update_source_metadata == nullptr) {
|
2020-12-17 15:01:54 -08:00
|
|
|
return Result::NOT_SUPPORTED;
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
2021-01-07 18:29:59 -08:00
|
|
|
return doUpdateSourceMetadata(sourceMetadata);
|
2020-11-20 18:42:21 +01:00
|
|
|
} else {
|
|
|
|
|
if (mStream->update_source_metadata_v7 == nullptr) {
|
2020-12-17 15:01:54 -08:00
|
|
|
return Result::NOT_SUPPORTED;
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
2020-12-17 15:01:54 -08:00
|
|
|
return doUpdateSourceMetadataV7(sourceMetadata);
|
2020-11-20 18:42:21 +01:00
|
|
|
}
|
2018-03-01 15:08:07 -08:00
|
|
|
}
|
2020-12-17 15:01:54 -08:00
|
|
|
#endif
|
2020-11-20 18:42:21 +01:00
|
|
|
|
2018-03-01 15:08:07 -08:00
|
|
|
Return<Result> StreamOut::selectPresentation(int32_t /*presentationId*/, int32_t /*programId*/) {
|
|
|
|
|
return Result::NOT_SUPPORTED; // TODO: propagate to legacy
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-02-14 17:13:52 -08:00
|
|
|
#if MAJOR_VERSION >= 6
|
|
|
|
|
Return<void> StreamOut::getDualMonoMode(getDualMonoMode_cb _hidl_cb) {
|
2020-08-19 15:56:29 +08:00
|
|
|
audio_dual_mono_mode_t mode = AUDIO_DUAL_MONO_MODE_OFF;
|
|
|
|
|
Result retval = mStream->get_dual_mono_mode != nullptr
|
|
|
|
|
? Stream::analyzeStatus("get_dual_mono_mode",
|
|
|
|
|
mStream->get_dual_mono_mode(mStream, &mode))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
|
|
|
|
_hidl_cb(retval, DualMonoMode(mode));
|
2020-02-14 17:13:52 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 15:56:29 +08:00
|
|
|
Return<Result> StreamOut::setDualMonoMode(DualMonoMode mode) {
|
|
|
|
|
return mStream->set_dual_mono_mode != nullptr
|
|
|
|
|
? Stream::analyzeStatus(
|
|
|
|
|
"set_dual_mono_mode",
|
|
|
|
|
mStream->set_dual_mono_mode(mStream,
|
|
|
|
|
static_cast<audio_dual_mono_mode_t>(mode)))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2020-02-14 17:13:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<void> StreamOut::getAudioDescriptionMixLevel(getAudioDescriptionMixLevel_cb _hidl_cb) {
|
2020-08-19 15:56:29 +08:00
|
|
|
float leveldB = -std::numeric_limits<float>::infinity();
|
|
|
|
|
Result retval = mStream->get_audio_description_mix_level != nullptr
|
|
|
|
|
? Stream::analyzeStatus(
|
|
|
|
|
"get_audio_description_mix_level",
|
|
|
|
|
mStream->get_audio_description_mix_level(mStream, &leveldB))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
|
|
|
|
_hidl_cb(retval, leveldB);
|
2020-02-14 17:13:52 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 15:56:29 +08:00
|
|
|
Return<Result> StreamOut::setAudioDescriptionMixLevel(float leveldB) {
|
|
|
|
|
return mStream->set_audio_description_mix_level != nullptr
|
|
|
|
|
? Stream::analyzeStatus(
|
|
|
|
|
"set_audio_description_mix_level",
|
|
|
|
|
mStream->set_audio_description_mix_level(mStream, leveldB))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2020-02-14 17:13:52 -08:00
|
|
|
}
|
2020-02-19 10:50:50 -08:00
|
|
|
|
|
|
|
|
Return<void> StreamOut::getPlaybackRateParameters(getPlaybackRateParameters_cb _hidl_cb) {
|
2020-08-19 15:56:29 +08:00
|
|
|
audio_playback_rate_t rate = AUDIO_PLAYBACK_RATE_INITIALIZER;
|
|
|
|
|
Result retval =
|
|
|
|
|
mStream->get_playback_rate_parameters != nullptr
|
|
|
|
|
? Stream::analyzeStatus("get_playback_rate_parameters",
|
|
|
|
|
mStream->get_playback_rate_parameters(mStream, &rate))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
|
|
|
|
_hidl_cb(retval,
|
|
|
|
|
PlaybackRate{rate.mSpeed, rate.mPitch, static_cast<TimestretchMode>(rate.mStretchMode),
|
|
|
|
|
static_cast<TimestretchFallbackMode>(rate.mFallbackMode)});
|
2020-02-19 10:50:50 -08:00
|
|
|
return Void();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 15:56:29 +08:00
|
|
|
Return<Result> StreamOut::setPlaybackRateParameters(const PlaybackRate& playbackRate) {
|
|
|
|
|
audio_playback_rate_t rate = {
|
|
|
|
|
playbackRate.speed, playbackRate.pitch,
|
|
|
|
|
static_cast<audio_timestretch_stretch_mode_t>(playbackRate.timestretchMode),
|
|
|
|
|
static_cast<audio_timestretch_fallback_mode_t>(playbackRate.fallbackMode)};
|
|
|
|
|
return mStream->set_playback_rate_parameters != nullptr
|
|
|
|
|
? Stream::analyzeStatus("set_playback_rate_parameters",
|
|
|
|
|
mStream->set_playback_rate_parameters(mStream, &rate))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
2020-02-19 10:50:50 -08:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 13:05:44 -08:00
|
|
|
Return<Result> StreamOut::setEventCallback(const sp<IStreamOutEventCallback>& callback) {
|
|
|
|
|
if (mStream->set_event_callback == nullptr) return Result::NOT_SUPPORTED;
|
|
|
|
|
int result = mStream->set_event_callback(mStream, StreamOut::asyncEventCallback, this);
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
mEventCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
return Stream::analyzeStatus("set_stream_out_callback", result, {ENOSYS} /*ignore*/);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
int StreamOut::asyncEventCallback(stream_event_callback_type_t event, void* param, void* cookie) {
|
|
|
|
|
StreamOut* self = reinterpret_cast<StreamOut*>(cookie);
|
2021-01-14 19:42:25 -08:00
|
|
|
sp<IStreamOutEventCallback> eventCallback = self->mEventCallback.load();
|
2020-02-12 13:05:44 -08:00
|
|
|
if (eventCallback.get() == nullptr) return 0;
|
|
|
|
|
ALOGV("%s event %d", __func__, event);
|
2020-03-19 20:39:12 +00:00
|
|
|
Return<void> result;
|
2020-02-12 13:05:44 -08:00
|
|
|
switch (event) {
|
|
|
|
|
case STREAM_EVENT_CBK_TYPE_CODEC_FORMAT_CHANGED: {
|
|
|
|
|
hidl_vec<uint8_t> audioMetadata;
|
2021-04-30 15:29:47 -07:00
|
|
|
// void* param is the byte string buffer from byte_string_from_audio_metadata().
|
|
|
|
|
// As the byte string buffer may have embedded zeroes, we cannot use strlen()
|
|
|
|
|
// but instead use audio_utils::metadata::dataByteStringLen().
|
|
|
|
|
audioMetadata.setToExternal((uint8_t*)param, audio_utils::metadata::dataByteStringLen(
|
|
|
|
|
(const uint8_t*)param));
|
2020-03-19 20:39:12 +00:00
|
|
|
result = eventCallback->onCodecFormatChanged(audioMetadata);
|
2020-02-12 13:05:44 -08:00
|
|
|
} break;
|
|
|
|
|
default:
|
|
|
|
|
ALOGW("%s unknown event %d", __func__, event);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-03-19 20:39:12 +00:00
|
|
|
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
|
2020-02-12 13:05:44 -08:00
|
|
|
return 0;
|
|
|
|
|
}
|
2022-01-27 15:07:15 +01:00
|
|
|
|
|
|
|
|
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
|
|
|
|
|
Return<Result> StreamOut::setLatencyMode(LatencyMode mode) {
|
|
|
|
|
return mStream->set_latency_mode != nullptr
|
|
|
|
|
? Stream::analyzeStatus(
|
|
|
|
|
"set_latency_mode",
|
|
|
|
|
mStream->set_latency_mode(mStream,
|
|
|
|
|
static_cast<audio_latency_mode_t>(mode)))
|
|
|
|
|
: Result::NOT_SUPPORTED;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Return<void> StreamOut::getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) {
|
|
|
|
|
Result retval = Result::NOT_SUPPORTED;
|
|
|
|
|
hidl_vec<LatencyMode> hidlModes;
|
|
|
|
|
size_t num_modes = AUDIO_LATENCY_MODE_CNT;
|
|
|
|
|
audio_latency_mode_t modes[AUDIO_LATENCY_MODE_CNT];
|
|
|
|
|
|
|
|
|
|
if (mStream->get_recommended_latency_modes != nullptr &&
|
|
|
|
|
mStream->get_recommended_latency_modes(mStream, &modes[0], &num_modes) == 0) {
|
|
|
|
|
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
|
|
|
|
|
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
|
|
|
|
|
retval = Result::INVALID_STATE;
|
|
|
|
|
} else {
|
|
|
|
|
hidlModes.resize(num_modes);
|
|
|
|
|
for (size_t i = 0; i < num_modes; ++i) {
|
|
|
|
|
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
|
|
|
|
|
}
|
|
|
|
|
retval = Result::OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_hidl_cb(retval, hidlModes);
|
|
|
|
|
return Void();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
|
void StreamOut::latencyModeCallback(audio_latency_mode_t* modes, size_t num_modes, void* cookie) {
|
|
|
|
|
StreamOut* self = reinterpret_cast<StreamOut*>(cookie);
|
|
|
|
|
sp<IStreamOutLatencyModeCallback> callback = self->mLatencyModeCallback.load();
|
|
|
|
|
if (callback.get() == nullptr) return;
|
|
|
|
|
|
|
|
|
|
ALOGV("%s", __func__);
|
|
|
|
|
|
|
|
|
|
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
|
|
|
|
|
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hidl_vec<LatencyMode> hidlModes(num_modes);
|
|
|
|
|
for (size_t i = 0; i < num_modes; ++i) {
|
|
|
|
|
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
|
|
|
|
|
}
|
|
|
|
|
Return<void> result = callback->onRecommendedLatencyModeChanged(hidlModes);
|
|
|
|
|
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Return<Result> StreamOut::setLatencyModeCallback(
|
|
|
|
|
const sp<IStreamOutLatencyModeCallback>& callback) {
|
|
|
|
|
if (mStream->set_latency_mode_callback == nullptr) return Result::NOT_SUPPORTED;
|
|
|
|
|
int result = mStream->set_latency_mode_callback(mStream, StreamOut::latencyModeCallback, this);
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
mLatencyModeCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
return Stream::analyzeStatus("set_latency_mode_callback", result, {ENOSYS} /*ignore*/);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-02-14 17:13:52 -08:00
|
|
|
#endif
|
|
|
|
|
|
2016-10-31 10:39:47 -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
|