Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // VideoCaptureController is the glue between VideoCaptureHost, | 5 // VideoCaptureController is the glue between VideoCaptureHost, |
| 6 // VideoCaptureManager and VideoCaptureDevice. | 6 // VideoCaptureManager and VideoCaptureDevice. |
| 7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and | 7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and |
| 8 // is responsible for keeping track of TransportDIBs and filling them with I420 | 8 // is responsible for keeping track of TransportDIBs and filling them with I420 |
| 9 // video frames for IPC communication between VideoCaptureHost and | 9 // video frames for IPC communication between VideoCaptureHost and |
| 10 // VideoCaptureMessageFilter. | 10 // VideoCaptureMessageFilter. |
| 11 // It implements media::VideoCaptureDevice::EventHandler to get video frames | 11 // It implements media::VideoCaptureDevice::EventHandler to get video frames |
| 12 // from a VideoCaptureDevice object and do color conversion straight into the | 12 // from a VideoCaptureDevice object and do color conversion straight into the |
| 13 // TransportDIBs to avoid a memory copy. | 13 // TransportDIBs to avoid a memory copy. |
| 14 | 14 |
| 15 #ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ | 15 #ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ |
| 16 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ | 16 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ |
| 17 | 17 |
| 18 #include <list> | 18 #include <list> |
| 19 #include <map> | 19 #include <map> |
| 20 | 20 |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/process.h" | 22 #include "base/process.h" |
| 23 #include "base/synchronization/lock.h" | 23 #include "base/synchronization/lock.h" |
| 24 #include "base/task.h" | 24 #include "base/task.h" |
| 25 #include "media/video/capture/video_capture_device.h" | 25 #include "media/video/capture/video_capture_device.h" |
| 26 #include "media/video/capture/video_capture_types.h" | 26 #include "media/video/capture/video_capture_types.h" |
| 27 #include "ui/gfx/surface/transport_dib.h" | 27 #include "ui/gfx/surface/transport_dib.h" |
| 28 | 28 |
| 29 // Id used for identifying an object of VideoCaptureController. | |
| 30 typedef std::pair<int32, int> VideoCaptureControllerId; | |
|
scherkus (not reviewing)
2011/05/31 19:37:23
nit: while you're changing this stuff... Id -> ID
wjia(left Chromium)
2011/05/31 20:38:00
Done.
| |
| 31 | |
| 32 class VideoCaptureControllerEventHandler { | |
|
jam
2011/05/31 19:00:08
nit: this should be in its own file
wjia(left Chromium)
2011/05/31 20:38:00
Done.
| |
| 33 public: | |
| 34 // An Error have occurred in the VideoCaptureDevice. | |
| 35 virtual void OnError(VideoCaptureControllerId id) = 0; | |
| 36 | |
| 37 // An TransportDIB have been filled with I420 video. | |
| 38 virtual void OnBufferReady(VideoCaptureControllerId id, | |
| 39 TransportDIB::Handle handle, | |
| 40 base::Time timestamp) = 0; | |
| 41 | |
| 42 // The frame resolution the VideoCaptureDevice capture video in. | |
| 43 virtual void OnFrameInfo(VideoCaptureControllerId id, | |
| 44 int width, | |
| 45 int height, | |
| 46 int frame_rate) = 0; | |
| 47 | |
| 48 // Report that this object can be deleted. | |
| 49 virtual void OnReadyToDelete(VideoCaptureControllerId id) = 0; | |
| 50 | |
| 51 protected: | |
| 52 virtual ~VideoCaptureControllerEventHandler() {} | |
| 53 }; | |
| 54 | |
| 29 class VideoCaptureController | 55 class VideoCaptureController |
| 30 : public base::RefCountedThreadSafe<VideoCaptureController>, | 56 : public base::RefCountedThreadSafe<VideoCaptureController>, |
| 31 public media::VideoCaptureDevice::EventHandler { | 57 public media::VideoCaptureDevice::EventHandler { |
| 32 public: | 58 public: |
| 33 // Id used for identifying an object of VideoCaptureController. | 59 VideoCaptureController(VideoCaptureControllerId id, |
| 34 typedef std::pair<int32, int> ControllerId; | |
| 35 class EventHandler { | |
| 36 public: | |
| 37 // An Error have occurred in the VideoCaptureDevice. | |
| 38 virtual void OnError(ControllerId id) = 0; | |
| 39 | |
| 40 // An TransportDIB have been filled with I420 video. | |
| 41 virtual void OnBufferReady(ControllerId id, | |
| 42 TransportDIB::Handle handle, | |
| 43 base::Time timestamp) = 0; | |
| 44 | |
| 45 // The frame resolution the VideoCaptureDevice capture video in. | |
| 46 virtual void OnFrameInfo(ControllerId id, | |
| 47 int width, | |
| 48 int height, | |
| 49 int frame_rate) = 0; | |
| 50 | |
| 51 // Report that this object can be deleted. | |
| 52 virtual void OnReadyToDelete(ControllerId id) = 0; | |
| 53 | |
| 54 protected: | |
| 55 virtual ~EventHandler() {} | |
| 56 }; | |
| 57 | |
| 58 VideoCaptureController(ControllerId id, | |
| 59 base::ProcessHandle render_process, | 60 base::ProcessHandle render_process, |
| 60 EventHandler* event_handler); | 61 VideoCaptureControllerEventHandler* event_handler); |
| 61 virtual ~VideoCaptureController(); | 62 virtual ~VideoCaptureController(); |
| 62 | 63 |
| 63 // Starts video capturing and tries to use the resolution specified in | 64 // Starts video capturing and tries to use the resolution specified in |
| 64 // params. | 65 // params. |
| 65 // When capturing has started EventHandler::OnFrameInfo is called with | 66 // When capturing has started VideoCaptureControllerEventHandler::OnFrameInfo |
| 66 // resolution that best matches the requested that the video capture device | 67 // is called with resolution that best matches the requested that the video |
| 67 // support. | 68 // capture device support. |
| 68 void StartCapture(const media::VideoCaptureParams& params); | 69 void StartCapture(const media::VideoCaptureParams& params); |
| 69 | 70 |
| 70 // Stop video capture. | 71 // Stop video capture. |
| 71 // When the capture is stopped and all TransportDIBS have been returned | 72 // When the capture is stopped and all TransportDIBS have been returned |
| 72 // EventHandler::OnReadyToDelete will be called. | 73 // VideoCaptureControllerEventHandler::OnReadyToDelete will be called. |
| 73 // stopped_task may be null but it can be used to get a notification when the | 74 // stopped_task may be null but it can be used to get a notification when the |
| 74 // device is stopped. | 75 // device is stopped. |
| 75 void StopCapture(Task* stopped_task); | 76 void StopCapture(Task* stopped_task); |
| 76 | 77 |
| 77 // Return a DIB previously given in EventHandler::OnBufferReady. | 78 // Return a DIB previously given in |
| 79 // VideoCaptureControllerEventHandler::OnBufferReady. | |
| 78 void ReturnTransportDIB(TransportDIB::Handle handle); | 80 void ReturnTransportDIB(TransportDIB::Handle handle); |
| 79 | 81 |
| 80 // Implement media::VideoCaptureDevice::EventHandler. | 82 // Implement media::VideoCaptureDevice::EventHandler. |
| 81 virtual void OnIncomingCapturedFrame(const uint8* data, | 83 virtual void OnIncomingCapturedFrame(const uint8* data, |
| 82 int length, | 84 int length, |
| 83 base::Time timestamp); | 85 base::Time timestamp); |
| 84 virtual void OnError(); | 86 virtual void OnError(); |
| 85 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info); | 87 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info); |
| 86 | 88 |
| 87 private: | 89 private: |
| 88 // Called by VideoCaptureManager when a device have been stopped. | 90 // Called by VideoCaptureManager when a device have been stopped. |
| 89 void OnDeviceStopped(Task* stopped_task); | 91 void OnDeviceStopped(Task* stopped_task); |
| 90 | 92 |
| 91 // Lock to protect free_dibs_ and owned_dibs_. | 93 // Lock to protect free_dibs_ and owned_dibs_. |
| 92 base::Lock lock_; | 94 base::Lock lock_; |
| 93 // Handle to the render process that will receive the DIBs. | 95 // Handle to the render process that will receive the DIBs. |
| 94 base::ProcessHandle render_handle_; | 96 base::ProcessHandle render_handle_; |
| 95 bool report_ready_to_delete_; | 97 bool report_ready_to_delete_; |
| 96 typedef std::list<TransportDIB::Handle> DIBHandleList; | 98 typedef std::list<TransportDIB::Handle> DIBHandleList; |
| 97 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap; | 99 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap; |
| 98 | 100 |
| 99 // Free DIBS that can be filled with video frames. | 101 // Free DIBS that can be filled with video frames. |
| 100 DIBHandleList free_dibs_; | 102 DIBHandleList free_dibs_; |
| 101 | 103 |
| 102 // All DIBS created by this object. | 104 // All DIBS created by this object. |
| 103 DIBMap owned_dibs_; | 105 DIBMap owned_dibs_; |
| 104 EventHandler* event_handler_; | 106 VideoCaptureControllerEventHandler* event_handler_; |
| 105 | 107 |
| 106 // The parameter that was requested when starting the capture device. | 108 // The parameter that was requested when starting the capture device. |
| 107 media::VideoCaptureParams params_; | 109 media::VideoCaptureParams params_; |
| 108 | 110 |
| 109 // Id used for identifying this object. | 111 // Id used for identifying this object. |
| 110 ControllerId id_; | 112 VideoCaptureControllerId id_; |
| 111 media::VideoCaptureDevice::Capability frame_info_; | 113 media::VideoCaptureDevice::Capability frame_info_; |
| 112 | 114 |
| 113 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); | 115 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); |
| 114 }; | 116 }; |
| 115 | 117 |
| 116 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ | 118 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |