OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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_FACTORY_ANDROID_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ |
| 7 |
| 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "cc/layers/video_frame_provider.h" |
| 10 #include "content/renderer/gpu/stream_texture_host_android.h" |
| 11 |
| 12 namespace WebKit { |
| 13 class WebGraphicsContext3D; |
| 14 } |
| 15 |
| 16 namespace content { |
| 17 |
| 18 // The proxy class for the gpu thread to notify the compositor thread |
| 19 // when a new video frame is available. |
| 20 class StreamTextureProxy : public StreamTextureHost::Listener { |
| 21 public: |
| 22 explicit StreamTextureProxy(StreamTextureHost* host); |
| 23 virtual ~StreamTextureProxy(); |
| 24 |
| 25 // Initialize and bind to the current thread, which becomes the thread that |
| 26 // a connected client will receive callbacks on. |
| 27 void BindToCurrentThread(int stream_id, int width, int height); |
| 28 |
| 29 bool IsBoundToThread() { return loop_.get() != NULL; } |
| 30 |
| 31 // Setting the target for callback when a frame is available. This function |
| 32 // could be called on both the main thread and the compositor thread. |
| 33 void SetClient(cc::VideoFrameProvider::Client* client); |
| 34 |
| 35 // StreamTextureHost::Listener implementation: |
| 36 virtual void OnFrameAvailable() OVERRIDE; |
| 37 virtual void OnMatrixChanged(const float matrix[16]) OVERRIDE; |
| 38 |
| 39 struct Deleter { |
| 40 inline void operator()(StreamTextureProxy* ptr) const { ptr->Release(); } |
| 41 }; |
| 42 |
| 43 private: |
| 44 // Causes this instance to be deleted on the thread it is bound to. |
| 45 void Release(); |
| 46 |
| 47 scoped_ptr<StreamTextureHost> host_; |
| 48 scoped_refptr<base::MessageLoopProxy> loop_; |
| 49 |
| 50 base::Lock client_lock_; |
| 51 cc::VideoFrameProvider::Client* client_; |
| 52 |
| 53 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureProxy); |
| 54 }; |
| 55 |
| 56 typedef scoped_ptr<StreamTextureProxy, StreamTextureProxy::Deleter> |
| 57 ScopedStreamTextureProxy; |
| 58 |
| 59 // Factory class for managing stream textures. |
| 60 class StreamTextureFactory { |
| 61 public: |
| 62 StreamTextureFactory(WebKit::WebGraphicsContext3D* context, |
| 63 GpuChannelHost* channel, |
| 64 int view_id); |
| 65 ~StreamTextureFactory(); |
| 66 |
| 67 // Create the StreamTextureProxy object. |
| 68 StreamTextureProxy* CreateProxy(); |
| 69 |
| 70 // Send an IPC message to the browser process to request a java surface |
| 71 // object for the given stream_id. After the the surface is created, |
| 72 // it will be passed back to the WebMediaPlayerAndroid object identified by |
| 73 // the player_id. |
| 74 void EstablishPeer(int stream_id, int player_id); |
| 75 |
| 76 // Create the streamTexture and return the stream Id and set the texture id. |
| 77 unsigned CreateStreamTexture(unsigned* texture_id); |
| 78 |
| 79 // Destroy the streamTexture for the given texture Id. |
| 80 void DestroyStreamTexture(unsigned texture_id); |
| 81 |
| 82 private: |
| 83 WebKit::WebGraphicsContext3D* context_; |
| 84 scoped_refptr<GpuChannelHost> channel_; |
| 85 int view_id_; |
| 86 |
| 87 DISALLOW_IMPLICIT_CONSTRUCTORS(StreamTextureFactory); |
| 88 }; |
| 89 |
| 90 } // namespace content |
| 91 |
| 92 #endif // CONTENT_RENDERER_MEDIA_ANDROID_STREAM_TEXTURE_FACTORY_ANDROID_H_ |
OLD | NEW |