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

Unified 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, 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/stream_impl.h
diff --git a/components/video_capture/stream_impl.h b/components/video_capture/stream_impl.h
new file mode 100644
index 0000000000000000000000000000000000000000..117b1d75b8ae6bb2bfc46ff64201ebcb8575669f
--- /dev/null
+++ b/components/video_capture/stream_impl.h
@@ -0,0 +1,100 @@
+// 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_IMPL_H_
+#define COMPONENTS_VIDEO_CAPTURE_STREAM_IMPL_H_
+
+#include <map>
+
+#include "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/weak_ptr.h"
+#include "base/threading/thread_checker.h"
+#include "components/video_capture/device_client_impl.h"
+#include "components/video_capture/public/interfaces/video_capture.mojom.h"
+#include "mojo/public/cpp/bindings/binding.h"
+#include "mojo/public/cpp/bindings/interface_request.h"
+#include "mojo/public/cpp/system/buffer.h"
+
+namespace base {
+class TimeTicks;
+}
+
+namespace media {
+class VideoFrame;
+}
+
+namespace video_capture {
+
+// This class bridges a DeviceClientImpl with the mojo pipe where we push
+// captured VideoFrames.
+class StreamImpl : public mojom::Stream, public DeviceClientImpl::Delegate {
+ public:
+ // |start_callback| is called when this object is ready to start receiving
+ // buffer and frame notifications.
+ // |close_callback| is called when this object should be destroyed.
+ StreamImpl(mojo::InterfaceRequest<mojom::Stream> request,
+ const base::Closure& start_callback,
+ const base::Closure& close_callback);
+
+ ~StreamImpl() override;
+
+ // mojom::Stream:
+ void Start(mojom::StreamClientPtr client) override;
+ void Pause() override;
+ void Resume() override;
+
+ // DeviceClientImpl::Delegate
+ void OnFrame(const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp,
+ const base::Closure& release_callback) override;
+ void OnError(const std::string& reason) override;
+
+ private:
+ friend class StreamImplTest;
+
+ // The following Notify* methods mimic those in StreamClient and act as a
+ // bridge to Mojo. They all must not be called until the stream has been
+ // Start()ed.
+
+ // Notifies the client that a new buffer is available.
+ void NotifyBufferCreated(int32_t id,
+ mojo::ScopedSharedBufferHandle handle,
+ size_t size);
+ // Notifies the client that a buffer has been destroyed.
+ void NotifyBufferDestroyed(int32_t id);
+ // Pushes a frame to the client. |release_callback| is run whenever the client
+ // is done with the frame, and is guaranteed to be called eventually.
+ void NotifyFrameAvailable(int32_t buffer_id,
+ const scoped_refptr<media::VideoFrame>& frame,
+ const base::TimeTicks& timestamp,
+ const base::Closure& release_callback);
+
+ // Called when the client notifies us that it's done with the most recent
+ // frame data in the buffer identified by |buffer_id|.
+ void OnFrameConsumed(int32_t buffer_id);
+
+ mojo::Binding<mojom::Stream> binding_;
+ const base::Closure start_callback_;
+ const base::Closure close_callback_;
+ mojom::StreamClientPtr client_;
+
+ bool paused_ = false;
+
+ // Map of pending frame release callbacks. This lets us ensure that any
+ // release callbacks we receive are eventually called even if e.g. the client
+ // connection dies. Indexed by buffer ID.
+ std::map<int32_t, base::Closure> pending_release_callbacks_;
+
+ base::ThreadChecker thread_checker_;
+
+ base::WeakPtrFactory<StreamImpl> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(StreamImpl);
+};
+
+} // namespace video_capture
+
+#endif // COMPONENTS_VIDEO_CAPTURE_STREAM_IMPL_H_

Powered by Google App Engine
This is Rietveld 408576698