| Index: media/capture/service/video_capture_stream_impl.h
|
| diff --git a/media/capture/service/video_capture_stream_impl.h b/media/capture/service/video_capture_stream_impl.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4c26323b1284d7a395d8d302ec6d555a99382c0a
|
| --- /dev/null
|
| +++ b/media/capture/service/video_capture_stream_impl.h
|
| @@ -0,0 +1,92 @@
|
| +// 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_VIDEO_CAPTURE_STREAM_IMPL_H_
|
| +#define MEDIA_CAPTURE_SERVICE_VIDEO_CAPTURE_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;
|
| +
|
| +// This class bridges a VideoCaptureDeviceClientImpl with the mojo pipe where we
|
| +// push captured VideoFrames.
|
| +class VideoCaptureStreamImpl : public mojom::VideoCaptureStream,
|
| + public VideoCaptureDeviceClientImpl::Delegate {
|
| + public:
|
| + // |stop_callback| is called when this object is stopped by its client.
|
| + // |error_callback| is called upon internal error or NotifyError().
|
| + VideoCaptureStreamImpl(
|
| + mojo::InterfaceRequest<mojom::VideoCaptureStream> request,
|
| + const base::Closure& stop_callback,
|
| + const base::Closure& error_callback);
|
| +
|
| + ~VideoCaptureStreamImpl() 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 VideoCaptureStreamImplTest;
|
| +
|
| + // The following Notify* methods mimic those in VideoCaptureStreamClient 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 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 stop_callback_;
|
| + 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<VideoCaptureStreamImpl> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(VideoCaptureStreamImpl);
|
| +};
|
| +
|
| +} // namespace media
|
| +
|
| +#endif // MEDIA_CAPTURE_SERVICE_VIDEO_CAPTURE_STREAM_IMPL_H_
|
|
|