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

Unified Diff: components/video_capture/public/cpp/stream_client_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, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/video_capture/public/cpp/stream_client_impl.h
diff --git a/components/video_capture/public/cpp/stream_client_impl.h b/components/video_capture/public/cpp/stream_client_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..51e6e9eb11aa32909b26ad1662a070bfe679d584
--- /dev/null
+++ b/components/video_capture/public/cpp/stream_client_impl.h
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_
+#define COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_
+
+#include <map>
+#include <vector>
+
+#include "base/callback_forward.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/time/time.h"
+#include "components/video_capture/public/interfaces/video_capture.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+
+namespace media {
+class VideoFrame;
+}
+
+namespace video_capture {
+
+// This class implements a simple sink for Stream frames. A video_capture client
+// can construct one of these over a Stream in order to start receiving video
+// frames from the stream.
+//
+// As each frame is received, the sink will call all of its frame callbacks
+// (added via AddFrameCallback) with a corresponding media::VideoFrame object.
+class StreamClientImpl : public mojom::StreamClient {
+ public:
+ using FrameCallback = base::Callback<void(scoped_refptr<media::VideoFrame>)>;
+
+ explicit StreamClientImpl(mojom::StreamPtr stream);
+
+ ~StreamClientImpl() override;
+
+ // Adds |callback| to the set of callbacks to notify each time a new frame
+ // arrives from the stream. All callbacks are always called from the thread
+ // on which the sink lives.
+ void AddFrameCallback(const FrameCallback& callback);
+
+ private:
+ class FrameBuffer;
+
+ // mojom::StreamClient:
+ void BufferCreated(mojom::FrameBufferInfoPtr info) override;
+ void BufferDestroyed(int32_t buffer_id) override;
+ void FrameAvailable(mojom::FrameInfoPtr info,
+ const FrameAvailableCallback& callback) override;
+
+ // A collection of callbacks to be notified every time a new video frame is
+ // received from the stream.
+ std::vector<FrameCallback> frame_callbacks_;
+
+ mojo::Binding<mojom::StreamClient> binding_;
+
+ mojom::StreamPtr stream_;
+
+ // A map of shared buffers created by the video_capture service for sharing
+ // captured video frame data.
+ std::map<int32_t, scoped_ptr<FrameBuffer>> buffer_map_;
+
+ bool first_frame_received_ = false;
+ base::TimeTicks first_frame_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(StreamClientImpl);
+};
+
+} // namespace video_capture
+
+#endif // COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_

Powered by Google App Engine
This is Rietveld 408576698