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 MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
6 #define MEDIA_CAPTURE_SERVICE_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 class VideoFrame; | |
29 | |
30 // This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we | |
31 // push captured VideoFrames. | |
32 class StreamImpl : public mojom::VideoCaptureStream, | |
perkj_chrome
2016/03/07 23:58:27
yes please change name of this class too.
mcasas
2016/03/08 23:57:29
Done.
| |
33 public VideoCaptureDeviceClientImpl::Delegate { | |
34 public: | |
35 // |start_callback| is called when this object is started by its client. | |
36 // |close_callback| is called when this object is stopped by its client. | |
perkj_chrome
2016/03/07 23:58:27
nit: stop_callback?
mcasas
2016/03/08 23:57:29
Done.
| |
37 // |error_callback| is called upon internal error or NotifyError(). | |
38 StreamImpl(mojo::InterfaceRequest<mojom::VideoCaptureStream> request, | |
39 const base::Closure& start_callback, | |
40 const base::Closure& close_callback, | |
perkj_chrome
2016/03/07 23:58:27
dito?
mcasas
2016/03/08 23:57:29
Done.
| |
41 const base::Closure& error_callback); | |
42 | |
43 ~StreamImpl() override; | |
44 | |
45 // mojom::VideoCaptureStream | |
46 void Start(mojom::VideoCaptureStreamClientPtr client) override; | |
47 void Stop() override; | |
48 | |
49 // VideoCaptureDeviceClientImpl::Delegate | |
50 void OnFrame(const scoped_refptr<MojoSharedBufferVideoFrame>& frame, | |
51 const base::TimeTicks& timestamp) override; | |
52 void OnError(const std::string& reason) override; | |
53 | |
54 private: | |
55 friend class StreamImplTest; | |
56 | |
57 // The following Notify* methods mimic those in StreamClient and act as a | |
perkj_chrome
2016/03/07 23:58:27
Update this comment after StreamClient name change
mcasas
2016/03/08 23:57:29
Done.
| |
58 // bridge to Mojo. They all must not be called until the stream has been | |
59 // Start()ed. | |
60 | |
61 // Pushes a |frame| to the client. | |
62 void NotifyOnFrameAvailable( | |
63 const scoped_refptr<MojoSharedBufferVideoFrame>& frame, | |
64 const base::TimeTicks& timestamp); | |
65 void NotifyError(const mojo::String& error); | |
66 | |
67 // Bound to the client's OnFrameAvailable message to let it notify us that | |
68 // it's | |
69 // finished with the VideoFrame identified by |buffer_id|. | |
70 void OnFrameConsumed(int32_t buffer_id); | |
71 | |
72 mojo::Binding<mojom::VideoCaptureStream> binding_; | |
73 const base::Closure start_callback_; | |
74 const base::Closure close_callback_; | |
perkj_chrome
2016/03/07 23:58:27
nit: stop_callback_
mcasas
2016/03/08 23:57:29
Done.
| |
75 const base::Closure error_callback_; | |
76 | |
77 mojom::VideoCaptureStreamClientPtr client_; | |
78 | |
79 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which | |
80 // the client knows it. The buffer ID is just a simple running counter. | |
81 int running_buffer_id_ = 0; | |
82 std::map<int32_t, scoped_refptr<MojoSharedBufferVideoFrame>> | |
83 in_use_video_frames_; | |
84 | |
85 // The TaskRunner where this class lives, needed for OnFrame() and OnError() | |
86 // to PostTask() to. | |
87 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
88 | |
89 base::WeakPtrFactory<StreamImpl> weak_factory_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(StreamImpl); | |
92 }; | |
93 | |
94 } // namespace media | |
95 | |
96 #endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
OLD | NEW |