summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2013-08-23 13:51:43 -0700
committerGlenn Kasten <gkasten@google.com>2013-09-03 11:24:02 -0700
commit767094dd98b01baf21de2ad09c27b3c98776cf73 (patch)
tree57b1a9c3b3d794bac2e1922b314046f02df18e7e
parente45a767e13fe3396185c9d378a70f7f11eb881d0 (diff)
downloadframeworks_av-767094dd98b01baf21de2ad09c27b3c98776cf73.zip
frameworks_av-767094dd98b01baf21de2ad09c27b3c98776cf73.tar.gz
frameworks_av-767094dd98b01baf21de2ad09c27b3c98776cf73.tar.bz2
Add NBAIO_Sink::getTimestamp()
with a real implementation in AudioStreamOutSink for dummy implementation initially in MonoPipe. Use in AudioFlinger::PlaybackThread::threadLoop_write() to keep the input to the timestamp latch up-to-date. Change-Id: I10ef277991b63bb43d55d6f3df75116ef32246cd
-rw-r--r--include/media/nbaio/AudioStreamOutSink.h2
-rw-r--r--include/media/nbaio/MonoPipe.h3
-rw-r--r--include/media/nbaio/NBAIO.h6
-rw-r--r--media/libnbaio/AudioStreamOutSink.cpp12
-rw-r--r--media/libnbaio/MonoPipe.cpp5
-rw-r--r--services/audioflinger/Threads.cpp4
6 files changed, 31 insertions, 1 deletions
diff --git a/include/media/nbaio/AudioStreamOutSink.h b/include/media/nbaio/AudioStreamOutSink.h
index 5976b18..7948d40 100644
--- a/include/media/nbaio/AudioStreamOutSink.h
+++ b/include/media/nbaio/AudioStreamOutSink.h
@@ -52,6 +52,8 @@ public:
// implementation of GNWT (if any)
virtual status_t getNextWriteTimestamp(int64_t *timestamp);
+ virtual status_t getTimestamp(AudioTimestamp& timestamp);
+
// NBAIO_Sink end
#if 0 // until necessary
diff --git a/include/media/nbaio/MonoPipe.h b/include/media/nbaio/MonoPipe.h
index 5fcfe9e..ffdcc21 100644
--- a/include/media/nbaio/MonoPipe.h
+++ b/include/media/nbaio/MonoPipe.h
@@ -88,6 +88,9 @@ public:
// Return true if the write side of a pipe is currently shutdown.
bool isShutdown();
+ // Return NO_ERROR if there is a timestamp available
+ status_t getTimestamp(AudioTimestamp& timestamp);
+
private:
// A pair of methods and a helper variable which allows the reader and the
// writer to update and observe the values of mFront and mNextRdPTS in an
diff --git a/include/media/nbaio/NBAIO.h b/include/media/nbaio/NBAIO.h
index f5d6eb5..cc5b3e6 100644
--- a/include/media/nbaio/NBAIO.h
+++ b/include/media/nbaio/NBAIO.h
@@ -28,6 +28,7 @@
#include <stdlib.h>
#include <utils/Errors.h>
#include <utils/RefBase.h>
+#include <media/AudioTimestamp.h>
namespace android {
@@ -213,6 +214,11 @@ public:
// <other> Something unexpected happened internally. Check the logs and start debugging.
virtual status_t getNextWriteTimestamp(int64_t *ts) { return INVALID_OPERATION; }
+ // Returns NO_ERROR if a timestamp is available. The timestamp includes the total number
+ // of frames presented to an external observer, together with the value of CLOCK_MONOTONIC
+ // as of this presentation count.
+ virtual status_t getTimestamp(AudioTimestamp& timestamp) { return INVALID_OPERATION; }
+
protected:
NBAIO_Sink(NBAIO_Format format = Format_Invalid) : NBAIO_Port(format), mFramesWritten(0) { }
virtual ~NBAIO_Sink() { }
diff --git a/media/libnbaio/AudioStreamOutSink.cpp b/media/libnbaio/AudioStreamOutSink.cpp
index 6f525e5..b2de8a2 100644
--- a/media/libnbaio/AudioStreamOutSink.cpp
+++ b/media/libnbaio/AudioStreamOutSink.cpp
@@ -79,4 +79,16 @@ status_t AudioStreamOutSink::getNextWriteTimestamp(int64_t *timestamp) {
return mStream->get_next_write_timestamp(mStream, timestamp);
}
+status_t AudioStreamOutSink::getTimestamp(AudioTimestamp& timestamp)
+{
+ // FIXME position64 won't be needed after AudioTimestamp.mPosition is changed to uint64_t
+ uint64_t position64;
+ int ok = mStream->get_presentation_position(mStream, &position64, &timestamp.mTime);
+ if (ok != 0) {
+ return INVALID_OPERATION;
+ }
+ timestamp.mPosition = position64;
+ return OK;
+}
+
} // namespace android
diff --git a/media/libnbaio/MonoPipe.cpp b/media/libnbaio/MonoPipe.cpp
index e8d3d9b..a74b49e 100644
--- a/media/libnbaio/MonoPipe.cpp
+++ b/media/libnbaio/MonoPipe.cpp
@@ -310,4 +310,9 @@ bool MonoPipe::isShutdown()
return mIsShutdown;
}
+status_t MonoPipe::getTimestamp(AudioTimestamp& timestamp)
+{
+ return INVALID_OPERATION;
+}
+
} // namespace android
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 3921b68..fda4211 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -1820,7 +1820,7 @@ ssize_t AudioFlinger::PlaybackThread::threadLoop_write()
} else {
bytesWritten = framesWritten;
}
- status_t status = INVALID_OPERATION; // mLatchD.mTimestamp is invalid
+ status_t status = mNormalSink->getTimestamp(mLatchD.mTimestamp);
if (status == NO_ERROR) {
size_t totalFramesWritten = mNormalSink->framesWritten();
if (totalFramesWritten >= mLatchD.mTimestamp.mPosition) {
@@ -1837,6 +1837,8 @@ ssize_t AudioFlinger::PlaybackThread::threadLoop_write()
ALOG_ASSERT(mCallbackThread != 0);
mCallbackThread->setWriteBlocked(true);
}
+ // FIXME We should have an implementation of timestamps for direct output threads.
+ // They are used e.g for multichannel PCM playback over HDMI.
bytesWritten = mOutput->stream->write(mOutput->stream,
mMixBuffer + offset, mBytesRemaining);
if (mUseAsyncWrite &&