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

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

Issue 843943002: Refactor VideoCapturerDelegate to use WeakPtr instead of refcount. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix source_formats_callback_.reset Created 5 years, 11 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_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/gtest_prod_util.h" 9 #include "base/gtest_prod_util.h"
10 #include "base/memory/weak_ptr.h"
10 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/threading/thread_checker.h" 12 #include "base/threading/thread_checker.h"
12 #include "content/common/media/video_capture.h" 13 #include "content/common/media/video_capture.h"
13 #include "content/renderer/media/media_stream_video_source.h" 14 #include "content/renderer/media/media_stream_video_source.h"
14 15
15 namespace content { 16 namespace content {
16 17
17 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource 18 // VideoCapturerDelegate is a delegate used by MediaStreamVideoCapturerSource
18 // for local video capturer. It uses VideoCaptureImplManager to start / stop 19 // for local video capturer. It uses VideoCaptureImplManager to start / stop
19 // and receive I420 frames from Chrome's video capture implementation. 20 // and receive I420 frames from Chrome's video capture implementation.
20 // 21 //
21 // This is a render thread only object. 22 // This is a render thread only object.
22 class CONTENT_EXPORT VideoCapturerDelegate 23 class CONTENT_EXPORT VideoCapturerDelegate {
23 : public base::RefCountedThreadSafe<VideoCapturerDelegate> {
24 public: 24 public:
25 typedef base::Callback<void(MediaStreamRequestResult result)> RunningCallback; 25 typedef base::Callback<void(MediaStreamRequestResult result)> RunningCallback;
26 26
27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info); 27 explicit VideoCapturerDelegate(const StreamDeviceInfo& device_info);
28 virtual ~VideoCapturerDelegate();
28 29
29 // Collects the formats that can currently be used. 30 // Collects the formats that can currently be used.
30 // |max_requested_height|, |max_requested_width|, and 31 // |max_requested_height|, |max_requested_width|, and
31 // |max_requested_frame_rate| is used by Tab and Screen capture to decide what 32 // |max_requested_frame_rate| is used by Tab and Screen capture to decide what
32 // resolution/framerate to generate. |callback| is triggered when the formats 33 // resolution/framerate to generate. |callback| is triggered when the formats
33 // have been collected. 34 // have been collected.
34 virtual void GetCurrentSupportedFormats( 35 virtual void GetCurrentSupportedFormats(
35 int max_requested_width, 36 int max_requested_width,
36 int max_requested_height, 37 int max_requested_height,
37 double max_requested_frame_rate, 38 double max_requested_frame_rate,
(...skipping 12 matching lines...) Expand all
50 51
51 // Stops capturing frames and clears all callbacks including the 52 // Stops capturing frames and clears all callbacks including the
52 // SupportedFormatsCallback callback. 53 // SupportedFormatsCallback callback.
53 virtual void StopCapture(); 54 virtual void StopCapture();
54 55
55 private: 56 private:
56 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended); 57 FRIEND_TEST_ALL_PREFIXES(MediaStreamVideoCapturerSourceTest, Ended);
57 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>; 58 friend class base::RefCountedThreadSafe<VideoCapturerDelegate>;
58 friend class MockVideoCapturerDelegate; 59 friend class MockVideoCapturerDelegate;
59 60
60 virtual ~VideoCapturerDelegate();
61
62 void OnStateUpdateOnRenderThread(VideoCaptureState state); 61 void OnStateUpdateOnRenderThread(VideoCaptureState state);
63 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats); 62 void OnDeviceFormatsInUseReceived(const media::VideoCaptureFormats& formats);
64 void OnDeviceSupportedFormatsEnumerated( 63 void OnDeviceSupportedFormatsEnumerated(
65 const media::VideoCaptureFormats& formats); 64 const media::VideoCaptureFormats& formats);
66 65
67 // 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
68 // capture session. 67 // capture session.
69 media::VideoCaptureSessionId session_id_; 68 media::VideoCaptureSessionId session_id_;
70 base::Closure release_device_cb_; 69 base::Closure release_device_cb_;
71 base::Closure stop_capture_cb_; 70 base::Closure stop_capture_cb_;
72 71
73 bool is_screen_cast_; 72 bool is_screen_cast_;
74 73
75 // |running_callback| is provided to this class in StartCapture and must be 74 // |running_callback| is provided to this class in StartCapture and must be
76 // valid until StopCapture is called. 75 // valid until StopCapture is called.
77 RunningCallback running_callback_; 76 RunningCallback running_callback_;
78 77
79 VideoCaptureDeviceFormatsCB source_formats_callback_; 78 VideoCaptureDeviceFormatsCB source_formats_callback_;
80 79
81 // Bound to the render thread. 80 // Bound to the render thread.
82 base::ThreadChecker thread_checker_; 81 base::ThreadChecker thread_checker_;
83 82
83 base::WeakPtrFactory<VideoCapturerDelegate> weak_factory_;
84
84 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate); 85 DISALLOW_COPY_AND_ASSIGN(VideoCapturerDelegate);
85 }; 86 };
86 87
87 // Owned by WebMediaStreamSource in Blink as a representation of a video 88 // Owned by WebMediaStreamSource in Blink as a representation of a video
88 // stream coming from a camera. 89 // stream coming from a camera.
89 // This is a render thread only object. All methods must be called on the 90 // This is a render thread only object. All methods must be called on the
90 // render thread. 91 // render thread.
91 class CONTENT_EXPORT MediaStreamVideoCapturerSource 92 class CONTENT_EXPORT MediaStreamVideoCapturerSource
92 : public MediaStreamVideoSource { 93 : public MediaStreamVideoSource {
93 public: 94 public:
94 MediaStreamVideoCapturerSource( 95 MediaStreamVideoCapturerSource(
95 const StreamDeviceInfo& device_info, 96 const StreamDeviceInfo& device_info,
96 const SourceStoppedCallback& stop_callback, 97 const SourceStoppedCallback& stop_callback,
97 const scoped_refptr<VideoCapturerDelegate>& delegate); 98 scoped_ptr<VideoCapturerDelegate> delegate);
98 99
99 virtual ~MediaStreamVideoCapturerSource(); 100 virtual ~MediaStreamVideoCapturerSource();
100 101
101 protected: 102 protected:
102 // Implements MediaStreamVideoSource. 103 // Implements MediaStreamVideoSource.
103 void GetCurrentSupportedFormats( 104 void GetCurrentSupportedFormats(
104 int max_requested_width, 105 int max_requested_width,
105 int max_requested_height, 106 int max_requested_height,
106 double max_requested_frame_rate, 107 double max_requested_frame_rate,
107 const VideoCaptureDeviceFormatsCB& callback) override; 108 const VideoCaptureDeviceFormatsCB& callback) override;
108 109
109 void StartSourceImpl( 110 void StartSourceImpl(
110 const media::VideoCaptureFormat& format, 111 const media::VideoCaptureFormat& format,
111 const VideoCaptureDeliverFrameCB& frame_callback) override; 112 const VideoCaptureDeliverFrameCB& frame_callback) override;
112 113
113 void StopSourceImpl() override; 114 void StopSourceImpl() override;
114 115
115 private: 116 private:
116 // The delegate that provides video frames. 117 // The delegate that provides video frames.
117 scoped_refptr<VideoCapturerDelegate> delegate_; 118 scoped_ptr<VideoCapturerDelegate> delegate_;
118 119
119 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource); 120 DISALLOW_COPY_AND_ASSIGN(MediaStreamVideoCapturerSource);
120 }; 121 };
121 122
122 } // namespace content 123 } // namespace content
123 124
124 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_ 125 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_VIDEO_CAPTURER_SOURCE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698