Home | History | Annotate | Download | only in private
      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_PRIVATE_VIDEO_FRAME_PRIVATE_H_
      6 #define PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_
      7 
      8 #include <string.h>
      9 
     10 #include "ppapi/c/pp_time.h"
     11 #include "ppapi/c/private/pp_video_frame_private.h"
     12 #include "ppapi/cpp/completion_callback.h"
     13 #include "ppapi/cpp/image_data.h"
     14 #include "ppapi/cpp/pass_ref.h"
     15 
     16 /// @file
     17 /// This file defines the struct used to hold a video frame.
     18 
     19 namespace pp {
     20 
     21 /// The <code>PP_VideoFrame_Private</code> struct represents a video frame.
     22 /// Video sources and destinations use frames to transfer video to and from
     23 /// the browser.
     24 class VideoFrame_Private {
     25  public:
     26   /// Default constructor for creating a <code>VideoFrame_Private</code> object.
     27   VideoFrame_Private();
     28 
     29   /// Constructor that takes an existing <code>PP_VideoFrame_Private</code>
     30   /// structure. The 'image_data' PP_Resource field in the structure will be
     31   /// managed by this instance.
     32   VideoFrame_Private(PassRef, const PP_VideoFrame_Private& pp_video_frame);
     33 
     34   /// Constructor that takes an existing <code>ImageData</code> instance and
     35   /// a timestamp.
     36   VideoFrame_Private(const ImageData& image_data, PP_TimeTicks timestamp);
     37 
     38   /// The copy constructor for <code>VideoFrame_Private</code>.
     39   ///
     40   /// @param[in] other A reference to a <code>VideoFrame_Private</code>.
     41   VideoFrame_Private(const VideoFrame_Private& other);
     42 
     43   ~VideoFrame_Private();
     44 
     45   /// The assignment operator for <code>VideoFrame_Private</code>.
     46   ///
     47   /// @param[in] other A reference to a <code>VideoFrame_Private</code>.
     48   VideoFrame_Private& operator=(const VideoFrame_Private& other);
     49 
     50   const PP_VideoFrame_Private& pp_video_frame() const {
     51     return video_frame_;
     52   }
     53 
     54   ImageData image_data() const {
     55     return image_data_;
     56   }
     57   void set_image_data(const ImageData& image_data) {
     58     image_data_ = image_data;
     59     // The assignment above manages the underlying PP_Resources. Copy the new
     60     // one into our internal video frame struct.
     61     video_frame_.image_data = image_data_.pp_resource();
     62   }
     63 
     64   PP_TimeTicks timestamp() const { return video_frame_.timestamp; }
     65   void set_timestamp(PP_TimeTicks timestamp) {
     66     video_frame_.timestamp = timestamp;
     67   }
     68 
     69  private:
     70   ImageData image_data_;  // This manages the PP_Resource in video_frame_.
     71   PP_VideoFrame_Private video_frame_;
     72 };
     73 
     74 namespace internal {
     75 
     76 // A specialization of CallbackOutputTraits to provide the callback system the
     77 // information on how to handle pp::VideoFrame_Private. This converts
     78 // PP_VideoFrame_Private to pp::VideoFrame_Private when passing to the plugin,
     79 // and specifically manages the PP_Resource embedded in the video_frame_ field.
     80 template<>
     81 struct CallbackOutputTraits<pp::VideoFrame_Private> {
     82   typedef PP_VideoFrame_Private* APIArgType;
     83   typedef PP_VideoFrame_Private StorageType;
     84 
     85   static inline APIArgType StorageToAPIArg(StorageType& t) {
     86     return &t;
     87   }
     88 
     89   static inline pp::VideoFrame_Private StorageToPluginArg(StorageType& t) {
     90     return pp::VideoFrame_Private(PASS_REF, t);
     91   }
     92 
     93   static inline void Initialize(StorageType* t) {
     94     VideoFrame_Private dummy;
     95     *t = dummy.pp_video_frame();
     96   }
     97 };
     98 
     99 }  // namespace internal
    100 
    101 }  // namespace pp
    102 
    103 #endif  // PPAPI_CPP_PRIVATE_VIDEO_FRAME_PRIVATE_H_
    104