OLD | NEW |
| (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_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | |
6 #define CONTENT_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | |
7 | |
8 #include "base/compiler_specific.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/weak_ptr.h" | |
11 #include "base/threading/thread_checker.h" | |
12 #include "content/child/scoped_web_callbacks.h" | |
13 #include "content/common/content_export.h" | |
14 #include "content/public/renderer/media_stream_video_sink.h" | |
15 #include "third_party/WebKit/public/platform/WebImageCaptureFrameGrabber.h" | |
16 | |
17 namespace blink { | |
18 class WebMediaStreamTrack; | |
19 } | |
20 | |
21 namespace content { | |
22 | |
23 // This class grabs Video Frames from a given Media Stream Video Track, binding | |
24 // a method of an ephemeral SingleShotFrameHandler every time grabFrame() is | |
25 // called. This method receives an incoming media::VideoFrame on a background | |
26 // thread and converts it into the appropriate SkBitmap which is sent back to | |
27 // OnSkBitmap(). This class is single threaded throughout. | |
28 class CONTENT_EXPORT ImageCaptureFrameGrabber final | |
29 : NON_EXPORTED_BASE(public blink::WebImageCaptureFrameGrabber), | |
30 NON_EXPORTED_BASE(public MediaStreamVideoSink) { | |
31 public: | |
32 using SkImageDeliverCB = base::Callback<void(sk_sp<SkImage>)>; | |
33 | |
34 ImageCaptureFrameGrabber(); | |
35 ~ImageCaptureFrameGrabber() override; | |
36 | |
37 // blink::WebImageCaptureFrameGrabber implementation. | |
38 void grabFrame(blink::WebMediaStreamTrack* track, | |
39 blink::WebImageCaptureGrabFrameCallbacks* callbacks) override; | |
40 | |
41 private: | |
42 // Internal class to receive, convert and forward one frame. | |
43 class SingleShotFrameHandler; | |
44 | |
45 void OnSkImage( | |
46 ScopedWebCallbacks<blink::WebImageCaptureGrabFrameCallbacks> callbacks, | |
47 sk_sp<SkImage> image); | |
48 | |
49 // Flag to indicate that there is a frame grabbing in progress. | |
50 bool frame_grab_in_progress_; | |
51 | |
52 base::ThreadChecker thread_checker_; | |
53 base::WeakPtrFactory<ImageCaptureFrameGrabber> weak_factory_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(ImageCaptureFrameGrabber); | |
56 }; | |
57 | |
58 } // namespace content | |
59 | |
60 #endif // CONTENT_RENDERER_MEDIA_IMAGE_CAPTURE_FRAME_GRABBER_H_ | |
OLD | NEW |