Update broken references to image assets
[chromium-blink-merge.git] / media / mojo / services / mojo_renderer_service.h
blob2fa0ce3fb1a308ded4edc782a97592f1fcf5a5c1
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_SERVICE_H_
6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_
8 #include "base/callback.h"
9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h"
14 #include "media/base/audio_decoder_config.h"
15 #include "media/base/buffering_state.h"
16 #include "media/base/media_export.h"
17 #include "media/base/pipeline_status.h"
18 #include "media/mojo/interfaces/renderer.mojom.h"
19 #include "media/mojo/services/mojo_cdm_service_context.h"
20 #include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
22 namespace mojo {
23 class ApplicationConnection;
26 namespace media {
28 class AudioRendererSink;
29 class DemuxerStreamProviderShim;
30 class CdmContextProvider;
31 class MediaLog;
32 class Renderer;
33 class RendererFactory;
34 class VideoRendererSink;
36 // A interfaces::Renderer implementation that uses media::AudioRenderer to
37 // decode and render audio to a sink obtained from the ApplicationConnection.
38 class MEDIA_EXPORT MojoRendererService
39 : NON_EXPORTED_BASE(interfaces::Renderer) {
40 public:
41 // |cdm_context_provider| can be used to find the CdmContext to support
42 // encrypted media. If null, encrypted media is not supported.
43 MojoRendererService(base::WeakPtr<CdmContextProvider> cdm_context_provider,
44 RendererFactory* renderer_factory,
45 const scoped_refptr<MediaLog>& media_log,
46 mojo::InterfaceRequest<interfaces::Renderer> request);
47 ~MojoRendererService() final;
49 // interfaces::Renderer implementation.
50 void Initialize(interfaces::RendererClientPtr client,
51 interfaces::DemuxerStreamPtr audio,
52 interfaces::DemuxerStreamPtr video,
53 const mojo::Callback<void(bool)>& callback) final;
54 void Flush(const mojo::Closure& callback) final;
55 void StartPlayingFrom(int64_t time_delta_usec) final;
56 void SetPlaybackRate(double playback_rate) final;
57 void SetVolume(float volume) final;
58 void SetCdm(int32_t cdm_id, const mojo::Callback<void(bool)>& callback) final;
60 private:
61 enum State {
62 STATE_UNINITIALIZED,
63 STATE_INITIALIZING,
64 STATE_FLUSHING,
65 STATE_PLAYING,
66 STATE_ERROR
69 // Called when the DemuxerStreamProviderShim is ready to go (has a config,
70 // pipe handle, etc) and can be handed off to a renderer for use.
71 void OnStreamReady(const mojo::Callback<void(bool)>& callback);
73 // Called when |audio_renderer_| initialization has completed.
74 void OnRendererInitializeDone(const mojo::Callback<void(bool)>& callback,
75 PipelineStatus status);
77 // Callback executed by filters to update statistics.
78 void OnUpdateStatistics(const PipelineStatistics& stats);
80 // Periodically polls the media time from the renderer and notifies the client
81 // if the media time has changed since the last update. If |force| is true,
82 // the client is notified even if the time is unchanged.
83 void UpdateMediaTime(bool force);
84 void CancelPeriodicMediaTimeUpdates();
85 void SchedulePeriodicMediaTimeUpdates();
87 // Callback executed by audio renderer when buffering state changes.
88 // TODO(tim): Need old and new.
89 void OnBufferingStateChanged(BufferingState new_buffering_state);
91 // Callback executed when a renderer has ended.
92 void OnRendererEnded();
94 // Callback executed when a runtime error happens.
95 void OnError(PipelineStatus error);
97 // Callback executed once Flush() completes.
98 void OnFlushCompleted(const mojo::Closure& callback);
100 // Callback executed once SetCdm() completes.
101 void OnCdmAttached(const mojo::Callback<void(bool)>& callback, bool success);
103 mojo::StrongBinding<interfaces::Renderer> binding_;
105 base::WeakPtr<CdmContextProvider> cdm_context_provider_;
107 State state_;
109 // Note: |renderer_| should be destructed before these objects to avoid access
110 // violation.
111 scoped_ptr<DemuxerStreamProviderShim> stream_provider_;
112 scoped_refptr<AudioRendererSink> audio_renderer_sink_;
113 scoped_ptr<VideoRendererSink> video_renderer_sink_;
115 scoped_ptr<media::Renderer> renderer_;
117 base::RepeatingTimer<MojoRendererService> time_update_timer_;
118 uint64_t last_media_time_usec_;
120 interfaces::RendererClientPtr client_;
122 base::WeakPtr<MojoRendererService> weak_this_;
123 base::WeakPtrFactory<MojoRendererService> weak_factory_;
125 DISALLOW_COPY_AND_ASSIGN(MojoRendererService);
128 } // namespace media
130 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_