Merge "When encountering a discontinuity, flush(clear) all content enqueued up to that"
This commit is contained in:
committed by
Android (Google) Code Review
commit
463854bead
@@ -14,6 +14,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//#define LOG_NDEBUG 0
|
||||||
|
#define LOG_TAG "stream"
|
||||||
|
#include "utils/Log.h"
|
||||||
|
|
||||||
#include <binder/ProcessState.h>
|
#include <binder/ProcessState.h>
|
||||||
|
|
||||||
#include <media/IStreamSource.h>
|
#include <media/IStreamSource.h>
|
||||||
@@ -50,7 +54,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
int mFd;
|
int mFd;
|
||||||
off64_t mFileSize;
|
off64_t mFileSize;
|
||||||
int64_t mNextSeekTimeUs;
|
uint64_t mNumPacketsSent;
|
||||||
|
|
||||||
sp<IStreamListener> mListener;
|
sp<IStreamListener> mListener;
|
||||||
Vector<sp<IMemory> > mBuffers;
|
Vector<sp<IMemory> > mBuffers;
|
||||||
@@ -61,7 +65,7 @@ private:
|
|||||||
MyStreamSource::MyStreamSource(int fd)
|
MyStreamSource::MyStreamSource(int fd)
|
||||||
: mFd(fd),
|
: mFd(fd),
|
||||||
mFileSize(0),
|
mFileSize(0),
|
||||||
mNextSeekTimeUs(-1) { // ALooper::GetNowUs() + 5000000ll) {
|
mNumPacketsSent(0) {
|
||||||
CHECK_GE(fd, 0);
|
CHECK_GE(fd, 0);
|
||||||
|
|
||||||
mFileSize = lseek64(fd, 0, SEEK_END);
|
mFileSize = lseek64(fd, 0, SEEK_END);
|
||||||
@@ -84,18 +88,24 @@ void MyStreamSource::setBuffers(const Vector<sp<IMemory> > &buffers) {
|
|||||||
void MyStreamSource::onBufferAvailable(size_t index) {
|
void MyStreamSource::onBufferAvailable(size_t index) {
|
||||||
CHECK_LT(index, mBuffers.size());
|
CHECK_LT(index, mBuffers.size());
|
||||||
|
|
||||||
if (mNextSeekTimeUs >= 0 && mNextSeekTimeUs <= ALooper::GetNowUs()) {
|
#if 0
|
||||||
off64_t offset = (off64_t)(((float)rand() / RAND_MAX) * mFileSize * 0.8);
|
if (mNumPacketsSent >= 20000) {
|
||||||
offset = (offset / 188) * 188;
|
LOGI("signalling discontinuity now");
|
||||||
|
|
||||||
|
off64_t offset = 0;
|
||||||
|
CHECK((offset % 188) == 0);
|
||||||
|
|
||||||
lseek(mFd, offset, SEEK_SET);
|
lseek(mFd, offset, SEEK_SET);
|
||||||
|
|
||||||
mListener->issueCommand(
|
sp<AMessage> extra = new AMessage;
|
||||||
IStreamListener::DISCONTINUITY, false /* synchronous */);
|
extra->setInt32(IStreamListener::kKeyFormatChange, 0);
|
||||||
|
|
||||||
mNextSeekTimeUs = -1;
|
mListener->issueCommand(
|
||||||
mNextSeekTimeUs = ALooper::GetNowUs() + 5000000ll;
|
IStreamListener::DISCONTINUITY, false /* synchronous */, extra);
|
||||||
|
|
||||||
|
mNumPacketsSent = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
sp<IMemory> mem = mBuffers.itemAt(index);
|
sp<IMemory> mem = mBuffers.itemAt(index);
|
||||||
|
|
||||||
@@ -104,6 +114,8 @@ void MyStreamSource::onBufferAvailable(size_t index) {
|
|||||||
mListener->issueCommand(IStreamListener::EOS, false /* synchronous */);
|
mListener->issueCommand(IStreamListener::EOS, false /* synchronous */);
|
||||||
} else {
|
} else {
|
||||||
mListener->queueBuffer(index, n);
|
mListener->queueBuffer(index, n);
|
||||||
|
|
||||||
|
mNumPacketsSent += n / 188;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -293,12 +305,17 @@ int main(int argc, char **argv) {
|
|||||||
sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;
|
sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;
|
||||||
CHECK_EQ(composerClient->initCheck(), (status_t)OK);
|
CHECK_EQ(composerClient->initCheck(), (status_t)OK);
|
||||||
|
|
||||||
|
ssize_t displayWidth = composerClient->getDisplayWidth(0);
|
||||||
|
ssize_t displayHeight = composerClient->getDisplayHeight(0);
|
||||||
|
|
||||||
|
LOGV("display is %d x %d\n", displayWidth, displayHeight);
|
||||||
|
|
||||||
sp<SurfaceControl> control =
|
sp<SurfaceControl> control =
|
||||||
composerClient->createSurface(
|
composerClient->createSurface(
|
||||||
String8("A Surface"),
|
String8("A Surface"),
|
||||||
0,
|
0,
|
||||||
1280,
|
displayWidth,
|
||||||
800,
|
displayHeight,
|
||||||
PIXEL_FORMAT_RGB_565,
|
PIXEL_FORMAT_RGB_565,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
|||||||
@@ -136,25 +136,29 @@ void AnotherPacketSource::queueAccessUnit(const sp<ABuffer> &buffer) {
|
|||||||
void AnotherPacketSource::queueDiscontinuity(
|
void AnotherPacketSource::queueDiscontinuity(
|
||||||
ATSParser::DiscontinuityType type,
|
ATSParser::DiscontinuityType type,
|
||||||
const sp<AMessage> &extra) {
|
const sp<AMessage> &extra) {
|
||||||
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
|
// Leave only discontinuities in the queue.
|
||||||
|
List<sp<ABuffer> >::iterator it = mBuffers.begin();
|
||||||
|
while (it != mBuffers.end()) {
|
||||||
|
sp<ABuffer> oldBuffer = *it;
|
||||||
|
|
||||||
|
int32_t oldDiscontinuityType;
|
||||||
|
if (!oldBuffer->meta()->findInt32(
|
||||||
|
"discontinuity", &oldDiscontinuityType)) {
|
||||||
|
it = mBuffers.erase(it);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
mEOSResult = OK;
|
||||||
|
|
||||||
sp<ABuffer> buffer = new ABuffer(0);
|
sp<ABuffer> buffer = new ABuffer(0);
|
||||||
buffer->meta()->setInt32("discontinuity", static_cast<int32_t>(type));
|
buffer->meta()->setInt32("discontinuity", static_cast<int32_t>(type));
|
||||||
buffer->meta()->setMessage("extra", extra);
|
buffer->meta()->setMessage("extra", extra);
|
||||||
|
|
||||||
Mutex::Autolock autoLock(mLock);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (type == ATSParser::DISCONTINUITY_SEEK
|
|
||||||
|| type == ATSParser::DISCONTINUITY_FORMATCHANGE) {
|
|
||||||
// XXX Fix this: This will also clear any pending discontinuities,
|
|
||||||
// If there's a pending DISCONTINUITY_FORMATCHANGE and the new
|
|
||||||
// discontinuity is "just" a DISCONTINUITY_SEEK, this will effectively
|
|
||||||
// downgrade the type of discontinuity received by the client.
|
|
||||||
|
|
||||||
mBuffers.clear();
|
|
||||||
mEOSResult = OK;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mBuffers.push_back(buffer);
|
mBuffers.push_back(buffer);
|
||||||
mCondition.signal();
|
mCondition.signal();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user