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/media_renderer.mojom.h"
14 class SingleThreadTaskRunner
;
19 class DemuxerStreamProvider
;
21 // A media::Renderer that proxies to a mojo::MediaRenderer. That
22 // mojo::MediaRenderer proxies back to the MojoRendererImpl via the
23 // mojo::MediaRendererClient interface.
25 // MojoRendererImpl implements media::Renderer for use as either an audio
27 class MojoRendererImpl
: public Renderer
, public mojo::MediaRendererClient
{
29 // |task_runner| is the TaskRunner on which all methods are invoked.
31 const scoped_refptr
<base::SingleThreadTaskRunner
>& task_runner
,
32 mojo::MediaRendererPtr remote_media_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 PaintCB
& paint_cb
,
41 const base::Closure
& ended_cb
,
42 const PipelineStatusCB
& error_cb
,
43 const base::Closure
& waiting_for_decryption_key_cb
) override
;
44 void SetCdm(CdmContext
* cdm_context
,
45 const CdmAttachedCB
& cdm_attached_cb
) override
;
46 void Flush(const base::Closure
& flush_cb
) override
;
47 void StartPlayingFrom(base::TimeDelta time
) override
;
48 void SetPlaybackRate(float playback_rate
) override
;
49 void SetVolume(float volume
) override
;
50 base::TimeDelta
GetMediaTime() override
;
51 bool HasAudio() override
;
52 bool HasVideo() override
;
54 // mojo::MediaRendererClient implementation.
55 void OnTimeUpdate(int64_t time_usec
, int64_t max_time_usec
) override
;
56 void OnBufferingStateChange(mojo::BufferingState state
) override
;
57 void OnEnded() override
;
58 void OnError() override
;
61 // Called when |remote_media_renderer_| has finished initializing.
64 // Task runner used to execute pipeline tasks.
65 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
67 DemuxerStreamProvider
* demuxer_stream_provider_
;
68 mojo::MediaRendererPtr remote_media_renderer_
;
69 mojo::Binding
<MediaRendererClient
> binding_
;
71 // Callbacks passed to Initialize() that we forward messages from
72 // |remote_media_renderer_| through.
73 PipelineStatusCB init_cb_
;
74 base::Closure ended_cb_
;
75 PipelineStatusCB error_cb_
;
76 BufferingStateCB buffering_state_cb_
;
78 // Lock used to serialize access for the following data members.
79 mutable base::Lock lock_
;
81 base::TimeDelta time_
;
82 // TODO(xhwang): It seems we don't need |max_time_| now. Drop it!
83 base::TimeDelta max_time_
;
85 base::WeakPtrFactory
<MojoRendererImpl
> weak_factory_
;
87 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl
);
92 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_