• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * video_buffer.cpp - 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@intel.com>
19  */
20 
21 #include "video_buffer.h"
22 #include <linux/videodev2.h>
23 
24 namespace XCam {
25 
VideoBufferPlanarInfo()26 VideoBufferPlanarInfo::VideoBufferPlanarInfo ()
27 {
28     width = 0;
29     height = 0;
30     pixel_bytes = 0;
31 }
32 
VideoBufferInfo()33 VideoBufferInfo::VideoBufferInfo ()
34 {
35     format = 0;
36     color_bits = 8;
37     width = 0;
38     height = 0;
39     aligned_width = 0;
40     aligned_height = 0;
41     size = 0;
42     components  = 0;
43     xcam_mem_clear (strides);
44     xcam_mem_clear (offsets);
45 }
46 
47 bool
init(uint32_t format,uint32_t width,uint32_t height,uint32_t aligned_width,uint32_t aligned_height,uint32_t size)48 VideoBufferInfo::init (
49     uint32_t format,
50     uint32_t width, uint32_t height,
51     uint32_t aligned_width, uint32_t aligned_height,
52     uint32_t size)
53 {
54 
55     XCamVideoBufferInfo *info = this;
56 
57     return (xcam_video_buffer_info_reset (
58                 info, format, width, height, aligned_width, aligned_height, size) == XCAM_RETURN_NO_ERROR);
59 }
60 
61 bool
is_valid() const62 VideoBufferInfo::is_valid () const
63 {
64     return format && aligned_width && aligned_height && size;
65 }
66 
67 bool
get_planar_info(VideoBufferPlanarInfo & planar,const uint32_t index) const68 VideoBufferInfo::get_planar_info (
69     VideoBufferPlanarInfo &planar, const uint32_t index) const
70 {
71     const XCamVideoBufferInfo *info = this;
72     XCamVideoBufferPlanarInfo *planar_info = &planar;
73     return (xcam_video_buffer_get_planar_info (info, planar_info, index) == XCAM_RETURN_NO_ERROR);
74 }
75 
~VideoBuffer()76 VideoBuffer::~VideoBuffer ()
77 {
78     clear_attached_buffers ();
79     clear_all_metadata ();
80     _parent.release ();
81 }
82 
83 bool
attach_buffer(const SmartPtr<VideoBuffer> & buf)84 VideoBuffer::attach_buffer (const SmartPtr<VideoBuffer>& buf)
85 {
86     _attached_bufs.push_back (buf);
87     return true;
88 }
89 
90 bool
detach_buffer(const SmartPtr<VideoBuffer> & buf)91 VideoBuffer::detach_buffer (const SmartPtr<VideoBuffer>& buf)
92 {
93     for (VideoBufferList::iterator iter = _attached_bufs.begin ();
94             iter != _attached_bufs.end (); ++iter) {
95         SmartPtr<VideoBuffer>& current = *iter;
96         if (current.ptr () == buf.ptr ()) {
97             _attached_bufs.erase (iter);
98             return true;
99         }
100     }
101 
102     //not found
103     return false;
104 }
105 
106 bool
copy_attaches(const SmartPtr<VideoBuffer> & buf)107 VideoBuffer::copy_attaches (const SmartPtr<VideoBuffer>& buf)
108 {
109     _attached_bufs.insert (
110         _attached_bufs.end (), buf->_attached_bufs.begin (), buf->_attached_bufs.end ());
111     return true;
112 }
113 
114 void
clear_attached_buffers()115 VideoBuffer::clear_attached_buffers ()
116 {
117     _attached_bufs.clear ();
118 }
119 
120 bool
add_metadata(const SmartPtr<MetaData> & data)121 VideoBuffer::add_metadata (const SmartPtr<MetaData>& data)
122 {
123     _metadata_list.push_back (data);
124     return true;
125 }
126 
127 bool
remove_metadata(const SmartPtr<MetaData> & data)128 VideoBuffer::remove_metadata (const SmartPtr<MetaData>& data)
129 {
130     for (MetaDataList::iterator iter = _metadata_list.begin ();
131             iter != _metadata_list.end (); ++iter) {
132         SmartPtr<MetaData>& current = *iter;
133         if (current.ptr () == data.ptr ()) {
134             _metadata_list.erase (iter);
135             return true;
136         }
137     }
138 
139     //not found
140     return false;
141 }
142 
143 void
clear_all_metadata()144 VideoBuffer::clear_all_metadata ()
145 {
146     _metadata_list.clear ();
147 }
148 
149 };
150