1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "media/base/renderer.h"
11 #include "media/mojo/interfaces/renderer.mojom.h"
14 class SingleThreadTaskRunner
;
19 class DemuxerStreamProvider
;
21 // A media::Renderer that proxies to a interfaces::Renderer. That
22 // interfaces::Renderer proxies back to the MojoRendererImpl via the
23 // interfaces::RendererClient interface.
25 // MojoRendererImpl implements media::Renderer for use as either an audio
27 class MojoRendererImpl
: public Renderer
, public interfaces::RendererClient
{
29 // |task_runner| is the TaskRunner on which all methods are invoked.
31 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
32 interfaces::RendererPtr remote_renderer
);
33 ~MojoRendererImpl() override
;
35 // Renderer implementation.
36 void Initialize(DemuxerStreamProvider
* demuxer_stream_provider
,
37 const PipelineStatusCB
& init_cb
,
38 const StatisticsCB
& statistics_cb
,
39 const BufferingStateCB
& buffering_state_cb
,
40 const base::Closure
& ended_cb
,
41 const PipelineStatusCB
& error_cb
,
42 const base::Closure
& waiting_for_decryption_key_cb
) override
;
43 void SetCdm(CdmContext
* cdm_context
,
44 const CdmAttachedCB
& cdm_attached_cb
) override
;
45 void Flush(const base::Closure
& flush_cb
) override
;
46 void StartPlayingFrom(base::TimeDelta time
) override
;
47 void SetPlaybackRate(double playback_rate
) override
;
48 void SetVolume(float volume
) override
;
49 base::TimeDelta
GetMediaTime() override
;
50 bool HasAudio() override
;
51 bool HasVideo() override
;
53 // interfaces::RendererClient implementation.
54 void OnTimeUpdate(int64_t time_usec
, int64_t max_time_usec
) override
;
55 void OnBufferingStateChange(interfaces::BufferingState state
) override
;
56 void OnEnded() override
;
57 void OnError() override
;
60 // Called when |remote_renderer_| has finished initializing.
61 void OnInitialized(bool success
);
63 // Task runner used to execute pipeline tasks.
64 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
66 DemuxerStreamProvider
* demuxer_stream_provider_
;
67 interfaces::RendererPtr remote_renderer_
;
68 mojo::Binding
<RendererClient
> binding_
;
70 // Callbacks passed to Initialize() that we forward messages from
71 // |remote_renderer_| through.
72 PipelineStatusCB init_cb_
;
73 base::Closure ended_cb_
;
74 PipelineStatusCB error_cb_
;
75 BufferingStateCB buffering_state_cb_
;
77 // Lock used to serialize access for the following data members.
78 mutable base::Lock lock_
;
80 base::TimeDelta time_
;
81 // TODO(xhwang): It seems we don't need |max_time_| now. Drop it!
82 base::TimeDelta max_time_
;
84 base::WeakPtrFactory
<MojoRendererImpl
> weak_factory_
;
86 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl
);
91 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_