| 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 CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
| 18 #include "base/threading/thread_checker.h" | 18 #include "base/threading/thread_checker.h" |
| 19 #include "cc/layers/video_frame_provider.h" | 19 #include "cc/layers/video_frame_provider.h" |
| 20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 21 #include "media/base/media_log.h" |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace blink { | 27 namespace blink { |
| 27 class WebMediaStream; | 28 class WebMediaStream; |
| 28 } | 29 } |
| 29 | 30 |
| 30 namespace gfx { | 31 namespace gfx { |
| 31 class Size; | 32 class Size; |
| 32 } | 33 } |
| 33 | 34 |
| 34 namespace media { | 35 namespace media { |
| 35 class MediaLog; | |
| 36 class VideoRendererAlgorithm; | 36 class VideoRendererAlgorithm; |
| 37 } | 37 } |
| 38 | 38 |
| 39 namespace content { | 39 namespace content { |
| 40 class WebMediaPlayerMS; | 40 class WebMediaPlayerMS; |
| 41 | 41 |
| 42 // This class is designed to handle the work load on compositor thread for | 42 // This class is designed to handle the work load on compositor thread for |
| 43 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed | 43 // WebMediaPlayerMS. It will be instantiated on the main thread, but destroyed |
| 44 // on the thread holding the last reference. | 44 // on the thread holding the last reference. |
| 45 // | 45 // |
| 46 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the | 46 // WebMediaPlayerMSCompositor utilizes VideoRendererAlgorithm to store the |
| 47 // incoming frames and select the best frame for rendering to maximize the | 47 // incoming frames and select the best frame for rendering to maximize the |
| 48 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. | 48 // smoothness, if REFERENCE_TIMEs are populated for incoming VideoFrames. |
| 49 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent | 49 // Otherwise, WebMediaPlayerMSCompositor will simply store the most recent |
| 50 // frame, and submit it whenever asked by the compositor. | 50 // frame, and submit it whenever asked by the compositor. |
| 51 class CONTENT_EXPORT WebMediaPlayerMSCompositor | 51 class CONTENT_EXPORT WebMediaPlayerMSCompositor |
| 52 : public NON_EXPORTED_BASE(cc::VideoFrameProvider), | 52 : public NON_EXPORTED_BASE(cc::VideoFrameProvider), |
| 53 public base::RefCountedThreadSafe<WebMediaPlayerMSCompositor> { | 53 public base::RefCountedThreadSafe<WebMediaPlayerMSCompositor> { |
| 54 public: | 54 public: |
| 55 // This |url| represents the media stream we are rendering. |url| is used to | 55 // This |url| represents the media stream we are rendering. |url| is used to |
| 56 // find out what web stream this WebMediaPlayerMSCompositor is playing, and | 56 // find out what web stream this WebMediaPlayerMSCompositor is playing, and |
| 57 // together with flag "--disable-rtc-smoothness-algorithm" determine whether | 57 // together with flag "--disable-rtc-smoothness-algorithm" determine whether |
| 58 // we enable algorithm or not. | 58 // we enable algorithm or not. |
| 59 WebMediaPlayerMSCompositor( | 59 WebMediaPlayerMSCompositor( |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | 60 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| 61 const blink::WebMediaStream& web_stream, | 61 const blink::WebMediaStream& web_stream, |
| 62 const base::WeakPtr<WebMediaPlayerMS>& player, | 62 const base::WeakPtr<WebMediaPlayerMS>& player); |
| 63 scoped_refptr<media::MediaLog> media_log_); | |
| 64 | 63 |
| 65 void EnqueueFrame(scoped_refptr<media::VideoFrame> frame); | 64 void EnqueueFrame(scoped_refptr<media::VideoFrame> frame); |
| 66 | 65 |
| 67 // Statistical data | 66 // Statistical data |
| 68 gfx::Size GetCurrentSize(); | 67 gfx::Size GetCurrentSize(); |
| 69 base::TimeDelta GetCurrentTime(); | 68 base::TimeDelta GetCurrentTime(); |
| 70 size_t total_frame_count(); | 69 size_t total_frame_count(); |
| 71 size_t dropped_frame_count(); | 70 size_t dropped_frame_count(); |
| 72 | 71 |
| 73 // VideoFrameProvider implementation. | 72 // VideoFrameProvider implementation. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 117 |
| 119 // Used for DCHECKs to ensure method calls executed in the correct thread. | 118 // Used for DCHECKs to ensure method calls executed in the correct thread. |
| 120 base::ThreadChecker thread_checker_; | 119 base::ThreadChecker thread_checker_; |
| 121 base::ThreadChecker io_thread_checker_; | 120 base::ThreadChecker io_thread_checker_; |
| 122 | 121 |
| 123 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 122 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 124 base::MessageLoop* main_message_loop_; | 123 base::MessageLoop* main_message_loop_; |
| 125 | 124 |
| 126 base::WeakPtr<WebMediaPlayerMS> player_; | 125 base::WeakPtr<WebMediaPlayerMS> player_; |
| 127 | 126 |
| 128 scoped_refptr<media::MediaLog> media_log_; | 127 // TODO(qiangchen, emircan): It might be nice to use a real MediaLog here from |
| 128 // the WebMediaPlayerMS instance, but it owns the MediaLog and this class has |
| 129 // non-deterministic destruction paths (either compositor or IO). |
| 130 media::MediaLog media_log_; |
| 129 | 131 |
| 130 size_t serial_; | 132 size_t serial_; |
| 131 | 133 |
| 132 // A pointer back to the compositor to inform it about state changes. This | 134 // A pointer back to the compositor to inform it about state changes. This |
| 133 // is not |nullptr| while the compositor is actively using this | 135 // is not |nullptr| while the compositor is actively using this |
| 134 // VideoFrameProvider. This will be set to |nullptr| when the compositor stops | 136 // VideoFrameProvider. This will be set to |nullptr| when the compositor stops |
| 135 // serving this VideoFrameProvider. | 137 // serving this VideoFrameProvider. |
| 136 cc::VideoFrameProvider::Client* video_frame_provider_client_; | 138 cc::VideoFrameProvider::Client* video_frame_provider_client_; |
| 137 | 139 |
| 138 // |current_frame_| is updated only on compositor thread. The object it | 140 // |current_frame_| is updated only on compositor thread. The object it |
| (...skipping 27 matching lines...) Expand all Loading... |
| 166 | 168 |
| 167 // |current_frame_lock_| protects |current_frame_used_by_compositor_|, | 169 // |current_frame_lock_| protects |current_frame_used_by_compositor_|, |
| 168 // |current_frame_|, and |rendering_frame_buffer_|. | 170 // |current_frame_|, and |rendering_frame_buffer_|. |
| 169 base::Lock current_frame_lock_; | 171 base::Lock current_frame_lock_; |
| 170 | 172 |
| 171 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMSCompositor); | 173 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerMSCompositor); |
| 172 }; | 174 }; |
| 173 } // namespace content | 175 } // namespace content |
| 174 | 176 |
| 175 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ | 177 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_MS_COMPOSITOR_H_ |
| OLD | NEW |