Skip to content

Commit

Permalink
Plumb callbacks from mojo media service to client.
Browse files Browse the repository at this point in the history
Add OnStatisticsUpdate and OnWaitingForDecryptionKey to
mojom::RendererClient, and call these callbacks from
MojoRendererService. These are needed for Cast Apps like Netflix that
depend on decoding statistics from the media pipeline.

BUG=585287
BUG= internal b/29390639

Review-Url: https://codereview.chromium.org/2101043003
Cr-Commit-Position: refs/heads/master@{#404486}
  • Loading branch information
slan authored and Commit bot committed Jul 8, 2016
1 parent d75fb6b commit 267e463
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 3 deletions.
2 changes: 2 additions & 0 deletions chromecast/browser/media/cast_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "chromecast/public/media/media_pipeline_device_params.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/demuxer_stream.h"
#include "media/base/demuxer_stream_provider.h"
#include "media/base/media_log.h"
#include "media/base/renderer_client.h"

namespace chromecast {
namespace media {
Expand Down
13 changes: 13 additions & 0 deletions media/mojo/clients/mojo_renderer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "media/base/demuxer_stream_provider.h"
#include "media/base/pipeline_status.h"
#include "media/base/renderer_client.h"
#include "media/base/video_renderer_sink.h"
#include "media/mojo/clients/mojo_demuxer_stream_impl.h"
Expand Down Expand Up @@ -239,6 +240,18 @@ void MojoRenderer::OnVideoOpacityChange(bool opaque) {
client_->OnVideoOpacityChange(opaque);
}

void MojoRenderer::OnStatisticsUpdate(const PipelineStatistics& stats) {
DVLOG(3) << __FUNCTION__;
DCHECK(task_runner_->BelongsToCurrentThread());
client_->OnStatisticsUpdate(stats);
}

void MojoRenderer::OnWaitingForDecryptionKey() {
DVLOG(1) << __FUNCTION__;
DCHECK(task_runner_->BelongsToCurrentThread());
client_->OnWaitingForDecryptionKey();
}

void MojoRenderer::OnConnectionError() {
DVLOG(1) << __FUNCTION__;
DCHECK(task_runner_->BelongsToCurrentThread());
Expand Down
2 changes: 2 additions & 0 deletions media/mojo/clients/mojo_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MojoRenderer : public Renderer, public mojom::RendererClient {
void OnError() override;
void OnVideoNaturalSizeChange(const gfx::Size& size) override;
void OnVideoOpacityChange(bool opaque) override;
void OnWaitingForDecryptionKey() override;
void OnStatisticsUpdate(const PipelineStatistics& stats) override;

// Binds |remote_renderer_| to the mojo message pipe. Can be called multiple
// times. If an error occurs during connection, OnConnectionError will be
Expand Down
2 changes: 2 additions & 0 deletions media/mojo/common/OWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
per-file *_struct_traits*.*=set noparent
per-file *_struct_traits*.*=file://ipc/SECURITY_OWNERS
per-file *_type_converter*.*=set noparent
per-file *_type_converter*.*=file://ipc/SECURITY_OWNERS
49 changes: 49 additions & 0 deletions media/mojo/common/pipeline_statistics_struct_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2016 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_MOJO_COMMON_PIPELINE_STATISTICS_STRUCT_TRAITS_H_
#define MEDIA_MOJO_COMMON_PIPELINE_STATISTICS_STRUCT_TRAITS_H_

#include "media/base/pipeline_status.h"
#include "media/mojo/interfaces/media_types.mojom.h"

namespace mojo {

template <>
struct StructTraits<media::mojom::PipelineStatistics,
media::PipelineStatistics> {
static uint64_t audio_bytes_decoded(const media::PipelineStatistics& input) {
return input.audio_bytes_decoded;
}
static uint64_t video_bytes_decoded(const media::PipelineStatistics& input) {
return input.video_bytes_decoded;
}
static uint32_t video_frames_decoded(const media::PipelineStatistics& input) {
return input.video_frames_decoded;
}
static uint32_t video_frames_dropped(const media::PipelineStatistics& input) {
return input.video_frames_dropped;
}
static int64_t audio_memory_usage(const media::PipelineStatistics& input) {
return input.audio_memory_usage;
}
static int64_t video_memory_usage(const media::PipelineStatistics& input) {
return input.video_memory_usage;
}

static bool Read(media::mojom::PipelineStatisticsDataView data,
media::PipelineStatistics* output) {
output->audio_bytes_decoded = data.audio_bytes_decoded();
output->video_bytes_decoded = data.video_bytes_decoded();
output->video_frames_decoded = data.video_frames_decoded();
output->video_frames_dropped = data.video_frames_dropped();
output->audio_memory_usage = data.audio_memory_usage();
output->video_memory_usage = data.video_memory_usage();
return true;
}
};

} // namespace mojo

#endif // MEDIA_MOJO_COMMON_PIPELINE_STATISTICS_STRUCT_TRAITS_H_
9 changes: 9 additions & 0 deletions media/mojo/interfaces/media_types.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,12 @@ struct VideoFrame {
uint64 u_offset;
uint64 v_offset;
};

struct PipelineStatistics {
uint64 audio_bytes_decoded;
uint64 video_bytes_decoded;
uint32 video_frames_decoded;
uint32 video_frames_dropped;
int64 audio_memory_usage;
int64 video_memory_usage;
};
8 changes: 8 additions & 0 deletions media/mojo/interfaces/pipeline_statistics.typemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright 2016 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.

mojom = "//media/mojo/interfaces/media_types.mojom"
public_headers = [ "//media/base/pipeline_status.h" ]
traits_headers = [ "//media/mojo/common/pipeline_statistics_struct_traits.h" ]
type_mappings = [ "media.mojom.PipelineStatistics=media::PipelineStatistics" ]
8 changes: 8 additions & 0 deletions media/mojo/interfaces/renderer.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ interface RendererClient {

// Executed for the first video frame and whenever opacity changes.
OnVideoOpacityChange(bool opaque);

// Called periodically to pass statistics to the web player. See
// media_types.mojom.
OnStatisticsUpdate(PipelineStatistics stats);

// Called when the remote renderering service is waiting on the decryption
// key.
OnWaitingForDecryptionKey();
};
5 changes: 4 additions & 1 deletion media/mojo/interfaces/typemaps.gni
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

typemaps = [ "//media/mojo/interfaces/audio_parameters.typemap" ]
typemaps = [
"//media/mojo/interfaces/audio_parameters.typemap",
"//media/mojo/interfaces/pipeline_statistics.typemap",
]
3 changes: 3 additions & 0 deletions media/mojo/services/media_mojo_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class MockRendererClient : public mojom::RendererClient {
MOCK_METHOD0(OnError, void());
MOCK_METHOD1(OnVideoOpacityChange, void(bool opaque));
MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size& size));
MOCK_METHOD1(OnStatisticsUpdate,
void(const media::PipelineStatistics& stats));
MOCK_METHOD0(OnWaitingForDecryptionKey, void());

private:
DISALLOW_COPY_AND_ASSIGN(MockRendererClient);
Expand Down
6 changes: 4 additions & 2 deletions media/mojo/services/mojo_renderer_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ void MojoRendererService::OnEnded() {
}

void MojoRendererService::OnStatisticsUpdate(const PipelineStatistics& stats) {
// TODO(alokp): Plumb the event to mojom::RendererClient. crbug/585287
DVLOG(3) << __FUNCTION__;
client_->OnStatisticsUpdate(stats);
}

void MojoRendererService::OnBufferingStateChange(BufferingState state) {
Expand All @@ -124,7 +125,8 @@ void MojoRendererService::OnBufferingStateChange(BufferingState state) {
}

void MojoRendererService::OnWaitingForDecryptionKey() {
// TODO(alokp): Plumb the event to mojom::RendererClient. crbug/585287
DVLOG(1) << __FUNCTION__;
client_->OnWaitingForDecryptionKey();
}

void MojoRendererService::OnVideoNaturalSizeChange(const gfx::Size& size) {
Expand Down

0 comments on commit 267e463

Please sign in to comment.