Merge "Revert "Allows the authoring engine to skip frame.""

This commit is contained in:
James Dong
2010-12-13 10:33:33 -08:00
committed by Android (Google) Code Review
6 changed files with 20 additions and 126 deletions

View File

@@ -78,31 +78,18 @@ struct MediaSource : public RefBase {
void clearSeekTo();
bool getSeekTo(int64_t *time_us, SeekMode *mode) const;
// Option allows encoder to skip some frames until the specified
// time stamp.
// To prevent from being abused, when the skipFrame timestamp is
// found to be more than 1 second later than the current timestamp,
// an error will be returned from read().
void clearSkipFrame();
bool getSkipFrame(int64_t *timeUs) const;
void setSkipFrame(int64_t timeUs);
void setLateBy(int64_t lateness_us);
int64_t getLateBy() const;
private:
enum Options {
// Bit map
kSeekTo_Option = 1,
kSkipFrame_Option = 2,
};
uint32_t mOptions;
int64_t mSeekTimeUs;
SeekMode mSeekMode;
int64_t mLatenessUs;
int64_t mSkipFrameUntilTimeUs;
};
// Causes this source to suspend pulling data from its upstream source

View File

@@ -167,7 +167,6 @@ private:
int64_t mSeekTimeUs;
ReadOptions::SeekMode mSeekMode;
int64_t mTargetTimeUs;
int64_t mSkipTimeUs;
MediaBuffer *mLeftOverBuffer;

View File

