Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Side by Side Diff: content/browser/renderer_host/video_capture_controller.h

Issue 7002027: VideoCaptureHost (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // VideoCaptureController is the glue between VideoCaptureHost,
6 // VideoCaptureManager and VideoCaptureDevice.
7 // It provides functions for VideoCaptureHost to start a VideoCaptureDevice and
8 // is responsible for keeping track of TransportDIBs and filling them with I420
9 // video frames for IPC communication between VideoCaptureHost and
10 // VideoCaptureMessageFilter.
11 // It implements media::VideoCaptureDevice::EventHandler to get video frames
12 // from a VideoCaptureDevice object and do color conversion straight into the
13 // TransportDIBs to avoid a memory copy.
14
15 #ifndef CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_
16 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_
17
18 #include <list>
19 #include <map>
20
21 #include "base/memory/ref_counted.h"
22 #include "base/synchronization/lock.h"
23 #include "base/task.h"
24 #include "media/video/capture/video_capture_device.h"
25 #include "media/video/capture/video_capture_types.h"
26 #include "ui/gfx/surface/transport_dib.h"
27
28 class VideoCaptureController
29 : public base::RefCountedThreadSafe<VideoCaptureController>,
30 public media::VideoCaptureDevice::EventHandler {
31 public:
32 // Id used for identifying an object of VideoCaptureController.
33 typedef std::pair<int32, int> ControllerId;
34 class EventHandler {
35 public:
36 // An Error have occurred in the VideoCaptureDevice.
37 virtual void OnError(ControllerId id) = 0;
38
39 // An TransportDIB have been filled with I420 video.
40 virtual void OnBufferReady(ControllerId id,
41 TransportDIB::Handle handle,
42 base::Time timestamp) = 0;
43
44 // The frame resolution the VideoCaptureDevice capture video in.
45 virtual void OnFrameInfo(ControllerId id,
46 int width,
47 int height,
48 int frame_rate) = 0;
49
50 // Report that this object can be deleted.
51 virtual void OnReadyToDelete(ControllerId id) = 0;
52
53 protected:
54 virtual ~EventHandler() {}
55 };
56
57 VideoCaptureController(ControllerId id, EventHandler* event_handler);
58 virtual ~VideoCaptureController();
59
60 // Starts video capturing and tries to use the resolution specified in
61 // params.
62 // When capturing has started EventHandler::OnFrameInfo is called with
63 // resolution that best matches the requested that the video capture device
64 // support.
65 void StartCapture(const media::VideoCaptureParams& params);
66
67 // Stop video capture.
68 // When the capture is stopped and all TransportDIBS have been returned
69 // EventHandler::OnReadyToDelete will be called.
70 // stopped_task may be null but it can be used to get a notification when the
71 // device is stopped.
72 void StopCapture(Task* stopped_task);
73
74 // Return a DIB previously given in EventHandler::OnBufferReady.
75 void ReturnTransportDIB(TransportDIB::Handle handle);
76
77 // Implement media::VideoCaptureDevice::EventHandler.
78 virtual void OnIncomingCapturedFrame(const uint8* data,
79 int length,
80 base::Time timestamp);
81 virtual void OnError();
82 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info);
83
84 private:
85 // Called by VideoCaptureManager when a device have been stopped.
86 void OnDeviceStopped(Task* stopped_task);
87
88 // Lock to protect free_dibs_ and owned_dibs_.
89 base::Lock lock_;
90 bool report_ready_to_delete_;
91 typedef std::list<TransportDIB::Handle> DIBHandleList;
92 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap;
93
94 // Free DIBS that can be filled with video frames.
95 DIBHandleList free_dibs_;
96
97 // All DIBS created by this object.
98 DIBMap owned_dibs_;
99 EventHandler* event_handler_;
100
101 // The parameter that was requested when starting the capture device.
102 media::VideoCaptureParams params_;
103
104 // Id used for identifying this object.
105 ControllerId id_;
106 media::VideoCaptureDevice::Capability frame_info_;
107
108 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController);
109 };
110
111 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698