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