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