| 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_SURFACE_TEXTURE_WRAPPER_IMPL_H_ |
| 6 #define _CONTENT_RENDERER_MEDIA_ANDROID_SURFACE_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/video_frame.h" |
| 13 #include "media/blink/surface_texture_frame_provider.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 // Concrete implementation of SurfaceTextureFrameProvider, backed by a |
| 18 // StreamTexture living in the GPU process. |
| 19 // |
| 20 // A SurfaceTexture is an Android primitive, joining an Android Surface (the |
| 21 // producer side, used by MediaPlayer for example) with a GL Texture (the |
| 22 // consumer side, used by our compositor). Its documentation can be found here: |
| 23 // https://developer.android.com/reference/android/graphics/SurfaceTexture.html |
| 24 // |
| 25 // The StreamTexture is an abstraction allowing Chrome to wrap a SurfaceTexture |
| 26 // living in the GPU process. It allows VideoFrames to be created from the |
| 27 // SurfaceTexture's texture, in the Renderer process. |
| 28 // |
| 29 // The general idea behind our use of StreamTexture is as follows: |
| 30 // - We create a client GL texture in the Renderer process. |
| 31 // - We request the creation of a StreamTexture via the StreamTextureFactory, |
| 32 // passing the client texture ID. The call is sent to the GPU process via the |
| 33 // CommandBuffer. The "platform" GL texture reference associated with the client |
| 34 // texture ID is looked up in the TextureManager. A StreamTexture is then |
| 35 // created, wrapping a SurfaceTexture created from the texture reference. The |
| 36 // SurfaceTexture's OnFrameAvailable() callback is tied to StreamTexture's |
| 37 // OnFrameAvailable(), which fires an IPC accross the GPU channel. |
| 38 // - We create a StreamTextureProxy in the Renderer process which listens for |
| 39 // the IPC fired by the StreamTexture's OnFrameAvailable() callback. |
| 40 // - We bind the StreamTextureProxy's lifetime to the |compositor_task_runner_|. |
| 41 // - We wrap the client texture into a VideoFrame. |
| 42 // - When the SurfaceTexture's OnFrameAvailable() callback is fired (and routed |
| 43 // to the StreamTextureProxy living on the compositor thread), we notify |
| 44 // |client_| that a new frame is available, via the DidReceiveFrame() callback. |
| 45 // |
| 46 // N.B: Technically, we only create one VideoFrame, but pretend it is a new one |
| 47 // and ask the compositor to re-paint it whenever the underlying texture's data |
| 48 // has changed. |
| 49 // |
| 50 // TODO(tguilbert): Register the underlying SurfaceTexture for retrieval in the |
| 51 // browser process. See crbug.com/627658. |
| 52 // |
| 53 class SurfaceTextureFrameProviderImpl |
| 54 : public media::SurfaceTextureFrameProvider { |
| 55 public: |
| 56 SurfaceTextureFrameProviderImpl(scoped_refptr<StreamTextureFactory> factory); |
| 57 virtual ~SurfaceTextureFrameProviderImpl(); |
| 58 |
| 59 // SurfaceTextureFrameProvider implementation. |
| 60 void Initialize(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 61 const gfx::Size& natural_size) override; |
| 62 int GetSurfaceTextureIdentifier() override; |
| 63 void UpdateTextureSize(const gfx::Size& natural_size) override; |
| 64 |
| 65 // cc::VideoFrameProvider implementation. |
| 66 void SetVideoFrameProviderClient( |
| 67 cc::VideoFrameProvider::Client* client) override; |
| 68 bool UpdateCurrentFrame(base::TimeTicks deadline_min, |
| 69 base::TimeTicks deadline_max) override; |
| 70 bool HasCurrentFrame() override; |
| 71 scoped_refptr<media::VideoFrame> GetCurrentFrame() override; |
| 72 void PutCurrentFrame() override; |
| 73 |
| 74 private: |
| 75 void ReallocateVideoFrame(const gfx::Size& natural_size); |
| 76 |
| 77 void SetCurrentFrameInternal(scoped_refptr<media::VideoFrame>& video_frame); |
| 78 |
| 79 // GL texture ID allocated to the video. |
| 80 unsigned int texture_id_; |
| 81 |
| 82 // GL texture mailbox for |texture_id_| to provide in the VideoFrame, and sync |
| 83 // point for when the mailbox was produced. |
| 84 gpu::Mailbox texture_mailbox_; |
| 85 |
| 86 // Stream texture ID allocated to the video. |
| 87 unsigned int stream_id_; |
| 88 |
| 89 // Object for calling back the compositor thread to repaint the video when a |
| 90 // frame available. It should be bound to the compositor thread. |
| 91 ScopedStreamTextureProxy stream_texture_proxy_; |
| 92 |
| 93 cc::VideoFrameProvider::Client* client_; |
| 94 |
| 95 // Size of the allocated underlying texture. |
| 96 gfx::Size natural_size_; |
| 97 |
| 98 scoped_refptr<StreamTextureFactory> factory_; |
| 99 |
| 100 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 101 |
| 102 base::Lock current_frame_lock_; |
| 103 scoped_refptr<media::VideoFrame> current_frame_; |
| 104 }; |
| 105 |
| 106 } // namespace media |
| 107 |
| 108 #endif // _CONTENT_RENDERER_MEDIA_ANDROID_SURFACE_TEXTURE_WRAPPER_IMPL_H_ |
| OLD | NEW |