Chromium Code Reviews| Index: content/renderer/media/android/stream_texture_wrapper_impl.h |
| diff --git a/content/renderer/media/android/stream_texture_wrapper_impl.h b/content/renderer/media/android/stream_texture_wrapper_impl.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fb44e140300c808d2d42f387aa58661dfa4394bb |
| --- /dev/null |
| +++ b/content/renderer/media/android/stream_texture_wrapper_impl.h |
| @@ -0,0 +1,121 @@ |
| +// 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 _CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_ |
|
DaleCurtis
2016/07/21 22:14:23
drop leading _
tguilbert
2016/07/21 23:06:42
Done.
|
| +#define _CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_ |
| + |
| +#include <memory> |
| + |
| +#include "content/renderer/media/android/stream_texture_factory.h" |
| +#include "gpu/command_buffer/common/mailbox.h" |
| +#include "media/base/android/stream_texture_wrapper.h" |
| +#include "media/base/video_frame.h" |
| + |
| +namespace content { |
| + |
| +// Concrete implementation of StreamTextureWrapper. Can be created on any, |
| +// thread, but will be initialized/destroyed on |main_tread_task_runner, and |
|
DaleCurtis
2016/07/21 22:14:22
Missing closing |
tguilbert
2016/07/21 23:06:42
Done.
watk
2016/07/23 03:13:39
main_tread_task_runner is not a thing?
|
| +// will signal the readyness of new frames on |compositor_task_runner_|. |
|
watk
2016/07/23 03:13:39
readiness
|
| +// |
| +// A SurfaceTexture is an Android primitive, joining an Android Surface (the |
| +// producer side, used by MediaPlayer for example) with a GL Texture (the |
| +// consumer side, used by our compositor). Its documentation can be found here: |
| +// https://developer.android.com/reference/android/graphics/SurfaceTexture.html |
| +// |
| +// The StreamTexture is an abstraction allowing Chrome to wrap a SurfaceTexture |
| +// living in the GPU process. It allows VideoFrames to be created from the |
| +// SurfaceTexture's texture, in the Renderer process. |
| +// |
| +// The general idea behind our use of StreamTexture is as follows: |
| +// - We create a client GL texture in the Renderer process. |
| +// - We request the creation of a StreamTexture via the StreamTextureFactory, |
| +// passing the client texture ID. The call is sent to the GPU process via the |
| +// CommandBuffer. The "platform" GL texture reference associated with the client |
| +// texture ID is looked up in the TextureManager. A StreamTexture is then |
| +// created, wrapping a SurfaceTexture created from the texture reference. The |
| +// SurfaceTexture's OnFrameAvailable() callback is tied to StreamTexture's |
| +// OnFrameAvailable(), which fires an IPC accross the GPU channel. |
| +// - We create a StreamTextureProxy in the Renderer process which listens for |
| +// the IPC fired by the StreamTexture's OnFrameAvailable() callback. |
| +// - We bind the StreamTextureProxy's lifetime to the |compositor_task_runner_|. |
| +// - We wrap the client texture into a VideoFrame. |
| +// - When the SurfaceTexture's OnFrameAvailable() callback is fired (and routed |
| +// to the StreamTextureProxy living on the compositor thread), we notify |
| +// |client_| that a new frame is available, via the DidReceiveFrame() callback. |
| +// |
| +// TODO(tguilbert): Register the underlying SurfaceTexture for retrieval in the |
| +// browser process. See crbug.com/627658. |
| +// |
| +class StreamTextureWrapperImpl : public media::StreamTextureWrapper { |
|
DaleCurtis
2016/07/21 22:14:22
Need CONTENT_EXPORT?
tguilbert
2016/07/21 23:06:42
Yes, I'm not building as component ATM however, be
|
| + public: |
| + StreamTextureWrapperImpl( |
| + scoped_refptr<StreamTextureFactory> factory, |
|
tguilbert
2016/07/21 22:03:37
FYI: I looked into moving StreamTextureFactory and
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner); |
|
DaleCurtis
2016/07/21 22:14:23
We use pass-by-value for scoped_refptr now since t
tguilbert
2016/07/21 23:06:42
Done.
|
| + virtual ~StreamTextureWrapperImpl(); |
| + |
| + // StreamTextureWrapper implementation. |
| + |
| + // Creates the underlying StreamTexture. Binds |client|'s DidReceiveFrame() to |
| + // |compositor_task_runner|. |
| + // Can be called from any thread, but runs on |main_task_runner_|. |
| + void Initialize( |
| + cc::VideoFrameProvider::Client* client, |
| + const gfx::Size& natural_size, |
| + const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, |
| + const base::Closure& init_cb) override; |
| + |
| + // Called when the Video size changes. |
| + // Can be called from any thread, but runs on |main_task_runner_|. |
| + void UpdateTextureSize(const gfx::Size& natural_size) override; |
| + |
| + // Returns the latest frame. |
| + // N.B: We create a single VideoFrame at initialization time (and update it |
| + // in UpdateTextureSize()), and repeatedly return it here. The underlying |
| + // texture's changes are signalled via |client_|'s DidReceiveFrame() callback. |
| + scoped_refptr<media::VideoFrame> GetCurrentFrame() override; |
| + |
| + // Destroys the StreamTextureWrapper safely on the |main_task_runner_|. |
| + void Destroy() override; |
| + |
| + private: |
| + void InitializeInternal(const base::Closure& init_cb); |
| + |
| + void ReallocateVideoFrame(const gfx::Size& natural_size); |
| + |
| + void SetCurrentFrameInternal( |
| + const scoped_refptr<media::VideoFrame>& video_frame); |
| + |
| + // GL texture ID allocated to the video. |
| + unsigned int texture_id_; |
|
DaleCurtis
2016/07/21 22:14:23
We try to avoid using unsigned int unless necessar
tguilbert
2016/07/21 23:06:42
StreamTextureFactory returns unsigned. I think thi
DaleCurtis
2016/07/22 18:09:31
They're just "unsigned" though, without the "int"
tguilbert
2016/07/26 00:13:51
Ah, yes :) Done!
|
| + |
| + // GL texture mailbox for |texture_id_| to provide in the VideoFrame, and sync |
| + // point for when the mailbox was produced. |
| + gpu::Mailbox texture_mailbox_; |
| + |
| + // Stream texture ID allocated to the video. |
| + unsigned int stream_id_; |
|
DaleCurtis
2016/07/21 22:14:22
stream_texture_id_ ? Just unsigned as well?
tguilbert
2016/07/21 23:06:42
Yes.
|
| + |
| + // Object for calling back the compositor thread to repaint the video when a |
| + // frame available. It should be bound to the compositor thread. |
| + ScopedStreamTextureProxy stream_texture_proxy_; |
| + |
| + cc::VideoFrameProvider::Client* client_; |
| + |
| + // Size of the allocated underlying texture. |
| + gfx::Size natural_size_; |
| + |
| + scoped_refptr<StreamTextureFactory> factory_; |
| + |
| + base::Lock current_frame_lock_; |
| + scoped_refptr<media::VideoFrame> current_frame_; |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| + |
| + base::WeakPtrFactory<StreamTextureWrapperImpl> weak_factory_; |
| +}; |
|
DaleCurtis
2016/07/21 22:14:22
DISALLOW_COPY_AND_ASSIGN() ?
tguilbert
2016/07/21 23:06:42
Done.
|
| + |
| +} // namespace media |
| + |
| +#endif // _CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_ |