OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ |
6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 23 matching lines...) Expand all Loading... |
34 // The proxy class for the gpu thread to notify the compositor thread | 34 // The proxy class for the gpu thread to notify the compositor thread |
35 // when a new video frame is available. | 35 // when a new video frame is available. |
36 class StreamTextureProxy : public StreamTextureHost::Listener { | 36 class StreamTextureProxy : public StreamTextureHost::Listener { |
37 public: | 37 public: |
38 ~StreamTextureProxy() override; | 38 ~StreamTextureProxy() override; |
39 | 39 |
40 // Initialize and bind to |task_runner|, which becomes the thread that the | 40 // Initialize and bind to |task_runner|, which becomes the thread that the |
41 // provided callback will be run on. This can be called on any thread, but | 41 // provided callback will be run on. This can be called on any thread, but |
42 // must be called with the same |task_runner| every time. | 42 // must be called with the same |task_runner| every time. |
43 void BindToTaskRunner( | 43 void BindToTaskRunner( |
44 int32_t stream_id, | |
45 const base::Closure& received_frame_cb, | 44 const base::Closure& received_frame_cb, |
46 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 45 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
47 | 46 |
48 // StreamTextureHost::Listener implementation: | 47 // StreamTextureHost::Listener implementation: |
49 void OnFrameAvailable() override; | 48 void OnFrameAvailable() override; |
50 | 49 |
| 50 // Set the streamTexture size. |
| 51 void SetStreamTextureSize(const gfx::Size& size); |
| 52 |
| 53 // Send an IPC message to the browser process to request a java surface |
| 54 // object for the given route_id. After the the surface is created, |
| 55 // it will be passed back to the WebMediaPlayerAndroid object identified by |
| 56 // the player_id. |
| 57 void EstablishPeer(int player_id, int frame_id); |
| 58 |
| 59 // Sends an IPC to the GPU process. |
| 60 // Asks the StreamTexture to forward its SurfaceTexture to the |
| 61 // ScopedSurfaceRequestManager, using the gpu::ScopedSurfaceRequestConduit. |
| 62 void ForwardStreamTextureForSurfaceRequest( |
| 63 const base::UnguessableToken& request_token); |
| 64 |
51 struct Deleter { | 65 struct Deleter { |
52 inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); } | 66 inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); } |
53 }; | 67 }; |
54 private: | 68 private: |
55 friend class StreamTextureFactory; | 69 friend class StreamTextureFactory; |
56 explicit StreamTextureProxy(StreamTextureHost* host); | 70 explicit StreamTextureProxy(StreamTextureHost* host); |
57 | 71 |
58 void BindOnThread(int32_t stream_id); | 72 void BindOnThread(); |
59 void Release(); | 73 void Release(); |
60 | 74 |
61 const std::unique_ptr<StreamTextureHost> host_; | 75 const std::unique_ptr<StreamTextureHost> host_; |
62 | 76 |
63 // Protects access to |received_frame_cb_| and |task_runner_|. | 77 // Protects access to |received_frame_cb_| and |task_runner_|. |
64 base::Lock lock_; | 78 base::Lock lock_; |
65 base::Closure received_frame_cb_; | 79 base::Closure received_frame_cb_; |
66 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 80 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
67 | 81 |
68 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxy); | 82 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxy); |
69 }; | 83 }; |
70 | 84 |
71 typedef std::unique_ptr<StreamTextureProxy, StreamTextureProxy::Deleter> | 85 typedef std::unique_ptr<StreamTextureProxy, StreamTextureProxy::Deleter> |
72 ScopedStreamTextureProxy; | 86 ScopedStreamTextureProxy; |
73 | 87 |
74 // Factory class for managing stream textures. | 88 // Factory class for managing stream textures. |
75 class CONTENT_EXPORT StreamTextureFactory | 89 class CONTENT_EXPORT StreamTextureFactory |
76 : public base::RefCounted<StreamTextureFactory> { | 90 : public base::RefCounted<StreamTextureFactory> { |
77 public: | 91 public: |
78 static scoped_refptr<StreamTextureFactory> Create( | 92 static scoped_refptr<StreamTextureFactory> Create( |
79 scoped_refptr<ContextProviderCommandBuffer> context_provider); | 93 scoped_refptr<ContextProviderCommandBuffer> context_provider); |
80 | 94 |
81 // Create the StreamTextureProxy object. | 95 // Create the StreamTextureProxy object. This internally calls |
82 StreamTextureProxy* CreateProxy(); | 96 // CreateSteamTexture with the recieved arguments. CreateSteamTexture |
83 | 97 // generates a texture and stores it in *texture_id, the texture is produced |
84 // Send an IPC message to the browser process to request a java surface | 98 // into a mailbox so it can be shipped in a VideoFrame, it creates a |
85 // object for the given stream_id. After the the surface is created, | 99 // gpu::StreamTexture and returns its route_id. If this route_id is invalid |
86 // it will be passed back to the WebMediaPlayerAndroid object identified by | 100 // nullptr is returned and *texture_id will be set to 0. If the route_id is |
87 // the player_id. | 101 // valid it returns StreamTextureProxy object. The caller needs to take care |
88 void EstablishPeer(int32_t stream_id, int player_id, int frame_id); | 102 // of cleaning up the texture_id. |
89 | 103 StreamTextureProxy* CreateProxy(unsigned texture_target, |
90 // Sends an IPC to the GPU process. | 104 unsigned* texture_id, |
91 // Asks the StreamTexture to forward its SurfaceTexture to the | 105 gpu::Mailbox* texture_mailbox); |
92 // ScopedSurfaceRequestManager, using the gpu::ScopedSurfaceRequestConduit. | |
93 void ForwardStreamTextureForSurfaceRequest( | |
94 int32_t stream_id, | |
95 const base::UnguessableToken& request_token); | |
96 | |
97 // Creates a gpu::StreamTexture and returns its id. Sets |*texture_id| to the | |
98 // client-side id of the gpu::StreamTexture. The texture is produced into | |
99 // a mailbox so it can be shipped in a VideoFrame. | |
100 unsigned CreateStreamTexture(unsigned texture_target, | |
101 unsigned* texture_id, | |
102 gpu::Mailbox* texture_mailbox); | |
103 | |
104 // Set the streamTexture size for the given stream Id. | |
105 void SetStreamTextureSize(int32_t texture_id, const gfx::Size& size); | |
106 | 106 |
107 gpu::gles2::GLES2Interface* ContextGL(); | 107 gpu::gles2::GLES2Interface* ContextGL(); |
108 | 108 |
109 private: | 109 private: |
110 friend class base::RefCounted<StreamTextureFactory>; | 110 friend class base::RefCounted<StreamTextureFactory>; |
111 StreamTextureFactory( | 111 StreamTextureFactory( |
112 scoped_refptr<ContextProviderCommandBuffer> context_provider); | 112 scoped_refptr<ContextProviderCommandBuffer> context_provider); |
113 ~StreamTextureFactory(); | 113 ~StreamTextureFactory(); |
| 114 // Creates a gpu::StreamTexture and returns its id. Sets |*texture_id| to the |
| 115 // client-side id of the gpu::StreamTexture. The texture is produced into |
| 116 // a mailbox so it can be shipped in a VideoFrame. |
| 117 unsigned CreateStreamTexture(unsigned texture_target, |
| 118 unsigned* texture_id, |
| 119 gpu::Mailbox* texture_mailbox); |
114 | 120 |
115 scoped_refptr<ContextProviderCommandBuffer> context_provider_; | 121 scoped_refptr<ContextProviderCommandBuffer> context_provider_; |
116 scoped_refptr<gpu::GpuChannelHost> channel_; | 122 scoped_refptr<gpu::GpuChannelHost> channel_; |
117 | 123 |
118 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactory); | 124 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactory); |
119 }; | 125 }; |
120 | 126 |
121 } // namespace content | 127 } // namespace content |
122 | 128 |
123 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ | 129 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_H_ |
OLD | NEW |