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

Side by Side Diff: components/video_capture/video_capture_adapter.h

Issue 1637793004: [WIP] Mojo Video Capture thingy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: heave!! Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2016 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 #ifndef COMPONENTS_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_
6 #define COMPONENTS_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_
7
8 #include <string>
9
10 #include "base/callback_forward.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/weak_ptr.h"
13 #include "base/threading/thread_checker.h"
14 #include "media/base/video_capture_types.h"
15 #include "media/base/video_types.h"
16 #include "media/capture/video/video_capture_device.h"
17
18 namespace base {
19 class TimeTicks;
20 }
21
22 namespace gfx {
23 class Size;
24 }
25
26 namespace media {
27 class VideoFrame;
28 }
29
30 namespace video_capture {
31
32 class MojoVideoFrame;
33
34 // Device Client implementation. We are owned by a VideoCaptureDevice that calls
35 // with captured data (usually via OnIncomingCapturedData()) that gets converted
36 // into a VideoFrame and sent to our Delegate.
37 // This class uses an internal VideoFramePool, a simple pool where allocated
38 // VideoFrames have a SharedMemory inside. The interface-defined Buffer is a
39 // thin wrapper around those.
40 // This class lives inside whichever thread the VideoCaptureDevice lives. It
41 // sends data back to its unique Delegate in that very thread.
42 class VideoCaptureAdapter : public media::VideoCaptureDevice::Client {
43 public:
44 class Delegate {
45 public:
46 virtual ~Delegate() {}
47
48 // Called when a new |frame| is available, on Device Thread.
49 virtual void OnFrame(const scoped_refptr<MojoVideoFrame>& frame,
50 const base::TimeTicks& timestamp) = 0;
51
52 // Called when there has been a fatal error which invalidates capture.
53 virtual void OnError(const std::string& reason) = 0;
54 };
55
56 // The Delegate implementation needs to be thread-safe. More specifically,
57 // each Delegate method should be safe to call on the same arbitrary thread.
58 // |delegate| is not owned and must outlive |this|.
59 explicit VideoCaptureAdapter(Delegate* delegate);
60
61 ~VideoCaptureAdapter() override;
62
63 private:
64 friend class VideoCaptureAdapterTest;
65 class VideoFramePool;
66
67 // media::VideoCaptureDevice::Client:
68 void OnIncomingCapturedData(const uint8_t* data,
69 int length,
70 const media::VideoCaptureFormat& frame_format,
71 int clockwise_rotation,
72 const base::TimeTicks& timestamp) override;
73 void OnIncomingCapturedYuvData(const uint8_t* y_data,
74 const uint8_t* u_data,
75 const uint8_t* v_data,
76 size_t y_stride,
77 size_t u_stride,
78 size_t v_stride,
79 const media::VideoCaptureFormat& frame_format,
80 int clockwise_rotation,
81 const base::TimeTicks& timestamp) override;
82 scoped_ptr<Buffer> ReserveOutputBuffer(
83 const gfx::Size& dimensions,
84 media::VideoPixelFormat pixel_format,
85 media::VideoPixelStorage pixel_storage) override;
86 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer,
87 const media::VideoCaptureFormat& frame_format,
88 const base::TimeTicks& timestamp) override;
89 void OnIncomingCapturedVideoFrame(
90 scoped_ptr<Buffer> buffer,
91 const scoped_refptr<media::VideoFrame>& frame,
92 const base::TimeTicks& timestamp) override;
93 void OnError(const tracked_objects::Location& from_here,
94 const std::string& reason) override;
95 double GetBufferPoolUtilization() const override;
96
97 // The |delegate_| to where we send the capture-converted VideoFrames.
98 Delegate* const delegate_;
99
100 // The underlying multithreaded MojoVideoFrame pool.
101 // TODO(mcasas): This shifts the burden of appropriate destruction sequence to
102 // the owner of VideoCaptureDevice and Delegate. Can it be done differently?
103 const scoped_refptr<VideoFramePool> video_frame_pool_;
104
105 // This class is single threaded except construction.
106 base::ThreadChecker thread_checker_;
107
108 base::WeakPtrFactory<VideoCaptureAdapter> weak_factory_;
109
110 DISALLOW_COPY_AND_ASSIGN(VideoCaptureAdapter);
111 };
112
113 } // namespace video_capture
114
115 #endif // COMPONENTS_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698