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 class VideoFrame; | |
27 } | |
28 | |
29 namespace media { | |
30 | |
31 class MojoVideoFrame; | |
32 | |
33 // This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we | |
34 // push captured VideoFrames. | |
35 class StreamImpl : public mojom::VideoCaptureStream, | |
36 public VideoCaptureDeviceClientImpl::Delegate { | |
37 public: | |
38 // |start_callback| is called when this object is started by its client. | |
39 // |close_callback| is called when this object is stopped by its client. | |
40 // |error_callback| is called upon internal error or NotifyError(). | |
41 StreamImpl(mojo::InterfaceRequest<mojom::VideoCaptureStream> request, | |
42 const base::Closure& start_callback, | |
43 const base::Closure& close_callback, | |
44 const base::Closure& error_callback); | |
45 | |
46 ~StreamImpl() override; | |
47 | |
48 // mojom::VideoCaptureStream | |
49 void Start(mojom::VideoCaptureStreamClientPtr client) override; | |
50 void Stop() override; | |
51 | |
52 // VideoCaptureDeviceClientImpl::Delegate | |
53 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, | |
54 const base::TimeTicks& timestamp) override; | |
55 void OnError(const std::string& reason) override; | |
56 | |
57 private: | |
58 friend class StreamImplTest; | |
59 | |
60 // The following Notify* methods mimic those in StreamClient and act as a | |
61 // bridge to Mojo. They all must not be called until the stream has been | |
62 // Start()ed. | |
63 | |
64 // Pushes a |frame| to the client. | |
65 void NotifyFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame, | |
66 const base::TimeTicks& timestamp); | |
67 void NotifyError(const mojo::String& error); | |
68 | |
69 // Bound to the client's FrameAvailable message to let it notify us that it's | |
70 // finished with the VideoFrame identified by |buffer_id|. | |
71 void OnFrameConsumed(int32_t buffer_id); | |
72 | |
73 mojo::Binding<mojom::VideoCaptureStream> binding_; | |
74 const base::Closure start_callback_; | |
75 const base::Closure close_callback_; | |
76 const base::Closure error_callback_; | |
77 | |
78 mojom::VideoCaptureStreamClientPtr client_; | |
79 | |
80 bool paused_ = false; | |
perkj_chrome
2016/03/04 15:34:02
not used ?
mcasas
2016/03/04 19:59:45
Done.
| |
81 | |
82 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which | |
83 // the client knows it. The buffer ID is just a simple running counter. | |
84 int running_buffer_id_ = 0; | |
85 std::map<int32_t, const scoped_refptr<MojoVideoFrame>&> in_use_video_frames_; | |
magjed_chromium
2016/03/04 15:41:42
nit: I would prefer the variable name |video_frame
magjed_chromium
2016/03/04 15:41:42
The value type in this std::map is a const-ref, wh
mcasas
2016/03/04 19:59:45
Done.
mcasas
2016/03/04 19:59:46
Then we'll change it of course.
magjed_chromium
2016/03/07 15:36:24
Yes, but you never access the mapped frame in the
mcasas
2016/03/07 20:57:49
Maybe we're not understanding how I thought this
w
magjed_chromium
2016/03/09 14:11:18
I didn't grok the purpose of this map since you do
| |
86 | |
87 // The TaskRunner where this class lives, needed for OnFrame() and OnError() | |
88 // to PostTask() to. | |
89 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
90 | |
91 base::WeakPtrFactory<StreamImpl> weak_factory_; | |
92 | |
93 DISALLOW_COPY_AND_ASSIGN(StreamImpl); | |
94 }; | |
95 | |
96 } // namespace media | |
97 | |
98 #endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
OLD | NEW |