Merge "SPDIFEncoder: add reset method for flush" into mnc-dev
diff --git a/audio_utils/include/audio_utils/spdif/SPDIFEncoder.h b/audio_utils/include/audio_utils/spdif/SPDIFEncoder.h
index 171fec1..8d8f71e 100644
--- a/audio_utils/include/audio_utils/spdif/SPDIFEncoder.h
+++ b/audio_utils/include/audio_utils/spdif/SPDIFEncoder.h
@@ -75,6 +75,12 @@
*/
static bool isFormatSupported(audio_format_t format);
+ /**
+ * Discard any data in the buffer. Reset frame scanners.
+ * This should be called when seeking to a new position in the stream.
+ */
+ void reset();
+
protected:
void clearBurstBuffer();
void writeBurstBufferShorts(const uint16_t* buffer, size_t numBytes);
diff --git a/audio_utils/spdif/SPDIFEncoder.cpp b/audio_utils/spdif/SPDIFEncoder.cpp
index 251e367..7a54627 100644
--- a/audio_utils/spdif/SPDIFEncoder.cpp
+++ b/audio_utils/spdif/SPDIFEncoder.cpp
@@ -104,7 +104,7 @@
size_t bytesToWrite = numShorts * sizeof(uint16_t);
if ((mByteCursor + bytesToWrite) > mBurstBufferSizeBytes) {
ALOGE("SPDIFEncoder: Burst buffer overflow!\n");
- clearBurstBuffer();
+ reset();
return;
}
memcpy(&mBurstBuffer[mByteCursor >> 1], buffer, bytesToWrite);
@@ -160,6 +160,17 @@
}
}
+void SPDIFEncoder::reset()
+{
+ ALOGV("SPDIFEncoder: reset()");
+ clearBurstBuffer();
+ if (mFramer != NULL) {
+ mFramer->resetBurst();
+ }
+ mPayloadBytesPending = 0;
+ mScanning = true;
+}
+
void SPDIFEncoder::flushBurstBuffer()
{
const int preambleSize = 4 * sizeof(uint16_t);
@@ -171,8 +182,7 @@
sendZeroPad();
writeOutput(mBurstBuffer, mByteCursor);
}
- clearBurstBuffer();
- mFramer->resetBurst();
+ reset();
}
void SPDIFEncoder::clearBurstBuffer()