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..aad48bf04634261395eef9bf05a83b0dae143fd5 |
| --- /dev/null |
| +++ b/media/capture/service/stream_impl.h |
| @@ -0,0 +1,98 @@ |
| +// 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 VideoFrame; |
| +} |
| + |
| +namespace media { |
| + |
| +class MojoVideoFrame; |
| + |
| +// This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we |
| +// push captured VideoFrames. |
| +class StreamImpl : public mojom::Stream, |
| + 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. |
| + // |error_callback| is called upon internal error or NotifyError(). |
| + StreamImpl(mojo::InterfaceRequest<mojom::Stream> request, |
| + const base::Closure& start_callback, |
| + const base::Closure& close_callback, |
| + const base::Closure& error_callback); |
| + |
| + ~StreamImpl() override; |
| + |
| + // mojom::Stream |
| + void Start(mojom::StreamClientPtr client) override; |
| + void Stop() override; |
| + |
| + // VideoCaptureDeviceClientImpl::Delegate |
| + void OnFrame(const scoped_refptr<MojoVideoFrame>& 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 |
| + // bridge to Mojo. They all must not be called until the stream has been |
| + // Start()ed. |
| + |
| + // Pushes a |frame| to the client. |
| + void NotifyFrameAvailable(const scoped_refptr<MojoVideoFrame>& frame, |
| + const base::TimeTicks& timestamp); |
| + void NotifyError(const mojo::String& error); |
| + |
| + // 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.
|
| + // identified by |buffer_id|. |
| + void OnFrameConsumed(int32_t buffer_id); |
| + |
| + mojo::Binding<mojom::Stream> binding_; |
| + const base::Closure start_callback_; |
| + const base::Closure close_callback_; |
| + const base::Closure error_callback_; |
| + |
| + mojom::StreamClientPtr client_; |
| + |
| + bool paused_ = false; |
| + |
| + // 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, const scoped_refptr<MojoVideoFrame>&> 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_ |