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 _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.
| |
| 6 #define _CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "content/renderer/media/android/stream_texture_factory.h" | |
| 11 #include "gpu/command_buffer/common/mailbox.h" | |
| 12 #include "media/base/android/stream_texture_wrapper.h" | |
| 13 #include "media/base/video_frame.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 // Concrete implementation of StreamTextureWrapper. Can be created on any, | |
| 18 // 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?
| |
| 19 // will signal the readyness of new frames on |compositor_task_runner_|. | |
|
watk
2016/07/23 03:13:39
readiness
| |
| 20 // | |
| 21 // A SurfaceTexture is an Android primitive, joining an Android Surface (the | |
| 22 // producer side, used by MediaPlayer for example) with a GL Texture (the | |
| 23 // consumer side, used by our compositor). Its documentation can be found here: | |
| 24 // https://developer.android.com/reference/android/graphics/SurfaceTexture.html | |
| 25 // | |
| 26 // The StreamTexture is an abstraction allowing Chrome to wrap a SurfaceTexture | |
| 27 // living in the GPU process. It allows VideoFrames to be created from the | |
| 28 // SurfaceTexture's texture, in the Renderer process. | |
| 29 // | |
| 30 // The general idea behind our use of StreamTexture is as follows: | |
| 31 // - We create a client GL texture in the Renderer process. | |
| 32 // - We request the creation of a StreamTexture via the StreamTextureFactory, | |
| 33 // passing the client texture ID. The call is sent to the GPU process via the | |
| 34 // CommandBuffer. The "platform" GL texture reference associated with the client | |
| 35 // texture ID is looked up in the TextureManager. A StreamTexture is then | |
| 36 // created, wrapping a SurfaceTexture created from the texture reference. The | |
| 37 // SurfaceTexture's OnFrameAvailable() callback is tied to StreamTexture's | |
| 38 // OnFrameAvailable(), which fires an IPC accross the GPU channel. | |
| 39 // - We create a StreamTextureProxy in the Renderer process which listens for | |
| 40 // the IPC fired by the StreamTexture's OnFrameAvailable() callback. | |
| 41 // - We bind the StreamTextureProxy's lifetime to the |compositor_task_runner_|. | |
| 42 // - We wrap the client texture into a VideoFrame. | |
| 43 // - When the SurfaceTexture's OnFrameAvailable() callback is fired (and routed | |
| 44 // to the StreamTextureProxy living on the compositor thread), we notify | |
| 45 // |client_| that a new frame is available, via the DidReceiveFrame() callback. | |
| 46 // | |
| 47 // TODO(tguilbert): Register the underlying SurfaceTexture for retrieval in the | |
| 48 // browser process. See crbug.com/627658. | |
| 49 // | |
| 50 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
| |
| 51 public: | |
| 52 StreamTextureWrapperImpl( | |
| 53 scoped_refptr<StreamTextureFactory> factory, | |
|
tguilbert
2016/07/21 22:03:37
FYI: I looked into moving StreamTextureFactory and
| |
| 54 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.
| |
| 55 virtual ~StreamTextureWrapperImpl(); | |
| 56 | |
| 57 // StreamTextureWrapper implementation. | |
| 58 | |
| 59 // Creates the underlying StreamTexture. Binds |client|'s DidReceiveFrame() to | |
| 60 // |compositor_task_runner|. | |
| 61 // Can be called from any thread, but runs on |main_task_runner_|. | |
| 62 void Initialize( | |
| 63 cc::VideoFrameProvider::Client* client, | |
| 64 const gfx::Size& natural_size, | |
| 65 const scoped_refptr<base::SingleThreadTaskRunner>& compositor_task_runner, | |
| 66 const base::Closure& init_cb) override; | |
| 67 | |
| 68 // Called when the Video size changes. | |
| 69 // Can be called from any thread, but runs on |main_task_runner_|. | |
| 70 void UpdateTextureSize(const gfx::Size& natural_size) override; | |
| 71 | |
| 72 // Returns the latest frame. | |
| 73 // N.B: We create a single VideoFrame at initialization time (and update it | |
| 74 // in UpdateTextureSize()), and repeatedly return it here. The underlying | |
| 75 // texture's changes are signalled via |client_|'s DidReceiveFrame() callback. | |
| 76 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; | |
| 77 | |
| 78 // Destroys the StreamTextureWrapper safely on the |main_task_runner_|. | |
| 79 void Destroy() override; | |
| 80 | |
| 81 private: | |
| 82 void InitializeInternal(const base::Closure& init_cb); | |
| 83 | |
| 84 void ReallocateVideoFrame(const gfx::Size& natural_size); | |
| 85 | |
| 86 void SetCurrentFrameInternal( | |
| 87 const scoped_refptr<media::VideoFrame>& video_frame); | |
| 88 | |
| 89 // GL texture ID allocated to the video. | |
| 90 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!
| |
| 91 | |
| 92 // GL texture mailbox for |texture_id_| to provide in the VideoFrame, and sync | |
| 93 // point for when the mailbox was produced. | |
| 94 gpu::Mailbox texture_mailbox_; | |
| 95 | |
| 96 // Stream texture ID allocated to the video. | |
| 97 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.
| |
| 98 | |
| 99 // Object for calling back the compositor thread to repaint the video when a | |
| 100 // frame available. It should be bound to the compositor thread. | |
| 101 ScopedStreamTextureProxy stream_texture_proxy_; | |
| 102 | |
| 103 cc::VideoFrameProvider::Client* client_; | |
| 104 | |
| 105 // Size of the allocated underlying texture. | |
| 106 gfx::Size natural_size_; | |
| 107 | |
| 108 scoped_refptr<StreamTextureFactory> factory_; | |
| 109 | |
| 110 base::Lock current_frame_lock_; | |
| 111 scoped_refptr<media::VideoFrame> current_frame_; | |
| 112 | |
| 113 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 114 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 115 | |
| 116 base::WeakPtrFactory<StreamTextureWrapperImpl> weak_factory_; | |
| 117 }; | |
|
DaleCurtis
2016/07/21 22:14:22
DISALLOW_COPY_AND_ASSIGN() ?
tguilbert
2016/07/21 23:06:42
Done.
| |
| 118 | |
| 119 } // namespace media | |
| 120 | |
| 121 #endif // _CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_WRAPPER_IMPL_H_ | |
| OLD | NEW |