Commit b96466e9 authored by liberato@chromium.org's avatar liberato@chromium.org Committed by Commit Bot

Add tracing to MediaCodecVideoDecoder.

Added MediaCodecVideoDecoder::destructor.
Added MediaCodecVideoDecoder::Destroy.
Added MediaCodecVideoDecoder::StartLazyInit.
Added MediaCodecVideoDecoder::OnSurfaceChosen.
Added MediaCodecVideoDecoder::OnSurfaceDestroyed.
Added MediaCodecVideoDecoder::StartDrainingCodec.
Added MediaCodecVideoDecoder::OnCodecDrained.

Also added an async event from when a frame is dequeued from the
codec, and when the resulting video frame is back on the mojo thread.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I580b91d5fefb14002730e0e899a8f44f0a0950bd
Reviewed-on: https://chromium-review.googlesource.com/c/1281906
Commit-Queue: Frank Liberato <liberato@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarXiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600822}
parent 206c0777
......@@ -223,6 +223,8 @@ jumbo_source_set("base") {
"routing_token_callback.h",
"sample_rates.cc",
"sample_rates.h",
"scoped_async_trace.cc",
"scoped_async_trace.h",
"seekable_buffer.cc",
"seekable_buffer.h",
"serial_runner.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/scoped_async_trace.h"
#include "base/memory/ptr_util.h"
#include "base/trace_event/trace_event.h"
namespace media {
// static
std::unique_ptr<ScopedAsyncTrace> ScopedAsyncTrace::CreateIfEnabled(
const char* category,
const char* name) {
bool enabled = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(category, &enabled);
return enabled ? base::WrapUnique(new ScopedAsyncTrace(category, name))
: nullptr;
}
ScopedAsyncTrace::ScopedAsyncTrace(const char* category, const char* name)
: category_(category), name_(name) {
TRACE_EVENT_ASYNC_BEGIN0(category_, name_, this);
}
ScopedAsyncTrace::~ScopedAsyncTrace() {
TRACE_EVENT_ASYNC_END0(category_, name_, this);
}
} // namespace media
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MEDIA_BASE_SCOPED_ASYNC_TRACE_H_
#define MEDIA_BASE_SCOPED_ASYNC_TRACE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "media/base/media_export.h"
namespace media {
// Utility class that starts and stops an async trace event. The intention is
// that it it will be created somewhere to start the trace event, passed around
// such as via unique_ptr argument in a callback, and eventually freed to end
// the trace event. This guarantees that it'll be closed, even if the callback
// is destroyed without being run.
class MEDIA_EXPORT ScopedAsyncTrace {
public:
// Create a ScopedAsyncTrace if tracing for |category| is enabled, else return
// nullptr. |name| provided to the trace as the name(!).
// IMPORTANT: These strings must outlive |this|, since tracing needs it. In
// other words, use literal strings only. See trace_event_common.h .
static std::unique_ptr<ScopedAsyncTrace> CreateIfEnabled(const char* category,
const char* name);
~ScopedAsyncTrace();
// TODO(liberato): Add StepInto / StepPast.
private:
ScopedAsyncTrace(const char* category, const char* name);
const char* category_ = nullptr;
const char* name_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(ScopedAsyncTrace);
};
} // namespace media
#endif // MEDIA_BASE_SCOPED_ASYNC_TRACE_H_
......@@ -70,6 +70,7 @@ bool CodecImage::BindTexImage(unsigned target) {
void CodecImage::ReleaseTexImage(unsigned target) {}
bool CodecImage::CopyTexImage(unsigned target) {
TRACE_EVENT0("media", "CodecImage::CopyTexImage");
if (!texture_owner_ || target != GL_TEXTURE_EXTERNAL_OES)
return false;
......@@ -97,6 +98,7 @@ bool CodecImage::ScheduleOverlayPlane(
const gfx::RectF& crop_rect,
bool enable_blend,
std::unique_ptr<gfx::GpuFence> gpu_fence) {
TRACE_EVENT0("media", "CodecImage::ScheduleOverlayPlane");
if (texture_owner_) {
DVLOG(1) << "Invalid call to ScheduleOverlayPlane; this image is "
"TextureOwner backed.";
......
......@@ -20,6 +20,7 @@
#include "media/base/cdm_context.h"
#include "media/base/decoder_buffer.h"
#include "media/base/media_switches.h"
#include "media/base/scoped_async_trace.h"
#include "media/base/video_codecs.h"
#include "media/base/video_decoder_config.h"
#include "media/base/video_frame.h"
......@@ -154,12 +155,14 @@ MediaCodecVideoDecoder::MediaCodecVideoDecoder(
MediaCodecVideoDecoder::~MediaCodecVideoDecoder() {
DVLOG(2) << __func__;
TRACE_EVENT0("media", "MediaCodecVideoDecoder::~MediaCodecVideoDecoder");
ReleaseCodec();
codec_allocator_->StopThread(this);
}
void MediaCodecVideoDecoder::Destroy() {
DVLOG(1) << __func__;
TRACE_EVENT0("media", "MediaCodecVideoDecoder::Destroy");
if (media_crypto_context_) {
// Cancel previously registered callback (if any).
......@@ -310,6 +313,7 @@ void MediaCodecVideoDecoder::OnKeyAdded() {
void MediaCodecVideoDecoder::StartLazyInit() {
DVLOG(2) << __func__;
TRACE_EVENT0("media", "MediaCodecVideoDecoder::StartLazyInit");
lazy_init_pending_ = false;
codec_allocator_->StartThread(this);
......@@ -333,6 +337,8 @@ void MediaCodecVideoDecoder::StartLazyInit() {
void MediaCodecVideoDecoder::OnVideoFrameFactoryInitialized(
scoped_refptr<TextureOwner> texture_owner) {
DVLOG(2) << __func__;
TRACE_EVENT0("media",
"MediaCodecVideoDecoder::OnVideoFrameFactoryInitialized");
if (!texture_owner) {
EnterTerminalState(State::kError);
return;
......@@ -376,6 +382,8 @@ void MediaCodecVideoDecoder::OnSurfaceChosen(
DVLOG(2) << __func__;
DCHECK(state_ == State::kInitializing ||
device_info_->IsSetOutputSurfaceSupported());
TRACE_EVENT1("media", "MediaCodecVideoDecoder::OnSurfaceChosen", "overlay",
overlay ? "yes" : "no");
if (overlay) {
overlay->AddSurfaceDestroyedCallback(
......@@ -397,6 +405,7 @@ void MediaCodecVideoDecoder::OnSurfaceChosen(
void MediaCodecVideoDecoder::OnSurfaceDestroyed(AndroidOverlay* overlay) {
DVLOG(2) << __func__;
DCHECK_NE(state_, State::kInitializing);
TRACE_EVENT0("media", "MediaCodecVideoDecoder::OnSurfaceDestroyed");
// If SetOutputSurface() is not supported we only ever observe destruction of
// a single overlay so this must be the one we're using. In this case it's
......@@ -733,12 +742,16 @@ bool MediaCodecVideoDecoder::DequeueOutput() {
1); // PRESUBMIT_IGNORE_UMA_MAX
gfx::Rect visible_rect(output_buffer->size());
std::unique_ptr<ScopedAsyncTrace> async_trace =
ScopedAsyncTrace::CreateIfEnabled(
"media", "MediaCodecVideoDecoder::CreateVideoFrame");
video_frame_factory_->CreateVideoFrame(
std::move(output_buffer), presentation_time,
GetNaturalSize(visible_rect, decoder_config_.GetPixelAspectRatio()),
CreatePromotionHintCB(),
base::Bind(&MediaCodecVideoDecoder::ForwardVideoFrame,
weak_factory_.GetWeakPtr(), reset_generation_));
base::BindOnce(&MediaCodecVideoDecoder::ForwardVideoFrame,
weak_factory_.GetWeakPtr(), reset_generation_,
std::move(async_trace)));
return true;
}
......@@ -754,6 +767,7 @@ void MediaCodecVideoDecoder::RunEosDecodeCb(int reset_generation) {
void MediaCodecVideoDecoder::ForwardVideoFrame(
int reset_generation,
std::unique_ptr<ScopedAsyncTrace> async_trace,
const scoped_refptr<VideoFrame>& frame) {
DVLOG(3) << __func__ << " : "
<< (frame ? frame->AsHumanReadableString() : "null");
......@@ -780,6 +794,7 @@ void MediaCodecVideoDecoder::Reset(const base::Closure& closure) {
void MediaCodecVideoDecoder::StartDrainingCodec(DrainType drain_type) {
DVLOG(2) << __func__;
TRACE_EVENT0("media", "MediaCodecVideoDecoder::StartDrainingCodec");
DCHECK(pending_decodes_.empty());
// It's okay if there's already a drain ongoing. We'll only enqueue an EOS if
// the codec isn't already draining.
......@@ -820,6 +835,7 @@ void MediaCodecVideoDecoder::StartDrainingCodec(DrainType drain_type) {
void MediaCodecVideoDecoder::OnCodecDrained() {
DVLOG(2) << __func__;
TRACE_EVENT0("media", "MediaCodecVideoDecoder::OnCodecDrained");
DrainType drain_type = *drain_type_;
drain_type_.reset();
......
......@@ -24,6 +24,8 @@
namespace media {
class ScopedAsyncTrace;
struct PendingDecode {
static PendingDecode CreateEos();
PendingDecode(scoped_refptr<DecoderBuffer> buffer,
......@@ -166,8 +168,10 @@ class MEDIA_GPU_EXPORT MediaCodecVideoDecoder : public VideoDecoder,
void RunEosDecodeCb(int reset_generation);
// Forwards |frame| via |output_cb_| if |reset_generation| matches
// |reset_generation_|.
// |reset_generation_|. |async_trace| is the (optional) scoped trace that
// started when we dequeued the corresponding output buffer.
void ForwardVideoFrame(int reset_generation,
std::unique_ptr<ScopedAsyncTrace> async_trace,
const scoped_refptr<VideoFrame>& frame);
// Starts draining the codec by queuing an EOS if required. It skips the drain
......
......@@ -63,14 +63,13 @@ class MockVideoFrameFactory : public VideoFrameFactory {
bool use_texture_owner_as_overlay,
InitCb init_cb));
MOCK_METHOD1(MockSetSurfaceBundle, void(scoped_refptr<AVDASurfaceBundle>));
MOCK_METHOD6(
MOCK_METHOD5(
MockCreateVideoFrame,
void(CodecOutputBuffer* raw_output_buffer,
scoped_refptr<TextureOwner> texture_owner,
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb));
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb));
MOCK_METHOD1(MockRunAfterPendingVideoFrames,
void(base::OnceClosure* closure));
MOCK_METHOD0(CancelPendingCallbacks, void());
......@@ -91,11 +90,11 @@ class MockVideoFrameFactory : public VideoFrameFactory {
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb) override {
VideoFrameFactory::OnceOutputCb output_cb) override {
MockCreateVideoFrame(output_buffer.get(), texture_owner_, timestamp,
natural_size, promotion_hint_cb, output_cb);
natural_size, promotion_hint_cb);
last_output_buffer_ = std::move(output_buffer);
output_cb.Run(VideoFrame::CreateBlackFrame(gfx::Size(10, 10)));
std::move(output_cb).Run(VideoFrame::CreateBlackFrame(gfx::Size(10, 10)));
}
void RunAfterPendingVideoFrames(base::OnceClosure closure) override {
......@@ -924,7 +923,7 @@ TEST_P(MediaCodecVideoDecoderTest, VideoFramesArePowerEfficient) {
// Produce one output.
codec->AcceptOneInput();
codec->ProduceOneOutput();
EXPECT_CALL(*video_frame_factory_, MockCreateVideoFrame(_, _, _, _, _, _));
EXPECT_CALL(*video_frame_factory_, MockCreateVideoFrame(_, _, _, _, _));
PumpCodec();
base::RunLoop().RunUntilIdle();
......
......@@ -32,6 +32,8 @@ class MEDIA_GPU_EXPORT VideoFrameFactory {
public:
using GetStubCb = base::Callback<gpu::CommandBufferStub*()>;
using InitCb = base::RepeatingCallback<void(scoped_refptr<TextureOwner>)>;
using OnceOutputCb =
base::OnceCallback<void(const scoped_refptr<VideoFrame>&)>;
VideoFrameFactory() = default;
virtual ~VideoFrameFactory() = default;
......@@ -52,16 +54,14 @@ class MEDIA_GPU_EXPORT VideoFrameFactory {
virtual void SetSurfaceBundle(
scoped_refptr<AVDASurfaceBundle> surface_bundle) = 0;
// Creates a new VideoFrame backed by |output_buffer| and |texture_owner|.
// |texture_owner| may be null if the buffer is backed by an overlay
// instead. Runs |output_cb| on the calling sequence to return the frame.
// TODO(liberato): update the comment.
// Creates a new VideoFrame backed by |output_buffer|. Runs |output_cb| on
// the calling sequence to return the frame.
virtual void CreateVideoFrame(
std::unique_ptr<CodecOutputBuffer> output_buffer,
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb) = 0;
OnceOutputCb output_cb) = 0;
// Runs |closure| on the calling sequence after all previous
// CreateVideoFrame() calls have completed.
......
......@@ -100,15 +100,16 @@ void VideoFrameFactoryImpl::CreateVideoFrame(
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb) {
OnceOutputCb output_cb) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
gpu_task_runner_->PostTask(
FROM_HERE,
base::Bind(&GpuVideoFrameFactory::CreateVideoFrame,
base::Unretained(gpu_video_frame_factory_.get()),
base::Passed(&output_buffer), texture_owner_, timestamp,
natural_size, std::move(promotion_hint_cb),
std::move(output_cb), base::ThreadTaskRunnerHandle::Get()));
base::BindOnce(&GpuVideoFrameFactory::CreateVideoFrame,
base::Unretained(gpu_video_frame_factory_.get()),
base::Passed(&output_buffer), texture_owner_, timestamp,
natural_size, std::move(promotion_hint_cb),
std::move(output_cb),
base::ThreadTaskRunnerHandle::Get()));
}
void VideoFrameFactoryImpl::RunAfterPendingVideoFrames(
......@@ -153,7 +154,7 @@ void GpuVideoFrameFactory::CreateVideoFrame(
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb,
VideoFrameFactory::OnceOutputCb output_cb,
scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
scoped_refptr<VideoFrame> frame;
......@@ -163,6 +164,7 @@ void GpuVideoFrameFactory::CreateVideoFrame(
timestamp, natural_size,
std::move(promotion_hint_cb), &frame, &texture,
&codec_image);
TRACE_EVENT0("media", "GpuVideoFrameFactory::CreateVideoFrame");
if (!frame || !texture)
return;
......@@ -199,7 +201,8 @@ void GpuVideoFrameFactory::CreateVideoFrame(
auto release_cb = mojo::WrapCallbackWithDefaultInvokeIfNotRun(
BindToCurrentLoop(std::move(drop_texture_ref)), gpu::SyncToken());
frame->SetReleaseMailboxCB(std::move(release_cb));
task_runner->PostTask(FROM_HERE, base::BindOnce(output_cb, std::move(frame)));
task_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(output_cb), std::move(frame)));
}
void GpuVideoFrameFactory::CreateVideoFrameInternal(
......
......@@ -48,7 +48,7 @@ class MEDIA_GPU_EXPORT VideoFrameFactoryImpl : public VideoFrameFactory {
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb) override;
OnceOutputCb output_cb) override;
void RunAfterPendingVideoFrames(base::OnceClosure closure) override;
private:
......@@ -84,7 +84,7 @@ class GpuVideoFrameFactory
base::TimeDelta timestamp,
gfx::Size natural_size,
PromotionHintAggregator::NotifyPromotionHintCB promotion_hint_cb,
VideoDecoder::OutputCB output_cb,
VideoFrameFactory::OnceOutputCb output_cb,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
// Set our image group. Must be called before the first call to
......
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