Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / pepper / pepper_video_source_host.h
blob8469fc938c050a53bcf3d8ae66c197b69ee372a8
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 "ppapi/c/pp_time.h"
15 #include "ppapi/c/ppb_image_data.h"
16 #include "ppapi/host/host_message_context.h"
17 #include "ppapi/host/resource_host.h"
19 struct PP_ImageDataDesc;
21 namespace media {
22 class VideoFrame;
23 } // namespace media
25 namespace content {
27 class PPB_ImageData_Impl;
28 class RendererPpapiHost;
29 class VideoTrackToPepperAdapter;
31 class CONTENT_EXPORT PepperVideoSourceHost : public ppapi::host::ResourceHost {
32 public:
33 PepperVideoSourceHost(RendererPpapiHost* host,
34 PP_Instance instance,
35 PP_Resource resource);
37 ~PepperVideoSourceHost() override;
39 int32_t OnResourceMessageReceived(
40 const IPC::Message& msg,
41 ppapi::host::HostMessageContext* context) override;
43 private:
44 // Helper object to receive frames on a video worker thread and pass them on
45 // to us.
46 class FrameReceiver;
48 int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
49 const std::string& stream_url);
50 int32_t OnHostMsgGetFrame(ppapi::host::HostMessageContext* context);
51 int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);
53 // Sends the reply to a GetFrame message from the plugin. A reply is always
54 // sent and last_frame_, reply_context_, and get_frame_pending_ are all reset.
55 void SendGetFrameReply();
56 // Sends the reply to a GetFrame message from the plugin in case of an error.
57 void SendGetFrameErrorReply(int32_t error);
59 void Close();
61 ppapi::host::ReplyMessageContext reply_context_;
63 scoped_ptr<VideoTrackToPepperAdapter> frame_source_;
64 scoped_refptr<FrameReceiver> frame_receiver_;
65 std::string stream_url_;
66 scoped_refptr<media::VideoFrame> last_frame_;
67 // An internal frame buffer to avoid reallocations. It is only allocated if
68 // scaling is needed.
69 scoped_refptr<media::VideoFrame> scaled_frame_;
70 bool get_frame_pending_;
71 // We use only one ImageData resource in order to avoid allocating
72 // shared memory repeatedly. We send the same one each time the plugin
73 // requests a frame. For this to work, the plugin must finish using
74 // the ImageData it receives prior to calling GetFrame, and not access
75 // the ImageData until it gets its next callback to GetFrame.
76 scoped_refptr<PPB_ImageData_Impl> shared_image_;
77 PP_ImageDataDesc shared_image_desc_;
79 base::WeakPtrFactory<PepperVideoSourceHost> weak_factory_;
81 DISALLOW_COPY_AND_ASSIGN(PepperVideoSourceHost);
84 } // namespace content
86 #endif // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_