OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_VIDEO_TRACK_ADAPTER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
6 #define CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ | 6 #define CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "content/renderer/media/media_stream_video_track.h" | 15 #include "content/renderer/media/media_stream_video_track.h" |
16 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
| 20 struct VideoTrackAdapterSettings { |
| 21 VideoTrackAdapterSettings() = default; |
| 22 VideoTrackAdapterSettings(int max_width, |
| 23 int max_height, |
| 24 double min_aspect_ratio, |
| 25 double max_aspect_ratio, |
| 26 double max_frame_rate); |
| 27 int max_width; |
| 28 int max_height; |
| 29 double min_aspect_ratio; |
| 30 double max_aspect_ratio; |
| 31 double max_frame_rate; |
| 32 }; |
| 33 |
20 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for | 34 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for |
21 // adapting the video resolution from a source implementation to the resolution | 35 // adapting the video resolution from a source implementation to the resolution |
22 // a track requires. Different tracks can have different resolution constraints. | 36 // a track requires. Different tracks can have different resolution constraints. |
23 // The constraints can be set as max width and height as well as max and min | 37 // The constraints can be set as max width and height as well as max and min |
24 // aspect ratio. | 38 // aspect ratio. |
25 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on | 39 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on |
26 // the IO-thread. | 40 // the IO-thread. |
27 // Adaptations is done by wrapping the original media::VideoFrame in a new | 41 // Adaptations is done by wrapping the original media::VideoFrame in a new |
28 // media::VideoFrame with a new visible_rect and natural_size. | 42 // media::VideoFrame with a new visible_rect and natural_size. |
29 class VideoTrackAdapter | 43 class VideoTrackAdapter |
30 : public base::RefCountedThreadSafe<VideoTrackAdapter> { | 44 : public base::RefCountedThreadSafe<VideoTrackAdapter> { |
31 public: | 45 public: |
32 typedef base::Callback<void(bool mute_state)> OnMutedCallback; | 46 typedef base::Callback<void(bool mute_state)> OnMutedCallback; |
33 | 47 |
34 explicit VideoTrackAdapter( | 48 explicit VideoTrackAdapter( |
35 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); | 49 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner); |
36 | 50 |
37 // Register |track| to receive video frames in |frame_callback| with | 51 // Register |track| to receive video frames in |frame_callback| with |
38 // a resolution within the boundaries of the arguments. | 52 // a resolution within the boundaries of the arguments. |
39 // Must be called on the main render thread. |frame_callback| is guaranteed to | 53 // Must be called on the main render thread. |frame_callback| is guaranteed to |
40 // be released on the main render thread. | 54 // be released on the main render thread. |
41 // |source_frame_rate| is used to calculate a prudent interval to check for | 55 // |source_frame_rate| is used to calculate a prudent interval to check for |
42 // passing frames and inform of the result via |on_muted_state_callback|. | 56 // passing frames and inform of the result via |on_muted_state_callback|. |
43 void AddTrack(const MediaStreamVideoTrack* track, | 57 void AddTrack(const MediaStreamVideoTrack* track, |
44 VideoCaptureDeliverFrameCB frame_callback, | 58 VideoCaptureDeliverFrameCB frame_callback, |
45 int max_width, int max_height, | 59 const VideoTrackAdapterSettings& settings); |
46 double min_aspect_ratio, | |
47 double max_aspect_ratio, | |
48 double max_frame_rate); | |
49 void RemoveTrack(const MediaStreamVideoTrack* track); | 60 void RemoveTrack(const MediaStreamVideoTrack* track); |
50 | 61 |
51 // Delivers |frame| to all tracks that have registered a callback. | 62 // Delivers |frame| to all tracks that have registered a callback. |
52 // Must be called on the IO-thread. | 63 // Must be called on the IO-thread. |
53 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, | 64 void DeliverFrameOnIO(const scoped_refptr<media::VideoFrame>& frame, |
54 base::TimeTicks estimated_capture_time); | 65 base::TimeTicks estimated_capture_time); |
55 | 66 |
56 base::SingleThreadTaskRunner* io_task_runner() const { | 67 base::SingleThreadTaskRunner* io_task_runner() const { |
57 DCHECK(thread_checker_.CalledOnValidThread()); | 68 DCHECK(thread_checker_.CalledOnValidThread()); |
58 return io_task_runner_.get(); | 69 return io_task_runner_.get(); |
59 } | 70 } |
60 | 71 |
61 // Start monitor that frames are delivered to this object. I.E, that | 72 // Start monitor that frames are delivered to this object. I.E, that |
62 // |DeliverFrameOnIO| is called with a frame rate of |source_frame_rate|. | 73 // |DeliverFrameOnIO| is called with a frame rate of |source_frame_rate|. |
63 // |on_muted_callback| is triggered on the main render thread. | 74 // |on_muted_callback| is triggered on the main render thread. |
64 void StartFrameMonitoring(double source_frame_rate, | 75 void StartFrameMonitoring(double source_frame_rate, |
65 const OnMutedCallback& on_muted_callback); | 76 const OnMutedCallback& on_muted_callback); |
66 void StopFrameMonitoring(); | 77 void StopFrameMonitoring(); |
67 | 78 |
68 static void CalculateTargetSize(const gfx::Size& input_size, | 79 static void CalculateTargetSize(const gfx::Size& input_size, |
69 const gfx::Size& max_frame_size, | 80 const gfx::Size& max_frame_size, |
70 double min_aspect_ratio, | 81 double min_aspect_ratio, |
71 double max_aspect_ratio, | 82 double max_aspect_ratio, |
72 gfx::Size* desired_size); | 83 gfx::Size* desired_size); |
73 | 84 |
74 private: | 85 private: |
75 virtual ~VideoTrackAdapter(); | 86 virtual ~VideoTrackAdapter(); |
76 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; | 87 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; |
77 | 88 |
78 void AddTrackOnIO( | 89 void AddTrackOnIO(const MediaStreamVideoTrack* track, |
79 const MediaStreamVideoTrack* track, | 90 VideoCaptureDeliverFrameCB frame_callback, |
80 VideoCaptureDeliverFrameCB frame_callback, | 91 const VideoTrackAdapterSettings& settings); |
81 const gfx::Size& max_frame_size, | |
82 double min_aspect_ratio, | |
83 double max_aspect_ratio, | |
84 double max_frame_rate); | |
85 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); | 92 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); |
86 | 93 |
87 void StartFrameMonitoringOnIO( | 94 void StartFrameMonitoringOnIO( |
88 const OnMutedCallback& on_muted_state_callback, | 95 const OnMutedCallback& on_muted_state_callback, |
89 double source_frame_rate); | 96 double source_frame_rate); |
90 void StopFrameMonitoringOnIO(); | 97 void StopFrameMonitoringOnIO(); |
91 | 98 |
92 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and | 99 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and |
93 // inform of the situation (muted, not muted) via |set_muted_state_callback|. | 100 // inform of the situation (muted, not muted) via |set_muted_state_callback|. |
94 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback, | 101 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback, |
(...skipping 29 matching lines...) Expand all Loading... |
124 | 131 |
125 // Frame rate configured on the video source, accessed on the IO-thread. | 132 // Frame rate configured on the video source, accessed on the IO-thread. |
126 float source_frame_rate_; | 133 float source_frame_rate_; |
127 | 134 |
128 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); | 135 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); |
129 }; | 136 }; |
130 | 137 |
131 } // namespace content | 138 } // namespace content |
132 | 139 |
133 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ | 140 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ |
OLD | NEW |