OLD | NEW |
(Empty) | |
| 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 CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "content/renderer/media/media_stream_video_track.h" |
| 13 #include "media/base/video_frame.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for |
| 18 // adapting the video resolution from a source implementation to the resolution |
| 19 // a track requires. Different tracks can have different resolution constraints. |
| 20 // The constraints can be set as max width and height as well as max and min |
| 21 // aspect ratio. |
| 22 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on |
| 23 // the IO-thread. |
| 24 // Adaptations is done by wrapping the original media::VideoFrame in a new |
| 25 // media::VideoFrame with a new visible_rect and natural_size. |
| 26 class VideoTrackAdapter |
| 27 : public base::RefCountedThreadSafe<VideoTrackAdapter> { |
| 28 public: |
| 29 explicit VideoTrackAdapter( |
| 30 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); |
| 31 |
| 32 // Register |track| to receive video frames in |frame_callback| with |
| 33 // a resolution within the boundaries of the arguments. |
| 34 // Must be called on the main render thread. |frame_callback| is guaranteed to |
| 35 // be released on the main render thread. |
| 36 void AddTrack(const MediaStreamVideoTrack* track, |
| 37 VideoCaptureDeliverFrameCB frame_callback, |
| 38 int max_width, int max_height, |
| 39 double min_aspect_ratio, |
| 40 double max_aspect_ratio); |
| 41 void RemoveTrack(const MediaStreamVideoTrack* track); |
| 42 |
| 43 // Delivers |frame| to all tracks that have registered a callback. |
| 44 // Must be called on the IO-thread. |
| 45 void DeliverFrameOnIO( |
| 46 const scoped_refptr<media::VideoFrame>& frame, |
| 47 const media::VideoCaptureFormat& format); |
| 48 |
| 49 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 return io_message_loop_; |
| 52 } |
| 53 |
| 54 private: |
| 55 virtual ~VideoTrackAdapter(); |
| 56 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; |
| 57 |
| 58 void AddTrackOnIO( |
| 59 const MediaStreamVideoTrack* track, |
| 60 VideoCaptureDeliverFrameCB frame_callback, |
| 61 int max_width, int max_height, |
| 62 double min_aspect_ratio, |
| 63 double max_aspect_ratio); |
| 64 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); |
| 65 |
| 66 // |thread_checker_| is bound to the main render thread. |
| 67 base::ThreadChecker thread_checker_; |
| 68 |
| 69 scoped_refptr<base::MessageLoopProxy> io_message_loop_; |
| 70 |
| 71 // |renderer_task_runner_| is used to ensure that |
| 72 // VideoCaptureDeliverFrameCB is released on the main render thread. |
| 73 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; |
| 74 |
| 75 // VideoFrameResolutionAdapter is an inner class that is created on the main |
| 76 // render thread but operates on the IO-thread. It does the resolution |
| 77 // adaptation and delivers frames to all registered tracks on the IO-thread. |
| 78 class VideoFrameResolutionAdapter; |
| 79 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> > |
| 80 FrameAdapters; |
| 81 FrameAdapters adapters_; |
| 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); |
| 84 }; |
| 85 |
| 86 } // namespace content |
| 87 |
| 88 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
OLD | NEW |