cc: Make picture pile base thread safe.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_video_source_host.h
blob13d7d130f6bed438a6e3cfaab5f6cbed89add55c
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 "base/threading/thread_checker.h"
13 #include "content/common/content_export.h"
14 #include "content/renderer/media/video_source_handler.h"
15 #include "ppapi/c/pp_time.h"
16 #include "ppapi/host/host_message_context.h"
17 #include "ppapi/host/resource_host.h"
19 struct PP_ImageDataDesc;
21 namespace content {
23 class RendererPpapiHost;
25 class CONTENT_EXPORT PepperVideoSourceHost : public ppapi::host::ResourceHost {
26 public:
27 PepperVideoSourceHost(RendererPpapiHost* host,
28 PP_Instance instance,
29 PP_Resource resource);
31 ~PepperVideoSourceHost() override;
33 int32_t OnResourceMessageReceived(
34 const IPC::Message& msg,
35 ppapi::host::HostMessageContext* context) override;
37 private:
38 // This helper object receives frames on a video worker thread and passes
39 // them on to us.
40 class FrameReceiver : public FrameReaderInterface,
41 public base::RefCountedThreadSafe<FrameReceiver> {
42 public:
43 explicit FrameReceiver(const base::WeakPtr<PepperVideoSourceHost>& host);
45 // FrameReaderInterface implementation.
46 void GotFrame(const scoped_refptr<media::VideoFrame>& frame) override;
48 private:
49 friend class base::RefCountedThreadSafe<FrameReceiver>;
50 ~FrameReceiver() override;
52 base::WeakPtr<PepperVideoSourceHost> host_;
53 // |thread_checker_| is bound to the main render thread.
54 base::ThreadChecker thread_checker_;
57 friend class FrameReceiver;
59 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
60 const std::string& stream_url);
61 int32_t OnHostMsgGetFrame(ppapi::host::HostMessageContext* context);
62 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
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);
70 void Close();
72 RendererPpapiHost* renderer_ppapi_host_;
74 ppapi::host::ReplyMessageContext reply_context_;
76 scoped_ptr<VideoSourceHandler> source_handler_;
77 scoped_refptr<FrameReceiver> frame_receiver_;
78 std::string stream_url_;
79 scoped_refptr<media::VideoFrame> last_frame_;
80 bool get_frame_pending_;
82 base::WeakPtrFactory<PepperVideoSourceHost> weak_factory_;
84 DISALLOW_COPY_AND_ASSIGN(PepperVideoSourceHost);
87 } // namespace content
89 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_