@@ -140,38 +140,6 @@ sp<MetaData> AudioSource::getFormat() {
return meta;
}
/*
* Returns -1 if frame skipping request is too long.
* Returns 0 if there is no need to skip frames.
* Returns 1 if we need to skip frames.
*/
static int skipFrame(int64_t timestampUs,
const MediaSource::ReadOptions *options) {
int64_t skipFrameUs;
if (!options || !options->getSkipFrame(&skipFrameUs)) {
return 0;
}
if (skipFrameUs <= timestampUs) {
return 0;
}
// Safe guard against the abuse of the kSkipFrame_Option.
if (skipFrameUs - timestampUs >= 1E6) {
LOGE("Frame skipping requested is way too long: %lld us",
skipFrameUs - timestampUs);
return -1;
}
LOGV("skipFrame: %lld us > timestamp: %lld us",
skipFrameUs, timestampUs);
return 1;
}
void AudioSource::rampVolume(
int32_t startFrame, int32_t rampDurationFrames,
uint8_t *data, size_t bytes) {
@@ -218,7 +186,7 @@ status_t AudioSource::read(
CHECK_EQ(mGroup->acquire_buffer(&buffer), OK);
int err = 0;
while (mStarted) {
if (mStarted) {
uint32_t numFramesRecorded;
mRecord->getPosition(&numFramesRecorded);
@@ -268,12 +236,6 @@ status_t AudioSource::read(
if (mCollectStats) {
mTotalLostFrames += (numLostBytes >> 1);
}
if ((err = skipFrame(timestampUs, options)) == -1) {
buffer->release();
return UNKNOWN_ERROR;
} else if (err != 0) {
continue;
}
memset(buffer->data(), 0, numLostBytes);
buffer->set_range(0, numLostBytes);
if (numFramesRecorded == 0) {
@@ -294,12 +256,6 @@ status_t AudioSource::read(
int64_t recordDurationUs = (1000000LL * n >> 1) / sampleRate;
timestampUs += recordDurationUs;
if ((err = skipFrame(timestampUs, options)) == -1) {
buffer->release();
return UNKNOWN_ERROR;
} else if (err != 0) {
continue;
}
if (mPrevSampleTimeUs - mStartTimeUs < kAutoRampStartUs) {
// Mute the initial video recording signal

View File

@@ -665,45 +665,22 @@ status_t CameraSource::read(
{
Mutex::Autolock autoLock(mLock);
while (mStarted) {
while(mFramesReceived.empty()) {
mFrameAvailableCondition.wait(mLock);
}
if (!mStarted) {
return OK;
}
frame = *mFramesReceived.begin();
mFramesReceived.erase(mFramesReceived.begin());
frameTime = *mFrameTimes.begin();
mFrameTimes.erase(mFrameTimes.begin());
int64_t skipTimeUs;
if (!options || !options->getSkipFrame(&skipTimeUs)) {
skipTimeUs = frameTime;
}
if (skipTimeUs > frameTime) {
LOGV("skipTimeUs: %lld us > frameTime: %lld us",
skipTimeUs, frameTime);
releaseOneRecordingFrame(frame);
++mNumFramesDropped;
// Safeguard against the abuse of the kSkipFrame_Option.
if (skipTimeUs - frameTime >= 1E6) {
LOGE("Frame skipping requested is way too long: %lld us",
skipTimeUs - frameTime);
return UNKNOWN_ERROR;
}
} else {
mFramesBeingEncoded.push_back(frame);
*buffer = new MediaBuffer(frame->pointer(), frame->size());
(*buffer)->setObserver(this);
(*buffer)->add_ref();
(*buffer)->meta_data()->setInt64(kKeyTime, frameTime);
return OK;
}
while (mStarted && mFramesReceived.empty()) {
mFrameAvailableCondition.wait(mLock);
}
if (!mStarted) {
return OK;
}
frame = *mFramesReceived.begin();
mFramesReceived.erase(mFramesReceived.begin());
frameTime = *mFrameTimes.begin();
mFrameTimes.erase(mFrameTimes.begin());
mFramesBeingEncoded.push_back(frame);
*buffer = new MediaBuffer(frame->pointer(), frame->size());
(*buffer)->setObserver(this);
(*buffer)->add_ref();
(*buffer)->meta_data()->setInt64(kKeyTime, frameTime);
}
return OK;
}
@@ -729,7 +706,7 @@ void CameraSource::dataCallbackTimestamp(int64_t timestampUs,
// May need to skip frame or modify timestamp. Currently implemented
// by the subclass CameraSourceTimeLapse.
if(skipCurrentFrame(timestampUs)) {
if (skipCurrentFrame(timestampUs)) {
releaseOneRecordingFrame(data);
return;
}

View File

@@ -32,7 +32,6 @@ void MediaSource::ReadOptions::reset() {
mOptions = 0;
mSeekTimeUs = 0;
mLatenessUs = 0;
mSkipFrameUntilTimeUs = 0;
}
void MediaSource::ReadOptions::setSeekTo(int64_t time_us, SeekMode mode) {
@@ -54,21 +53,6 @@ bool MediaSource::ReadOptions::getSeekTo(
return (mOptions & kSeekTo_Option) != 0;
}
void MediaSource::ReadOptions::clearSkipFrame() {
mOptions &= ~kSkipFrame_Option;
mSkipFrameUntilTimeUs = 0;
}
void MediaSource::ReadOptions::setSkipFrame(int64_t timeUs) {
mOptions |= kSkipFrame_Option;
mSkipFrameUntilTimeUs = timeUs;
}
bool MediaSource::ReadOptions::getSkipFrame(int64_t *timeUs) const {
*timeUs = mSkipFrameUntilTimeUs;
return (mOptions & kSkipFrame_Option) != 0;
}
void MediaSource::ReadOptions::setLateBy(int64_t lateness_us) {
mLatenessUs = lateness_us;
}

View File

@@ -1426,7 +1426,6 @@ OMXCodec::OMXCodec(
mSeekTimeUs(-1),
mSeekMode(ReadOptions::SEEK_CLOSEST_SYNC),
mTargetTimeUs(-1),
mSkipTimeUs(-1),
mLeftOverBuffer(NULL),
mPaused(false),
mNativeWindow(nativeWindow) {
@@ -2635,15 +2634,13 @@ bool OMXCodec::drainInputBuffer(BufferInfo *info) {
for (;;) {
MediaBuffer *srcBuffer;
MediaSource::ReadOptions options;
if (mSkipTimeUs >= 0) {
options.setSkipFrame(mSkipTimeUs);
}
if (mSeekTimeUs >= 0) {
if (mLeftOverBuffer) {
mLeftOverBuffer->release();
mLeftOverBuffer = NULL;
}
MediaSource::ReadOptions options;
options.setSeekTo(mSeekTimeUs, mSeekMode);
mSeekTimeUs = -1;
@@ -2668,7 +2665,7 @@ bool OMXCodec::drainInputBuffer(BufferInfo *info) {
err = OK;
} else {
err = mSource->read(&srcBuffer, &options);
err = mSource->read(&srcBuffer);
}
if (err != OK) {
@@ -3304,12 +3301,6 @@ status_t OMXCodec::read(
if (options && options->getSeekTo(&seekTimeUs, &seekMode)) {
seeking = true;
}
int64_t skipTimeUs;
if (options && options->getSkipFrame(&skipTimeUs)) {
mSkipTimeUs = skipTimeUs;
} else {
mSkipTimeUs = -1;
}
if (mInitialBufferSubmit) {
mInitialBufferSubmit = false;