| OLD | NEW |
| (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_SINK_H_ |
| 6 #define COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/time/time.h" |
| 16 #include "components/video_capture/public/interfaces/video_capture.mojom.h" |
| 17 #include "mojo/public/cpp/bindings/binding.h" |
| 18 |
| 19 namespace media { |
| 20 class VideoFrame; |
| 21 } |
| 22 |
| 23 namespace video_capture { |
| 24 |
| 25 // This class implements a simple sink for Stream frames. A video_capture client |
| 26 // can construct one of these over a Stream in order to start receiving video |
| 27 // frames from the stream. |
| 28 // |
| 29 // As each frame is received, the sink will call all of its frame callbacks |
| 30 // (added via AddFrameCallback) with a corresponding media::VideoFrame object. |
| 31 class StreamClientImpl : public mojom::StreamClient { |
| 32 public: |
| 33 using OnFrameReceivedCallback = |
| 34 base::Callback<void(scoped_refptr<media::VideoFrame>)>; |
| 35 |
| 36 explicit StreamClientImpl(mojom::StreamPtr stream); |
| 37 |
| 38 ~StreamClientImpl() override; |
| 39 |
| 40 // Adds |callback| to the set of callbacks to notify each time a new frame |
| 41 // arrives from the stream. All callbacks are always called from the thread |
| 42 // on which the sink lives. |
| 43 void AddOnFrameReceivedCallback(const OnFrameReceivedCallback& callback); |
| 44 |
| 45 private: |
| 46 class FrameBuffer; |
| 47 |
| 48 // mojom::StreamClient |
| 49 void FrameAvailable(mojom::FrameInfoPtr info, |
| 50 const FrameAvailableCallback& callback) override; |
| 51 void Error(const mojo::String& error) override; |
| 52 |
| 53 // A collection of callbacks to be notified every time a new video frame is |
| 54 // received from the stream. |
| 55 std::vector<OnFrameReceivedCallback> on_frame_received_callbacks_; |
| 56 |
| 57 mojo::Binding<mojom::StreamClient> binding_; |
| 58 |
| 59 mojom::StreamPtr stream_; |
| 60 |
| 61 base::TimeTicks first_frame_time_; |
| 62 |
| 63 DISALLOW_COPY_AND_ASSIGN(StreamClientImpl); |
| 64 }; |
| 65 |
| 66 } // namespace video_capture |
| 67 |
| 68 #endif // COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_ |
| OLD | NEW |