Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / mojo / services / mojo_renderer_impl.h
blobe574b15059993c48e28707437d1cc5916082142b
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"
12 #include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"
14 namespace base {
15 class SingleThreadTaskRunner;
18 namespace media {
20 class DemuxerStreamProvider;
22 // A media::Renderer that proxies to a interfaces::Renderer. That
23 // interfaces::Renderer proxies back to the MojoRendererImpl via the
24 // interfaces::RendererClient interface.
26 // MojoRendererImpl implements media::Renderer for use as either an audio
27 // or video renderer.
28 class MojoRendererImpl : public Renderer, public interfaces::RendererClient {
29 public:
30 // |task_runner| is the TaskRunner on which all methods are invoked.
31 MojoRendererImpl(
32 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
33 interfaces::RendererPtr remote_renderer);
34 ~MojoRendererImpl() override;
36 // Renderer implementation.
37 void Initialize(DemuxerStreamProvider* demuxer_stream_provider,
38 const PipelineStatusCB& init_cb,
39 const StatisticsCB& statistics_cb,
40 const BufferingStateCB& buffering_state_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(double playback_rate) override;
49 void SetVolume(float volume) override;
50 base::TimeDelta GetMediaTime() override;
51 bool HasAudio() override;
52 bool HasVideo() override;
54 // interfaces::RendererClient implementation.
55 void OnTimeUpdate(int64_t time_usec, int64_t max_time_usec) override;
56 void OnBufferingStateChange(interfaces::BufferingState state) override;
57 void OnEnded() override;
58 void OnError() override;
60 private:
61 // Called when |remote_renderer_| has finished initializing.
62 void OnInitialized(bool success);
64 // Task runner used to execute pipeline tasks.
65 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
67 DemuxerStreamProvider* demuxer_stream_provider_;
68 interfaces::RendererPtr remote_renderer_;
69 mojo::Binding<RendererClient> binding_;
71 // Callbacks passed to Initialize() that we forward messages from
72 // |remote_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);
90 } // namespace media
92 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_