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

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/process.h"
23 #include "base/synchronization/lock.h"
24 #include "base/task.h"
25 #include "media/video/capture/video_capture_device.h"
26 #include "media/video/capture/video_capture_types.h"
27 #include "ui/gfx/surface/transport_dib.h"
28
29 class VideoCaptureController
30 : public base::RefCountedThreadSafe<VideoCaptureController>,
31 public media::VideoCaptureDevice::EventHandler {
32 public:
33 // Id used for identifying an object of VideoCaptureController.
34 typedef std::pair<int32, int> ControllerId;
35 class EventHandler {
36 public:
37 // An Error have occurred in the VideoCaptureDevice.
38 virtual void OnError(ControllerId id) = 0;
39
40 // An TransportDIB have been filled with I420 video.
41 virtual void OnBufferReady(ControllerId id,
42 TransportDIB::Handle handle,
43 base::Time timestamp) = 0;
44
45 // The frame resolution the VideoCaptureDevice capture video in.
46 virtual void OnFrameInfo(ControllerId id,
47 int width,
48 int height,
49 int frame_rate) = 0;
50
51 // Report that this object can be deleted.
52 virtual void OnReadyToDelete(ControllerId id) = 0;
53
54 protected:
55 virtual ~EventHandler() {}
56 };
57
58 VideoCaptureController(ControllerId id,
59 base::ProcessHandle render_process,
60 EventHandler* event_handler);
61 virtual ~VideoCaptureController();
62
63 // Starts video capturing and tries to use the resolution specified in
64 // params.
65 // When capturing has started EventHandler::OnFrameInfo is called with
66 // resolution that best matches the requested that the video capture device
67 // support.
68 void StartCapture(const media::VideoCaptureParams& params);
69
70 // Stop video capture.
71 // When the capture is stopped and all TransportDIBS have been returned
72 // EventHandler::OnReadyToDelete will be called.
73 // stopped_task may be null but it can be used to get a notification when the
74 // device is stopped.
75 void StopCapture(Task* stopped_task);
76
77 // Return a DIB previously given in EventHandler::OnBufferReady.
78 void ReturnTransportDIB(TransportDIB::Handle handle);
79
80 // Implement media::VideoCaptureDevice::EventHandler.
81 virtual void OnIncomingCapturedFrame(const uint8* data,
82 int length,
83 base::Time timestamp);
84 virtual void OnError();
85 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info);
86
87 private:
88 // Called by VideoCaptureManager when a device have been stopped.
89 void OnDeviceStopped(Task* stopped_task);
90
91 // Lock to protect free_dibs_ and owned_dibs_.
92 base::Lock lock_;
93 // Handle to the render process that will receive the DIBs.
94 base::ProcessHandle render_handle_;
95 bool report_ready_to_delete_;
96 typedef std::list<TransportDIB::Handle> DIBHandleList;
97 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap;
98
99 // Free DIBS that can be filled with video frames.
100 DIBHandleList free_dibs_;
101
102 // All DIBS created by this object.
103 DIBMap owned_dibs_;
104 EventHandler* event_handler_;
105
106 // The parameter that was requested when starting the capture device.
107 media::VideoCaptureParams params_;
108
109 // Id used for identifying this object.
110 ControllerId id_;
111 media::VideoCaptureDevice::Capability frame_info_;
112
113 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureController);
114 };
115
116 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698