Commit 50b12560 authored by John Rummell's avatar John Rummell Committed by Commit Bot

Avoid saving previous frame just to determine what has changed

There is no need to pass the previous frame when only a few values are
needed. This will free space by allowing the previous frame to be freed
earlier.

BUG=946265
TEST=WebMediaPlayerMSTest content_unittests pass

Change-Id: I799a7d105c119760e440ca76c0b7b7cd82e4c524
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1601827
Commit-Queue: John Rummell <jrummell@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660658}
parent 1a30e7ce
......@@ -521,49 +521,75 @@ void WebMediaPlayerMSCompositor::SetCurrentFrame(
++dropped_frame_count_;
current_frame_rendered_ = false;
scoped_refptr<media::VideoFrame> old_frame = std::move(current_frame_);
current_frame_ = frame;
// Compare current frame with |frame|. Initialize values as if there is no
// current frame.
bool is_first_frame = true;
bool has_frame_size_changed = false;
base::Optional<media::VideoRotation> new_rotation = media::VIDEO_ROTATION_0;
base::Optional<bool> new_opacity;
new_opacity = media::IsOpaque(frame->format());
media::VideoRotation current_video_rotation;
if (frame->metadata()->GetRotation(media::VideoFrameMetadata::ROTATION,
&current_video_rotation)) {
new_rotation = current_video_rotation;
}
if (current_frame_) {
// We have a current frame, so determine what has changed.
is_first_frame = false;
if (!current_frame_->metadata()->GetRotation(
media::VideoFrameMetadata::ROTATION, &current_video_rotation) ||
current_video_rotation == *new_rotation) {
new_rotation.reset();
}
if (*new_opacity == media::IsOpaque(current_frame_->format()))
new_opacity.reset();
has_frame_size_changed =
frame->natural_size() != current_frame_->natural_size();
}
current_frame_ = std::move(frame);
// Complete the checks after |current_frame_| is accessible to avoid
// deadlocks, see https://crbug.com/901744.
video_frame_compositor_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WebMediaPlayerMSCompositor::CheckForFrameChanges, this,
std::move(old_frame), std::move(frame)));
is_first_frame, has_frame_size_changed,
std::move(new_rotation), std::move(new_opacity)));
}
void WebMediaPlayerMSCompositor::CheckForFrameChanges(
scoped_refptr<media::VideoFrame> old_frame,
scoped_refptr<media::VideoFrame> new_frame) {
bool is_first_frame,
bool has_frame_size_changed,
base::Optional<media::VideoRotation> new_frame_rotation,
base::Optional<bool> new_frame_opacity) {
DCHECK(video_frame_compositor_task_runner_->BelongsToCurrentThread());
const bool new_frame_is_opaque = media::IsOpaque(new_frame->format());
media::VideoRotation new_frame_video_rotation = media::VIDEO_ROTATION_0;
ignore_result(new_frame->metadata()->GetRotation(
media::VideoFrameMetadata::ROTATION, &new_frame_video_rotation));
if (!old_frame) {
if (is_first_frame) {
main_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&WebMediaPlayerMS::OnFirstFrameReceived, player_,
new_frame_video_rotation, new_frame_is_opaque));
*new_frame_rotation, *new_frame_opacity));
return;
}
media::VideoRotation old_frame_video_rotation = media::VIDEO_ROTATION_0;
ignore_result(old_frame->metadata()->GetRotation(
media::VideoFrameMetadata::ROTATION, &old_frame_video_rotation));
if (new_frame_video_rotation != old_frame_video_rotation) {
if (new_frame_rotation.has_value()) {
main_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&WebMediaPlayerMS::OnRotationChanged, player_,
new_frame_video_rotation));
*new_frame_rotation));
if (submitter_)
submitter_->SetRotation(new_frame_video_rotation);
submitter_->SetRotation(*new_frame_rotation);
}
if (new_frame_is_opaque != media::IsOpaque(old_frame->format())) {
if (new_frame_opacity.has_value()) {
main_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&WebMediaPlayerMS::OnOpacityChanged, player_,
new_frame_is_opaque));
*new_frame_opacity));
}
if (old_frame->natural_size() != new_frame->natural_size()) {
if (has_frame_size_changed) {
main_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&WebMediaPlayerMS::TriggerResize, player_));
}
......
......@@ -13,6 +13,7 @@
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_checker.h"
#include "cc/layers/surface_layer.h"
......@@ -147,8 +148,11 @@ class CONTENT_EXPORT WebMediaPlayerMSCompositor
void SetCurrentFrame(scoped_refptr<media::VideoFrame> frame);
// Following the update to |current_frame_|, this will check for changes that
// require updating video layer.
void CheckForFrameChanges(scoped_refptr<media::VideoFrame> old_frame,
scoped_refptr<media::VideoFrame> new_frame);
void CheckForFrameChanges(
bool is_first_frame,
bool has_frame_size_changed,
base::Optional<media::VideoRotation> new_frame_rotation,
base::Optional<bool> new_frame_opacity);
void StartRenderingInternal();
void StopRenderingInternal();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment