Loading media/libstagefright/bqhelper/GraphicBufferSource.cpp +30 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <media/stagefright/foundation/ColorUtils.h> #include <media/stagefright/foundation/FileDescriptor.h> #include <android-base/properties.h> #include <media/hardware/MetadataBufferType.h> #include <ui/GraphicBuffer.h> #include <gui/BufferItem.h> Loading Loading @@ -800,6 +801,9 @@ void GraphicBufferSource::queueFrameRepeat_l() { } } #ifdef __clang__ __attribute__((no_sanitize("integer"))) #endif bool GraphicBufferSource::calculateCodecTimestamp_l( nsecs_t bufferTimeNs, int64_t *codecTimeUs) { int64_t timeUs = bufferTimeNs / 1000; Loading @@ -816,14 +820,15 @@ bool GraphicBufferSource::calculateCodecTimestamp_l( mPrevFrameUs = mBaseFrameUs = std::llround((timeUs * mCaptureFps) / mFps); mFrameCount = 0; } else { // snap to nearest capture point } else if (mSnapTimestamps) { double nFrames = (timeUs - mPrevCaptureUs) * mCaptureFps / 1000000; if (nFrames < 0.5 - kTimestampFluctuation) { // skip this frame as it's too close to previous capture ALOGD("skipping frame, timeUs %lld", static_cast<long long>(timeUs)); ALOGD("skipping frame, timeUs %lld", static_cast<long long>(timeUs)); return false; } // snap to nearest capture point if (nFrames <= 1.0) { nFrames = 1.0; } Loading @@ -832,6 +837,22 @@ bool GraphicBufferSource::calculateCodecTimestamp_l( mFrameCount * 1000000 / mCaptureFps); mPrevFrameUs = mBaseFrameUs + std::llround( mFrameCount * 1000000 / mFps); } else { if (timeUs <= mPrevCaptureUs) { if (mFrameDropper != NULL && mFrameDropper->disabled()) { // Warn only, client has disabled frame drop logic possibly for image // encoding cases where camera's ZSL mode could send out of order frames. ALOGW("Received frame that's going backward in time"); } else { // Drop the frame if it's going backward in time. Bad timestamp // could disrupt encoder's rate control completely. ALOGW("Dropping frame that's going backward in time"); return false; } } mPrevCaptureUs = timeUs; mPrevFrameUs = mBaseFrameUs + std::llround( (timeUs - mBaseCaptureUs) * (mCaptureFps / mFps)); } ALOGV("timeUs %lld, captureUs %lld, frameUs %lld", Loading Loading @@ -1359,6 +1380,12 @@ status_t GraphicBufferSource::setTimeLapseConfig(double fps, double captureFps) mFps = fps; mCaptureFps = captureFps; if (captureFps > fps) { mSnapTimestamps = 1 == base::GetIntProperty( "debug.stagefright.snap_timestamps", int64_t(1)); } else { mSnapTimestamps = false; } return OK; } Loading media/libstagefright/bqhelper/include/media/stagefright/bqhelper/GraphicBufferSource.h +26 −5 Original line number Diff line number Diff line Loading @@ -461,12 +461,33 @@ private: // Slow motion mode is enabled if both encoding and capture frame rates are // defined and the encoding frame rate is less than half the capture frame // rate. In this mode, the source is expected to produce frames with an even // timestamp interval (after rounding) with the configured capture fps. The // first source timestamp is used as the source base time. Afterwards, the // timestamp of each source frame is snapped to the nearest expected capture // timestamp and scaled to match the configured encoding frame rate. // timestamp interval (after rounding) with the configured capture fps. // // These modes must be configured by calling setTimeLapseConfig() before // using this source. // // Timestamp snapping for slow motion recording // ============================================ // // When the slow motion mode is configured with setTimeLapseConfig(), the // property "debug.stagefright.snap_timestamps" will be checked. If the // value of the property is set to any value other than 1, mSnapTimestamps // will be set to false. Otherwise, mSnapTimestamps will be set to true. // (mSnapTimestamps will be false for time lapse recording regardless of the // value of the property.) // // If mSnapTimestamps is true, i.e., timestamp snapping is enabled, the // first source timestamp will be used as the source base time; afterwards, // the timestamp of each source frame will be snapped to the nearest // expected capture timestamp and scaled to match the configured encoding // frame rate. // // If timestamp snapping is disabled, the timestamp of source frames will // be scaled to match the ratio between the configured encoding frame rate // and the configured capture frame rate. // These modes must be enabled before using this source. // whether timestamps will be snapped bool mSnapTimestamps{true}; // adjusted capture timestamp of the base frame int64_t mBaseCaptureUs; Loading Loading
media/libstagefright/bqhelper/GraphicBufferSource.cpp +30 −3 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ #include <media/stagefright/foundation/ColorUtils.h> #include <media/stagefright/foundation/FileDescriptor.h> #include <android-base/properties.h> #include <media/hardware/MetadataBufferType.h> #include <ui/GraphicBuffer.h> #include <gui/BufferItem.h> Loading Loading @@ -800,6 +801,9 @@ void GraphicBufferSource::queueFrameRepeat_l() { } } #ifdef __clang__ __attribute__((no_sanitize("integer"))) #endif bool GraphicBufferSource::calculateCodecTimestamp_l( nsecs_t bufferTimeNs, int64_t *codecTimeUs) { int64_t timeUs = bufferTimeNs / 1000; Loading @@ -816,14 +820,15 @@ bool GraphicBufferSource::calculateCodecTimestamp_l( mPrevFrameUs = mBaseFrameUs = std::llround((timeUs * mCaptureFps) / mFps); mFrameCount = 0; } else { // snap to nearest capture point } else if (mSnapTimestamps) { double nFrames = (timeUs - mPrevCaptureUs) * mCaptureFps / 1000000; if (nFrames < 0.5 - kTimestampFluctuation) { // skip this frame as it's too close to previous capture ALOGD("skipping frame, timeUs %lld", static_cast<long long>(timeUs)); ALOGD("skipping frame, timeUs %lld", static_cast<long long>(timeUs)); return false; } // snap to nearest capture point if (nFrames <= 1.0) { nFrames = 1.0; } Loading @@ -832,6 +837,22 @@ bool GraphicBufferSource::calculateCodecTimestamp_l( mFrameCount * 1000000 / mCaptureFps); mPrevFrameUs = mBaseFrameUs + std::llround( mFrameCount * 1000000 / mFps); } else { if (timeUs <= mPrevCaptureUs) { if (mFrameDropper != NULL && mFrameDropper->disabled()) { // Warn only, client has disabled frame drop logic possibly for image // encoding cases where camera's ZSL mode could send out of order frames. ALOGW("Received frame that's going backward in time"); } else { // Drop the frame if it's going backward in time. Bad timestamp // could disrupt encoder's rate control completely. ALOGW("Dropping frame that's going backward in time"); return false; } } mPrevCaptureUs = timeUs; mPrevFrameUs = mBaseFrameUs + std::llround( (timeUs - mBaseCaptureUs) * (mCaptureFps / mFps)); } ALOGV("timeUs %lld, captureUs %lld, frameUs %lld", Loading Loading @@ -1359,6 +1380,12 @@ status_t GraphicBufferSource::setTimeLapseConfig(double fps, double captureFps) mFps = fps; mCaptureFps = captureFps; if (captureFps > fps) { mSnapTimestamps = 1 == base::GetIntProperty( "debug.stagefright.snap_timestamps", int64_t(1)); } else { mSnapTimestamps = false; } return OK; } Loading
media/libstagefright/bqhelper/include/media/stagefright/bqhelper/GraphicBufferSource.h +26 −5 Original line number Diff line number Diff line Loading @@ -461,12 +461,33 @@ private: // Slow motion mode is enabled if both encoding and capture frame rates are // defined and the encoding frame rate is less than half the capture frame // rate. In this mode, the source is expected to produce frames with an even // timestamp interval (after rounding) with the configured capture fps. The // first source timestamp is used as the source base time. Afterwards, the // timestamp of each source frame is snapped to the nearest expected capture // timestamp and scaled to match the configured encoding frame rate. // timestamp interval (after rounding) with the configured capture fps. // // These modes must be configured by calling setTimeLapseConfig() before // using this source. // // Timestamp snapping for slow motion recording // ============================================ // // When the slow motion mode is configured with setTimeLapseConfig(), the // property "debug.stagefright.snap_timestamps" will be checked. If the // value of the property is set to any value other than 1, mSnapTimestamps // will be set to false. Otherwise, mSnapTimestamps will be set to true. // (mSnapTimestamps will be false for time lapse recording regardless of the // value of the property.) // // If mSnapTimestamps is true, i.e., timestamp snapping is enabled, the // first source timestamp will be used as the source base time; afterwards, // the timestamp of each source frame will be snapped to the nearest // expected capture timestamp and scaled to match the configured encoding // frame rate. // // If timestamp snapping is disabled, the timestamp of source frames will // be scaled to match the ratio between the configured encoding frame rate // and the configured capture frame rate. // These modes must be enabled before using this source. // whether timestamps will be snapped bool mSnapTimestamps{true}; // adjusted capture timestamp of the base frame int64_t mBaseCaptureUs; Loading