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

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

Issue 509873002: Refactor MediaStreamTrack video onmute event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed nits. Created 6 years, 3 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 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 25 matching lines...) Expand all
36 // a resolution within the boundaries of the arguments. 36 // a resolution within the boundaries of the arguments.
37 // Must be called on the main render thread. |frame_callback| is guaranteed to 37 // Must be called on the main render thread. |frame_callback| is guaranteed to
38 // be released on the main render thread. 38 // be released on the main render thread.
39 // |source_frame_rate| is used to calculate a prudent interval to check for 39 // |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|. 40 // passing frames and inform of the result via |on_muted_state_callback|.
41 void AddTrack(const MediaStreamVideoTrack* track, 41 void AddTrack(const MediaStreamVideoTrack* track,
42 VideoCaptureDeliverFrameCB frame_callback, 42 VideoCaptureDeliverFrameCB frame_callback,
43 int max_width, int max_height, 43 int max_width, int max_height,
44 double min_aspect_ratio, 44 double min_aspect_ratio,
45 double max_aspect_ratio, 45 double max_aspect_ratio,
46 double max_frame_rate, 46 double max_frame_rate);
47 double source_frame_rate,
48 const OnMutedCallback& on_muted_state_callback);
49 void RemoveTrack(const MediaStreamVideoTrack* track); 47 void RemoveTrack(const MediaStreamVideoTrack* track);
50 48
51 // Delivers |frame| to all tracks that have registered a callback. 49 // Delivers |frame| to all tracks that have registered a callback.
52 // Must be called on the IO-thread. 50 // Must be called on the IO-thread.
53 void DeliverFrameOnIO( 51 void DeliverFrameOnIO(
54 const scoped_refptr<media::VideoFrame>& frame, 52 const scoped_refptr<media::VideoFrame>& frame,
55 const media::VideoCaptureFormat& format, 53 const media::VideoCaptureFormat& format,
56 const base::TimeTicks& estimated_capture_time); 54 const base::TimeTicks& estimated_capture_time);
57 55
58 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() { 56 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() {
59 DCHECK(thread_checker_.CalledOnValidThread()); 57 DCHECK(thread_checker_.CalledOnValidThread());
60 return io_message_loop_; 58 return io_message_loop_;
61 } 59 }
62 60
61 // 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 // |on_muted_callback| is triggered on the main render thread.
64 void StartFrameMonitoring(double source_frame_rate,
65 const OnMutedCallback& on_muted_callback);
66 void StopFrameMonitoring();
67
63 private: 68 private:
64 virtual ~VideoTrackAdapter(); 69 virtual ~VideoTrackAdapter();
65 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; 70 friend class base::RefCountedThreadSafe<VideoTrackAdapter>;
66 71
67 void AddTrackOnIO( 72 void AddTrackOnIO(
68 const MediaStreamVideoTrack* track, 73 const MediaStreamVideoTrack* track,
69 VideoCaptureDeliverFrameCB frame_callback, 74 VideoCaptureDeliverFrameCB frame_callback,
70 const gfx::Size& max_frame_size, 75 const gfx::Size& max_frame_size,
71 double min_aspect_ratio, 76 double min_aspect_ratio,
72 double max_aspect_ratio, 77 double max_aspect_ratio,
73 double max_frame_rate); 78 double max_frame_rate);
74 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); 79 void RemoveTrackOnIO(const MediaStreamVideoTrack* track);
75 80
76 void StartTrackMonitoringOnIO( 81 void StartFrameMonitoringOnIO(
77 const OnMutedCallback& on_muted_state_callback, 82 const OnMutedCallback& on_muted_state_callback,
78 double source_frame_rate); 83 double source_frame_rate);
84 void StopFrameMonitoringOnIO();
79 85
80 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and 86 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and
81 // inform of the situation (muted, not muted) via |set_muted_state_callback|. 87 // inform of the situation (muted, not muted) via |set_muted_state_callback|.
82 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback, 88 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback,
83 uint64 old_frame_counter_snapshot); 89 uint64 old_frame_counter_snapshot);
84 90
85 // |thread_checker_| is bound to the main render thread. 91 // |thread_checker_| is bound to the main render thread.
86 base::ThreadChecker thread_checker_; 92 base::ThreadChecker thread_checker_;
87 93
88 scoped_refptr<base::MessageLoopProxy> io_message_loop_; 94 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
89 95
90 // |renderer_task_runner_| is used to ensure that 96 // |renderer_task_runner_| is used to ensure that
91 // VideoCaptureDeliverFrameCB is released on the main render thread. 97 // VideoCaptureDeliverFrameCB is released on the main render thread.
92 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; 98 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_;
93 99
94 // VideoFrameResolutionAdapter is an inner class that is created on the main 100 // VideoFrameResolutionAdapter is an inner class that is created on the main
95 // render thread but operates on the IO-thread. It does the resolution 101 // render thread but operates on the IO-thread. It does the resolution
96 // adaptation and delivers frames to all registered tracks on the IO-thread. 102 // adaptation and delivers frames to all registered tracks on the IO-thread.
97 class VideoFrameResolutionAdapter; 103 class VideoFrameResolutionAdapter;
98 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> > 104 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> >
99 FrameAdapters; 105 FrameAdapters;
100 FrameAdapters adapters_; 106 FrameAdapters adapters_;
101 107
108 // Set to true if frame monitoring has been started. It is only accessed on
109 // the IO-thread.
110 bool monitoring_frame_rate_;
111
112 // Keeps track of it frames have been received. It is only accessed on the
113 // IO-thread.
114 bool muted_state_;
115
102 // Running frame counter, accessed on the IO-thread. 116 // Running frame counter, accessed on the IO-thread.
103 uint64 frame_counter_; 117 uint64 frame_counter_;
104 118
105 // Frame rate configured on the video source, accessed on the IO-thread. 119 // Frame rate configured on the video source, accessed on the IO-thread.
106 float source_frame_rate_; 120 float source_frame_rate_;
107 121
108 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); 122 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter);
109 }; 123 };
110 124
111 } // namespace content 125 } // namespace content
112 126
113 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ 127 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_
OLDNEW
« no previous file with comments | « content/renderer/media/mock_media_stream_video_source.h ('k') | content/renderer/media/video_track_adapter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698