Require Renderer::Initialize() to return a status code via callback.
[chromium-blink-merge.git] / media / mojo / services / mojo_renderer_service.h
blob0c6b7eeb4a2049282919f02813fce066786f1fc1
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 "third_party/mojo/src/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,
61 PipelineStatus status);
63 // Callback executed by filters to update statistics.
64 void OnUpdateStatistics(const PipelineStatistics& stats);
66 // Periodically polls the media time from the renderer and notifies the client
67 // if the media time has changed since the last update. If |force| is true,
68 // the client is notified even if the time is unchanged.
69 void UpdateMediaTime(bool force);
70 void CancelPeriodicMediaTimeUpdates();
71 void SchedulePeriodicMediaTimeUpdates();
73 // Callback executed by audio renderer when buffering state changes.
74 // TODO(tim): Need old and new.
75 void OnBufferingStateChanged(BufferingState new_buffering_state);
77 // Callback executed when a renderer has ended.
78 void OnRendererEnded();
80 // Callback executed when a runtime error happens.
81 void OnError(PipelineStatus error);
83 // Callback executed once Flush() completes.
84 void OnFlushCompleted(const mojo::Closure& callback);
86 State state_;
88 scoped_refptr<AudioRendererSink> audio_renderer_sink_;
89 scoped_ptr<Renderer> renderer_;
90 scoped_ptr<DemuxerStreamProviderShim> stream_provider_;
92 base::RepeatingTimer<MojoRendererService> time_update_timer_;
93 uint64_t last_media_time_usec_;
95 base::WeakPtr<MojoRendererService> weak_this_;
96 base::WeakPtrFactory<MojoRendererService> weak_factory_;
98 DISALLOW_COPY_AND_ASSIGN(MojoRendererService);
101 } // namespace media
103 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_SERVICE_H_