1 // Copyright (c) 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_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_ 6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/memory/ref_counted.h" 10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/weak_ptr.h" 12 #include "content/common/content_export.h" 13 #include "content/renderer/media/video_source_handler.h" 14 #include "ppapi/c/pp_time.h" 15 #include "ppapi/host/host_message_context.h" 16 #include "ppapi/host/resource_host.h" 17 18 struct PP_ImageDataDesc; 19 20 namespace content { 21 22 class RendererPpapiHost; 23 24 class CONTENT_EXPORT PepperVideoSourceHost : public ppapi::host::ResourceHost { 25 public: 26 PepperVideoSourceHost(RendererPpapiHost* host, 27 PP_Instance instance, 28 PP_Resource resource); 29 30 virtual ~PepperVideoSourceHost(); 31 32 virtual int32_t OnResourceMessageReceived( 33 const IPC::Message& msg, 34 ppapi::host::HostMessageContext* context) OVERRIDE; 35 36 private: 37 // This helper object receives frames on a video worker thread and passes 38 // them on to us. 39 class FrameReceiver : public FrameReaderInterface, 40 public base::RefCountedThreadSafe<FrameReceiver> { 41 public: 42 explicit FrameReceiver(const base::WeakPtr<PepperVideoSourceHost>& host); 43 44 // FrameReaderInterface implementation. 45 virtual bool GotFrame(const scoped_refptr<media::VideoFrame>& frame) 46 OVERRIDE; 47 48 void OnGotFrame(const scoped_refptr<media::VideoFrame>& frame); 49 50 private: 51 friend class base::RefCountedThreadSafe<FrameReceiver>; 52 virtual ~FrameReceiver(); 53 54 base::WeakPtr<PepperVideoSourceHost> host_; 55 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_; 56 }; 57 58 friend class FrameReceiver; 59 60 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context, 61 const std::string& stream_url); 62 int32_t OnHostMsgGetFrame(ppapi::host::HostMessageContext* context); 63 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context); 64 65 // Sends the reply to a GetFrame message from the plugin. A reply is always 66 // sent and last_frame_, reply_context_, and get_frame_pending_ are all reset. 67 void SendGetFrameReply(); 68 // Sends the reply to a GetFrame message from the plugin in case of an error. 69 void SendGetFrameErrorReply(int32_t error); 70 71 void Close(); 72 73 RendererPpapiHost* renderer_ppapi_host_; 74 75 ppapi::host::ReplyMessageContext reply_context_; 76 77 scoped_ptr<VideoSourceHandler> source_handler_; 78 scoped_refptr<FrameReceiver> frame_receiver_; 79 std::string stream_url_; 80 scoped_refptr<media::VideoFrame> last_frame_; 81 bool get_frame_pending_; 82 83 base::WeakPtrFactory<PepperVideoSourceHost> weak_factory_; 84 85 DISALLOW_COPY_AND_ASSIGN(PepperVideoSourceHost); 86 }; 87 88 } // namespace content 89 90 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_ 91