Index: media/capture/service/stream_impl.h |
diff --git a/media/capture/service/stream_impl.h b/media/capture/service/stream_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..332d37d4f8edf71dbe82c54acc940387164c26fa |
--- /dev/null |
+++ b/media/capture/service/stream_impl.h |
@@ -0,0 +1,97 @@ |
+// 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 MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ |
+#define MEDIA_CAPTURE_SERVICE_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 "media/capture/interfaces/video_capture.mojom.h" |
+#include "media/capture/service/video_capture_device_client_impl.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 SingleThreadTaskRunner; |
+class TimeTicks; |
+} |
+ |
+namespace media { |
+class VideoFrame; |
+} |
+ |
+namespace media { |
+ |
+class MojoVideoFrame; |
+ |
+// This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we |
+// push captured VideoFrames. |
+class StreamImpl : public mojom::VideoCaptureStream, |
+ public VideoCaptureDeviceClientImpl::Delegate { |
+ public: |
+ // |start_callback| is called when this object is started by its client. |
+ // |close_callback| is called when this object is stopped by its client. |
+ // |error_callback| is called upon internal error or NotifyError(). |
+ StreamImpl(mojo::InterfaceRequest<mojom::VideoCaptureStream> request, |
+ const base::Closure& start_callback, |
+ const base::Closure& close_callback, |
+ const base::Closure& error_callback); |
+ |
+ ~StreamImpl() override; |
+ |
+ // mojom::VideoCaptureStream |
+ void Start(mojom::VideoCaptureStreamClientPtr client) override; |
+ void Stop() override; |
+ |
+ // VideoCaptureDeviceClientImpl::Delegate |
+ void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, |
+ const base::TimeTicks& timestamp) 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. |
+ |
+ // Pushes a |frame| to the client. |
+ void NotifyOnFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame, |
+ const base::TimeTicks& timestamp); |
+ void NotifyError(const mojo::String& error); |
+ |
+ // Bound to the client's OnFrameAvailable message to let it notify us that |
+ // it's |
+ // finished with the VideoFrame identified by |buffer_id|. |
+ void OnFrameConsumed(int32_t buffer_id); |
+ |
+ mojo::Binding<mojom::VideoCaptureStream> binding_; |
+ const base::Closure start_callback_; |
+ const base::Closure close_callback_; |
+ const base::Closure error_callback_; |
+ |
+ mojom::VideoCaptureStreamClientPtr client_; |
+ |
+ // Map of VideoFrames in use by a client. Each VF gets an id assigned by which |
+ // the client knows it. The buffer ID is just a simple running counter. |
+ int running_buffer_id_ = 0; |
+ std::map<int32_t, scoped_refptr<MojoVideoFrame>> in_use_video_frames_; |
+ |
+ // The TaskRunner where this class lives, needed for OnFrame() and OnError() |
+ // to PostTask() to. |
+ const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
+ |
+ base::WeakPtrFactory<StreamImpl> weak_factory_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(StreamImpl); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ |