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

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

Issue 366243003: VideoTrackAdapter: Add passing frames monitor, notify MSVCS -> MSVTrack(s) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Correct handling of 0.0fps frame rate sources Created 6 years, 5 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 | Annotate | Revision Log
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/renderer/media/media_stream_video_track.h" 13 #include "content/renderer/media/media_stream_video_track.h"
14 #include "media/base/video_frame.h" 14 #include "media/base/video_frame.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for 18 // VideoTrackAdapter is a helper class used by MediaStreamVideoSource used for
19 // adapting the video resolution from a source implementation to the resolution 19 // adapting the video resolution from a source implementation to the resolution
20 // a track requires. Different tracks can have different resolution constraints. 20 // 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 21 // The constraints can be set as max width and height as well as max and min
22 // aspect ratio. 22 // aspect ratio.
23 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on 23 // Video frames are delivered to a track using a VideoCaptureDeliverFrameCB on
24 // the IO-thread. 24 // the IO-thread.
25 // Adaptations is done by wrapping the original media::VideoFrame in a new 25 // Adaptations is done by wrapping the original media::VideoFrame in a new
26 // media::VideoFrame with a new visible_rect and natural_size. 26 // media::VideoFrame with a new visible_rect and natural_size.
27 class VideoTrackAdapter 27 class VideoTrackAdapter
28 : public base::RefCountedThreadSafe<VideoTrackAdapter> { 28 : public base::RefCountedThreadSafe<VideoTrackAdapter> {
29 public: 29 public:
30 typedef base::Callback<void(bool mute_state)> OnMutedCallback;
31
30 explicit VideoTrackAdapter( 32 explicit VideoTrackAdapter(
31 const scoped_refptr<base::MessageLoopProxy>& io_message_loop); 33 const scoped_refptr<base::MessageLoopProxy>& io_message_loop);
32 34
33 // Register |track| to receive video frames in |frame_callback| with 35 // Register |track| to receive video frames in |frame_callback| with
34 // a resolution within the boundaries of the arguments. 36 // a resolution within the boundaries of the arguments.
35 // 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
36 // 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
40 // passing frames and inform of the result via |on_muted_state_callback|.
37 void AddTrack(const MediaStreamVideoTrack* track, 41 void AddTrack(const MediaStreamVideoTrack* track,
38 VideoCaptureDeliverFrameCB frame_callback, 42 VideoCaptureDeliverFrameCB frame_callback,
39 int max_width, int max_height, 43 int max_width, int max_height,
40 double min_aspect_ratio, 44 double min_aspect_ratio,
41 double max_aspect_ratio, 45 double max_aspect_ratio,
42 double max_frame_rate); 46 double max_frame_rate,
47 double source_frame_rate,
48 const OnMutedCallback& on_muted_state_callback);
43 void RemoveTrack(const MediaStreamVideoTrack* track); 49 void RemoveTrack(const MediaStreamVideoTrack* track);
44 50
45 // Delivers |frame| to all tracks that have registered a callback. 51 // Delivers |frame| to all tracks that have registered a callback.
46 // Must be called on the IO-thread. 52 // Must be called on the IO-thread.
47 void DeliverFrameOnIO( 53 void DeliverFrameOnIO(
48 const scoped_refptr<media::VideoFrame>& frame, 54 const scoped_refptr<media::VideoFrame>& frame,
49 const media::VideoCaptureFormat& format, 55 const media::VideoCaptureFormat& format,
50 const base::TimeTicks& estimated_capture_time); 56 const base::TimeTicks& estimated_capture_time);
51 57
52 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() { 58 const scoped_refptr<base::MessageLoopProxy>& io_message_loop() {
53 DCHECK(thread_checker_.CalledOnValidThread()); 59 DCHECK(thread_checker_.CalledOnValidThread());
54 return io_message_loop_; 60 return io_message_loop_;
55 } 61 }
56 62
57 private: 63 private:
58 virtual ~VideoTrackAdapter(); 64 virtual ~VideoTrackAdapter();
59 friend class base::RefCountedThreadSafe<VideoTrackAdapter>; 65 friend class base::RefCountedThreadSafe<VideoTrackAdapter>;
60 66
61 void AddTrackOnIO( 67 void AddTrackOnIO(
62 const MediaStreamVideoTrack* track, 68 const MediaStreamVideoTrack* track,
63 VideoCaptureDeliverFrameCB frame_callback, 69 VideoCaptureDeliverFrameCB frame_callback,
64 const gfx::Size& max_frame_size, 70 const gfx::Size& max_frame_size,
65 double min_aspect_ratio, 71 double min_aspect_ratio,
66 double max_aspect_ratio, 72 double max_aspect_ratio,
67 double max_frame_rate); 73 double max_frame_rate);
68 void RemoveTrackOnIO(const MediaStreamVideoTrack* track); 74 void RemoveTrackOnIO(const MediaStreamVideoTrack* track);
69 75
76 void StartTrackMonitoringOnIO(
77 const OnMutedCallback& on_muted_state_callback,
78 double source_frame_rate);
79
80 // Compare |frame_counter_snapshot| with the current |frame_counter_|, and
81 // inform of the situation (muted, not muted) via |set_muted_state_callback|.
82 void CheckFramesReceivedOnIO(const OnMutedCallback& set_muted_state_callback,
83 uint64 old_frame_counter_snapshot);
84
70 // |thread_checker_| is bound to the main render thread. 85 // |thread_checker_| is bound to the main render thread.
71 base::ThreadChecker thread_checker_; 86 base::ThreadChecker thread_checker_;
72 87
73 scoped_refptr<base::MessageLoopProxy> io_message_loop_; 88 scoped_refptr<base::MessageLoopProxy> io_message_loop_;
74 89
75 // |renderer_task_runner_| is used to ensure that 90 // |renderer_task_runner_| is used to ensure that
76 // VideoCaptureDeliverFrameCB is released on the main render thread. 91 // VideoCaptureDeliverFrameCB is released on the main render thread.
77 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_; 92 scoped_refptr<base::SingleThreadTaskRunner> renderer_task_runner_;
78 93
79 // VideoFrameResolutionAdapter is an inner class that is created on the main 94 // VideoFrameResolutionAdapter is an inner class that is created on the main
80 // render thread but operates on the IO-thread. It does the resolution 95 // render thread but operates on the IO-thread. It does the resolution
81 // adaptation and delivers frames to all registered tracks on the IO-thread. 96 // adaptation and delivers frames to all registered tracks on the IO-thread.
82 class VideoFrameResolutionAdapter; 97 class VideoFrameResolutionAdapter;
83 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> > 98 typedef std::vector<scoped_refptr<VideoFrameResolutionAdapter> >
84 FrameAdapters; 99 FrameAdapters;
85 FrameAdapters adapters_; 100 FrameAdapters adapters_;
86 101
102 // Running frame counter, accessed on the IO-thread.
103 uint64 frame_counter_;
104
105 // Frame rate configured on the video source, accessed on the IO-thread.
106 float source_frame_rate_;
107
87 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter); 108 DISALLOW_COPY_AND_ASSIGN(VideoTrackAdapter);
88 }; 109 };
89 110
90 } // namespace content 111 } // namespace content
91 112
92 #endif // CONTENT_RENDERER_MEDIA_VIDEO_TRACK_ADAPTER_H_ 113 #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