Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Unified Diff: media/mojo/services/gpu_mojo_media_client.cc

Issue 2544113002: Example MojoVideoDecoder decoder using the command buffer.
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/mojo/services/gpu_mojo_media_client.h ('k') | media/mojo/services/media_service_factory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/gpu_mojo_media_client.cc
diff --git a/media/mojo/services/gpu_mojo_media_client.cc b/media/mojo/services/gpu_mojo_media_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6c4606c2d7b14a76a0feb6f9a4fc9a033d67c3c8
--- /dev/null
+++ b/media/mojo/services/gpu_mojo_media_client.cc
@@ -0,0 +1,128 @@
+// 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.
+
+#include "media/mojo/services/gpu_mojo_media_client.h"
+
+#include "media/base/audio_decoder.h"
+#include "media/base/cdm_factory.h"
+#include "media/base/video_decoder.h"
+
+#if defined(OS_ANDROID)
+#include "base/memory/ptr_util.h"
+#include "media/base/android/android_cdm_factory.h"
+#include "media/filters/android/media_codec_audio_decoder.h"
+#include "media/mojo/interfaces/provision_fetcher.mojom.h"
+#include "media/mojo/services/mojo_provision_fetcher.h"
+#include "services/service_manager/public/cpp/connect.h"
+#endif // defined(OS_ANDROID)
+
+#include "gpu/ipc/service/gpu_channel.h"
+#include "gpu/ipc/service/gpu_command_buffer_stub.h"
+#include "media/gpu/ipc/service/media_gpu_channel_manager.h"
+
+namespace media {
+
+namespace {
+
+#if defined(OS_ANDROID)
+std::unique_ptr<ProvisionFetcher> CreateProvisionFetcher(
+ service_manager::mojom::InterfaceProvider* interface_provider) {
+ mojom::ProvisionFetcherPtr provision_fetcher_ptr;
+ service_manager::GetInterface(interface_provider, &provision_fetcher_ptr);
+ return base::MakeUnique<MojoProvisionFetcher>(
+ std::move(provision_fetcher_ptr));
+}
+#endif // defined(OS_ANDROID)
+
+class TestVideoDecoder : public VideoDecoder {
+ public:
+ TestVideoDecoder(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
+ base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager,
+ mojom::CommandBufferIdPtr command_buffer_id)
+ : weak_factory_(this) {
+ CHECK(command_buffer_id);
+ weak_this_ = weak_factory_.GetWeakPtr();
+ gpu_task_runner->PostTask(FROM_HERE, base::Bind(
+ &TestVideoDecoder::InitializeOnGpuThread, weak_this_,
+ media_gpu_channel_manager, command_buffer_id->channel_token,
+ command_buffer_id->route_id));
+ }
+
+ void InitializeOnGpuThread(
+ base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager,
+ base::UnguessableToken channel_token,
+ int32_t route_id) {
+ CHECK(media_gpu_channel_manager);
+ gpu::GpuChannel* channel = media_gpu_channel_manager->LookupChannel(
+ channel_token);
+ CHECK(channel);
+ gpu::GpuCommandBufferStub* stub = channel->LookupCommandBuffer(route_id);
+ CHECK(stub);
+ LOG(ERROR) << "route_id: " << stub->route_id();
+ LOG(ERROR) << "stream_id: " << stub->stream_id();
+ }
+
+ std::string GetDisplayName() const override {
+ return "TestVideoDecoder";
+ }
+
+ void Initialize(const VideoDecoderConfig& config,
+ bool low_delay,
+ CdmContext* cdm_context,
+ const InitCB& init_cb,
+ const OutputCB& output_cb) override {
+ }
+
+ void Decode(const scoped_refptr<DecoderBuffer>& buffer,
+ const DecodeCB& decode_cb) override {
+ }
+
+ void Reset(const base::Closure& closure) override {
+ }
+
+ private:
+ base::WeakPtr<TestVideoDecoder> weak_this_;
+ base::WeakPtrFactory<TestVideoDecoder> weak_factory_;
+};
+
+} // namespace
+
+GpuMojoMediaClient::GpuMojoMediaClient(
+ scoped_refptr<base::SingleThreadTaskRunner> gpu_task_runner,
+ base::WeakPtr<MediaGpuChannelManager> media_gpu_channel_manager)
+ : gpu_task_runner_(std::move(gpu_task_runner)),
+ media_gpu_channel_manager_(std::move(media_gpu_channel_manager)) {}
+
+GpuMojoMediaClient::~GpuMojoMediaClient() {}
+
+std::unique_ptr<AudioDecoder> GpuMojoMediaClient::CreateAudioDecoder(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner) {
+#if defined(OS_ANDROID)
+ return base::MakeUnique<MediaCodecAudioDecoder>(task_runner);
+#else
+ return nullptr;
+#endif // defined(OS_ANDROID)
+}
+
+std::unique_ptr<VideoDecoder> GpuMojoMediaClient::CreateVideoDecoder(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ mojom::CommandBufferIdPtr command_buffer_id) {
+ return base::MakeUnique<TestVideoDecoder>(
+ std::move(task_runner), gpu_task_runner_, media_gpu_channel_manager_,
+ std::move(command_buffer_id));
+}
+
+std::unique_ptr<CdmFactory> GpuMojoMediaClient::CreateCdmFactory(
+ service_manager::mojom::InterfaceProvider* interface_provider) {
+#if defined(OS_ANDROID)
+ return base::MakeUnique<AndroidCdmFactory>(
+ base::Bind(&CreateProvisionFetcher, interface_provider));
+#else
+ return nullptr;
+#endif // defined(OS_ANDROID)
+}
+
+} // namespace media
« no previous file with comments | « media/mojo/services/gpu_mojo_media_client.h ('k') | media/mojo/services/media_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698