| 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 "content/browser/renderer_host/video_capture_controller_event_handler.h
" |
| 25 #include "media/video/capture/video_capture_device.h" | 26 #include "media/video/capture/video_capture_device.h" |
| 26 #include "media/video/capture/video_capture_types.h" | 27 #include "media/video/capture/video_capture_types.h" |
| 27 #include "ui/gfx/surface/transport_dib.h" | 28 #include "ui/gfx/surface/transport_dib.h" |
| 28 | 29 |
| 29 class VideoCaptureController | 30 class VideoCaptureController |
| 30 : public base::RefCountedThreadSafe<VideoCaptureController>, | 31 : public base::RefCountedThreadSafe<VideoCaptureController>, |
| 31 public media::VideoCaptureDevice::EventHandler { | 32 public media::VideoCaptureDevice::EventHandler { |
| 32 public: | 33 public: |
| 33 // Id used for identifying an object of VideoCaptureController. | 34 VideoCaptureController(const 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, | 35 base::ProcessHandle render_process, |
| 60 EventHandler* event_handler); | 36 VideoCaptureControllerEventHandler* event_handler); |
| 61 virtual ~VideoCaptureController(); | 37 virtual ~VideoCaptureController(); |
| 62 | 38 |
| 63 // Starts video capturing and tries to use the resolution specified in | 39 // Starts video capturing and tries to use the resolution specified in |
| 64 // params. | 40 // params. |
| 65 // When capturing has started EventHandler::OnFrameInfo is called with | 41 // When capturing has started VideoCaptureControllerEventHandler::OnFrameInfo |
| 66 // resolution that best matches the requested that the video capture device | 42 // is called with resolution that best matches the requested that the video |
| 67 // support. | 43 // capture device support. |
| 68 void StartCapture(const media::VideoCaptureParams& params); | 44 void StartCapture(const media::VideoCaptureParams& params); |
| 69 | 45 |
| 70 // Stop video capture. | 46 // Stop video capture. |
| 71 // When the capture is stopped and all TransportDIBS have been returned | 47 // When the capture is stopped and all TransportDIBS have been returned |
| 72 // EventHandler::OnReadyToDelete will be called. | 48 // VideoCaptureControllerEventHandler::OnReadyToDelete will be called. |
| 73 // stopped_task may be null but it can be used to get a notification when the | 49 // stopped_task may be null but it can be used to get a notification when the |
| 74 // device is stopped. | 50 // device is stopped. |
| 75 void StopCapture(Task* stopped_task); | 51 void StopCapture(Task* stopped_task); |
| 76 | 52 |
| 77 // Return a DIB previously given in EventHandler::OnBufferReady. | 53 // Return a DIB previously given in |
| 54 // VideoCaptureControllerEventHandler::OnBufferReady. |
| 78 void ReturnTransportDIB(TransportDIB::Handle handle); | 55 void ReturnTransportDIB(TransportDIB::Handle handle); |
| 79 | 56 |
| 80 // Implement media::VideoCaptureDevice::EventHandler. | 57 // Implement media::VideoCaptureDevice::EventHandler. |
| 81 virtual void OnIncomingCapturedFrame(const uint8* data, | 58 virtual void OnIncomingCapturedFrame(const uint8* data, |
| 82 int length, | 59 int length, |
| 83 base::Time timestamp); | 60 base::Time timestamp); |
| 84 virtual void OnError(); | 61 virtual void OnError(); |
| 85 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info); | 62 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info); |
| 86 | 63 |
| 87 private: | 64 private: |
| 88 // Called by VideoCaptureManager when a device have been stopped. | 65 // Called by VideoCaptureManager when a device have been stopped. |
| 89 void OnDeviceStopped(Task* stopped_task); | 66 void OnDeviceStopped(Task* stopped_task); |
| 90 | 67 |
| 91 // Lock to protect free_dibs_ and owned_dibs_. | 68 // Lock to protect free_dibs_ and owned_dibs_. |
| 92 base::Lock lock_; | 69 base::Lock lock_; |
| 93 // Handle to the render process that will receive the DIBs. | 70 // Handle to the render process that will receive the DIBs. |
| 94 base::ProcessHandle render_handle_; | 71 base::ProcessHandle render_handle_; |
| 95 bool report_ready_to_delete_; | 72 bool report_ready_to_delete_; |
| 96 typedef std::list<TransportDIB::Handle> DIBHandleList; | 73 typedef std::list<TransportDIB::Handle> DIBHandleList; |
| 97 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap; | 74 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap; |
| 98 | 75 |
| 99 // Free DIBS that can be filled with video frames. | 76 // Free DIBS that can be filled with video frames. |
| 100 DIBHandleList free_dibs_; | 77 DIBHandleList free_dibs_; |
| 101 | 78 |
| 102 // All DIBS created by this object. | 79 // All DIBS created by this object. |
| 103 DIBMap owned_dibs_; | 80 DIBMap owned_dibs_; |
| 104 EventHandler* event_handler_; | 81 VideoCaptureControllerEventHandler* event_handler_; |
| 105 | 82 |
| 106 // The parameter that was requested when starting the capture device. | 83 // The parameter that was requested when starting the capture device. |
| 107 media::VideoCaptureParams params_; | 84 media::VideoCaptureParams params_; |
| 108 | 85 |
| 109 // Id used for identifying this object. | 86 // ID used for identifying this object. |
| 110 ControllerId id_; | 87 VideoCaptureControllerID id_; |
| 111 media::VideoCaptureDevice::Capability frame_info_; | 88 media::VideoCaptureDevice::Capability frame_info_; |
| 112 | 89 |
| 113 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); | 90 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController); |
| 114 }; | 91 }; |
| 115 | 92 |
| 116 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ | 93 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_ |
| OLD | NEW |