| 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 FrameCallback = base::Callback<void(scoped_refptr<media::VideoFrame>)>; |
| 34 |
| 35 explicit StreamClientImpl(mojom::StreamPtr stream); |
| 36 |
| 37 ~StreamClientImpl() override; |
| 38 |
| 39 // Adds |callback| to the set of callbacks to notify each time a new frame |
| 40 // arrives from the stream. All callbacks are always called from the thread |
| 41 // on which the sink lives. |
| 42 void AddFrameCallback(const FrameCallback& callback); |
| 43 |
| 44 private: |
| 45 class FrameBuffer; |
| 46 |
| 47 // mojom::StreamClient: |
| 48 void BufferCreated(mojom::FrameBufferInfoPtr info) override; |
| 49 void BufferDestroyed(int32_t buffer_id) override; |
| 50 void FrameAvailable(mojom::FrameInfoPtr info, |
| 51 const FrameAvailableCallback& callback) 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<FrameCallback> frame_callbacks_; |
| 56 |
| 57 mojo::Binding<mojom::StreamClient> binding_; |
| 58 |
| 59 mojom::StreamPtr stream_; |
| 60 |
| 61 // A map of shared buffers created by the video_capture service for sharing |
| 62 // captured video frame data. |
| 63 std::map<int32_t, scoped_ptr<FrameBuffer>> buffer_map_; |
| 64 |
| 65 bool first_frame_received_ = false; |
| 66 base::TimeTicks first_frame_time_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(StreamClientImpl); |
| 69 }; |
| 70 |
| 71 } // namespace video_capture |
| 72 |
| 73 #endif // COMPONENTS_VIDEO_CAPTURE_STREAM_SINK_H_ |
| OLD | NEW |