Chromium Code Reviews| 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..62bbddb6fa80370d51db1e9fdc16fd30d19ccf6a |
| --- /dev/null |
| +++ b/components/video_capture/public/cpp/stream_client_impl.h |
| @@ -0,0 +1,66 @@ |
| +// 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 { |
|
Ken Rockot(use gerrit already)
2016/02/12 21:29:51
nit: One of the nice advantages of stashing all mo
|
| + public: |
| + using OnFrameReceivedCallback = |
| + 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 AddOnFrameReceivedCallback(const OnFrameReceivedCallback& callback); |
|
emircan
2016/02/16 17:45:48
I like this idea generally. However, giving multip
mcasas
2016/02/16 23:17:21
After discussing with rockot@, I think I'm removin
|
| + |
| + private: |
| + // mojom::StreamClient |
| + void FrameAvailable(mojom::FrameInfoPtr info, |
| + const FrameAvailableCallback& callback) override; |
| + void Error(const mojo::String& error) override; |
| + |
| + // A collection of callbacks to be notified every time a new video frame is |
| + // received from the stream. |
| + std::vector<OnFrameReceivedCallback> on_frame_received_callbacks_; |
| + |
| + mojo::Binding<mojom::StreamClient> binding_; |
| + |
| + mojom::StreamPtr stream_; |
| + |
| + base::TimeTicks first_frame_time_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StreamClientImpl); |
| +}; |
| + |
| +} // namespace video_capture |
| + |
| +#endif // COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_ |