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 3 // found in the LICENSE file. 4 // 5 // This file contains abstract classes used for media filter to handle video 6 // capture devices. 7 8 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ 9 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ 10 11 #include "base/memory/ref_counted.h" 12 #include "base/time/time.h" 13 #include "media/base/media_export.h" 14 #include "media/base/video_frame.h" 15 #include "media/video/capture/video_capture_types.h" 16 17 namespace media { 18 19 class MEDIA_EXPORT VideoCapture { 20 public: 21 // TODO(wjia): consider merging with media::VideoFrame if possible. 22 class VideoFrameBuffer : public base::RefCountedThreadSafe<VideoFrameBuffer> { 23 public: 24 VideoFrameBuffer() 25 : width(0), 26 height(0), 27 stride(0), 28 buffer_size(0), 29 memory_pointer(NULL) {} 30 31 int width; 32 int height; 33 int stride; 34 size_t buffer_size; 35 uint8* memory_pointer; 36 base::Time timestamp; 37 38 private: 39 friend class base::RefCountedThreadSafe<VideoFrameBuffer>; 40 ~VideoFrameBuffer() {} 41 42 DISALLOW_COPY_AND_ASSIGN(VideoFrameBuffer); 43 }; 44 45 // TODO(wjia): add error codes. 46 // TODO(wjia): support weak ptr. 47 // Callbacks provided by client for notification of events. 48 class MEDIA_EXPORT EventHandler { 49 public: 50 // Notify client that video capture has been started. 51 virtual void OnStarted(VideoCapture* capture) = 0; 52 53 // Notify client that video capture has been stopped. 54 virtual void OnStopped(VideoCapture* capture) = 0; 55 56 // Notify client that video capture has been paused. 57 virtual void OnPaused(VideoCapture* capture) = 0; 58 59 // Notify client that video capture has hit some error |error_code|. 60 virtual void OnError(VideoCapture* capture, int error_code) = 0; 61 62 // Notify client that the client has been removed and no more calls will be 63 // received. 64 virtual void OnRemoved(VideoCapture* capture) = 0; 65 66 // Notify client that a buffer is available. 67 virtual void OnBufferReady(VideoCapture* capture, 68 scoped_refptr<VideoFrameBuffer> buffer) = 0; 69 70 // Notify client about device info. 71 virtual void OnDeviceInfoReceived( 72 VideoCapture* capture, 73 const VideoCaptureParams& device_info) = 0; 74 75 // Notify client about the newly changed device info. 76 virtual void OnDeviceInfoChanged( 77 VideoCapture* capture, 78 const VideoCaptureParams& device_info) {}; 79 80 protected: 81 virtual ~EventHandler() {} 82 }; 83 84 VideoCapture() {} 85 86 // Request video capture to start capturing with |capability|. 87 // Also register |handler| with video capture for event handling. 88 // |handler| must remain valid until it has received |OnRemoved()|. 89 virtual void StartCapture(EventHandler* handler, 90 const VideoCaptureCapability& capability) = 0; 91 92 // Request video capture to stop capturing for client |handler|. 93 // |handler| must remain valid until it has received |OnRemoved()|. 94 virtual void StopCapture(EventHandler* handler) = 0; 95 96 // Feed buffer to video capture when done with it. 97 virtual void FeedBuffer(scoped_refptr<VideoFrameBuffer> buffer) = 0; 98 99 virtual bool CaptureStarted() = 0; 100 virtual int CaptureWidth() = 0; 101 virtual int CaptureHeight() = 0; 102 virtual int CaptureFrameRate() = 0; 103 104 protected: 105 virtual ~VideoCapture() {} 106 107 private: 108 DISALLOW_COPY_AND_ASSIGN(VideoCapture); 109 }; 110 111 } // namespace media 112 113 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_ 114