Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / pepper / pepper_video_source_host.h
bloba1414ceadeb1e44d75d248e5a91b33789b1509ee
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.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_
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"
18 struct PP_ImageDataDesc;
20 namespace content {
22 class RendererPpapiHost;
24 class CONTENT_EXPORT PepperVideoSourceHost : public ppapi::host::ResourceHost {
25 public:
26 PepperVideoSourceHost(RendererPpapiHost* host,
27 PP_Instance instance,
28 PP_Resource resource);
30 virtual ~PepperVideoSourceHost();
32 virtual int32_t OnResourceMessageReceived(
33 const IPC::Message& msg,
34 ppapi::host::HostMessageContext* context) OVERRIDE;
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);
44 // FrameReaderInterface implementation.
45 virtual bool GotFrame(const scoped_refptr<media::VideoFrame>& frame)
46 OVERRIDE;
48 void OnGotFrame(const scoped_refptr<media::VideoFrame>& frame);
50 private:
51 friend class base::RefCountedThreadSafe<FrameReceiver>;
52 virtual ~FrameReceiver();
54 base::WeakPtr<PepperVideoSourceHost> host_;
55 scoped_refptr<base::MessageLoopProxy> main_message_loop_proxy_;
58 friend class FrameReceiver;
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);
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);
71 void Close();
73 RendererPpapiHost* renderer_ppapi_host_;
75 ppapi::host::ReplyMessageContext reply_context_;
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_;
83 base::WeakPtrFactory<PepperVideoSourceHost> weak_factory_;
85 DISALLOW_COPY_AND_ASSIGN(PepperVideoSourceHost);
88 } // namespace content
90 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_