Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chromecast/public/media/media_pipeline_backend.h

Issue 1372393007: [Chromecast] Upgrade to new CMA backend API (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix GN build Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_ 5 #ifndef CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_
6 #define CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_ 6 #define CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_
7 7
8 #include "decoder_config.h"
9
8 namespace chromecast { 10 namespace chromecast {
11 struct Size;
erickung1 2015/10/09 17:53:29 nit: a blank line between #10 and #11
kmackay 2015/10/09 20:35:40 I put a blank line before the media namespace. I u
9 namespace media { 12 namespace media {
13 class CastDecoderBuffer;
erickung1 2015/10/09 17:53:29 nit: ditto between #12 and #13
14 class DecryptContext;
10 15
11 class AudioPipelineDevice; 16 // Interface for platform-specific output of media.
12 class MediaClockDevice;
13 struct MediaPipelineDeviceParams;
14 class VideoPipelineDevice;
15
16 // Interface for creating and managing ownership of platform-specific clock,
17 // audio and video devices. cast_shell owns the MediaPipelineBackend for
18 // as long as it is needed; the implementation is responsible for
19 // tearing down the individual components correctly when it is destroyed.
20 // A new MediaPipelineBackend will be instantiated for each media player 17 // A new MediaPipelineBackend will be instantiated for each media player
21 // instance. 18 // instance and raw audio stream. If a backend has both video and audio
19 // decoders, they must be synchronized. Platforms must support 1
20 // synchronized backend and >= 3 backends with audio only simultaneously. If
erickung1 2015/10/09 17:53:29 Is this the restriction in Chromecast + Chromium r
kmackay 2015/10/09 20:35:40 I removed the comment, but we need to have some gu
21 // more backends are requested than the platform supports, the unsupported
22 // extra backends may return nullptr for CreateAudioDecoder/CreateVideoDecoder.
23 // The basic usage pattern is:
24 // * Decoder objects created, then Initialize called
25 // * Start/Stop/Pause/Resume used to manage playback state
26 // * Decoder objects are used to pass actual stream data buffers
27 // * Backend must make appropriate callbacks on the provided Delegate
28 // All functions will be called on the media thread. Delegate callbacks
29 // must be made on this thread also (using provided TaskRunner if necessary).
22 class MediaPipelineBackend { 30 class MediaPipelineBackend {
23 public: 31 public:
32 // Return code for PushBuffer
33 enum BufferStatus {
34 kBufferSuccess,
35 kBufferFailed,
36 kBufferPending,
37 };
38
39 class Decoder {
erickung1 2015/10/09 17:53:29 should we hide destructor of Decoder/VideoDecoder/
kmackay 2015/10/09 20:35:40 Done.
40 public:
41 typedef MediaPipelineBackend::BufferStatus BufferStatus;
42
43 // Statistics (computed since pipeline last started playing).
44 // For video, a sample is defined as a frame.
45 struct Statistics {
46 uint64_t decoded_bytes;
47 uint64_t decoded_samples;
48 uint64_t dropped_samples;
49 };
50
51 virtual ~Decoder() {}
52
53 // Pushes a buffer of data for decoding and output. If the implementation
54 // cannot push the buffer now, it must store the buffer, return
55 // |kBufferPending| and execute the push at a later time when it becomes
56 // possible to do so. The implementation must then invoke
57 // Client::OnPushComplete. Pushing a pending buffer should be aborted if
58 // Stop is called; OnPushAudioComplete need not be invoked in this case.
59 // If |kBufferPending| is returned, the pipeline will stop pushing any
60 // further buffers until OnPushComplete is invoked.
61 // OnPushComplete should be only be invoked to indicate completion of a
62 // pending buffer push - not for the immediate |kBufferSuccess| return case.
63 // The decrypt_context and buffer's lifetimes are managed by the caller code
64 // - they MUST NOT be deleted by the MediaPipelineBackend implementation,
65 // and MUST NOT be dereferenced after completion of buffer push (i.e.
66 // kBufferSuccess/kBufferFailure for synchronous completion, OnPushComplete
67 // for kBufferPending case).
68 virtual BufferStatus PushBuffer(DecryptContext* decrypt_context,
69 CastDecoderBuffer* buffer) = 0;
70
71 // Returns the playback statistics since this decoder's creation. Only
72 // called when playing or paused.
73 virtual void GetStatistics(Statistics* statistics) = 0;
74 };
75
76 class AudioDecoder : public Decoder {
77 public:
78 // Info on pipeline latency: amount of data in pipeline not rendered yet,
79 // and timestamp of system clock (must be CLOCK_MONOTONIC) at which delay
80 // measurement was taken. Both times in microseconds.
81 struct RenderingDelay {
82 RenderingDelay()
83 : delay_microseconds(INT64_MIN), timestamp_microseconds(INT64_MIN) {}
84 RenderingDelay(int64_t delay_microseconds_in,
85 int64_t timestamp_microseconds_in)
86 : delay_microseconds(delay_microseconds_in),
87 timestamp_microseconds(timestamp_microseconds_in) {}
88 int64_t delay_microseconds;
89 int64_t timestamp_microseconds;
90 };
91
92 // Provides the audio configuration. Called once before the backend is
93 // initialized, and again any time the configuration changes (in any state).
94 // Returns true if the configuration is a supported configuration.
95 virtual bool SetConfig(const AudioConfig& config) = 0;
96
97 // Sets the volume multiplier for this audio stream.
98 // The multiplier is in the range [0.0, 1.0]. If not called, a default
99 // multiplier of 1.0 is assumed. Returns true if successful.
100 virtual bool SetVolume(float multiplier) = 0;
101
102 // Returns the pipeline latency: i.e. the amount of data
103 // in the pipeline that have not been rendered yet, in microseconds.
104 // Returns delay = INT64_MIN if the latency is not available.
105 virtual RenderingDelay GetRenderingDelay() = 0;
106 };
107
108 class VideoDecoder : public Decoder {
109 public:
110 // Provides the video configuration. Called once before the backend is
111 // initialized, and again any time the configuration changes (in any state).
112 // Returns true if the configuration is a supported configuration.
113 virtual bool SetConfig(const VideoConfig& config) = 0;
114 };
115
116 // Delegate methods must be called on the main CMA thread.
117 class Delegate {
118 public:
119 // Must be called when video resolution change is detected by decoder.
120 virtual void OnVideoResolutionChanged(VideoDecoder* decoder,
121 const Size& size) = 0;
122
123 // See comments on PushBuffer. Must not be called with kBufferPending.
124 virtual void OnPushBufferComplete(Decoder* decoder,
125 BufferStatus status) = 0;
126
127 // Must be called after an end-of-stream buffer has been rendered (ie, the
128 // last real buffer has been sent to the output hardware).
129 virtual void OnEndOfStream(Decoder* decoder) = 0;
130
131 // May be called if a decoder error occurs. No more calls to PushBuffer()
132 // will be made after this is called.
133 virtual void OnDecoderError(Decoder* decoder) = 0;
134
135 protected:
136 virtual ~Delegate() {}
137 };
138
24 virtual ~MediaPipelineBackend() {} 139 virtual ~MediaPipelineBackend() {}
25 140
26 // Returns the platform-specific pipeline clock. 141 // Creates a new AudioDecoder attached to this pipeline. MediaPipelineBackend
27 virtual MediaClockDevice* GetClock() = 0; 142 // maintains ownership of the decoder object (and must not delete before it's
143 // destroyed). Will be called zero or more times, all calls made before
144 // Initialize. May return nullptr if the platform implementation cannot
145 // support any additional simultaneous playback at this time.
146 virtual AudioDecoder* CreateAudioDecoder() = 0;
28 147
29 // Returns the platform-specific audio backend. 148 // Creates a new VideoDecoder attached to this pipeline. MediaPipelineBackend
30 virtual AudioPipelineDevice* GetAudio() = 0; 149 // maintains ownership of the decoder object (and must not delete before it's
150 // destroyed). Will be called zero or more times, all calls made before
151 // Initialize. Note: Even if your backend only supports audio, you must
152 // provide a default implementation of VideoDecoder; one way to do this is to
153 // inherit from MediaPipelineBackendDefault. May return nullptr if the
154 // platform implementation cannot support any additional simultaneous playback
155 // at this time.
156 virtual VideoDecoder* CreateVideoDecoder() = 0;
31 157
32 // Returns the platform-specific video backend. 158 // Initializes the backend. This will be called once, after Decoder creation
33 virtual VideoPipelineDevice* GetVideo() = 0; 159 // but before all other functions. Hardware resources for all decoders should
160 // be acquired here. Backend is then considered in Initialized state.
161 // Returns false for failure.
162 virtual bool Initialize(Delegate* delegate) = 0;
163
164 // Places pipeline into playing state. Playback will start at given time once
165 // buffers are pushed. Called only when in Initialized state.
166 virtual bool Start(int64_t start_pts) = 0;
167
168 // Returns pipeline to 'Initialized' state. May be called while playing or
169 // paused. Buffers cannot be pushed in Initialized state.
170 virtual bool Stop() = 0;
171
172 // Pauses media playback. Called only when in playing state.
173 virtual bool Pause() = 0;
174
175 // Resumes media playback. Called only when in paused state.
176 virtual bool Resume() = 0;
177
178 // Gets the current playback time.
erickung1 2015/10/09 17:53:29 May be better to provide the unit of the value it
kmackay 2015/10/09 20:35:40 Done.
179 virtual int64_t GetCurrentPts() = 0;
180
181 // Sets the playback rate. |rate| > 0. If this is not called, a default rate
182 // of 1.0 is assumed. Returns true if successful.
183 virtual bool SetPlaybackRate(float rate) = 0;
34 }; 184 };
35 185
36 } // namespace media 186 } // namespace media
37 } // namespace chromecast 187 } // namespace chromecast
38 188
39 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_DEVICE_FACTORY_H_ 189 #endif // CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698