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

Side by Side Diff: content/browser/renderer_host/video_capture_memory.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 // VideoCaptureMemory is the glue between VideoCaptureHost, VideoCaptureManager
6 // and VideoCaptrurDevice.
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_MEMORY_H_
16 #define CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_MEMORY_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 VideoCaptureMemory
29 : public base::RefCountedThreadSafe<VideoCaptureMemory>,
30 public media::VideoCaptureDevice::EventHandler {
31 public:
32 // Id used for identifying an object of VideoCaptureMemory
33 typedef std::pair<int32, int> VideoCaptureMemoryId;
34 class EventHandler {
35 public:
36 // An Error have occurred in the VideoCaptureDevice.
37 virtual void OnError(VideoCaptureMemoryId id) = 0;
38 // An TransportDIB have been filled with I420 video.
39 virtual void OnBufferReady(VideoCaptureMemoryId id,
40 TransportDIB::Handle handle,
41 base::Time timestamp) = 0;
42 // The frame resolution the VideoCaptureDevice capture video in.
43 virtual void OnFrameInfo(VideoCaptureMemoryId id,
44 int width,
45 int height,
46 int frame_rate) = 0;
47 // Report that this object can be deleted.
48 virtual void OnReadyToDelete(VideoCaptureMemoryId id) = 0;
49
50 protected:
51 virtual ~EventHandler() {}
52 };
53
54 VideoCaptureMemory(VideoCaptureMemoryId id,
55 VideoCaptureMemory::EventHandler* event_handler);
56 ~VideoCaptureMemory();
57
58 // Starts video capturing and tries to use the resolution specified in
59 // params.
60 // When capturing has started EventHandler::OnFrameInfo is called with
61 // resolution that best matches the requested that the video capture device
62 // support.
63 void StartCapture(const media::VideoCaptureParams& params);
64 // Stop video capture.
65 // When the capture is stopped and all TransportDIBS have been returned
66 // EventHandler::OnReadyToDelete will be called.
67 // stopped_task may be null but it can be used to get a notification when the
68 // device is stopped.
69 void StopCapture(Task* stopped_task);
70 // Return a DIB previously given in EventHandler::OnBufferReady.
71 void ReturnTransportDIB(TransportDIB::Handle handle);
72
73 // Implement media::VideoCaptureDevice::EventHandler
74 virtual void OnIncomingCapturedFrame(const uint8* data,
75 int length,
76 base::Time timestamp);
77 virtual void OnError();
78 virtual void OnFrameInfo(const media::VideoCaptureDevice::Capability& info);
79
80 private:
81 typedef std::list<TransportDIB::Handle> DIBHANDLEList;
wjia(left Chromium) 2011/05/19 04:24:37 typedef precedes where it's used.
Per K 2011/05/19 08:55:31 Done.
82 typedef std::map<TransportDIB::Handle, TransportDIB*> DIBMap;
83
84 // Called by VideoCaptureManager when a device have been stopped.
85 void OnDeviceStopped(Task* stopped_task);
86
87 // Lock to protect free_dibs_.
88 base::Lock lock_;
89 bool report_ready_to_delete_;
90 // Free DIBS that can be filled with video frames.
91 DIBHANDLEList free_dibs_;
92 // All DIBS created by this object.
93 DIBMap owned_dibs_;
94 EventHandler& event_handler_;
95 // The parameter that was requested when starting the capture device.
96 media::VideoCaptureParams params_;
97 // Id used for identifying this object.
98 VideoCaptureMemoryId id_;
99 media::VideoCaptureDevice::Capability frame_info_;
100 };
101
102 #endif // CONTENT_BROWSER_RENDERER_HOST_VIDEO_CAPTURE_MEMORY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698