OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // VideoCaptureImpl represents a capture device in renderer process. It provides |
| 6 // interfaces for clients to Start/Stop capture. It also communicates to clients |
| 7 // when buffer is ready, state of capture device is changed. |
| 8 |
| 9 #ifndef CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 10 #define CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
| 11 |
| 12 #include <list> |
| 13 #include <map> |
| 14 |
| 15 #include "base/message_loop_proxy.h" |
| 16 #include "content/renderer/video_capture_message_filter.h" |
| 17 #include "media/base/callback.h" |
| 18 #include "media/video/capture/video_capture.h" |
| 19 #include "ui/gfx/surface/transport_dib.h" |
| 20 |
| 21 class VideoCaptureImpl |
| 22 : public media::VideoCapture, |
| 23 public VideoCaptureMessageFilter::Delegate { |
| 24 public: |
| 25 // media::VideoCapture interface. |
| 26 virtual void StartCapture(media::VideoCapture::EventHandler* handler, |
| 27 const VideoCaptureCapability& capability); |
| 28 virtual void StopCapture(media::VideoCapture::EventHandler* handler); |
| 29 virtual bool CaptureStarted(); |
| 30 virtual int CaptureWidth(); |
| 31 virtual int CaptureHeight(); |
| 32 virtual int CaptureFrameRate(); |
| 33 |
| 34 // VideoCaptureMessageFilter::Delegate interface. |
| 35 virtual void OnBufferReceived(TransportDIB::Handle handle, |
| 36 base::Time timestamp); |
| 37 virtual void OnStateChanged(const media::VideoCapture::State& state); |
| 38 virtual void OnDeviceInfoReceived( |
| 39 const media::VideoCaptureParams& device_info); |
| 40 |
| 41 bool pending_start() { |
| 42 return (new_width_ > 0 && new_height_ > 0); |
| 43 } |
| 44 |
| 45 private: |
| 46 friend class VideoCaptureImplManager; |
| 47 friend class VideoCaptureImplTest; |
| 48 |
| 49 enum State { |
| 50 kStarted, |
| 51 kStopping, |
| 52 kStopped |
| 53 }; |
| 54 |
| 55 struct DIBBuffer { |
| 56 public: |
| 57 DIBBuffer(TransportDIB* d, media::VideoCapture::VideoFrameBuffer* ptr); |
| 58 ~DIBBuffer(); |
| 59 |
| 60 TransportDIB* dib; |
| 61 scoped_refptr<media::VideoCapture::VideoFrameBuffer> mapped_memory; |
| 62 }; |
| 63 |
| 64 VideoCaptureImpl(media::VideoCaptureSessionId id, |
| 65 scoped_refptr<base::MessageLoopProxy> ml_proxy, |
| 66 VideoCaptureMessageFilter* filter); |
| 67 virtual ~VideoCaptureImpl(); |
| 68 |
| 69 void Init(); |
| 70 void DeInit(Task* task); |
| 71 void StopDevice(); |
| 72 void RestartCapture(); |
| 73 void StartCaptureInternal(); |
| 74 void AddDelegateOnIOThread(); |
| 75 void RemoveDelegateOnIOThread(Task* task); |
| 76 |
| 77 scoped_refptr<VideoCaptureMessageFilter> message_filter_; |
| 78 media::VideoCaptureSessionId session_id_; |
| 79 scoped_refptr<base::MessageLoopProxy> ml_proxy_; |
| 80 int device_id_; |
| 81 |
| 82 // Pool of DIBs. |
| 83 typedef std::list<DIBBuffer*> CachedDIB; |
| 84 CachedDIB cached_dibs_; |
| 85 |
| 86 typedef std::map<media::VideoCapture::EventHandler*, VideoCaptureCapability> |
| 87 ClientInfo; |
| 88 ClientInfo clients_; |
| 89 std::list<media::VideoCapture::EventHandler*> master_clients_; |
| 90 |
| 91 typedef std::map<media::VideoCapture::EventHandler*, int> PendingClient; |
| 92 PendingClient pending_clients_; |
| 93 |
| 94 int width_; |
| 95 int height_; |
| 96 int frame_rate_; |
| 97 media::VideoFrame::Format video_type_; |
| 98 |
| 99 int new_width_; |
| 100 int new_height_; |
| 101 State state_; |
| 102 |
| 103 DISALLOW_COPY_AND_ASSIGN(VideoCaptureImpl); |
| 104 }; |
| 105 |
| 106 DISABLE_RUNNABLE_METHOD_REFCOUNT(VideoCaptureImpl); |
| 107 |
| 108 #endif // CONTENT_RENDERER_MEDIA_VIDEO_CAPTURE_IMPL_H_ |
OLD | NEW |