Merge "audiohal: Prevent logspam when calling get_presentation_position" into oc-dev

This commit is contained in:
TreeHugger Robot 2017-06-08 22:47:01 +00:00 committed by Android (Google) Code Review
commit 80e9912183
4 changed files with 34 additions and 18 deletions

View file

@ -44,8 +44,20 @@ Stream::~Stream() {
}
// static
Result Stream::analyzeStatus(const char* funcName, int status, int ignoreError, int ignoreError2) {
if (status != 0 && status != -ignoreError && status != -ignoreError2) {
Result Stream::analyzeStatus(const char* funcName, int status) {
static const std::vector<int> empty;
return analyzeStatus(funcName, status, empty);
}
template <typename T>
inline bool element_in(T e, const std::vector<T>& v) {
return std::find(v.begin(), v.end(), e) != v.end();
}
// static
Result Stream::analyzeStatus(const char* funcName, int status,
const std::vector<int>& ignoreErrors) {
if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) {
ALOGW("Error from HAL stream in function %s: %s", funcName, strerror(-status));
}
switch (status) {

View file

@ -17,6 +17,8 @@
#ifndef ANDROID_HARDWARE_AUDIO_V2_0_STREAM_H
#define ANDROID_HARDWARE_AUDIO_V2_0_STREAM_H
#include <vector>
#include <android/hardware/audio/2.0/IStream.h>
#include <hardware/audio.h>
#include <hidl/Status.h>
@ -79,10 +81,11 @@ struct Stream : public IStream, public ParametersUtil {
Return<Result> close() override;
// Utility methods for extending interfaces.
static Result analyzeStatus(
const char* funcName, int status, int ignoreError = OK, int ignoreError2 = OK);
static Result analyzeStatus(const char* funcName, int status);
static Result analyzeStatus(const char* funcName, int status,
const std::vector<int>& ignoreErrors);
private:
private:
audio_stream_t *mStream;
virtual ~Stream();

View file

@ -416,15 +416,15 @@ Return<uint32_t> StreamIn::getInputFramesLost() {
// static
Result StreamIn::getCapturePositionImpl(audio_stream_in_t* stream,
uint64_t* frames, uint64_t* time) {
// HAL may have a stub function, always returning ENOSYS, don't
// spam the log in this case.
static const std::vector<int> ignoredErrors{ENOSYS};
Result retval(Result::NOT_SUPPORTED);
if (stream->get_capture_position != NULL) return retval;
int64_t halFrames, halTime;
retval = Stream::analyzeStatus(
"get_capture_position",
stream->get_capture_position(stream, &halFrames, &halTime),
// HAL may have a stub function, always returning ENOSYS, don't
// spam the log in this case.
ENOSYS);
retval = Stream::analyzeStatus("get_capture_position",
stream->get_capture_position(stream, &halFrames, &halTime),
ignoredErrors);
if (retval == Result::OK) {
*frames = halFrames;
*time = halTime;

View file

@ -487,16 +487,17 @@ Return<Result> StreamOut::flush() {
Result StreamOut::getPresentationPositionImpl(audio_stream_out_t* stream,
uint64_t* frames,
TimeSpec* timeStamp) {
// 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.
static const std::vector<int> ignoredErrors{EINVAL, EAGAIN, ENODATA};
Result retval(Result::NOT_SUPPORTED);
if (stream->get_presentation_position == NULL) return retval;
struct timespec halTimeStamp;
retval = Stream::analyzeStatus(
"get_presentation_position",
stream->get_presentation_position(stream, frames, &halTimeStamp),
// 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.
EINVAL, EAGAIN);
retval = Stream::analyzeStatus("get_presentation_position",
stream->get_presentation_position(stream, frames, &halTimeStamp),
ignoredErrors);
if (retval == Result::OK) {
timeStamp->tvSec = halTimeStamp.tv_sec;
timeStamp->tvNSec = halTimeStamp.tv_nsec;