1 /* 2 * video_buffer.h - video buffer base 3 * 4 * Copyright (c) 2014-2015 Intel Corporation 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Wind Yuan <feng.yuan (at) intel.com> 19 */ 20 21 #ifndef XCAM_VIDEO_BUFFER_H 22 #define XCAM_VIDEO_BUFFER_H 23 24 #include <xcam_std.h> 25 #include <meta_data.h> 26 #include <base/xcam_buffer.h> 27 #include <list> 28 29 namespace XCam { 30 31 class VideoBuffer; 32 typedef std::list<SmartPtr<VideoBuffer>> VideoBufferList; 33 34 struct VideoBufferPlanarInfo 35 : XCamVideoBufferPlanarInfo 36 { 37 VideoBufferPlanarInfo (); 38 }; 39 40 struct VideoBufferInfo 41 : XCamVideoBufferInfo 42 { 43 VideoBufferInfo (); 44 bool init ( 45 uint32_t format, 46 uint32_t width, uint32_t height, 47 uint32_t aligned_width = 0, uint32_t aligned_height = 0, uint32_t size = 0); 48 49 bool get_planar_info ( 50 VideoBufferPlanarInfo &planar, const uint32_t index = 0) const; 51 52 bool is_valid () const; 53 }; 54 55 class VideoBuffer { 56 public: 57 explicit VideoBuffer (int64_t timestamp = InvalidTimestamp) 58 : _timestamp (timestamp) 59 {} 60 explicit VideoBuffer (const VideoBufferInfo &info, int64_t timestamp = InvalidTimestamp) 61 : _videoinfo (info) 62 , _timestamp (timestamp) 63 {} 64 virtual ~VideoBuffer (); 65 66 void set_parent (const SmartPtr<VideoBuffer> &parent) { 67 _parent = parent; 68 } 69 70 virtual uint8_t *map () = 0; 71 virtual bool unmap () = 0; 72 virtual int get_fd () = 0; 73 74 const VideoBufferInfo & get_video_info () const { 75 return _videoinfo; 76 } 77 int64_t get_timestamp () const { 78 return _timestamp; 79 } 80 81 void set_video_info (const VideoBufferInfo &info) { 82 _videoinfo = info; 83 } 84 85 void set_timestamp (int64_t timestamp) { 86 _timestamp = timestamp; 87 } 88 89 uint32_t get_size () const { 90 return _videoinfo.size; 91 } 92 93 bool attach_buffer (const SmartPtr<VideoBuffer>& buf); 94 bool detach_buffer (const SmartPtr<VideoBuffer>& buf); 95 bool copy_attaches (const SmartPtr<VideoBuffer>& buf); 96 void clear_attached_buffers (); 97 98 template <typename BufType> 99 SmartPtr<BufType> find_typed_attach (); 100 101 bool add_metadata (const SmartPtr<MetaData>& data); 102 bool remove_metadata (const SmartPtr<MetaData>& data); 103 void clear_all_metadata (); 104 105 template <typename MetaType> 106 SmartPtr<MetaType> find_typed_metadata (); 107 108 private: 109 XCAM_DEAD_COPY (VideoBuffer); 110 111 protected: 112 VideoBufferList _attached_bufs; 113 MetaDataList _metadata_list; 114 115 private: 116 VideoBufferInfo _videoinfo; 117 int64_t _timestamp; // in microseconds 118 119 SmartPtr<VideoBuffer> _parent; 120 }; 121 122 template <typename BufType> 123 SmartPtr<BufType> VideoBuffer::find_typed_attach () 124 { 125 for (VideoBufferList::iterator iter = _attached_bufs.begin (); 126 iter != _attached_bufs.end (); ++iter) { 127 SmartPtr<BufType> buf = (*iter).dynamic_cast_ptr<BufType> (); 128 if (buf.ptr ()) 129 return buf; 130 } 131 132 return NULL; 133 } 134 135 template <typename MetaType> 136 SmartPtr<MetaType> VideoBuffer::find_typed_metadata () 137 { 138 for (MetaDataList::iterator iter = _metadata_list.begin (); 139 iter != _metadata_list.end (); ++iter) { 140 SmartPtr<MetaType> buf = (*iter).dynamic_cast_ptr<MetaType> (); 141 if (buf.ptr ()) 142 return buf; 143 } 144 145 return NULL; 146 } 147 148 XCamVideoBuffer *convert_to_external_buffer (const SmartPtr<VideoBuffer> &buf); 149 150 }; 151 152 #endif //XCAM_VIDEO_BUFFER_H