am cfd55579: OMXCodec now notifies the reader of changes in the output format by returning a special result/error code.

Merge commit 'cfd55579c2e20514b181809dfaf30bd6f7e04c7e' into eclair-mr2-plus-aosp

* commit 'cfd55579c2e20514b181809dfaf30bd6f7e04c7e':
  OMXCodec now notifies the reader of changes in the output format by returning a special result/error code.
This commit is contained in:
Andreas Huber
2009-10-13 09:56:09 -07:00
committed by Android Git Automerger
7 changed files with 46 additions and 2 deletions

View File

@@ -71,7 +71,12 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
options.clearSeekTo();
bool shouldSeek = false;
if (err != OK) {
if (err == INFO_FORMAT_CHANGED) {
CHECK_EQ(buffer, NULL);
printf("format changed.\n");
continue;
} else if (err != OK) {
printf("reached EOF.\n");
shouldSeek = true;
@@ -136,6 +141,12 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
if (err != OK) {
CHECK_EQ(buffer, NULL);
if (err == INFO_FORMAT_CHANGED) {
printf("format changed.\n");
continue;
}
break;
}

View File

@@ -36,6 +36,9 @@ enum {
ERROR_BUFFER_TOO_SMALL = MEDIA_ERROR_BASE - 9,
ERROR_UNSUPPORTED = MEDIA_ERROR_BASE - 10,
ERROR_END_OF_STREAM = MEDIA_ERROR_BASE - 11,
// Not technically an error.
INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
};
} // namespace android

View File

@@ -51,6 +51,9 @@ struct MediaSource : public RefBase {
// buffer is available, an error is encountered of the end of the stream
// is reached.
// End of stream is signalled by a result of ERROR_END_OF_STREAM.
// A result of INFO_FORMAT_CHANGED indicates that the format of this
// MediaSource has changed mid-stream, the client can continue reading
// but should be prepared for buffers of the new configuration.
virtual status_t read(
MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;

View File

@@ -124,6 +124,7 @@ private:
bool mInitialBufferSubmit;
bool mSignalledEOS;
bool mNoMoreOutputData;
bool mOutputPortSettingsHaveChanged;
int64_t mSeekTimeUs;
Mutex mLock;

View File

@@ -130,7 +130,10 @@ VideoFrame *StagefrightMetadataRetriever::captureFrame() {
decoder->start();
MediaBuffer *buffer;
status_t err = decoder->read(&buffer);
status_t err;
do {
err = decoder->read(&buffer);
} while (err == INFO_FORMAT_CHANGED);
if (err != OK) {
CHECK_EQ(buffer, NULL);

View File

@@ -250,6 +250,13 @@ void MediaPlayerImpl::videoEntry() {
status_t err = mVideoDecoder->read(&buffer, &options);
CHECK((err == OK && buffer != NULL) || (err != OK && buffer == NULL));
if (err == INFO_FORMAT_CHANGED) {
LOGI("format changed.");
depopulateISurface();
populateISurface();
continue;
}
if (err == ERROR_END_OF_STREAM || err != OK) {
eof = true;
continue;
@@ -601,6 +608,9 @@ void MediaPlayerImpl::populateISurface() {
success = success && meta->findInt32(kKeyHeight, &decodedHeight);
CHECK(success);
LOGI("mVideoWidth=%ld, mVideoHeight=%ld, decodedWidth=%ld, decodedHeight=%ld",
mVideoWidth, mVideoHeight, decodedWidth, decodedHeight);
if (mSurface.get() != NULL) {
mVideoRenderer =
mClient.interface()->createRenderer(

View File

@@ -677,6 +677,7 @@ OMXCodec::OMXCodec(
mInitialBufferSubmit(true),
mSignalledEOS(false),
mNoMoreOutputData(false),
mOutputPortSettingsHaveChanged(false),
mSeekTimeUs(-1) {
mPortStatus[kPortIndexInput] = ENABLED;
mPortStatus[kPortIndexOutput] = ENABLED;
@@ -1078,6 +1079,9 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
if (mState == RECONFIGURING) {
CHECK_EQ(portIndex, kPortIndexOutput);
initOutputFormat(mSource->getFormat());
mOutputPortSettingsHaveChanged = true;
enablePortAsync(portIndex);
status_t err = allocateBuffersOnPort(portIndex);
@@ -1782,6 +1786,7 @@ status_t OMXCodec::start(MetaData *) {
mInitialBufferSubmit = true;
mSignalledEOS = false;
mNoMoreOutputData = false;
mOutputPortSettingsHaveChanged = false;
mSeekTimeUs = -1;
mFilledBuffers.clear();
@@ -1852,6 +1857,8 @@ status_t OMXCodec::stop() {
}
sp<MetaData> OMXCodec::getFormat() {
Mutex::Autolock autoLock(mLock);
return mOutputFormat;
}
@@ -1915,6 +1922,12 @@ status_t OMXCodec::read(
return ERROR_END_OF_STREAM;
}
if (mOutputPortSettingsHaveChanged) {
mOutputPortSettingsHaveChanged = false;
return INFO_FORMAT_CHANGED;
}
size_t index = *mFilledBuffers.begin();
mFilledBuffers.erase(mFilledBuffers.begin());