}
// 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) {
#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>
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();
// 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;
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;