OMXCodec now notifies the reader of changes in the output format by returning a special result/error code.
This commit is contained in:
@@ -71,7 +71,12 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
|
|||||||
options.clearSeekTo();
|
options.clearSeekTo();
|
||||||
|
|
||||||
bool shouldSeek = false;
|
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");
|
printf("reached EOF.\n");
|
||||||
|
|
||||||
shouldSeek = true;
|
shouldSeek = true;
|
||||||
@@ -136,6 +141,12 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
|
|||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
CHECK_EQ(buffer, NULL);
|
CHECK_EQ(buffer, NULL);
|
||||||
|
|
||||||
|
if (err == INFO_FORMAT_CHANGED) {
|
||||||
|
printf("format changed.\n");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ enum {
|
|||||||
ERROR_BUFFER_TOO_SMALL = MEDIA_ERROR_BASE - 9,
|
ERROR_BUFFER_TOO_SMALL = MEDIA_ERROR_BASE - 9,
|
||||||
ERROR_UNSUPPORTED = MEDIA_ERROR_BASE - 10,
|
ERROR_UNSUPPORTED = MEDIA_ERROR_BASE - 10,
|
||||||
ERROR_END_OF_STREAM = MEDIA_ERROR_BASE - 11,
|
ERROR_END_OF_STREAM = MEDIA_ERROR_BASE - 11,
|
||||||
|
|
||||||
|
// Not technically an error.
|
||||||
|
INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ struct MediaSource : public RefBase {
|
|||||||
// buffer is available, an error is encountered of the end of the stream
|
// buffer is available, an error is encountered of the end of the stream
|
||||||
// is reached.
|
// is reached.
|
||||||
// End of stream is signalled by a result of ERROR_END_OF_STREAM.
|
// 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(
|
virtual status_t read(
|
||||||
MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;
|
MediaBuffer **buffer, const ReadOptions *options = NULL) = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ private:
|
|||||||
bool mInitialBufferSubmit;
|
bool mInitialBufferSubmit;
|
||||||
bool mSignalledEOS;
|
bool mSignalledEOS;
|
||||||
bool mNoMoreOutputData;
|
bool mNoMoreOutputData;
|
||||||
|
bool mOutputPortSettingsHaveChanged;
|
||||||
int64_t mSeekTimeUs;
|
int64_t mSeekTimeUs;
|
||||||
|
|
||||||
Mutex mLock;
|
Mutex mLock;
|
||||||
|
|||||||
@@ -130,7 +130,10 @@ VideoFrame *StagefrightMetadataRetriever::captureFrame() {
|
|||||||
decoder->start();
|
decoder->start();
|
||||||
|
|
||||||
MediaBuffer *buffer;
|
MediaBuffer *buffer;
|
||||||
status_t err = decoder->read(&buffer);
|
status_t err;
|
||||||
|
do {
|
||||||
|
err = decoder->read(&buffer);
|
||||||
|
} while (err == INFO_FORMAT_CHANGED);
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
CHECK_EQ(buffer, NULL);
|
CHECK_EQ(buffer, NULL);
|
||||||
|
|||||||
@@ -250,6 +250,13 @@ void MediaPlayerImpl::videoEntry() {
|
|||||||
status_t err = mVideoDecoder->read(&buffer, &options);
|
status_t err = mVideoDecoder->read(&buffer, &options);
|
||||||
CHECK((err == OK && buffer != NULL) || (err != OK && buffer == NULL));
|
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) {
|
if (err == ERROR_END_OF_STREAM || err != OK) {
|
||||||
eof = true;
|
eof = true;
|
||||||
continue;
|
continue;
|
||||||
@@ -601,6 +608,9 @@ void MediaPlayerImpl::populateISurface() {
|
|||||||
success = success && meta->findInt32(kKeyHeight, &decodedHeight);
|
success = success && meta->findInt32(kKeyHeight, &decodedHeight);
|
||||||
CHECK(success);
|
CHECK(success);
|
||||||
|
|
||||||
|
LOGI("mVideoWidth=%ld, mVideoHeight=%ld, decodedWidth=%ld, decodedHeight=%ld",
|
||||||
|
mVideoWidth, mVideoHeight, decodedWidth, decodedHeight);
|
||||||
|
|
||||||
if (mSurface.get() != NULL) {
|
if (mSurface.get() != NULL) {
|
||||||
mVideoRenderer =
|
mVideoRenderer =
|
||||||
mClient.interface()->createRenderer(
|
mClient.interface()->createRenderer(
|
||||||
|
|||||||
@@ -677,6 +677,7 @@ OMXCodec::OMXCodec(
|
|||||||
mInitialBufferSubmit(true),
|
mInitialBufferSubmit(true),
|
||||||
mSignalledEOS(false),
|
mSignalledEOS(false),
|
||||||
mNoMoreOutputData(false),
|
mNoMoreOutputData(false),
|
||||||
|
mOutputPortSettingsHaveChanged(false),
|
||||||
mSeekTimeUs(-1) {
|
mSeekTimeUs(-1) {
|
||||||
mPortStatus[kPortIndexInput] = ENABLED;
|
mPortStatus[kPortIndexInput] = ENABLED;
|
||||||
mPortStatus[kPortIndexOutput] = ENABLED;
|
mPortStatus[kPortIndexOutput] = ENABLED;
|
||||||
@@ -1078,6 +1079,9 @@ void OMXCodec::onCmdComplete(OMX_COMMANDTYPE cmd, OMX_U32 data) {
|
|||||||
if (mState == RECONFIGURING) {
|
if (mState == RECONFIGURING) {
|
||||||
CHECK_EQ(portIndex, kPortIndexOutput);
|
CHECK_EQ(portIndex, kPortIndexOutput);
|
||||||
|
|
||||||
|
initOutputFormat(mSource->getFormat());
|
||||||
|
mOutputPortSettingsHaveChanged = true;
|
||||||
|
|
||||||
enablePortAsync(portIndex);
|
enablePortAsync(portIndex);
|
||||||
|
|
||||||
status_t err = allocateBuffersOnPort(portIndex);
|
status_t err = allocateBuffersOnPort(portIndex);
|
||||||
@@ -1782,6 +1786,7 @@ status_t OMXCodec::start(MetaData *) {
|
|||||||
mInitialBufferSubmit = true;
|
mInitialBufferSubmit = true;
|
||||||
mSignalledEOS = false;
|
mSignalledEOS = false;
|
||||||
mNoMoreOutputData = false;
|
mNoMoreOutputData = false;
|
||||||
|
mOutputPortSettingsHaveChanged = false;
|
||||||
mSeekTimeUs = -1;
|
mSeekTimeUs = -1;
|
||||||
mFilledBuffers.clear();
|
mFilledBuffers.clear();
|
||||||
|
|
||||||
@@ -1852,6 +1857,8 @@ status_t OMXCodec::stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sp<MetaData> OMXCodec::getFormat() {
|
sp<MetaData> OMXCodec::getFormat() {
|
||||||
|
Mutex::Autolock autoLock(mLock);
|
||||||
|
|
||||||
return mOutputFormat;
|
return mOutputFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1915,6 +1922,12 @@ status_t OMXCodec::read(
|
|||||||
return ERROR_END_OF_STREAM;
|
return ERROR_END_OF_STREAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mOutputPortSettingsHaveChanged) {
|
||||||
|
mOutputPortSettingsHaveChanged = false;
|
||||||
|
|
||||||
|
return INFO_FORMAT_CHANGED;
|
||||||
|
}
|
||||||
|
|
||||||
size_t index = *mFilledBuffers.begin();
|
size_t index = *mFilledBuffers.begin();
|
||||||
mFilledBuffers.erase(mFilledBuffers.begin());
|
mFilledBuffers.erase(mFilledBuffers.begin());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user