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.
5 // This file contains abstract classes used for media filter to handle video
8 #ifndef MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
9 #define MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/time/time.h"
14 #include "media/base/media_export.h"
15 #include "media/video/capture/video_capture_types.h"
21 class MEDIA_EXPORT VideoCapture {
23 // TODO(wjia): add error codes.
24 // TODO(wjia): support weak ptr.
25 // Callbacks provided by client for notification of events.
26 class MEDIA_EXPORT EventHandler {
28 // Notify client that video capture has been started.
29 virtual void OnStarted(VideoCapture* capture) = 0;
31 // Notify client that video capture has been stopped.
32 virtual void OnStopped(VideoCapture* capture) = 0;
34 // Notify client that video capture has been paused.
35 virtual void OnPaused(VideoCapture* capture) = 0;
37 // Notify client that video capture has hit some error |error_code|.
38 virtual void OnError(VideoCapture* capture, int error_code) = 0;
40 // Notify client that the client has been removed and no more calls will be
42 virtual void OnRemoved(VideoCapture* capture) = 0;
44 // Notify client that a buffer is available.
45 virtual void OnFrameReady(
46 VideoCapture* capture,
47 const scoped_refptr<media::VideoFrame>& frame) = 0;
50 virtual ~EventHandler() {}
53 typedef base::Callback<void(const media::VideoCaptureFormats&)>
54 DeviceFormatsCallback;
56 typedef base::Callback<void(const media::VideoCaptureFormats&)>
57 DeviceFormatsInUseCallback;
61 // Request video capture to start capturing with |params|.
62 // Also register |handler| with video capture for event handling.
63 // |handler| must remain valid until it has received |OnRemoved()|.
64 virtual void StartCapture(EventHandler* handler,
65 const VideoCaptureParams& params) = 0;
67 // Request video capture to stop capturing for client |handler|.
68 // |handler| must remain valid until it has received |OnRemoved()|.
69 virtual void StopCapture(EventHandler* handler) = 0;
71 virtual bool CaptureStarted() = 0;
72 virtual int CaptureFrameRate() = 0;
74 // Request the device capture supported formats. This method can be called
75 // before startCapture() and/or after stopCapture() so a |callback| is used
76 // instead of replying via EventHandler.
77 virtual void GetDeviceSupportedFormats(
78 const DeviceFormatsCallback& callback) = 0;
80 // Request the device capture in-use format(s), possibly by other user(s) in
81 // other renderer(s). If there is no format in use, the vector returned in
82 // the callback will be empty.
83 virtual void GetDeviceFormatsInUse(
84 const DeviceFormatsInUseCallback& callback) = 0;
87 virtual ~VideoCapture() {}
90 DISALLOW_COPY_AND_ASSIGN(VideoCapture);
95 #endif // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_