Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / media / mojo / services / mojo_renderer_service.h
blob7ad544b2ea1ae0f0c5a05e0f28effe75afc3c4b5
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/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h"
13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/buffering_state.h"
15 #include "media/base/pipeline_status.h"
16 #include "media/mojo/interfaces/media_renderer.mojom.h"
17 #include "mojo/public/cpp/bindings/interface_impl.h"
19 namespace mojo {
20 class ApplicationConnection;
23 namespace media {
25 class AudioRendererSink;
26 class DemuxerStreamProviderShim;
27 class MojoDemuxerStreamAdapter;
28 class Renderer;
30 // A mojo::MediaRenderer implementation that uses media::AudioRenderer to
31 // decode and render audio to a sink obtained from the ApplicationConnection.
32 class MojoRendererService : public mojo::InterfaceImpl<mojo::MediaRenderer> {
33 public:
34 MojoRendererService();
35 ~MojoRendererService() override;
37 // mojo::MediaRenderer implementation.
38 void Initialize(mojo::DemuxerStreamPtr audio,
39 mojo::DemuxerStreamPtr video,
40 const mojo::Closure& callback) override;
41 void Flush(const mojo::Closure& callback) override;
42 void StartPlayingFrom(int64_t time_delta_usec) override;
43 void SetPlaybackRate(float playback_rate) override;
44 void SetVolume(float volume) override;
46 private:
47 enum State {
48 STATE_UNINITIALIZED,
49 STATE_INITIALIZING,
50 STATE_FLUSHING,
51 STATE_PLAYING,
52 STATE_ERROR
55 // Called when the MojoDemuxerStreamAdapter is ready to go (has a config,
56 // pipe handle, etc) and can be handed off to a renderer for use.
57 void OnStreamReady(const mojo::Closure& callback);
59 // Called when |audio_renderer_| initialization has completed.
60 void OnRendererInitializeDone(const mojo::Closure& callback);
62 // Callback executed by filters to update statistics.
63 void OnUpdateStatistics(const PipelineStatistics& stats);
65 // Periodically polls the media time from the renderer and notifies the client
66 // if the media time has changed since the last update. If |force| is true,
67 // the client is notified even if the time is unchanged.
68 void UpdateMediaTime(bool force);
69 void CancelPeriodicMediaTimeUpdates();
70 void SchedulePeriodicMediaTimeUpdates();
72 // Callback executed by audio renderer when buffering state changes.
73 // TODO(tim): Need old and new.
74 void OnBufferingStateChanged(BufferingState new_buffering_state);
76 // Callback executed when a renderer has ended.
77 void OnRendererEnded();
79 // Callback executed when a runtime error happens.
80 void OnError(PipelineStatus error);
82 // Callback executed once Flush() completes.
83 void OnFlushCompleted(const mojo::Closure& callback);
85 State state_;
87 scoped_refptr<AudioRendererSink> audio_renderer_sink_;
88 scoped_ptr<Renderer> renderer_;
89 scoped_ptr<DemuxerStreamProviderShim> stream_provider_;
91 base::RepeatingTimer<MojoRendererService> time_update_timer_;
92 uint64_t last_media_time_usec_;
94 base::WeakPtr<MojoRendererService> weak_this_;
95 base::WeakPtrFactory<MojoRendererService> weak_factory_;
97 DISALLOW_COPY_AND_ASSIGN(MojoRendererService);
100 } // namespace media
102 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_