Chromium Code Reviews| 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 MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
| 6 #define MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "media/capture/interfaces/video_capture.mojom.h" | |
| 15 #include "media/capture/service/video_capture_device_client_impl.h" | |
| 16 #include "mojo/public/cpp/bindings/binding.h" | |
| 17 #include "mojo/public/cpp/bindings/interface_request.h" | |
| 18 #include "mojo/public/cpp/system/buffer.h" | |
| 19 | |
| 20 namespace base { | |
| 21 class SingleThreadTaskRunner; | |
| 22 class TimeTicks; | |
| 23 } | |
| 24 | |
| 25 namespace media { | |
| 26 class VideoFrame; | |
| 27 } | |
| 28 | |
| 29 namespace media { | |
| 30 | |
| 31 class MojoVideoFrame; | |
| 32 | |
| 33 // This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we | |
| 34 // push captured VideoFrames. | |
| 35 class StreamImpl : public mojom::Stream, | |
| 36 public VideoCaptureDeviceClientImpl::Delegate { | |
| 37 public: | |
| 38 // |start_callback| is called when this object is started by its client. | |
| 39 // |close_callback| is called when this object is stopped by its client. | |
| 40 // |error_callback| is called upon internal error or NotifyError(). | |
| 41 StreamImpl(mojo::InterfaceRequest<mojom::Stream> request, | |
| 42 const base::Closure& start_callback, | |
| 43 const base::Closure& close_callback, | |
| 44 const base::Closure& error_callback); | |
| 45 | |
| 46 ~StreamImpl() override; | |
| 47 | |
| 48 // mojom::Stream | |
| 49 void Start(mojom::StreamClientPtr client) override; | |
| 50 void Stop() override; | |
| 51 | |
| 52 // VideoCaptureDeviceClientImpl::Delegate | |
| 53 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, | |
| 54 const base::TimeTicks& timestamp) override; | |
| 55 void OnError(const std::string& reason) override; | |
| 56 | |
| 57 private: | |
| 58 friend class StreamImplTest; | |
| 59 | |
| 60 // The following Notify* methods mimic those in StreamClient and act as a | |
| 61 // bridge to Mojo. They all must not be called until the stream has been | |
| 62 // Start()ed. | |
| 63 | |
| 64 // Pushes a |frame| to the client. | |
| 65 void NotifyFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame, | |
| 66 const base::TimeTicks& timestamp); | |
| 67 void NotifyError(const mojo::String& error); | |
| 68 | |
| 69 // Bound for the client to notify us that it's done with the VideoFrame | |
|
perkj_chrome
2016/03/03 13:12:41
bound to what? Bound to the video frame destructor
mcasas
2016/03/03 18:41:15
Explained.
| |
| 70 // identified by |buffer_id|. | |
| 71 void OnFrameConsumed(int32_t buffer_id); | |
| 72 | |
| 73 mojo::Binding<mojom::Stream> binding_; | |
| 74 const base::Closure start_callback_; | |
| 75 const base::Closure close_callback_; | |
| 76 const base::Closure error_callback_; | |
| 77 | |
| 78 mojom::StreamClientPtr client_; | |
| 79 | |
| 80 bool paused_ = false; | |
| 81 | |
| 82 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which | |
| 83 // the client knows it. The buffer ID is just a simple running counter. | |
| 84 int running_buffer_id_ = 0; | |
| 85 std::map<int32_t, const scoped_refptr<MojoVideoFrame>&> in_use_video_frames_; | |
| 86 | |
| 87 // The TaskRunner where this class lives, needed for OnFrame() and OnError() | |
| 88 // to PostTask() to. | |
| 89 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 90 | |
| 91 base::WeakPtrFactory<StreamImpl> weak_factory_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(StreamImpl); | |
| 94 }; | |
| 95 | |
| 96 } // namespace media | |
| 97 | |
| 98 #endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
| OLD | NEW |