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

Side by Side Diff: media/capture/service/video_capture_device_client_impl.h

Issue 1699553002: Mojo Video Capture service in media/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased to using MojoSharedBufferVideoFrame Created 4 years, 9 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 CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_
6 #define CONTENT_BROWSER_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
28 class MojoSharedBufferVideoFrame;
29 class VideoFrame;
30
31 // Device Client implementation. We are owned by a VideoCaptureDevice that calls
32 // with captured data (usually via OnIncomingCapturedData()) that gets converted
33 // into a VideoFrame and sent to our Delegate.
34 // This class uses an internal VideoFramePool, a simple pool where allocated
35 // VideoFrames have a SharedMemory inside. The interface-defined Buffer is a
36 // thin wrapper around those.
37 // This class lives inside whichever thread the VideoCaptureDevice lives. It
38 // sends data back to its unique Delegate in that very thread.
39 class VideoCaptureDeviceClientImpl : public media::VideoCaptureDevice::Client {
40 public:
41 class Delegate {
42 public:
43 virtual ~Delegate() {}
44
45 // Called when a new |frame| is available, on Device Thread.
46 virtual void OnFrame(const scoped_refptr<MojoSharedBufferVideoFrame>& frame,
47 const base::TimeTicks& timestamp) = 0;
48
49 // Called when there has been a fatal error which invalidates capture.
50 virtual void OnError(const std::string& reason) = 0;
51 };
52
53 // The Delegate implementation needs to be thread-safe. More specifically,
54 // each Delegate method should be safe to call on the same arbitrary thread.
55 // |delegate| is not owned and must outlive |this|.
56 explicit VideoCaptureDeviceClientImpl(Delegate* delegate);
57
58 ~VideoCaptureDeviceClientImpl() override;
59
60 private:
61 friend class VideoCaptureDeviceClientImplTest;
62 class VideoFramePool;
63
64 // media::VideoCaptureDevice::Client:
65 void OnIncomingCapturedData(const uint8_t* data,
66 int length,
67 const media::VideoCaptureFormat& frame_format,
68 int clockwise_rotation,
69 const base::TimeTicks& timestamp) override;
70 scoped_ptr<Buffer> ReserveOutputBuffer(
71 const gfx::Size& dimensions,
72 media::VideoPixelFormat pixel_format,
73 media::VideoPixelStorage pixel_storage) override;
74 void OnIncomingCapturedBuffer(scoped_ptr<Buffer> buffer,
75 const media::VideoCaptureFormat& frame_format,
76 const base::TimeTicks& timestamp) override;
77 void OnIncomingCapturedVideoFrame(
78 scoped_ptr<Buffer> buffer,
79 const scoped_refptr<media::VideoFrame>& frame,
80 const base::TimeTicks& timestamp) override;
81 void OnError(const tracked_objects::Location& from_here,
82 const std::string& reason) override;
83 double GetBufferPoolUtilization() const override;
84
85 // The |delegate_| to where we send the capture-converted VideoFrames.
86 Delegate* const delegate_;
87
88 // The underlying multithreaded MojoSharedBufferVideoFrame pool.
89 const scoped_refptr<VideoFramePool> video_frame_pool_;
90
91 // This class is single threaded except construction.
92 base::ThreadChecker thread_checker_;
93
94 base::WeakPtrFactory<VideoCaptureDeviceClientImpl> weak_factory_;
95
96 DISALLOW_COPY_AND_ASSIGN(VideoCaptureDeviceClientImpl);
97 };
98
99 } // namespace media
100
101 #endif // CONTENT_BROWSER_VIDEO_CAPTURE_VIDEO_CAPTURE_ADAPTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698