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/demuxer_stream_provider.h" |
17 #include "media/base/pipeline_status.h" | 18 #include "media/base/pipeline_status.h" |
18 #include "media/base/renderer_client.h" | 19 #include "media/base/renderer_client.h" |
19 #include "media/mojo/interfaces/renderer.mojom.h" | 20 #include "media/mojo/interfaces/renderer.mojom.h" |
20 #include "mojo/public/cpp/bindings/strong_binding.h" | 21 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 22 #include "url/gurl.h" |
21 | 23 |
22 namespace media { | 24 namespace media { |
23 | 25 |
24 class DemuxerStreamProviderShim; | 26 class DemuxerStreamProviderShim; |
25 class MediaKeys; | 27 class MediaKeys; |
26 class MojoCdmServiceContext; | 28 class MojoCdmServiceContext; |
27 class Renderer; | 29 class Renderer; |
28 | 30 |
29 // A mojom::Renderer implementation that use a media::Renderer to render | 31 // A mojom::Renderer implementation that use a media::Renderer to render |
30 // media streams. | 32 // media streams. |
31 class MojoRendererService : public mojom::Renderer, public RendererClient { | 33 class MojoRendererService : public mojom::Renderer, public RendererClient { |
32 public: | 34 public: |
33 // |mojo_cdm_service_context| can be used to find the CDM to support | 35 // |mojo_cdm_service_context| can be used to find the CDM to support |
34 // encrypted media. If null, encrypted media is not supported. | 36 // encrypted media. If null, encrypted media is not supported. |
35 MojoRendererService( | 37 MojoRendererService( |
36 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, | 38 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context, |
37 std::unique_ptr<media::Renderer> renderer, | 39 std::unique_ptr<media::Renderer> renderer, |
38 mojo::InterfaceRequest<mojom::Renderer> request); | 40 mojo::InterfaceRequest<mojom::Renderer> request); |
39 ~MojoRendererService() final; | 41 ~MojoRendererService() final; |
40 | 42 |
41 // mojom::Renderer implementation. | 43 // mojom::Renderer implementation. |
42 void Initialize(mojom::RendererClientPtr client, | 44 void Initialize(mojom::RendererClientPtr client, |
43 mojom::DemuxerStreamPtr audio, | 45 mojom::DemuxerStreamPtr audio, |
44 mojom::DemuxerStreamPtr video, | 46 mojom::DemuxerStreamPtr video, |
| 47 const mojo::String& url, |
| 48 int64_t surface_id, |
45 const mojo::Callback<void(bool)>& callback) final; | 49 const mojo::Callback<void(bool)>& callback) final; |
46 void Flush(const mojo::Closure& callback) final; | 50 void Flush(const mojo::Closure& callback) final; |
47 void StartPlayingFrom(int64_t time_delta_usec) final; | 51 void StartPlayingFrom(int64_t time_delta_usec) final; |
48 void SetPlaybackRate(double playback_rate) final; | 52 void SetPlaybackRate(double playback_rate) final; |
49 void SetVolume(float volume) final; | 53 void SetVolume(float volume) final; |
50 void SetCdm(int32_t cdm_id, const mojo::Callback<void(bool)>& callback) final; | 54 void SetCdm(int32_t cdm_id, const mojo::Callback<void(bool)>& callback) final; |
51 | 55 |
52 private: | 56 private: |
53 enum State { | 57 enum State { |
54 STATE_UNINITIALIZED, | 58 STATE_UNINITIALIZED, |
55 STATE_INITIALIZING, | 59 STATE_INITIALIZING, |
56 STATE_FLUSHING, | 60 STATE_FLUSHING, |
57 STATE_PLAYING, | 61 STATE_PLAYING, |
58 STATE_ERROR | 62 STATE_ERROR |
59 }; | 63 }; |
60 | 64 |
61 // RendererClient implementation. | 65 // RendererClient implementation. |
62 void OnError(PipelineStatus status) final; | 66 void OnError(PipelineStatus status) final; |
63 void OnEnded() final; | 67 void OnEnded() final; |
64 void OnStatisticsUpdate(const PipelineStatistics& stats) final; | 68 void OnStatisticsUpdate(const PipelineStatistics& stats) final; |
65 void OnBufferingStateChange(BufferingState state) final; | 69 void OnBufferingStateChange(BufferingState state) final; |
66 void OnWaitingForDecryptionKey() final; | 70 void OnWaitingForDecryptionKey() final; |
67 void OnVideoNaturalSizeChange(const gfx::Size& size) final; | 71 void OnVideoNaturalSizeChange(const gfx::Size& size) final; |
68 void OnVideoOpacityChange(bool opaque) final; | 72 void OnVideoOpacityChange(bool opaque) final; |
| 73 void OnDurationChange(base::TimeDelta duration) final; |
69 | 74 |
70 // Called when the DemuxerStreamProviderShim is ready to go (has a config, | 75 // Called when the DemuxerStreamProviderShim is ready to go (has a config, |
71 // pipe handle, etc) and can be handed off to a renderer for use. | 76 // pipe handle, etc) and can be handed off to a renderer for use. |
72 void OnStreamReady(const mojo::Callback<void(bool)>& callback); | 77 void OnStreamReady(const mojo::Callback<void(bool)>& callback); |
73 | 78 |
74 // Called when |audio_renderer_| initialization has completed. | 79 // Called when |audio_renderer_| initialization has completed. |
75 void OnRendererInitializeDone(const mojo::Callback<void(bool)>& callback, | 80 void OnRendererInitializeDone(const mojo::Callback<void(bool)>& callback, |
76 PipelineStatus status); | 81 PipelineStatus status); |
77 | 82 |
78 // Periodically polls the media time from the renderer and notifies the client | 83 // Periodically polls the media time from the renderer and notifies the client |
(...skipping 10 matching lines...) Expand all Loading... |
89 void OnCdmAttached(scoped_refptr<MediaKeys> cdm, | 94 void OnCdmAttached(scoped_refptr<MediaKeys> cdm, |
90 const mojo::Callback<void(bool)>& callback, | 95 const mojo::Callback<void(bool)>& callback, |
91 bool success); | 96 bool success); |
92 | 97 |
93 mojo::StrongBinding<mojom::Renderer> binding_; | 98 mojo::StrongBinding<mojom::Renderer> binding_; |
94 | 99 |
95 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context_; | 100 base::WeakPtr<MojoCdmServiceContext> mojo_cdm_service_context_; |
96 | 101 |
97 State state_; | 102 State state_; |
98 | 103 |
99 std::unique_ptr<DemuxerStreamProviderShim> stream_provider_; | 104 std::unique_ptr<DemuxerStreamProvider> stream_provider_; |
100 | 105 |
101 base::RepeatingTimer time_update_timer_; | 106 base::RepeatingTimer time_update_timer_; |
102 uint64_t last_media_time_usec_; | 107 uint64_t last_media_time_usec_; |
103 | 108 |
104 mojom::RendererClientPtr client_; | 109 mojom::RendererClientPtr client_; |
105 | 110 |
106 // Hold a reference to the CDM set on the |renderer_| so that the CDM won't be | 111 // Hold a reference to the CDM set on the |renderer_| so that the CDM won't be |
107 // destructed while the |renderer_| is still using it. | 112 // destructed while the |renderer_| is still using it. |
108 scoped_refptr<MediaKeys> cdm_; | 113 scoped_refptr<MediaKeys> cdm_; |
109 | 114 |
110 // Note: Destroy |renderer_| first to avoid access violation into other | 115 // Note: Destroy |renderer_| first to avoid access violation into other |
111 // members, e.g. |stream_provider_| and |cdm_|. | 116 // members, e.g. |stream_provider_| and |cdm_|. |
112 // Must use "media::" because "Renderer" is ambiguous. | 117 // Must use "media::" because "Renderer" is ambiguous. |
113 std::unique_ptr<media::Renderer> renderer_; | 118 std::unique_ptr<media::Renderer> renderer_; |
114 | 119 |
115 base::WeakPtr<MojoRendererService> weak_this_; | 120 base::WeakPtr<MojoRendererService> weak_this_; |
116 base::WeakPtrFactory<MojoRendererService> weak_factory_; | 121 base::WeakPtrFactory<MojoRendererService> weak_factory_; |
117 | 122 |
118 DISALLOW_COPY_AND_ASSIGN(MojoRendererService); | 123 DISALLOW_COPY_AND_ASSIGN(MojoRendererService); |
119 }; | 124 }; |
120 | 125 |
121 } // namespace media | 126 } // namespace media |
122 | 127 |
123 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ | 128 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_ |
OLD | NEW |