File: pepper_video_source_host.h

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (101 lines) | stat: -rw-r--r-- 3,643 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_
#define CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_

#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h"
#include "content/common/content_export.h"
#include "content/renderer/media/video_source_handler.h"
#include "ppapi/c/pp_time.h"
#include "ppapi/c/ppb_image_data.h"
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/resource_host.h"

struct PP_ImageDataDesc;

namespace content {

class PPB_ImageData_Impl;
class RendererPpapiHost;

class CONTENT_EXPORT PepperVideoSourceHost : public ppapi::host::ResourceHost {
 public:
  PepperVideoSourceHost(RendererPpapiHost* host,
                        PP_Instance instance,
                        PP_Resource resource);

  ~PepperVideoSourceHost() override;

  int32_t OnResourceMessageReceived(
      const IPC::Message& msg,
      ppapi::host::HostMessageContext* context) override;

 private:
  // This helper object receives frames on a video worker thread and passes
  // them on to us.
  class FrameReceiver : public FrameReaderInterface,
                        public base::RefCountedThreadSafe<FrameReceiver> {
   public:
    explicit FrameReceiver(const base::WeakPtr<PepperVideoSourceHost>& host);

    // FrameReaderInterface implementation.
    void GotFrame(const scoped_refptr<media::VideoFrame>& frame) override;

   private:
    friend class base::RefCountedThreadSafe<FrameReceiver>;
    ~FrameReceiver() override;

    base::WeakPtr<PepperVideoSourceHost> host_;
    // |thread_checker_| is bound to the main render thread.
    base::ThreadChecker thread_checker_;
  };

  friend class FrameReceiver;

  int32_t OnHostMsgOpen(ppapi::host::HostMessageContext* context,
                        const std::string& stream_url);
  int32_t OnHostMsgGetFrame(ppapi::host::HostMessageContext* context);
  int32_t OnHostMsgClose(ppapi::host::HostMessageContext* context);

  // Sends the reply to a GetFrame message from the plugin. A reply is always
  // sent and last_frame_, reply_context_, and get_frame_pending_ are all reset.
  void SendGetFrameReply();
  // Sends the reply to a GetFrame message from the plugin in case of an error.
  void SendGetFrameErrorReply(int32_t error);

  void Close();

  RendererPpapiHost* renderer_ppapi_host_;

  ppapi::host::ReplyMessageContext reply_context_;

  scoped_ptr<VideoSourceHandler> source_handler_;
  scoped_refptr<FrameReceiver> frame_receiver_;
  std::string stream_url_;
  scoped_refptr<media::VideoFrame> last_frame_;
  // An internal frame buffer to avoid reallocations. It is only allocated if
  // scaling is needed.
  scoped_refptr<media::VideoFrame> scaled_frame_;
  bool get_frame_pending_;
  // We use only one ImageData resource in order to avoid allocating
  // shared memory repeatedly. We send the same one each time the plugin
  // requests a frame. For this to work, the plugin must finish using
  // the ImageData it receives prior to calling GetFrame, and not access
  // the ImageData until it gets its next callback to GetFrame.
  scoped_refptr<PPB_ImageData_Impl> shared_image_;
  PP_ImageDataDesc shared_image_desc_;

  base::WeakPtrFactory<PepperVideoSourceHost> weak_factory_;

  DISALLOW_COPY_AND_ASSIGN(PepperVideoSourceHost);
};

}  // namespace content

#endif  // CONTENT_RENDERER_PEPPER_PEPPER_VIDEO_SOURCE_HOST_H_