| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ | 5 #ifndef MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ |
| 6 #define MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ | 6 #define MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 private: | 88 private: |
| 89 // Callback for |video_frame_stream_| initialization. | 89 // Callback for |video_frame_stream_| initialization. |
| 90 void OnVideoFrameStreamInitialized(bool success); | 90 void OnVideoFrameStreamInitialized(bool success); |
| 91 | 91 |
| 92 // Functions to notify certain events to the RendererClient. | 92 // Functions to notify certain events to the RendererClient. |
| 93 void OnPlaybackError(PipelineStatus error); | 93 void OnPlaybackError(PipelineStatus error); |
| 94 void OnPlaybackEnded(); | 94 void OnPlaybackEnded(); |
| 95 void OnStatisticsUpdate(const PipelineStatistics& stats); | 95 void OnStatisticsUpdate(const PipelineStatistics& stats); |
| 96 void OnBufferingStateChange(BufferingState state); | 96 void OnBufferingStateChange(BufferingState state); |
| 97 void OnWaitingForDecryptionKey(); | 97 void OnWaitingForDecryptionKey(); |
| 98 void OnVideoNaturalSizeChange(const gfx::Size& size); | |
| 99 void OnVideoOpacityChange(bool opaque); | |
| 100 | 98 |
| 101 // Callback for |video_frame_stream_| to deliver decoded video frames and | 99 // Callback for |video_frame_stream_| to deliver decoded video frames and |
| 102 // report video decoding status. If a frame is available the planes will be | 100 // report video decoding status. If a frame is available the planes will be |
| 103 // copied asynchronously and FrameReady will be called once finished copying. | 101 // copied asynchronously and FrameReady will be called once finished copying. |
| 104 void FrameReadyForCopyingToGpuMemoryBuffers( | 102 void FrameReadyForCopyingToGpuMemoryBuffers( |
| 105 VideoFrameStream::Status status, | 103 VideoFrameStream::Status status, |
| 106 const scoped_refptr<VideoFrame>& frame); | 104 const scoped_refptr<VideoFrame>& frame); |
| 107 | 105 |
| 108 // Callback for |video_frame_stream_| to deliver decoded video frames and | 106 // Callback for |video_frame_stream_| to deliver decoded video frames and |
| 109 // report video decoding status. | 107 // report video decoding status. |
| 110 void FrameReady(uint32_t sequence_token, | 108 void FrameReady(uint32_t sequence_token, |
| 111 VideoFrameStream::Status status, | 109 VideoFrameStream::Status status, |
| 112 const scoped_refptr<VideoFrame>& frame); | 110 const scoped_refptr<VideoFrame>& frame); |
| 113 | 111 |
| 114 // Helper method for enqueueing a frame to |alogorithm_|. | 112 // Helper method for enqueueing a frame to |alogorithm_|. |
| 115 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame); | 113 void AddReadyFrame_Locked(const scoped_refptr<VideoFrame>& frame); |
| 116 | 114 |
| 117 // Helper method that schedules an asynchronous read from the | 115 // Helper method that schedules an asynchronous read from the |
| 118 // |video_frame_stream_| as long as there isn't a pending read and we have | 116 // |video_frame_stream_| as long as there isn't a pending read and we have |
| 119 // capacity. | 117 // capacity. |
| 120 void AttemptRead(); | |
| 121 void AttemptRead_Locked(); | 118 void AttemptRead_Locked(); |
| 122 | 119 |
| 123 // Called when VideoFrameStream::Reset() completes. | 120 // Called when VideoFrameStream::Reset() completes. |
| 124 void OnVideoFrameStreamResetDone(); | 121 void OnVideoFrameStreamResetDone(); |
| 125 | 122 |
| 126 // Returns true if the renderer has enough data for playback purposes. | 123 // Returns true if the renderer has enough data for playback purposes. |
| 127 // Note that having enough data may be due to reaching end of stream. | 124 // Note that having enough data may be due to reaching end of stream. |
| 128 bool HaveEnoughData_Locked(); | 125 bool HaveEnoughData_Locked(); |
| 129 void TransitionToHaveEnough_Locked(); | 126 void TransitionToHaveEnough_Locked(); |
| 130 void TransitionToHaveNothing(); | 127 void TransitionToHaveNothing(); |
| 131 | 128 |
| 132 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets | 129 // Runs |statistics_cb_| with |frames_decoded_| and |frames_dropped_|, resets |
| 133 // them to 0. | 130 // them to 0. |
| 134 void UpdateStats_Locked(); | 131 void UpdateStats_Locked(); |
| 135 | 132 |
| 136 // Called after we've painted the first frame. If |time_progressing_| is | |
| 137 // false it Stop() on |sink_|. | |
| 138 void MaybeStopSinkAfterFirstPaint(); | |
| 139 | |
| 140 // Returns true if there is no more room for additional buffered frames. | 133 // Returns true if there is no more room for additional buffered frames. |
| 141 bool HaveReachedBufferingCap(); | 134 bool HaveReachedBufferingCap(); |
| 142 | 135 |
| 143 // Starts or stops |sink_| respectively. Do not call while |lock_| is held. | 136 // Starts or stops |sink_| respectively. Do not call while |lock_| is held. |
| 144 void StartSink(); | 137 void StartSink(); |
| 145 void StopSink(); | 138 void StopSink(); |
| 146 | 139 |
| 147 // Fires |ended_cb_| if there are no remaining usable frames and | 140 // Fires |ended_cb_| if there are no remaining usable frames and |
| 148 // |received_end_of_stream_| is true. Sets |rendered_end_of_stream_| if it | 141 // |received_end_of_stream_| is true. Sets |rendered_end_of_stream_| if it |
| 149 // does so. | 142 // does so. |
| 150 // | 143 // |
| 151 // When called from the media thread, |time_progressing| should reflect the | 144 // When called from the media thread, |time_progressing| should reflect the |
| 152 // value of |time_progressing_|. When called from Render() on the sink | 145 // value of |time_progressing_|. When called from Render() on the sink |
| 153 // callback thread, the inverse of |render_first_frame_and_stop_| should be | 146 // callback thread, |time_progressing| must be true since Render() could not |
| 154 // used as a proxy for |time_progressing_|. | 147 // have been called otherwise. |
| 155 void MaybeFireEndedCallback_Locked(bool time_progressing); | 148 void MaybeFireEndedCallback_Locked(bool time_progressing); |
| 156 | 149 |
| 157 // Helper method for converting a single media timestamp to wall clock time. | 150 // Helper method for converting a single media timestamp to wall clock time. |
| 158 base::TimeTicks ConvertMediaTimestamp(base::TimeDelta media_timestamp); | 151 base::TimeTicks ConvertMediaTimestamp(base::TimeDelta media_timestamp); |
| 159 | 152 |
| 160 base::TimeTicks GetCurrentMediaTimeAsWallClockTime(); | 153 base::TimeTicks GetCurrentMediaTimeAsWallClockTime(); |
| 161 | 154 |
| 162 // Helper method for checking if a frame timestamp plus the frame's expected | 155 // Helper method for checking if a frame timestamp plus the frame's expected |
| 163 // duration is before |start_timestamp_|. | 156 // duration is before |start_timestamp_|. |
| 164 bool IsBeforeStartTime(base::TimeDelta timestamp); | 157 bool IsBeforeStartTime(base::TimeDelta timestamp); |
| 165 | 158 |
| 166 // Attempts to remove frames which are no longer effective for rendering when | 159 // Attempts to remove frames which are no longer effective for rendering when |
| 167 // |buffering_state_| == BUFFERING_HAVE_NOTHING or |was_background_rendering_| | 160 // |buffering_state_| == BUFFERING_HAVE_NOTHING or |was_background_rendering_| |
| 168 // is true. If the current media time as provided by |wall_clock_time_cb_| is | 161 // is true. If the current media time as provided by |wall_clock_time_cb_| is |
| 169 // null, no frame expiration will be done. | 162 // null, no frame expiration will be done. |
| 170 // | 163 // |
| 171 // When background rendering the method will expire all frames before the | 164 // When background rendering the method will expire all frames before the |
| 172 // current wall clock time since it's expected that there will be long delays | 165 // current wall clock time since it's expected that there will be long delays |
| 173 // between each Render() call in this state. | 166 // between each Render() call in this state. |
| 174 // | 167 // |
| 175 // When in the underflow state the method will first attempt to remove expired | 168 // When in the underflow state the method will first attempt to remove expired |
| 176 // frames before the current media time plus duration. If |sink_started_| is | 169 // frames before the current media time plus duration. If |sink_started_| is |
| 177 // true, nothing more can be done. However, if false, and there are still no | 170 // true, nothing more can be done. However, if false, and there are still no |
| 178 // effective frames in the queue, the entire frame queue will be released to | 171 // effective frames in the queue, the entire frame queue will be released to |
| 179 // avoid any stalling. | 172 // avoid any stalling. |
| 180 void RemoveFramesForUnderflowOrBackgroundRendering(); | 173 void RemoveFramesForUnderflowOrBackgroundRendering(); |
| 181 | 174 |
| 175 // Notifies |client_| in the event of frame size or opacity changes. Must be |
| 176 // called on |task_runner_|. |
| 177 void CheckForMetadataChanges(VideoPixelFormat pixel_format, |
| 178 const gfx::Size& natural_size); |
| 179 |
| 180 // Both calls AttemptRead_Locked() and CheckForMetadataChanges(). Must be |
| 181 // called on |task_runner_|. |
| 182 void AttemptReadAndCheckForMetadataChanges(VideoPixelFormat pixel_format, |
| 183 const gfx::Size& natural_size); |
| 184 |
| 182 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 185 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 183 | 186 |
| 184 // Sink which calls into VideoRendererImpl via Render() for video frames. Do | 187 // Sink which calls into VideoRendererImpl via Render() for video frames. Do |
| 185 // not call any methods on the sink while |lock_| is held or the two threads | 188 // not call any methods on the sink while |lock_| is held or the two threads |
| 186 // might deadlock. Do not call Start() or Stop() on the sink directly, use | 189 // might deadlock. Do not call Start() or Stop() on the sink directly, use |
| 187 // StartSink() and StopSink() to ensure background rendering is started. Only | 190 // StartSink() and StopSink() to ensure background rendering is started. Only |
| 188 // access these values on |task_runner_|. | 191 // access these values on |task_runner_|. |
| 189 VideoRendererSink* const sink_; | 192 VideoRendererSink* const sink_; |
| 190 bool sink_started_; | 193 bool sink_started_; |
| 191 | 194 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 273 |
| 271 // Indicates that Render() was called with |background_rendering| set to true, | 274 // Indicates that Render() was called with |background_rendering| set to true, |
| 272 // so we've entered a background rendering mode where dropped frames are not | 275 // so we've entered a background rendering mode where dropped frames are not |
| 273 // counted. Must be accessed under |lock_| once |sink_| is started. | 276 // counted. Must be accessed under |lock_| once |sink_| is started. |
| 274 bool was_background_rendering_; | 277 bool was_background_rendering_; |
| 275 | 278 |
| 276 // Indicates whether or not media time is currently progressing or not. Must | 279 // Indicates whether or not media time is currently progressing or not. Must |
| 277 // only be accessed from |task_runner_|. | 280 // only be accessed from |task_runner_|. |
| 278 bool time_progressing_; | 281 bool time_progressing_; |
| 279 | 282 |
| 280 // Indicates that Render() should only render the first frame and then request | |
| 281 // that the sink be stopped. |posted_maybe_stop_after_first_paint_| is used | |
| 282 // to avoid repeated task posts. | |
| 283 bool render_first_frame_and_stop_; | |
| 284 bool posted_maybe_stop_after_first_paint_; | |
| 285 | |
| 286 // Memory usage of |algorithm_| recorded during the last UpdateStats_Locked() | 283 // Memory usage of |algorithm_| recorded during the last UpdateStats_Locked() |
| 287 // call. | 284 // call. |
| 288 int64_t last_video_memory_usage_; | 285 int64_t last_video_memory_usage_; |
| 289 | 286 |
| 290 // Indicates if Render() has been called yet. | 287 // Indicates if a frame has been processed by CheckForMetadataChanges(). |
| 291 bool have_renderered_frames_; | 288 bool have_renderered_frames_; |
| 289 |
| 292 // Tracks last frame properties to detect and notify client of any changes. | 290 // Tracks last frame properties to detect and notify client of any changes. |
| 293 gfx::Size last_frame_natural_size_; | 291 gfx::Size last_frame_natural_size_; |
| 294 bool last_frame_opaque_; | 292 bool last_frame_opaque_; |
| 295 | 293 |
| 296 // NOTE: Weak pointers must be invalidated before all other member variables. | 294 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 297 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; | 295 base::WeakPtrFactory<VideoRendererImpl> weak_factory_; |
| 298 | 296 |
| 299 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); | 297 DISALLOW_COPY_AND_ASSIGN(VideoRendererImpl); |
| 300 }; | 298 }; |
| 301 | 299 |
| 302 } // namespace media | 300 } // namespace media |
| 303 | 301 |
| 304 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ | 302 #endif // MEDIA_RENDERERS_VIDEO_RENDERER_IMPL_H_ |
| OLD | NEW |