Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ppapi / cpp / video_frame.h
blobcb695962dd7aa0abc2a94919292a3a41a94625d1
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 PPAPI_CPP_VIDEO_FRAME_H_
6 #define PPAPI_CPP_VIDEO_FRAME_H_
8 #include "ppapi/c/pp_time.h"
9 #include "ppapi/c/pp_video_frame.h"
10 #include "ppapi/cpp/completion_callback.h"
11 #include "ppapi/cpp/image_data.h"
12 #include "ppapi/cpp/pass_ref.h"
14 /// @file
15 /// This file defines the video frame struct used by video readers and writers.
17 namespace pp {
19 // VideoFrame ------------------------------------------------------------------
21 /// The <code>VideoFrame</code> class represents a frame of video in a stream.
22 class VideoFrame {
23 public:
24 /// Default constructor for creating a <code>VideoFrame</code> object.
25 VideoFrame();
27 /// Constructor that takes an existing <code>PP_VideoFrame</code> structure.
28 /// The 'image_data' PP_Resource field in the structure will be managed by
29 /// this instance.
30 VideoFrame(PassRef, const PP_VideoFrame& pp_video_frame);
32 /// Constructor that takes an existing <code>ImageData</code> instance and
33 /// a timestamp.
34 VideoFrame(const ImageData& image_data, PP_TimeTicks timestamp);
36 /// The copy constructor for <code>VideoFrame</code>.
37 ///
38 /// @param[in] other A reference to a <code>VideoFrame</code>.
39 VideoFrame(const VideoFrame& other);
41 ~VideoFrame();
43 VideoFrame& operator=(const VideoFrame& other);
45 const PP_VideoFrame& pp_video_frame() const {
46 return video_frame_;
49 ImageData image_data() const {
50 return image_data_;
52 void set_image_data(const ImageData& image_data) {
53 image_data_ = image_data;
54 // The assignment above manages the underlying PP_Resources. Copy the new
55 // one into our internal video frame struct.
56 video_frame_.image_data = image_data_.pp_resource();
59 PP_TimeTicks timestamp() const { return video_frame_.timestamp; }
60 void set_timestamp(PP_TimeTicks timestamp) {
61 video_frame_.timestamp = timestamp;
64 private:
65 ImageData image_data_; // This manages the PP_Resource in video_frame_.
66 PP_VideoFrame video_frame_;
69 namespace internal {
71 // A specialization of CallbackOutputTraits to provide the callback system the
72 // information on how to handle pp::VideoFrame. This converts PP_VideoFrame to
73 // pp::VideoFrame when passing to the plugin, and specifically manages the
74 // PP_Resource embedded in the video_frame_ field.
75 template<>
76 struct CallbackOutputTraits<pp::VideoFrame> {
77 typedef PP_VideoFrame* APIArgType;
78 typedef PP_VideoFrame StorageType;
80 static inline APIArgType StorageToAPIArg(StorageType& t) {
81 return &t;
84 static inline pp::VideoFrame StorageToPluginArg(StorageType& t) {
85 return pp::VideoFrame(PASS_REF, t);
89 } // namespace internal
91 } // namespace pp
93 #endif // PPAPI_CPP_VIDEO_FRAME_H_