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

Side by Side Diff: components/video_capture/stream_impl.h

Issue 1637793004: [WIP] Mojo Video Capture thingy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 COMPONENTS_VIDEO_CAPTURE_STREAM_IMPL_H_
6 #define COMPONENTS_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 "base/threading/thread_checker.h"
15 #include "components/video_capture/device_client_impl.h"
16 #include "components/video_capture/public/interfaces/video_capture.mojom.h"
17 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/interface_request.h"
19 #include "mojo/public/cpp/system/buffer.h"
20
21 namespace base {
22 class TimeTicks;
23 }
24
25 namespace media {
26 class VideoFrame;
27 }
28
29 namespace video_capture {
30
31 // This class bridges a DeviceClientImpl with the mojo pipe where we push
32 // captured VideoFrames.
33 class StreamImpl : public mojom::Stream, public DeviceClientImpl::Delegate {
34 public:
35 // |start_callback| is called when this object is ready to start receiving
36 // buffer and frame notifications.
37 // |close_callback| is called when this object should be destroyed.
38 StreamImpl(mojo::InterfaceRequest<mojom::Stream> request,
39 const base::Closure& start_callback,
40 const base::Closure& close_callback);
41
42 ~StreamImpl() override;
43
44 // mojom::Stream:
45 void Start(mojom::StreamClientPtr client) override;
46 void Pause() override;
47 void Resume() override;
48
49 // DeviceClientImpl::Delegate
50 void OnFrame(const scoped_refptr<media::VideoFrame>& frame,
51 const base::TimeTicks& timestamp,
52 const base::Closure& release_callback) override;
53 void OnError(const std::string& reason) override;
54
55 private:
56 friend class StreamImplTest;
57
58 // The following Notify* methods mimic those in StreamClient and act as a
59 // bridge to Mojo. They all must not be called until the stream has been
60 // Start()ed.
61
62 // Notifies the client that a new buffer is available.
63 void NotifyBufferCreated(int32_t id,
64 mojo::ScopedSharedBufferHandle handle,
65 size_t size);
66 // Notifies the client that a buffer has been destroyed.
67 void NotifyBufferDestroyed(int32_t id);
68 // Pushes a frame to the client. |release_callback| is run whenever the client
69 // is done with the frame, and is guaranteed to be called eventually.
70 void NotifyFrameAvailable(int32_t buffer_id,
71 const scoped_refptr<media::VideoFrame>& frame,
72 const base::TimeTicks& timestamp,
73 const base::Closure& release_callback);
74
75 // Called when the client notifies us that it's done with the most recent
76 // frame data in the buffer identified by |buffer_id|.
77 void OnFrameConsumed(int32_t buffer_id);
78
79 mojo::Binding<mojom::Stream> binding_;
80 const base::Closure start_callback_;
81 const base::Closure close_callback_;
82 mojom::StreamClientPtr client_;
83
84 bool paused_ = false;
85
86 // Map of pending frame release callbacks. This lets us ensure that any
87 // release callbacks we receive are eventually called even if e.g. the client
88 // connection dies. Indexed by buffer ID.
89 std::map<int32_t, base::Closure> pending_release_callbacks_;
90
91 base::ThreadChecker thread_checker_;
92
93 base::WeakPtrFactory<StreamImpl> weak_factory_;
94
95 DISALLOW_COPY_AND_ASSIGN(StreamImpl);
96 };
97
98 } // namespace video_capture
99
100 #endif // COMPONENTS_VIDEO_CAPTURE_STREAM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698