| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #ifndef PPAPI_CPP_VIDEO_H_ |
| 6 #define PPAPI_CPP_VIDEO_H_ |
| 7 |
| 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" |
| 13 #include "ppapi/cpp/resource.h" |
| 14 |
| 15 /// @file |
| 16 /// This file defines the API to create and use video stream readers and |
| 17 /// writers. |
| 18 |
| 19 namespace pp { |
| 20 |
| 21 class InstanceHandle; |
| 22 |
| 23 // VideoFrame ------------------------------------------------------------------ |
| 24 |
| 25 /// The <code>VideoFrame</code> class represents a frame of video in a stream. |
| 26 class VideoFrame { |
| 27 public: |
| 28 /// Default constructor for creating a <code>VideoFrame</code> object. |
| 29 VideoFrame(); |
| 30 /// Constructor that takes an existing <code>PP_VideoFrame</code> structure. |
| 31 /// The 'image_data' PP_Resource field in the structure will be managed by |
| 32 /// this instance. |
| 33 VideoFrame(PassRef, const PP_VideoFrame& pp_video_frame); |
| 34 /// The copy constructor for <code>VideoFrame</code>. |
| 35 /// |
| 36 /// @param[in] other A reference to a <code>VideoFrame</code>. |
| 37 VideoFrame(const VideoFrame& other); |
| 38 ~VideoFrame(); |
| 39 |
| 40 VideoFrame& operator=(const VideoFrame& other); |
| 41 |
| 42 const PP_VideoFrame& pp_video_frame() const { |
| 43 return video_frame_; |
| 44 } |
| 45 |
| 46 ImageData image_data() const { |
| 47 return image_data_; |
| 48 } |
| 49 void set_image_data(const ImageData& image_data) { |
| 50 image_data_ = image_data; |
| 51 // The assignment above manages the underlying PP_Resources. Copy the new |
| 52 // one into our internal video frame struct. |
| 53 video_frame_.image_data = image_data_.pp_resource(); |
| 54 } |
| 55 |
| 56 PP_TimeTicks timestamp() const { return video_frame_.timestamp; } |
| 57 void set_timestamp(PP_TimeTicks timestamp) { |
| 58 video_frame_.timestamp = timestamp; |
| 59 } |
| 60 |
| 61 private: |
| 62 ImageData image_data_; // This manages the PP_Resource in video_frame_. |
| 63 PP_VideoFrame video_frame_; |
| 64 }; |
| 65 |
| 66 // VideoReader ----------------------------------------------------------------- |
| 67 |
| 68 /// The <code>VideoReader</code> class represents a video reader resource. |
| 69 class VideoReader : public Resource { |
| 70 public: |
| 71 /// Default constructor for creating a <code>VideoReader</code> object. |
| 72 VideoReader(); |
| 73 |
| 74 /// Constructor for creating a <code>VideoReader</code> for an instance. |
| 75 explicit VideoReader(const InstanceHandle& instance); |
| 76 |
| 77 /// The copy constructor for <code>VideoReader</code>. |
| 78 /// |
| 79 /// @param[in] other A reference to a <code>VideoReader</code>. |
| 80 VideoReader(const VideoReader& other); |
| 81 |
| 82 /// A constructor used when you have received a PP_Resource as a return |
| 83 /// value that has had its reference count incremented for you. |
| 84 /// |
| 85 /// @param[in] resource A PP_Resource corresponding to a video reader. |
| 86 VideoReader(PassRef, PP_Resource resource); |
| 87 |
| 88 /// Opens a stream for reading video and associates it with the given id. |
| 89 /// |
| 90 /// @param[in] stream_id A <code>Var</code> uniquely identifying the stream |
| 91 /// to read from. |
| 92 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
| 93 /// completion of Open. |
| 94 /// |
| 95 /// @return A return code from <code>pp_errors.h</code>. |
| 96 int32_t Open(const pp::Var& stream_id, |
| 97 const CompletionCallback& cc); |
| 98 |
| 99 /// Gets the next frame of video from the reader's stream. |
| 100 /// |
| 101 /// @param[in] callback A <code>CompletionCallbackWithOutput</code> to be |
| 102 /// called upon completion of GetNextFrame. |
| 103 /// |
| 104 /// @return A return code from <code>pp_errors.h</code>. |
| 105 int32_t GetNextFrame(const CompletionCallbackWithOutput<VideoFrame>& cc); |
| 106 |
| 107 /// Closes the reader's current stream. |
| 108 void Close(); |
| 109 }; |
| 110 |
| 111 // VideoWriter ----------------------------------------------------------------- |
| 112 |
| 113 /// The <code>VideoWriter</code> class represents a video writer resource. |
| 114 class VideoWriter : public Resource { |
| 115 public: |
| 116 /// Default constructor for creating a <code>VideoWriter</code> object. |
| 117 VideoWriter(); |
| 118 |
| 119 /// Constructor for creating a <code>VideoWriter</code> for an instance. |
| 120 explicit VideoWriter(const InstanceHandle& instance); |
| 121 |
| 122 /// The copy constructor for <code>VideoWriter</code>. |
| 123 /// |
| 124 /// @param[in] other A reference to a <code>VideoWriter</code>. |
| 125 VideoWriter(const VideoWriter& other); |
| 126 |
| 127 /// A constructor used when you have received a PP_Resource as a return |
| 128 /// value that has had its reference count incremented for you. |
| 129 /// |
| 130 /// @param[in] resource A PP_Resource corresponding to a video writer. |
| 131 VideoWriter(PassRef, PP_Resource resource); |
| 132 |
| 133 /// Opens a stream for writing video and associates it with the given id. |
| 134 /// |
| 135 /// @param[in] stream_id A <code>Var</code> uniquely identifying the stream |
| 136 /// to write to. |
| 137 /// @param[in] callback A <code>CompletionCallback</code> to be called upon |
| 138 /// completion of Open. |
| 139 /// |
| 140 /// @return A return code from <code>pp_errors.h</code>. |
| 141 int32_t Open(const pp::Var& stream_id, |
| 142 const CompletionCallback& cc); |
| 143 |
| 144 /// Emits the next frame of video to the writer's stream. |
| 145 /// |
| 146 /// @param[in] frame A <code>VideoFrame</code> containing the frame to write |
| 147 /// to the open stream. |
| 148 /// |
| 149 /// @return A return code from <code>pp_errors.h</code>. |
| 150 int32_t PutNextFrame(const VideoFrame& frame); |
| 151 |
| 152 /// Closes the writer's current stream. |
| 153 void Close(); |
| 154 }; |
| 155 |
| 156 namespace internal { |
| 157 |
| 158 // A specialization of CallbackOutputTraits to provide the callback system the |
| 159 // information on how to handle pp::VideoFrame. This converts PP_VideoFrame to |
| 160 // pp::VideoFrame when passing to the plugin, and specifically manages the |
| 161 // PP_Resource embedded in the video_frame_ field. |
| 162 template<> |
| 163 struct CallbackOutputTraits<pp::VideoFrame> { |
| 164 typedef PP_VideoFrame* APIArgType; |
| 165 typedef PP_VideoFrame StorageType; |
| 166 |
| 167 static inline APIArgType StorageToAPIArg(StorageType& t) { |
| 168 return &t; |
| 169 } |
| 170 |
| 171 static inline pp::VideoFrame StorageToPluginArg(StorageType& t) { |
| 172 return pp::VideoFrame(PASS_REF, t); |
| 173 } |
| 174 }; |
| 175 |
| 176 } // namespace internal |
| 177 |
| 178 } // namespace pp |
| 179 |
| 180 #endif // PPAPI_CPP_VIDEO_H_ |
| OLD | NEW |