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 video_capture::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<video_capture::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 // video_capture::Stream | |
| 49 void Start(video_capture::StreamClientPtr client) override; | |
| 50 void Pause() override; | |
| 51 void Resume() override; | |
| 52 void Stop() override; | |
| 53 | |
| 54 // VideoCaptureDeviceClientImpl::Delegate | |
| 55 void OnFrame(const scoped_refptr<MojoVideoFrame>& frame, | |
| 56 const base::TimeTicks& timestamp) override; | |
| 57 void OnError(const std::string& reason) override; | |
| 58 | |
| 59 private: | |
| 60 friend class StreamImplTest; | |
| 61 | |
| 62 // The following Notify* methods mimic those in StreamClient and act as a | |
| 63 // bridge to Mojo. They all must not be called until the stream has been | |
| 64 // Start()ed. | |
| 65 | |
| 66 // Pushes a |frame| to the client. | |
| 67 void NotifyFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame, | |
| 68 const base::TimeTicks& timestamp); | |
| 69 void NotifyError(const mojo::String& error); | |
| 70 | |
| 71 // Bound for the client to notify us that it's done with the VideoFrame | |
| 72 // identified by |buffer_id|. | |
| 73 void OnFrameConsumed(int32_t buffer_id); | |
| 74 | |
| 75 mojo::Binding<video_capture::Stream> binding_; | |
| 76 const base::Closure start_callback_; | |
| 77 const base::Closure close_callback_; | |
| 78 const base::Closure error_callback_; | |
| 79 | |
| 80 video_capture::StreamClientPtr client_; | |
| 81 | |
| 82 bool paused_ = false; | |
| 83 | |
| 84 // Map of VideoFrames in use by a client. Each VF gets an id assigned by which | |
| 85 // the client knows it. The buffer ID is just a simple running counter. | |
| 86 int running_buffer_id_ = 0; | |
| 87 std::map<int32_t, const scoped_refptr<MojoVideoFrame>&> in_use_video_frames_; | |
| 88 | |
| 89 // The TaskRunner where this class lives, needed for OnFrame() and OnErro() to | |
|
Ken Rockot(use gerrit already)
2016/03/02 02:52:08
nit: OnError()
mcasas
2016/03/02 19:53:51
Done.
| |
| 90 // PostTask() to. | |
| 91 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
| 92 | |
| 93 base::WeakPtrFactory<StreamImpl> weak_factory_; | |
| 94 | |
| 95 DISALLOW_COPY_AND_ASSIGN(StreamImpl); | |
| 96 }; | |
| 97 | |
| 98 } // namespace media | |
| 99 | |
| 100 #endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ | |
| OLD | NEW |