Simplify frame presentation.

This commit is contained in:
John Preston 2020-07-17 22:59:25 +04:00
parent da3bbba497
commit 16177eae2b
2 changed files with 30 additions and 30 deletions

View file

@ -52,6 +52,8 @@ public:
const FrameRequest &request); const FrameRequest &request);
void removeFrameRequest(const Instance *instance); void removeFrameRequest(const Instance *instance);
void rasterizeFrame(not_null<Frame*> frame);
private: private:
enum class FrameResult { enum class FrameResult {
Done, Done,
@ -354,36 +356,37 @@ QSize VideoTrackObject::chooseOriginalResize() const {
return chosen; return chosen;
} }
void VideoTrackObject::rasterizeFrame(not_null<Frame*> frame) {
Expects(frame->position != kFinishedPosition);
fillRequests(frame);
frame->alpha = (frame->decoded->format == AV_PIX_FMT_BGRA);
frame->original = ConvertFrame(
_stream,
frame->decoded.get(),
chooseOriginalResize(),
std::move(frame->original));
if (frame->original.isNull()) {
frame->prepared.clear();
fail(Error::InvalidData);
return;
}
VideoTrack::PrepareFrameByRequests(frame, _stream.rotation);
Ensures(VideoTrack::IsRasterized(frame));
}
void VideoTrackObject::presentFrameIfNeeded() { void VideoTrackObject::presentFrameIfNeeded() {
if (_pausedTime != kTimeUnknown || _resumedTime == kTimeUnknown) { if (_pausedTime != kTimeUnknown || _resumedTime == kTimeUnknown) {
return; return;
} }
const auto rasterize = [&](not_null<Frame*> frame) {
Expects(frame->position != kFinishedPosition);
fillRequests(frame);
frame->alpha = (frame->decoded->format == AV_PIX_FMT_BGRA);
frame->original = ConvertFrame(
_stream,
frame->decoded.get(),
chooseOriginalResize(),
std::move(frame->original));
if (frame->original.isNull()) {
frame->prepared.clear();
fail(Error::InvalidData);
return;
}
VideoTrack::PrepareFrameByRequests(frame, _stream.rotation);
Ensures(VideoTrack::IsRasterized(frame));
};
const auto dropStaleFrames = !_options.waitForMarkAsShown; const auto dropStaleFrames = !_options.waitForMarkAsShown;
const auto presented = _shared->presentFrame( const auto presented = _shared->presentFrame(
this,
trackTime(), trackTime(),
_options.speed, _options.speed,
dropStaleFrames, dropStaleFrames);
rasterize);
addTimelineDelay(presented.addedWorldTimeDelay); addTimelineDelay(presented.addedWorldTimeDelay);
if (presented.displayPosition == kFinishedPosition) { if (presented.displayPosition == kFinishedPosition) {
interrupt(); interrupt();
@ -693,12 +696,11 @@ bool VideoTrack::Shared::firstPresentHappened() const {
Unexpected("Counter value in VideoTrack::Shared::firstPresentHappened."); Unexpected("Counter value in VideoTrack::Shared::firstPresentHappened.");
} }
template <typename RasterizeCallback>
auto VideoTrack::Shared::presentFrame( auto VideoTrack::Shared::presentFrame(
not_null<VideoTrackObject*> object,
TimePoint time, TimePoint time,
float64 playbackSpeed, float64 playbackSpeed,
bool dropStaleFrames, bool dropStaleFrames)
RasterizeCallback &&rasterize)
-> PresentFrame { -> PresentFrame {
const auto present = [&](int counter, int index) -> PresentFrame { const auto present = [&](int counter, int index) -> PresentFrame {
const auto frame = getFrame(index); const auto frame = getFrame(index);
@ -707,7 +709,7 @@ auto VideoTrack::Shared::presentFrame(
if (position == kFinishedPosition) { if (position == kFinishedPosition) {
return { kFinishedPosition, kTimeUnknown, addedWorldTimeDelay }; return { kFinishedPosition, kTimeUnknown, addedWorldTimeDelay };
} }
rasterize(frame); object->rasterizeFrame(frame);
if (!IsRasterized(frame)) { if (!IsRasterized(frame)) {
// Error happened during frame prepare. // Error happened during frame prepare.
return { kTimeUnknown, kTimeUnknown, addedWorldTimeDelay }; return { kTimeUnknown, kTimeUnknown, addedWorldTimeDelay };

View file

@ -108,13 +108,11 @@ private:
crl::time trackTime, crl::time trackTime,
bool dropStaleFrames); bool dropStaleFrames);
// RasterizeCallback(not_null<Frame*>).
template <typename RasterizeCallback>
[[nodiscard]] PresentFrame presentFrame( [[nodiscard]] PresentFrame presentFrame(
not_null<VideoTrackObject*> object,
TimePoint trackTime, TimePoint trackTime,
float64 playbackSpeed, float64 playbackSpeed,
bool dropStaleFrames, bool dropStaleFrames);
RasterizeCallback &&rasterize);
[[nodiscard]] bool firstPresentHappened() const; [[nodiscard]] bool firstPresentHappened() const;
// Called from the main thread. // Called from the main thread.