Chromium Code Reviews| Index: media/capture/service/stream_impl.h |
| diff --git a/media/capture/service/stream_impl.h b/media/capture/service/stream_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e0c43891b6fa6fecd3de4bab1e5b5988ebae358 |
| --- /dev/null |
| +++ b/media/capture/service/stream_impl.h |
| @@ -0,0 +1,96 @@ |
| +// 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 MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ |
| +#define MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "media/capture/interfaces/video_capture.mojom.h" |
| +#include "media/capture/service/video_capture_device_client_impl.h" |
| +#include "mojo/public/cpp/bindings/binding.h" |
| +#include "mojo/public/cpp/bindings/interface_request.h" |
| +#include "mojo/public/cpp/system/buffer.h" |
| + |
| +namespace base { |
| +class SingleThreadTaskRunner; |
| +class TimeTicks; |
| +} |
| + |
| +namespace media { |
| + |
| +class MojoSharedBufferVideoFrame; |
| +class VideoFrame; |
| + |
| +// This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we |
| +// push captured VideoFrames. |
| +class StreamImpl : public mojom::VideoCaptureStream, |
|
perkj_chrome
2016/03/07 23:58:27
yes please change name of this class too.
mcasas
2016/03/08 23:57:29
Done.
|
| + public VideoCaptureDeviceClientImpl::Delegate { |
| + public: |
| + // |start_callback| is called when this object is started by its client. |
| + // |close_callback| is called when this object is stopped by its client. |
|
perkj_chrome
2016/03/07 23:58:27
nit: stop_callback?
mcasas
2016/03/08 23:57:29
Done.
|
| + // |error_callback| is called upon internal error or NotifyError(). |
| + StreamImpl(mojo::InterfaceRequest<mojom::VideoCaptureStream> request, |
| + const base::Closure& start_callback, |
| + const base::Closure& close_callback, |
|
perkj_chrome
2016/03/07 23:58:27
dito?
mcasas
2016/03/08 23:57:29
Done.
|
| + const base::Closure& error_callback); |
| + |
| + ~StreamImpl() override; |
| + |
| + // mojom::VideoCaptureStream |
| + void Start(mojom::VideoCaptureStreamClientPtr client) override; |
| + void Stop() override; |
| + |
| + // VideoCaptureDeviceClientImpl::Delegate |
| + void OnFrame(const scoped_refptr<MojoSharedBufferVideoFrame>& frame, |
| + const base::TimeTicks& timestamp) override; |
| + void OnError(const std::string& reason) override; |
| + |
| + private: |
| + friend class StreamImplTest; |
| + |
| + // The following Notify* methods mimic those in StreamClient and act as a |
|
perkj_chrome
2016/03/07 23:58:27
Update this comment after StreamClient name change
mcasas
2016/03/08 23:57:29
Done.
|
| + // bridge to Mojo. They all must not be called until the stream has been |
| + // Start()ed. |
| + |
| + // Pushes a |frame| to the client. |
| + void NotifyOnFrameAvailable( |
| + const scoped_refptr<MojoSharedBufferVideoFrame>& frame, |
| + const base::TimeTicks& timestamp); |
| + void NotifyError(const mojo::String& error); |
| + |
| + // Bound to the client's OnFrameAvailable message to let it notify us that |
| + // it's |
| + // finished with the VideoFrame identified by |buffer_id|. |
| + void OnFrameConsumed(int32_t buffer_id); |
| + |
| + mojo::Binding<mojom::VideoCaptureStream> binding_; |
| + const base::Closure start_callback_; |
| + const base::Closure close_callback_; |
|
perkj_chrome
2016/03/07 23:58:27
nit: stop_callback_
mcasas
2016/03/08 23:57:29
Done.
|
| + const base::Closure error_callback_; |
| + |
| + mojom::VideoCaptureStreamClientPtr client_; |
| + |
| + // Map of VideoFrames in use by a client. Each VF gets an id assigned by which |
| + // the client knows it. The buffer ID is just a simple running counter. |
| + int running_buffer_id_ = 0; |
| + std::map<int32_t, scoped_refptr<MojoSharedBufferVideoFrame>> |
| + in_use_video_frames_; |
| + |
| + // The TaskRunner where this class lives, needed for OnFrame() and OnError() |
| + // to PostTask() to. |
| + const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| + |
| + base::WeakPtrFactory<StreamImpl> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StreamImpl); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_CAPTURE_SERVICE_STREAM_IMPL_H_ |