OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ |
6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
16 #include "media/base/buffering_state.h" | 16 #include "media/base/buffering_state.h" |
17 #include "media/base/pipeline_status.h" | 17 #include "media/base/pipeline_status.h" |
| 18 #include "media/base/renderer_client.h" |
18 #include "media/mojo/interfaces/renderer.mojom.h" | 19 #include "media/mojo/interfaces/renderer.mojom.h" |
19 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
20 | 21 |
21 namespace media { | 22 namespace media { |
22 | 23 |
23 class DemuxerStreamProviderShim; | 24 class DemuxerStreamProviderShim; |
24 class MediaKeys; | 25 class MediaKeys; |
25 class MojoCdmServiceContext; | 26 class MojoCdmServiceContext; |
26 class Renderer; | 27 class Renderer; |
27 | 28 |
28 // An interfaces::Renderer implementation that use a media::Renderer to render | 29 // An interfaces::Renderer implementation that use a media::Renderer to render |
29 // media streams. | 30 // media streams. |
30 class MojoRendererService : interfaces::Renderer { | 31 class MojoRendererService : public interfaces::Renderer, public RendererClient { |
31 public: | 32 public: |
32 // |mojo_cdm_service_context| can be used to find the CDM to support | 33 // |mojo_cdm_service_context| can be used to find the CDM to support |
33 // encrypted media. If null, encrypted media is not supported. | 34 // encrypted media. If null, encrypted media is not supported. |
34 MojoRendererService( | 35 MojoRendererService( |
35 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, | 36 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
36 std::unique_ptr<media::Renderer> renderer, | 37 std::unique_ptr<media::Renderer> renderer, |
37 mojo::InterfaceRequest<interfaces::Renderer> request); | 38 mojo::InterfaceRequest<interfaces::Renderer> request); |
38 ~MojoRendererService() final; | 39 ~MojoRendererService() final; |
39 | 40 |
40 // interfaces::Renderer implementation. | 41 // interfaces::Renderer implementation. |
41 void Initialize(interfaces::RendererClientPtr client, | 42 void Initialize(interfaces::RendererClientPtr client, |
42 interfaces::DemuxerStreamPtr audio, | 43 interfaces::DemuxerStreamPtr audio, |
43 interfaces::DemuxerStreamPtr video, | 44 interfaces::DemuxerStreamPtr video, |
44 const mojo::Callback<void(bool)>& callback) final; | 45 const mojo::Callback<void(bool)>& callback) final; |
45 void Flush(const mojo::Closure& callback) final; | 46 void Flush(const mojo::Closure& callback) final; |
46 void StartPlayingFrom(int64_t time_delta_usec) final; | 47 void StartPlayingFrom(int64_t time_delta_usec) final; |
47 void SetPlaybackRate(double playback_rate) final; | 48 void SetPlaybackRate(double playback_rate) final; |
48 void SetVolume(float volume) final; | 49 void SetVolume(float volume) final; |
49 void SetCdm(int32_t cdm_id, const mojo::Callback<void(bool)>& callback) final; | 50 void SetCdm(int32_t cdm_id, const mojo::Callback<void(bool)>& callback) final; |
50 | 51 |
51 private: | 52 private: |
52 enum State { | 53 enum State { |
53 STATE_UNINITIALIZED, | 54 STATE_UNINITIALIZED, |
54 STATE_INITIALIZING, | 55 STATE_INITIALIZING, |
55 STATE_FLUSHING, | 56 STATE_FLUSHING, |
56 STATE_PLAYING, | 57 STATE_PLAYING, |
57 STATE_ERROR | 58 STATE_ERROR |
58 }; | 59 }; |
59 | 60 |
| 61 // RendererClient implementation. |
| 62 void OnError(PipelineStatus status) final; |
| 63 void OnEnded() final; |
| 64 void OnStatisticsUpdate(const PipelineStatistics& stats) final; |
| 65 void OnBufferingStateChange(BufferingState state) final; |
| 66 void OnWaitingForDecryptionKey() final; |
| 67 |
60 // Called when the DemuxerStreamProviderShim is ready to go (has a config, | 68 // Called when the DemuxerStreamProviderShim is ready to go (has a config, |
61 // pipe handle, etc) and can be handed off to a renderer for use. | 69 // pipe handle, etc) and can be handed off to a renderer for use. |
62 void OnStreamReady(const mojo::Callback<void(bool)>& callback); | 70 void OnStreamReady(const mojo::Callback<void(bool)>& callback); |
63 | 71 |
64 // Called when |audio_renderer_| initialization has completed. | 72 // Called when |audio_renderer_| initialization has completed. |
65 void OnRendererInitializeDone(const mojo::Callback<void(bool)>& callback, | 73 void OnRendererInitializeDone(const mojo::Callback<void(bool)>& callback, |
66 PipelineStatus status); | 74 PipelineStatus status); |
67 | 75 |
68 // Callback executed by filters to update statistics. | |
69 void OnUpdateStatistics(const PipelineStatistics& stats); | |
70 | |
71 // Periodically polls the media time from the renderer and notifies the client | 76 // Periodically polls the media time from the renderer and notifies the client |
72 // if the media time has changed since the last update. If |force| is true, | 77 // if the media time has changed since the last update. If |force| is true, |
73 // the client is notified even if the time is unchanged. | 78 // the client is notified even if the time is unchanged. |
74 void UpdateMediaTime(bool force); | 79 void UpdateMediaTime(bool force); |
75 void CancelPeriodicMediaTimeUpdates(); | 80 void CancelPeriodicMediaTimeUpdates(); |
76 void SchedulePeriodicMediaTimeUpdates(); | 81 void SchedulePeriodicMediaTimeUpdates(); |
77 | 82 |
78 // Callback executed by audio renderer when buffering state changes. | |
79 // TODO(tim): Need old and new. | |
80 void OnBufferingStateChanged(BufferingState new_buffering_state); | |
81 | |
82 // Callback executed when a renderer has ended. | |
83 void OnRendererEnded(); | |
84 | |
85 // Callback executed when a runtime error happens. | |
86 void OnError(PipelineStatus error); | |
87 | |
88 // Callback executed once Flush() completes. | 83 // Callback executed once Flush() completes. |
89 void OnFlushCompleted(const mojo::Closure& callback); | 84 void OnFlushCompleted(const mojo::Closure& callback); |
90 | 85 |
91 // Callback executed once SetCdm() completes. | 86 // Callback executed once SetCdm() completes. |
92 void OnCdmAttached(scoped_refptr<MediaKeys> cdm, | 87 void OnCdmAttached(scoped_refptr<MediaKeys> cdm, |
93 const mojo::Callback<void(bool)>& callback, | 88 const mojo::Callback<void(bool)>& callback, |
94 bool success); | 89 bool success); |
95 | 90 |
96 mojo::StrongBinding<interfaces::Renderer> binding_; | 91 mojo::StrongBinding<interfaces::Renderer> binding_; |
97 | 92 |
(...skipping 19 matching lines...) Expand all Loading... |
117 | 112 |
118 base::WeakPtr<MojoRendererService> weak_this_; | 113 base::WeakPtr<MojoRendererService> weak_this_; |
119 base::WeakPtrFactory<MojoRendererService> weak_factory_; | 114 base::WeakPtrFactory<MojoRendererService> weak_factory_; |
120 | 115 |
121 DISALLOW_COPY_AND_ASSIGN(MojoRendererService); | 116 DISALLOW_COPY_AND_ASSIGN(MojoRendererService); |
122 }; | 117 }; |
123 | 118 |
124 } // namespace media | 119 } // namespace media |
125 | 120 |
126 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ | 121 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ |
OLD | NEW |