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

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

Issue 23587018: Replace media::VideoCapture::VideoFrameBuffer with media::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: 4fe79a572 Initial. Created 7 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // VideoCaptureImpl represents a capture device in renderer process. It provides 5 // VideoCaptureImpl represents a capture device in renderer process. It provides
6 // interfaces for clients to Start/Stop capture. It also communicates to clients 6 // interfaces for clients to Start/Stop capture. It also communicates to clients
7 // when buffer is ready, state of capture device is changed. 7 // when buffer is ready, state of capture device is changed.
8 8
9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which 9 // VideoCaptureImpl is also a delegate of VideoCaptureMessageFilter which
10 // relays operation of capture device to browser process and receives response 10 // relays operation of capture device to browser process and receives response
(...skipping 15 matching lines...) Expand all
26 // will dangle after the delete goes through. The "as long as" is guaranteed by 26 // will dangle after the delete goes through. The "as long as" is guaranteed by
27 // clients of VideoCaptureImplManager not using devices after they've 27 // clients of VideoCaptureImplManager not using devices after they've
28 // RemoveDevice'd them. 28 // RemoveDevice'd them.
29 29
30 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ 30 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
31 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ 31 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
32 32
33 #include <list> 33 #include <list>
34 #include <map> 34 #include <map>
35 35
36 #include "base/memory/weak_ptr.h"
36 #include "content/common/content_export.h" 37 #include "content/common/content_export.h"
37 #include "content/common/media/video_capture.h" 38 #include "content/common/media/video_capture.h"
38 #include "content/renderer/media/video_capture_message_filter.h" 39 #include "content/renderer/media/video_capture_message_filter.h"
39 #include "media/video/capture/video_capture.h" 40 #include "media/video/capture/video_capture.h"
40 #include "media/video/capture/video_capture_types.h" 41 #include "media/video/capture/video_capture_types.h"
41 42
42 namespace base { 43 namespace base {
43 class MessageLoopProxy; 44 class MessageLoopProxy;
44 } 45 }
45 46
46 namespace content { 47 namespace content {
47 48
48 class CONTENT_EXPORT VideoCaptureImpl 49 class CONTENT_EXPORT VideoCaptureImpl
49 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate { 50 : public media::VideoCapture, public VideoCaptureMessageFilter::Delegate {
50 public: 51 public:
51 // media::VideoCapture interface. 52 // media::VideoCapture interface.
52 virtual void StartCapture( 53 virtual void StartCapture(
53 media::VideoCapture::EventHandler* handler, 54 media::VideoCapture::EventHandler* handler,
54 const media::VideoCaptureCapability& capability) OVERRIDE; 55 const media::VideoCaptureCapability& capability) OVERRIDE;
55 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE; 56 virtual void StopCapture(media::VideoCapture::EventHandler* handler) OVERRIDE;
56 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) OVERRIDE;
57 virtual bool CaptureStarted() OVERRIDE; 57 virtual bool CaptureStarted() OVERRIDE;
58 virtual int CaptureWidth() OVERRIDE; 58 virtual int CaptureWidth() OVERRIDE;
59 virtual int CaptureHeight() OVERRIDE; 59 virtual int CaptureHeight() OVERRIDE;
60 virtual int CaptureFrameRate() OVERRIDE; 60 virtual int CaptureFrameRate() OVERRIDE;
61 61
62 // VideoCaptureMessageFilter::Delegate interface. 62 // VideoCaptureMessageFilter::Delegate interface.
63 virtual void OnBufferCreated(base::SharedMemoryHandle handle, 63 virtual void OnBufferCreated(base::SharedMemoryHandle handle,
64 int length, int buffer_id) OVERRIDE; 64 int length, int buffer_id) OVERRIDE;
65 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE; 65 virtual void OnBufferReceived(int buffer_id, base::Time timestamp) OVERRIDE;
66 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE; 66 virtual void OnStateChanged(VideoCaptureState state) OVERRIDE;
67 virtual void OnDeviceInfoReceived( 67 virtual void OnDeviceInfoReceived(
68 const media::VideoCaptureParams& device_info) OVERRIDE; 68 const media::VideoCaptureParams& device_info) OVERRIDE;
69 virtual void OnDeviceInfoChanged( 69 virtual void OnDeviceInfoChanged(
70 const media::VideoCaptureParams& device_info) OVERRIDE; 70 const media::VideoCaptureParams& device_info) OVERRIDE;
71 virtual void OnDelegateAdded(int32 device_id) OVERRIDE; 71 virtual void OnDelegateAdded(int32 device_id) OVERRIDE;
72 72
73 // Stop/resume delivering video frames to clients, based on flag |suspend|. 73 // Stop/resume delivering video frames to clients, based on flag |suspend|.
74 virtual void SuspendCapture(bool suspend); 74 virtual void SuspendCapture(bool suspend);
75 75
76 private: 76 private:
77 friend class VideoCaptureImplManager; 77 friend class VideoCaptureImplManager;
78 friend class VideoCaptureImplTest; 78 friend class VideoCaptureImplTest;
79 friend class MockVideoCaptureImpl; 79 friend class MockVideoCaptureImpl;
80 80
81 struct DIBBuffer; 81 class ClientBuffer;
82 typedef std::map<media::VideoCapture::EventHandler*, 82 typedef std::map<media::VideoCapture::EventHandler*,
83 media::VideoCaptureCapability> ClientInfo; 83 media::VideoCaptureCapability> ClientInfo;
84 84
85 VideoCaptureImpl(media::VideoCaptureSessionId id, 85 VideoCaptureImpl(media::VideoCaptureSessionId id,
86 base::MessageLoopProxy* capture_message_loop_proxy, 86 base::MessageLoopProxy* capture_message_loop_proxy,
87 VideoCaptureMessageFilter* filter); 87 VideoCaptureMessageFilter* filter);
88 virtual ~VideoCaptureImpl(); 88 virtual ~VideoCaptureImpl();
89 89
90 void DoStartCaptureOnCaptureThread( 90 void DoStartCaptureOnCaptureThread(
91 media::VideoCapture::EventHandler* handler, 91 media::VideoCapture::EventHandler* handler,
92 const media::VideoCaptureCapability& capability); 92 const media::VideoCaptureCapability& capability);
93 void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler); 93 void DoStopCaptureOnCaptureThread(media::VideoCapture::EventHandler* handler);
94 void DoFeedBufferOnCaptureThread(scoped_refptr<VideoFrameBuffer> buffer);
95
96 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle, 94 void DoBufferCreatedOnCaptureThread(base::SharedMemoryHandle handle,
97 int length, int buffer_id); 95 int length, int buffer_id);
98 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp); 96 void DoBufferReceivedOnCaptureThread(int buffer_id, base::Time timestamp);
97 void DoClientBufferFinishedOnCaptureThread(
98 int buffer_id,
99 const scoped_refptr<ClientBuffer>& buffer);
99 void DoStateChangedOnCaptureThread(VideoCaptureState state); 100 void DoStateChangedOnCaptureThread(VideoCaptureState state);
100 void DoDeviceInfoReceivedOnCaptureThread( 101 void DoDeviceInfoReceivedOnCaptureThread(
101 const media::VideoCaptureParams& device_info); 102 const media::VideoCaptureParams& device_info);
102 void DoDeviceInfoChangedOnCaptureThread( 103 void DoDeviceInfoChangedOnCaptureThread(
103 const media::VideoCaptureParams& device_info); 104 const media::VideoCaptureParams& device_info);
104 void DoDelegateAddedOnCaptureThread(int32 device_id); 105 void DoDelegateAddedOnCaptureThread(int32 device_id);
105 106
106 void DoSuspendCaptureOnCaptureThread(bool suspend); 107 void DoSuspendCaptureOnCaptureThread(bool suspend);
107 108
108 void Init(); 109 void Init();
109 void DeInit(base::Closure task); 110 void DeInit(base::Closure task);
110 void DoDeInitOnCaptureThread(base::Closure task); 111 void DoDeInitOnCaptureThread(base::Closure task);
111 void StopDevice(); 112 void StopDevice();
112 void RestartCapture(); 113 void RestartCapture();
113 void StartCaptureInternal(); 114 void StartCaptureInternal();
114 void AddDelegateOnIOThread(); 115 void AddDelegateOnIOThread();
115 void RemoveDelegateOnIOThread(base::Closure task); 116 void RemoveDelegateOnIOThread(base::Closure task);
116 virtual void Send(IPC::Message* message); 117 virtual void Send(IPC::Message* message);
117 118
118 // Helpers. 119 // Helpers.
119 bool ClientHasDIB() const;
120 bool RemoveClient(media::VideoCapture::EventHandler* handler, 120 bool RemoveClient(media::VideoCapture::EventHandler* handler,
121 ClientInfo* clients); 121 ClientInfo* clients);
122 122
123 const scoped_refptr<VideoCaptureMessageFilter> message_filter_; 123 const scoped_refptr<VideoCaptureMessageFilter> message_filter_;
124 const scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_; 124 const scoped_refptr<base::MessageLoopProxy> capture_message_loop_proxy_;
125 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; 125 const scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_;
126 int device_id_; 126 int device_id_;
127 127
128 // Pool of DIBs. The key is buffer_id. 128 // Buffers available for sending to the client.
129 typedef std::map<int, DIBBuffer*> CachedDIB; 129 typedef std::map<int32, scoped_refptr<ClientBuffer> > ClientBufferMap;
130 CachedDIB cached_dibs_; 130 ClientBufferMap client_buffers_;
131 // WeakPtrFactory pointing back to |this| object, for use with
132 // media::VideoFrames constructed in OnBufferReceived() from buffers cached
133 // in |client_buffers_|.
134 base::WeakPtrFactory<VideoCaptureImpl> client_buffer_weak_this_factory_;
131 135
132 ClientInfo clients_; 136 ClientInfo clients_;
133 137
134 ClientInfo clients_pending_on_filter_; 138 ClientInfo clients_pending_on_filter_;
135 ClientInfo clients_pending_on_restart_; 139 ClientInfo clients_pending_on_restart_;
136 140
137 media::VideoPixelFormat video_type_; 141 media::VideoPixelFormat video_type_;
138 142
139 // Member capture_format_ represents the video format requested by the client 143 // Member capture_format_ represents the video format requested by the client
140 // to this class via DoStartCaptureOnCaptureThread. 144 // to this class via DoStartCaptureOnCaptureThread.
141 media::VideoCaptureCapability capture_format_; 145 media::VideoCaptureCapability capture_format_;
142 146
143 // The device's video capture format sent from browser process side. 147 // The device's video capture format sent from browser process side.
144 media::VideoCaptureParams device_info_; 148 media::VideoCaptureParams device_info_;
145 bool device_info_available_; 149 bool device_info_available_;
146 150
147 bool suspended_; 151 bool suspended_;
148 VideoCaptureState state_; 152 VideoCaptureState state_;
149 153
150 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); 154 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl);
151 }; 155 };
152 156
153 } // namespace content 157 } // namespace content
154 158
155 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ 159 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698