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

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

Issue 1699553002: Mojo Video Capture service in media/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@s comments and renaming 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 MEDIA_CAPTURE_SERVICE_VIDEO_CAPTURE_STREAM_IMPL_H_
6 #define MEDIA_CAPTURE_SERVICE_VIDEO_CAPTURE_STREAM_IMPL_H_
7
8 #include <map>
9
10 #include "base/callback.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "media/capture/interfaces/video_capture.mojom.h"
15 #include "media/capture/service/video_capture_device_client_impl.h"
16 #include "mojo/public/cpp/bindings/binding.h"
17 #include "mojo/public/cpp/bindings/interface_request.h"
18 #include "mojo/public/cpp/system/buffer.h"
19
20 namespace base {
21 class SingleThreadTaskRunner;
22 class TimeTicks;
23 }
24
25 namespace media {
26
27 class MojoSharedBufferVideoFrame;
28
29 // This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we
30 // push captured VideoFrames.
31 class VideoCaptureStreamImpl : public mojom::VideoCaptureStream,
32 public VideoCaptureDeviceClientImpl::Delegate {
33 public:
34 // |stop_callback| is called when this object is stopped by its client.
35 // |error_callback| is called upon internal error or NotifyError().
36 VideoCaptureStreamImpl(
37 mojo::InterfaceRequest<mojom::VideoCaptureStream> request,
38 const base::Closure& stop_callback,
39 const base::Closure& error_callback);
40
41 ~VideoCaptureStreamImpl() override;
42
43 // mojom::VideoCaptureStream
44 void Start(mojom::VideoCaptureStreamClientPtr client) override;
45 void Stop() override;
46
47 // VideoCaptureDeviceClientImpl::Delegate
48 void OnFrame(const scoped_refptr<MojoSharedBufferVideoFrame>& frame,
49 const base::TimeTicks& timestamp) override;
50 void OnError(const std::string& reason) override;
51
52 private:
53 friend class VideoCaptureStreamImplTest;
54
55 // The following Notify* methods mimic those in VideoCaptureStreamClient and
56 // act as a bridge to Mojo. They all must not be called until the stream has
57 // been Start()ed.
58
59 // Pushes a |frame| to the client.
60 void NotifyOnFrameAvailable(
61 const scoped_refptr<MojoSharedBufferVideoFrame>& frame,
62 const base::TimeTicks& timestamp);
63 void NotifyError(const mojo::String& error);
64
65 // Bound to the client's OnFrameAvailable message to let it notify us that
66 // it's finished with the VideoFrame identified by |buffer_id|.
67 void OnFrameConsumed(int32_t buffer_id);
68
69 mojo::Binding<mojom::VideoCaptureStream> binding_;
70 const base::Closure stop_callback_;
71 const base::Closure error_callback_;
72
73 mojom::VideoCaptureStreamClientPtr client_;
74
75 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which
76 // the client knows it. The buffer ID is just a simple running counter.
77 int running_buffer_id_ = 0;
78 std::map<int32_t, scoped_refptr<MojoSharedBufferVideoFrame>>
79 in_use_video_frames_;
80
81 // The TaskRunner where this class lives, needed for OnFrame() and OnError()
82 // to PostTask() to.
83 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
84
85 base::WeakPtrFactory<VideoCaptureStreamImpl> weak_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(VideoCaptureStreamImpl);
88 };
89
90 } // namespace media
91
92 #endif // MEDIA_CAPTURE_SERVICE_VIDEO_CAPTURE_STREAM_IMPL_H_
OLDNEW
« no previous file with comments | « media/capture/service/video_capture_handler_impl_unittest.cc ('k') | media/capture/service/video_capture_stream_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698