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

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

Issue 242013002: Refactor video capturing code in the render process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged again :( Created 6 years, 8 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_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/threading/thread_checker.h"
10 #include "content/common/media/video_capture.h" 11 #include "content/common/media/video_capture.h"
11 #include "content/renderer/media/media_stream_video_source.h" 12 #include "content/renderer/media/media_stream_video_source.h"
12 #include "media/video/capture/video_capture.h"
13 13
14 namespace content { 14 namespace content {
15 15
16 class VideoCaptureHandle;
17
18 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource 16 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource
19 // for local video capturer. It uses VideoCaptureImplManager to start / stop 17 // for local video capturer. It uses VideoCaptureImplManager to start / stop
20 // and receive I420 frames from Chrome's video capture implementation. 18 // and receive I420 frames from Chrome's video capture implementation.
19 //
20 // This is a render thread only object.
21 class CONTENT_EXPORT VideoCapturerDelegate 21 class CONTENT_EXPORT VideoCapturerDelegate
22 : public media::VideoCapture::EventHandler, 22 : public base::RefCountedThreadSafe<VideoCapturerDelegate> {
23 public base::RefCountedThreadSafe<VideoCapturerDelegate> {
24 public: 23 public:
25 typedef base::Callback<void(const scoped_refptr<media::VideoFrame>&)>
26 NewFrameCallback;
27 typedef base::Callback<void(bool running)> StartedCallback; 24 typedef base::Callback<void(bool running)> StartedCallback;
28 typedef base::Callback<void(const media::VideoCaptureFormats& formats)>
29 SupportedFormatsCallback;
30 25
31 explicit VideoCapturerDelegate( 26 explicit VideoCapturerDelegate(
32 const StreamDeviceInfo& device_info); 27 const StreamDeviceInfo& device_info);
33 28
34 // Collects the formats that can currently be used. 29 // Collects the formats that can currently be used.
35 // |max_requested_height| and |max_requested_width| is used by Tab and Screen 30 // |max_requested_height| and |max_requested_width| is used by Tab and Screen
36 // capture to decide what resolution to generate. 31 // capture to decide what resolution to generate.
37 // |callback| is triggered when the formats have been collected. 32 // |callback| is triggered when the formats have been collected.
38 virtual void GetCurrentSupportedFormats( 33 virtual void GetCurrentSupportedFormats(
39 int max_requested_width, 34 int max_requested_width,
40 int max_requested_height, 35 int max_requested_height,
41 const SupportedFormatsCallback& callback); 36 const VideoCaptureDeviceFormatsCB& callback);
42 37
43 // Starts deliver frames using the resolution in |params|. 38 // Starts deliver frames using the resolution in |params|.
44 // |new_frame_callback| is triggered when a new video frame is available. 39 // |new_frame_callback| is triggered when a new video frame is available.
45 // |started_callback| is triggered before the first video frame is received 40 // |started_callback| is triggered before the first video frame is received
46 // or if the underlying video capturer fails to start. 41 // or if the underlying video capturer fails to start.
47 virtual void StartDeliver( 42 virtual void StartToDeliver(
Ami GONE FROM CHROMIUM 2014/04/24 21:04:31 From earlier: why is this not StartCapture?
Alpha Left Google 2014/04/24 22:50:34 Done.
48 const media::VideoCaptureParams& params, 43 const media::VideoCaptureParams& params,
49 const NewFrameCallback& new_frame_callback, 44 const VideoCaptureDeliverFrameCB& new_frame_callback,
50 const StartedCallback& started_callback); 45 const StartedCallback& started_callback);
51 46
52 // Stops deliver frames and clears all callbacks including the 47 // Stops deliver frames and clears all callbacks including the
53 // SupportedFormatsCallback callback. 48 // SupportedFormatsCallback callback.
54 virtual void StopDeliver(); 49 virtual void StopDeliver();
55 50
56 protected:
57 // media::VideoCapture::EventHandler implementation.
58 // These functions are called on the IO thread (same as where
59 // |capture_engine_| runs).
60 virtual void OnStarted(media::VideoCapture* capture) OVERRIDE;
61 virtual void OnStopped(media::VideoCapture* capture) OVERRIDE;
62 virtual void OnPaused(media::VideoCapture* capture) OVERRIDE;
63 virtual void OnError(media::VideoCapture* capture, int error_code) OVERRIDE;
64 virtual void OnRemoved(media::VideoCapture* capture) OVERRIDE;
65 virtual void OnFrameReady(
66 media::VideoCapture* capture,
67 const scoped_refptr<media::VideoFrame>& frame) OVERRIDE;
68
69 private: 51 private:
70 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; 52 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>;
71 friend class MockVideoCapturerDelegate; 53 friend class MockVideoCapturerDelegate;
72 54
73 virtual ~VideoCapturerDelegate(); 55 virtual ~VideoCapturerDelegate();
74 56
75 void OnFrameReadyOnRenderThread( 57 void OnFrameReadyOnRenderThread(
76 media::VideoCapture* capture, 58 const scoped_refptr<media::VideoFrame>& frame,
77 const scoped_refptr<media::VideoFrame>& frame); 59 const media::VideoCaptureFormat& format,
78 void OnErrorOnRenderThread(media::VideoCapture* capture); 60 const base::TimeTicks& timestamp);
61 void OnStateUpdateOnRenderThread(VideoCaptureState state);
79 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); 62 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats);
80 void OnDeviceSupportedFormatsEnumerated( 63 void OnDeviceSupportedFormatsEnumerated(
81 const media::VideoCaptureFormats& formats); 64 const media::VideoCaptureFormats& formats);
82 65
83 // The id identifies which video capture device is used for this video 66 // The id identifies which video capture device is used for this video
84 // capture session. 67 // capture session.
85 media::VideoCaptureSessionId session_id_; 68 media::VideoCaptureSessionId session_id_;
86 scoped_ptr<VideoCaptureHandle> capture_engine_; 69 base::Closure release_device_cb_;
70 base::Closure stop_capture_cb_;
87 71
88 bool is_screen_cast_; 72 bool is_screen_cast_;
89 73
90 // Accessed on the thread where StartDeliver is called. 74 // Accessed on the thread where StartToDeliver is called.
Ami GONE FROM CHROMIUM 2014/04/24 21:04:31 l.20 told me that this class is only accessed on a
Alpha Left Google 2014/04/24 22:50:34 This comment is not necessary.
91 bool got_first_frame_; 75 bool got_first_frame_;
92 76
93 // |new_frame_callback_| is provided to this class in StartDeliver and must be 77 // |new_frame_callback_| is provided to this class in StartToDeliver and must
94 // valid until StopDeliver is called. 78 // be valid until StopDeliver is called.
95 NewFrameCallback new_frame_callback_; 79 VideoCaptureDeliverFrameCB new_frame_callback_;
96 // |started_callback| is provided to this class in StartDeliver and must be 80 // |started_callback| is provided to this class in StartToDeliver and must be
97 // valid until StopDeliver is called. 81 // valid until StopDeliver is called.
98 StartedCallback started_callback_; 82 StartedCallback started_callback_;
99 // Message loop of the caller of StartDeliver.
100 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
101 83
102 SupportedFormatsCallback source_formats_callback_; 84 VideoCaptureDeviceFormatsCB source_formats_callback_;
85
86 // Bound to the render thread.
87 base::ThreadChecker thread_checker_;
103 88
104 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); 89 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate);
105 }; 90 };
106 91
107 class CONTENT_EXPORT MediaStreamVideoCapturerSource 92 class CONTENT_EXPORT MediaStreamVideoCapturerSource
Ami GONE FROM CHROMIUM 2014/04/24 21:04:31 doco thread & lifecycle (who owns it, when is it d
Alpha Left Google 2014/04/24 22:50:34 Done.
108 : public MediaStreamVideoSource { 93 : public MediaStreamVideoSource {
109 public: 94 public:
110 MediaStreamVideoCapturerSource( 95 MediaStreamVideoCapturerSource(
111 const StreamDeviceInfo& device_info, 96 const StreamDeviceInfo& device_info,
112 const SourceStoppedCallback& stop_callback, 97 const SourceStoppedCallback& stop_callback,
113 const scoped_refptr<VideoCapturerDelegate>& delegate); 98 const scoped_refptr<VideoCapturerDelegate>& delegate);
114 99
115 virtual ~MediaStreamVideoCapturerSource(); 100 virtual ~MediaStreamVideoCapturerSource();
116 101
117 protected: 102 protected:
(...skipping 10 matching lines...) Expand all
128 private: 113 private:
129 // The delegate that provides video frames. 114 // The delegate that provides video frames.
130 scoped_refptr<VideoCapturerDelegate> delegate_; 115 scoped_refptr<VideoCapturerDelegate> delegate_;
131 116
132 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); 117 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource);
133 }; 118 };
134 119
135 } // namespace content 120 } // namespace content
136 121
137 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ 122 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698