Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: content/renderer/media/video_track_adapter.h

Issue 617093003: Add MediaStreamSource frame rate calculation to the tracker. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding type name. Fixing IPC type problem. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 8 #include <vector>
9 #include <queue>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "content/renderer/media/media_stream_video_track.h" 14 #include "content/renderer/media/media_stream_video_track.h"
14 #include "media/base/video_frame.h" 15 #include "media/base/video_frame.h"
15 16
16 namespace content { 17 namespace content {
17 18
18 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for 19 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for
19 // adapting the video resolution from a source implementation to the resolution 20 // adapting the video resolution from a source implementation to the resolution
20 // a track requires. Different tracks can have different resolution constraints. 21 // a track requires. Different tracks can have different resolution constraints.
21 // The constraints can be set as max width and height as well as max and min 22 // The constraints can be set as max width and height as well as max and min
22 // aspect ratio. 23 // aspect ratio.
23 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on 24 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on
24 // the IO-thread. 25 // the IO-thread.
25 // Adaptations is done by wrapping the original media::VideoFrame in a new 26 // Adaptations is done by wrapping the original media::VideoFrame in a new
26 // media::VideoFrame with a new visible_rect and natural_size. 27 // media::VideoFrame with a new visible_rect and natural_size.
27 class VideoTrackAdapter 28 class VideoTrackAdapter
28 : public base::RefCountedThreadSafe<VideoTrackAdapter> { 29 : public base::RefCountedThreadSafe<VideoTrackAdapter> {
29 public: 30 public:
30 typedef base::Callback<void(bool mute_state)> OnMutedCallback; 31 typedef base::Callback<void(float framerate, int dropped_frames)> OnFrameRateC allback;
31 32
32 explicit VideoTrackAdapter( 33 explicit VideoTrackAdapter(
33 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); 34 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
34 35
35 // Register |track| to receive video frames in |frame_callback| with 36 // Register |track| to receive video frames in |frame_callback| with
36 // a resolution within the boundaries of the arguments. 37 // a resolution within the boundaries of the arguments.
37 // Must be called on the main render thread. |frame_callback| is guaranteed to 38 // Must be called on the main render thread. |frame_callback| is guaranteed to
38 // be released on the main render thread. 39 // be released on the main render thread.
39 // |source_frame_rate| is used to calculate a prudent interval to check for 40 // |source_frame_rate| is used to calculate a prudent interval to check for
40 // passing frames and inform of the result via |on_muted_state_callback|. 41 // passing frames and inform of the result via |on_muted_state_callback|.
(...skipping 14 matching lines...) Expand all
55 56
56 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() { 57 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() {
57 DCHECK(thread_checker_.CalledOnValidThread()); 58 DCHECK(thread_checker_.CalledOnValidThread());
58 return io_message_loop_; 59 return io_message_loop_;
59 } 60 }
60 61
61 // Start monitor that frames are delivered to this object. I.E, that 62 // Start monitor that frames are delivered to this object. I.E, that
62 // |DeliverFrameOnIO| is called with a frame rate of |source_frame_rate|. 63 // |DeliverFrameOnIO| is called with a frame rate of |source_frame_rate|.
63 // |on_muted_callback| is triggered on the main render thread. 64 // |on_muted_callback| is triggered on the main render thread.
64 void StartFrameMonitoring(double source_frame_rate, 65 void StartFrameMonitoring(double source_frame_rate,
65 const OnMutedCallback& on_muted_callback); 66 const OnFrameRateCallback& on_muted_callback);
66 void StopFrameMonitoring(); 67 void StopFrameMonitoring();
67 68
68 private: 69 private:
69 virtual ~VideoTrackAdapter(); 70 virtual ~VideoTrackAdapter();
70 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; 71 friend class base::RefCountedThreadSafe<VideoTrackAdapter>;
71 72
73 typedef base::Callback<void(float framerate, int dropped_frames)>
74 FrameRateCallback;
75
72 void AddTrackOnIO( 76 void AddTrackOnIO(
73 const MediaStreamVideoTrack* track, 77 const MediaStreamVideoTrack* track,
74 VideoCaptureDeliverFrameCB frame_callback, 78 VideoCaptureDeliverFrameCB frame_callback,
75 const gfx::Size& max_frame_size, 79 const gfx::Size& max_frame_size,
76 double min_aspect_ratio, 80 double min_aspect_ratio,
77 double max_aspect_ratio, 81 double max_aspect_ratio,
78 double max_frame_rate); 82 double max_frame_rate);
79 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); 83 void RemoveTrackOnIO(const MediaStreamVideoTrack* track);
80 84
81 void StartFrameMonitoringOnIO( 85 void StartFrameMonitoringOnIO(
82 const OnMutedCallback& on_muted_state_callback, 86 const OnFrameRateCallback& on_muted_state_callback,
83 double source_frame_rate); 87 double source_frame_rate);
84 void StopFrameMonitoringOnIO(); 88 void StopFrameMonitoringOnIO();
85 89
86 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and 90 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and
87 // inform of the situation (muted, not muted) via |set_muted_state_callback|. 91 // inform of the situation (muted, not muted) via |set_muted_state_callback|.
88 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback, 92 void CheckFramesReceivedOnIO(const OnFrameRateCallback& set_muted_state_callba ck,
89 uint64 old_frame_counter_snapshot); 93 uint64 old_frame_counter_snapshot,
94 int old_dropped_frame_counter_snapshot);
95
96 void UpdateFrameRateOnIO(base::TimeDelta timestamp);
97 float GetFrameRateOnIO();
90 98
91 // |thread_checker_| is bound to the main render thread. 99 // |thread_checker_| is bound to the main render thread.
92 base::ThreadChecker thread_checker_; 100 base::ThreadChecker thread_checker_;
93 101
94 scoped_refptr<base::MessageLoopProxy> io_message_loop_; 102 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
95 103
96 // |renderer_task_runner_| is used to ensure that 104 // |renderer_task_runner_| is used to ensure that
97 // VideoCaptureDeliverFrameCB is released on the main render thread. 105 // VideoCaptureDeliverFrameCB is released on the main render thread.
98 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; 106 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_;
99 107
(...skipping 12 matching lines...) Expand all
112 // Keeps track of it frames have been received. It is only accessed on the 120 // Keeps track of it frames have been received. It is only accessed on the
113 // IO-thread. 121 // IO-thread.
114 bool muted_state_; 122 bool muted_state_;
115 123
116 // Running frame counter, accessed on the IO-thread. 124 // Running frame counter, accessed on the IO-thread.
117 uint64 frame_counter_; 125 uint64 frame_counter_;
118 126
119 // Frame rate configured on the video source, accessed on the IO-thread. 127 // Frame rate configured on the video source, accessed on the IO-thread.
120 float source_frame_rate_; 128 float source_frame_rate_;
121 129
130 int dropped_frames_counter_;
131 std::queue<base::TimeDelta> frame_timestamps_;
132
122 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); 133 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter);
123 }; 134 };
124 135
125 } // namespace content 136 } // namespace content
126 137
127 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ 138 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/peer_connection_tracker.cc ('k') | content/renderer/media/video_track_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698