1 // Copyright 2015 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/common/content_export.h"
12 #include "media/video/capture/video_capture_device.h"
15 class VideoCaptureBufferPool
;
16 class VideoCaptureController
;
18 // Receives events from the VideoCaptureDevice and posts them to a |controller_|
19 // on the IO thread. An instance of this class may safely outlive its target
20 // VideoCaptureController. This is a shallow class meant to convert incoming
21 // frames and holds no significant state.
23 // Methods of this class may be called from any thread, and in practice will
24 // often be called on some auxiliary thread depending on the platform and the
25 // device type; including, for example, the DirectShow thread on Windows, the
26 // v4l2_thread on Linux, and the UI thread for tab capture.
27 class CONTENT_EXPORT VideoCaptureDeviceClient
28 : public media::VideoCaptureDevice::Client
{
30 VideoCaptureDeviceClient(
31 const base::WeakPtr
<VideoCaptureController
>& controller
,
32 const scoped_refptr
<VideoCaptureBufferPool
>& buffer_pool
);
33 ~VideoCaptureDeviceClient() override
;
35 // VideoCaptureDevice::Client implementation.
36 void OnIncomingCapturedData(const uint8
* data
,
38 const media::VideoCaptureFormat
& frame_format
,
40 const base::TimeTicks
& timestamp
) override
;
41 void OnIncomingCapturedYuvData(const uint8
* y_data
,
47 const media::VideoCaptureFormat
& frame_format
,
48 int clockwise_rotation
,
49 const base::TimeTicks
& timestamp
) override
;
50 scoped_refptr
<Buffer
> ReserveOutputBuffer(media::VideoFrame::Format format
,
51 const gfx::Size
& size
) override
;
52 void OnIncomingCapturedVideoFrame(
53 const scoped_refptr
<Buffer
>& buffer
,
54 const scoped_refptr
<media::VideoFrame
>& frame
,
55 const base::TimeTicks
& timestamp
) override
;
56 void OnError(const std::string
& reason
) override
;
57 void OnLog(const std::string
& message
) override
;
60 // The controller to which we post events.
61 const base::WeakPtr
<VideoCaptureController
> controller_
;
63 // The pool of shared-memory buffers used for capturing.
64 const scoped_refptr
<VideoCaptureBufferPool
> buffer_pool_
;
66 media::VideoPixelFormat last_captured_pixel_format_
;
68 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClient
);
72 } // namespace content
74 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_DEVICE_CLIENT_H_