• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/video/capture/video_capture_types.h"
15 
16 namespace media {
17 
18 class VideoFrame;
19 
20 class MEDIA_EXPORT VideoCapture {
21  public:
22   // TODO(wjia): add error codes.
23   // TODO(wjia): support weak ptr.
24   // Callbacks provided by client for notification of events.
25   class MEDIA_EXPORT EventHandler {
26    public:
27     // Notify client that video capture has been started.
28     virtual void OnStarted(VideoCapture* capture) = 0;
29 
30     // Notify client that video capture has been stopped.
31     virtual void OnStopped(VideoCapture* capture) = 0;
32 
33     // Notify client that video capture has been paused.
34     virtual void OnPaused(VideoCapture* capture) = 0;
35 
36     // Notify client that video capture has hit some error |error_code|.
37     virtual void OnError(VideoCapture* capture, int error_code) = 0;
38 
39     // Notify client that the client has been removed and no more calls will be
40     // received.
41     virtual void OnRemoved(VideoCapture* capture) = 0;
42 
43     // Notify client that a buffer is available.
44     virtual void OnFrameReady(
45         VideoCapture* capture,
46         const scoped_refptr<media::VideoFrame>& frame) = 0;
47 
48    protected:
~EventHandler()49     virtual ~EventHandler() {}
50   };
51 
VideoCapture()52   VideoCapture() {}
53 
54   // Request video capture to start capturing with |params|.
55   // Also register |handler| with video capture for event handling.
56   // |handler| must remain valid until it has received |OnRemoved()|.
57   virtual void StartCapture(EventHandler* handler,
58                             const VideoCaptureParams& params) = 0;
59 
60   // Request video capture to stop capturing for client |handler|.
61   // |handler| must remain valid until it has received |OnRemoved()|.
62   virtual void StopCapture(EventHandler* handler) = 0;
63 
64   virtual bool CaptureStarted() = 0;
65   virtual int CaptureFrameRate() = 0;
66 
67  protected:
~VideoCapture()68   virtual ~VideoCapture() {}
69 
70  private:
71   DISALLOW_COPY_AND_ASSIGN(VideoCapture);
72 };
73 
74 }  // namespace media
75 
76 #endif  // MEDIA_VIDEO_CAPTURE_VIDEO_CAPTURE_H_
77