Upload upstream chromium 85.0.4183.84
[platform/framework/web/chromium-efl.git] / media / base / renderer.h
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.
4
5 #ifndef MEDIA_BASE_RENDERER_H_
6 #define MEDIA_BASE_RENDERER_H_
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/optional.h"
12 #include "base/time/time.h"
13 #include "media/base/buffering_state.h"
14 #include "media/base/demuxer_stream.h"
15 #include "media/base/media_export.h"
16 #include "media/base/pipeline_status.h"
17
18 namespace media {
19
20 class CdmContext;
21 class MediaResource;
22 class RendererClient;
23
24 class MEDIA_EXPORT Renderer {
25  public:
26   Renderer();
27
28   // Stops rendering and fires any pending callbacks.
29   virtual ~Renderer();
30
31   // Initializes the Renderer with |media_resource|, executing |init_cb| upon
32   // completion. |media_resource| must be valid for the lifetime of the Renderer
33   // object.  |init_cb| must only be run after this method has returned. Firing
34   // |init_cb| may result in the immediate destruction of the caller, so it must
35   // be run only prior to returning.
36   virtual void Initialize(MediaResource* media_resource,
37                           RendererClient* client,
38                           PipelineStatusCallback init_cb) = 0;
39
40   // Associates the |cdm_context| with this Renderer for decryption (and
41   // decoding) of media data, then fires |cdm_attached_cb| with whether the
42   // operation succeeded.
43   using CdmAttachedCB = base::OnceCallback<void(bool)>;
44   virtual void SetCdm(CdmContext* cdm_context, CdmAttachedCB cdm_attached_cb);
45
46   // Specifies a latency hint from the site. Renderers should clamp the hint
47   // value to reasonable min and max and use the resulting value as a target
48   // latency such that the buffering state reaches HAVE_ENOUGH when this amount
49   // of decoded data is buffered. A nullopt hint indicates the user is clearing
50   // their preference and the renderer should restore its default buffering
51   // thresholds.
52   virtual void SetLatencyHint(base::Optional<base::TimeDelta> latency_hint) = 0;
53
54   // Sets whether pitch adjustment should be applied when the playback rate is
55   // different than 1.0.
56   virtual void SetPreservesPitch(bool preserves_pitch);
57
58   // The following functions must be called after Initialize().
59
60   // Discards any buffered data, executing |flush_cb| when completed.
61   virtual void Flush(base::OnceClosure flush_cb) = 0;
62
63   // Starts rendering from |time|.
64   virtual void StartPlayingFrom(base::TimeDelta time) = 0;
65
66   // Updates the current playback rate. The default playback rate should be 0.
67   virtual void SetPlaybackRate(double playback_rate) = 0;
68
69   // Sets the output volume. The default volume should be 1.
70   virtual void SetVolume(float volume) = 0;
71
72   // Returns the current media time.
73   //
74   // This method must be safe to call from any thread.
75   virtual base::TimeDelta GetMediaTime() = 0;
76
77   // Provides a list of DemuxerStreams correlating to the tracks which should
78   // be played. An empty list would mean that any playing track of the same
79   // type should be flushed and disabled. Any provided Streams should be played
80   // by whatever mechanism the subclass of Renderer choses for managing it's AV
81   // playback.
82   virtual void OnSelectedVideoTracksChanged(
83       const std::vector<DemuxerStream*>& enabled_tracks,
84       base::OnceClosure change_completed_cb);
85   virtual void OnEnabledAudioTracksChanged(
86       const std::vector<DemuxerStream*>& enabled_tracks,
87       base::OnceClosure change_completed_cb);
88
89  private:
90   DISALLOW_COPY_AND_ASSIGN(Renderer);
91 };
92
93 }  // namespace media
94
95 #endif  // MEDIA_BASE_RENDERER_H_