Chromium Code Reviews| OLD | NEW |
|---|---|
| 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; | |
| 9 namespace media { | 12 namespace media { |
| 13 class CastDecoderBuffer; | |
| 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 | |
|
slan
2015/10/06 19:34:00
We should be able to query the backend for the num
kmackay
2015/10/06 21:44:55
Added comment that the backend can return nullptr
slan
2015/10/06 22:15:06
Thanks.
| |
| 20 // synchronized backend and >= 3 backends with audio simultaneously. | |
| 21 // The basic usage pattern is: | |
| 22 // * Decoder objects created, then Initialize called | |
| 23 // * Start/Stop/Pause/Resume used to manage playback state | |
| 24 // * Decoder objects are used to pass actual stream data buffers | |
| 25 // * Backend must make appropriate callbacks on the provided Delegate | |
| 26 // All functions will be called on the media thread. Delegate callbacks | |
| 27 // must be made on this thread also (using provided TaskRunner if necessary). | |
| 22 class MediaPipelineBackend { | 28 class MediaPipelineBackend { |
| 23 public: | 29 public: |
| 30 // Return code for PushBuffer | |
| 31 enum BufferStatus { | |
| 32 kBufferSuccess, | |
| 33 kBufferFailed, | |
| 34 kBufferPending, | |
| 35 }; | |
| 36 | |
| 37 class Decoder { | |
| 38 public: | |
| 39 typedef MediaPipelineBackend::BufferStatus BufferStatus; | |
| 40 | |
| 41 // Statistics (computed since pipeline last started playing). | |
| 42 // For video, a sample is defined as a frame. | |
| 43 struct Statistics { | |
| 44 uint64_t decoded_bytes; | |
| 45 uint64_t decoded_samples; | |
| 46 uint64_t dropped_samples; | |
| 47 }; | |
| 48 | |
| 49 virtual ~Decoder() {} | |
| 50 | |
| 51 // Pushes a buffer of data for decoding. If the implementation cannot push | |
| 52 // the buffer now, it must store the buffer, return |kBufferPending| and | |
| 53 // execute the push at a later time when it becomes possible to do so. The | |
| 54 // implementation must then invoke Client::OnPushComplete. Pushing a | |
| 55 // pending buffer should be aborted if Stop is called; OnPushAudioComplete | |
| 56 // need not be invoked in this case. | |
| 57 // If |kBufferPending| is returned, the pipeline will stop pushing any | |
| 58 // further buffers until OnPushComplete is invoked. | |
| 59 // OnPushComplete should be only be invoked to indicate completion of a | |
| 60 // pending buffer push - not for the immediate |kBufferSuccess| return case. | |
| 61 // The decrypt_context and buffer's lifetimes are managed by the caller code | |
| 62 // - they MUST NOT be deleted by the MediaPipelineBackend implementation, | |
| 63 // and MUST NOT be dereferenced after completion of buffer push (i.e. | |
| 64 // kBufferSuccess/kBufferFailure for synchronous completion, OnPushComplete | |
| 65 // for kBufferPending case). | |
| 66 virtual BufferStatus PushBuffer(DecryptContext* decrypt_context, | |
| 67 CastDecoderBuffer* buffer) = 0; | |
| 68 | |
| 69 // Returns the playback statistics since this decoder's creation. Only | |
| 70 // called when playing or paused. | |
| 71 virtual void GetStatistics(Statistics* statistics) = 0; | |
| 72 }; | |
| 73 | |
| 74 class AudioDecoder : public Decoder { | |
| 75 public: | |
| 76 // Info on pipeline latency: amount of data in pipeline not rendered yet, | |
| 77 // and timestamp of system clock (must be CLOCK_MONOTONIC) at which delay | |
| 78 // measurement was taken. Both times in microseconds. | |
| 79 struct RenderingDelay { | |
| 80 RenderingDelay() | |
| 81 : delay_microseconds(INT64_MIN), timestamp_microseconds(INT64_MIN) {} | |
| 82 RenderingDelay(int64_t delay_microseconds_in, | |
| 83 int64_t timestamp_microseconds_in) | |
| 84 : delay_microseconds(delay_microseconds_in), | |
| 85 timestamp_microseconds(timestamp_microseconds_in) {} | |
| 86 int64_t delay_microseconds; | |
| 87 int64_t timestamp_microseconds; | |
| 88 }; | |
| 89 | |
| 90 // Provides the audio configuration. Called once before the backend is | |
| 91 // initialized, and again any time the configuration changes (in any state). | |
| 92 // Returns true if the configuration is a supported configuration. | |
| 93 virtual bool SetConfig(const AudioConfig& config) = 0; | |
| 94 | |
| 95 // Sets the volume multiplier for this audio stream. | |
| 96 // The multiplier is in the range [0.0, 1.0]. If not called, a default | |
| 97 // multiplier of 1.0 is assumed. Returns true if successful. | |
| 98 virtual bool SetVolume(float multiplier) = 0; | |
| 99 | |
| 100 // Returns the pipeline latency: i.e. the amount of data | |
| 101 // in the pipeline that have not been rendered yet, in microseconds. | |
| 102 // Returns delay = INT64_MIN if the latency is not available. | |
| 103 virtual RenderingDelay GetRenderingDelay() = 0; | |
| 104 }; | |
| 105 | |
| 106 class VideoDecoder : public Decoder { | |
| 107 public: | |
| 108 // Provides the video configuration. Called once before the backend is | |
| 109 // initialized, and again any time the configuration changes (in any state). | |
| 110 // Returns true if the configuration is a supported configuration. | |
| 111 virtual bool SetConfig(const VideoConfig& config) = 0; | |
| 112 }; | |
| 113 | |
| 114 // Delegate methods must be called on the main CMA thread. | |
| 115 class Delegate { | |
| 116 public: | |
| 117 // Must be called when video resolution change is detected by decoder. | |
| 118 virtual void OnVideoResolutionChanged(Decoder* decoder, | |
|
slan
2015/10/06 19:34:00
Why not VideoDecoder* here? Does a Delegate for an
kmackay
2015/10/06 21:44:55
Done.
| |
| 119 const Size& size) = 0; | |
| 120 | |
| 121 // See comments on PushBuffer. Must not be called with kBufferPending. | |
| 122 virtual void OnPushBufferComplete(Decoder* decoder, | |
| 123 BufferStatus status) = 0; | |
| 124 | |
| 125 // Must be called after an end-of-stream buffer has been rendered. | |
|
slan
2015/10/06 19:34:00
Define "rendered" here: decoded?
kmackay
2015/10/06 21:44:55
Rendered to output (ie, sent to the output hardwar
| |
| 126 virtual void OnEndOfStream(Decoder* decoder) = 0; | |
| 127 | |
| 128 // May be called if a decoder error occurs. No more calls to PushBuffer() | |
| 129 // will be made after this is called. | |
| 130 virtual void OnDecoderError(Decoder* decoder) = 0; | |
| 131 | |
| 132 protected: | |
| 133 virtual ~Delegate() {} | |
| 134 }; | |
| 135 | |
| 24 virtual ~MediaPipelineBackend() {} | 136 virtual ~MediaPipelineBackend() {} |
| 25 | 137 |
| 26 // Returns the platform-specific pipeline clock. | 138 // Creates a new AudioDecoder attached to this pipeline. MediaPipelineBackend |
| 27 virtual MediaClockDevice* GetClock() = 0; | 139 // maintains ownership of the decoder object (and must not delete before it's |
| 140 // destroyed). Will be called zero or more times, all calls made before | |
| 141 // Initialize. | |
| 142 virtual AudioDecoder* CreateAudioDecoder() = 0; | |
| 28 | 143 |
| 29 // Returns the platform-specific audio backend. | 144 // Creates a new VideoDecoder attached to this pipeline. MediaPipelineBackend |
| 30 virtual AudioPipelineDevice* GetAudio() = 0; | 145 // maintains ownership of the decoder object (and must not delete before it's |
| 146 // destroyed). Will be called zero or more times, all calls made before | |
| 147 // Initialize. Note: Even if your backend only supports audio, you must | |
| 148 // provide a default implementation of VideoDecoder; one way to do this is to | |
| 149 // inherit from MediaPipelineBackendDefault. | |
| 150 virtual VideoDecoder* CreateVideoDecoder() = 0; | |
| 31 | 151 |
| 32 // Returns the platform-specific video backend. | 152 // Initializes the backend. This will be called once, after Decoder creation |
| 33 virtual VideoPipelineDevice* GetVideo() = 0; | 153 // but before all other functions. Hardware resources for all decoders should |
| 154 // be acquired here. Backend is then considered in Initialized state. | |
| 155 // Returns false for failure. | |
| 156 virtual bool Initialize(Delegate* delegate) = 0; | |
| 157 | |
| 158 // Places pipeline into playing state. Playback will start at given time once | |
| 159 // buffers are pushed. Called only when in Initialized state. | |
| 160 virtual bool Start(int64_t start_pts) = 0; | |
| 161 | |
| 162 // Returns pipeline to 'Initialized' state. May be called while playing or | |
| 163 // paused. Buffers cannot be pushed in Initialized state. | |
| 164 virtual bool Stop() = 0; | |
| 165 | |
| 166 // Pauses media playback. Called only when in playing state. | |
| 167 virtual bool Pause() = 0; | |
| 168 | |
| 169 // Resumes media playback. Called only when in paused state. | |
| 170 virtual bool Resume() = 0; | |
| 171 | |
| 172 // Gets the current playback time. | |
| 173 virtual int64_t GetCurrentPts() = 0; | |
| 174 | |
| 175 // Sets the playback rate. |rate| > 0. If this is not called, a default rate | |
| 176 // of 1.0 is assumed. Returns true if successful. | |
| 177 virtual bool SetPlaybackRate(float rate) = 0; | |
| 34 }; | 178 }; |
| 35 | 179 |
| 36 } // namespace media | 180 } // namespace media |
| 37 } // namespace chromecast | 181 } // namespace chromecast |
| 38 | 182 |
| 39 #endif // CHROMECAST_MEDIA_CMA_BACKEND_MEDIA_PIPELINE_DEVICE_FACTORY_H_ | 183 #endif // CHROMECAST_PUBLIC_MEDIA_MEDIA_PIPELINE_BACKEND_H_ |
| OLD | NEW |