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/media_renderer.mojom.h"
19 #include "third_party/mojo/src/mojo/public/cpp/bindings/interface_impl.h"
22 class ApplicationConnection
;
27 class AudioRendererSink
;
28 class DemuxerStreamProviderShim
;
30 class VideoRendererSink
;
32 // A mojo::MediaRenderer implementation that uses media::AudioRenderer to
33 // decode and render audio to a sink obtained from the ApplicationConnection.
34 class MEDIA_EXPORT MojoRendererService
35 : NON_EXPORTED_BASE(public mojo::InterfaceImpl
<mojo::MediaRenderer
>) {
37 MojoRendererService();
38 ~MojoRendererService() override
;
40 // mojo::MediaRenderer implementation.
41 void Initialize(mojo::MediaRendererClientPtr client
,
42 mojo::DemuxerStreamPtr audio
,
43 mojo::DemuxerStreamPtr video
,
44 const mojo::Closure
& callback
) override
;
45 void Flush(const mojo::Closure
& callback
) override
;
46 void StartPlayingFrom(int64_t time_delta_usec
) override
;
47 void SetPlaybackRate(double playback_rate
) override
;
48 void SetVolume(float volume
) override
;
59 // Called when the DemuxerStreamProviderShim is ready to go (has a config,
60 // pipe handle, etc) and can be handed off to a renderer for use.
61 void OnStreamReady(const mojo::Closure
& callback
);
63 // Called when |audio_renderer_| initialization has completed.
64 void OnRendererInitializeDone(const mojo::Closure
& callback
,
65 PipelineStatus status
);
67 // Callback executed by filters to update statistics.
68 void OnUpdateStatistics(const PipelineStatistics
& stats
);
70 // Periodically polls the media time from the renderer and notifies the client
71 // if the media time has changed since the last update. If |force| is true,
72 // the client is notified even if the time is unchanged.
73 void UpdateMediaTime(bool force
);
74 void CancelPeriodicMediaTimeUpdates();
75 void SchedulePeriodicMediaTimeUpdates();
77 // Callback executed by audio renderer when buffering state changes.
78 // TODO(tim): Need old and new.
79 void OnBufferingStateChanged(BufferingState new_buffering_state
);
81 // Callback executed when a renderer has ended.
82 void OnRendererEnded();
84 // Callback executed when a runtime error happens.
85 void OnError(PipelineStatus error
);
87 // Callback executed once Flush() completes.
88 void OnFlushCompleted(const mojo::Closure
& callback
);
92 scoped_refptr
<AudioRendererSink
> audio_renderer_sink_
;
93 scoped_ptr
<VideoRendererSink
> video_renderer_sink_
;
94 scoped_ptr
<Renderer
> renderer_
;
95 scoped_ptr
<DemuxerStreamProviderShim
> stream_provider_
;
97 base::RepeatingTimer
<MojoRendererService
> time_update_timer_
;
98 uint64_t last_media_time_usec_
;
100 mojo::MediaRendererClientPtr client_
;
102 base::WeakPtr
<MojoRendererService
> weak_this_
;
103 base::WeakPtrFactory
<MojoRendererService
> weak_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(MojoRendererService
);
110 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_