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

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: heave!! 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 "components/video_capture/public/interfaces/video_capture.mojom.h"
15 #include "components/video_capture/video_capture_adapter.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 video_capture {
30
31 class MojoVideoFrame;
32
33 // This class bridges a VideoCaptureAdapter with the mojo pipe where we push
34 // captured VideoFrames.
35 class StreamImpl : public mojom::Stream, public VideoCaptureAdapter::Delegate {
36 public:
37 // |start_callback| is called when this object is started by its client.
38 // |close_callback| is called when this object is stopped by its client.
39 // |error_callback| is called upon internal error or NotifyError().
40 StreamImpl(mojo::InterfaceRequest<mojom::Stream> request,
41 const base::Closure& start_callback,
42 const base::Closure& close_callback,
43 const base::Closure& error_callback);
44
45 ~StreamImpl() override;
46
47 // mojom::Stream
48 void Start(mojom::StreamClientPtr client) override;
49 void Pause() override;
50 void Resume() override;
51 void Stop() override;
52
53 // VideoCaptureAdapter::Delegate
54 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame,
55 const base::TimeTicks& timestamp) override;
56 void OnError(const std::string& reason) override;
57
58 private:
59 friend class StreamImplTest;
60
61 // The following Notify* methods mimic those in StreamClient and act as a
62 // bridge to Mojo. They all must not be called until the stream has been
63 // Start()ed.
64
65 // Pushes a |frame| to the client.
66 void NotifyFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame,
67 const base::TimeTicks& timestamp);
68 void NotifyError(const mojo::String& error);
69
70 // Bound for the client to notify us that it's done with the VideoFrame
71 // identified by |buffer_id|.
72 void OnFrameConsumed(int32_t buffer_id);
73
74 mojo::Binding<mojom::Stream> binding_;
75 const base::Closure start_callback_;
76 const base::Closure close_callback_;
77 const base::Closure error_callback_;
78
79 mojom::StreamClientPtr client_;
80
81 bool paused_ = false;
82
83 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which
84 // the client knows it. The buffer ID is just a simple running counter.
85 int running_buffer_id_ = 0;
86 std::map<int32_t, const scoped_refptr<MojoVideoFrame>&> in_use_video_frames_;
87
88 // The TaskRunner where this class lives, needed for OnFrame() and OnErro() to
89 // PostTask() to.
90 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
91
92 base::WeakPtrFactory<StreamImpl> weak_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(StreamImpl);
95 };
96
97 } // namespace video_capture
98
99 #endif // COMPONENTS_VIDEO_CAPTURE_STREAM_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698