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