hc
2023-11-22 f743a7adbd6e230d66a6206fa115b59fec2d88eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * video_buffer.cpp - video buffer base
 *
 *  Copyright (c) 2014-2015 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Author: Wind Yuan <feng.yuan@intel.com>
 */
 
#include "video_buffer.h"
#include <linux/videodev2.h>
 
namespace XCam {
 
VideoBufferPlanarInfo::VideoBufferPlanarInfo ()
{
    width = 0;
    height = 0;
    pixel_bytes = 0;
}
 
VideoBufferInfo::VideoBufferInfo ()
{
    format = 0;
    color_bits = 8;
    width = 0;
    height = 0;
    aligned_width = 0;
    aligned_height = 0;
    size = 0;
    components  = 0;
    xcam_mem_clear (strides);
    xcam_mem_clear (offsets);
}
 
bool
VideoBufferInfo::init (
    uint32_t format,
    uint32_t width, uint32_t height,
    uint32_t aligned_width, uint32_t aligned_height,
    uint32_t size, bool compacted)
{
 
    XCamVideoBufferInfo *info = this;
 
    return (xcam_video_buffer_info_reset (
                info, format, width, height, aligned_width, aligned_height, size, compacted) == XCAM_RETURN_NO_ERROR);
}
 
bool
VideoBufferInfo::fill (const XCamVideoBufferInfo &info)
{
   format = info.format;
   color_bits = info.color_bits;
   width = info.width;
   height = info.height;
   aligned_width = info.aligned_width;
   aligned_height = info.aligned_height;
   size = info.size;
   components = info.components;
   for (int i = 0; i < XCAM_VIDEO_MAX_COMPONENTS; i++) {
       strides[i] = info.strides[i];
       offsets[i] = info.offsets[i];
   }
 
   return true;
}
 
bool
VideoBufferInfo::is_valid () const
{
    return format && aligned_width && aligned_height && size;
}
 
bool
VideoBufferInfo::get_planar_info (
    VideoBufferPlanarInfo &planar, const uint32_t index) const
{
    const XCamVideoBufferInfo *info = this;
    XCamVideoBufferPlanarInfo *planar_info = &planar;
    return (xcam_video_buffer_get_planar_info (info, planar_info, index) == XCAM_RETURN_NO_ERROR);
}
 
VideoBuffer::~VideoBuffer ()
{
    clear_attached_buffers ();
    clear_all_metadata ();
    _parent.release ();
}
 
bool
VideoBuffer::attach_buffer (const SmartPtr<VideoBuffer>& buf)
{
    _attached_bufs.push_back (buf);
    return true;
}
 
bool
VideoBuffer::detach_buffer (const SmartPtr<VideoBuffer>& buf)
{
    for (VideoBufferList::iterator iter = _attached_bufs.begin ();
            iter != _attached_bufs.end (); ++iter) {
        SmartPtr<VideoBuffer>& current = *iter;
        if (current.ptr () == buf.ptr ()) {
            _attached_bufs.erase (iter);
            return true;
        }
    }
 
    //not found
    return false;
}
 
bool
VideoBuffer::copy_attaches (const SmartPtr<VideoBuffer>& buf)
{
    _attached_bufs.insert (
        _attached_bufs.end (), buf->_attached_bufs.begin (), buf->_attached_bufs.end ());
    return true;
}
 
void
VideoBuffer::clear_attached_buffers ()
{
    _attached_bufs.clear ();
}
 
bool
VideoBuffer::add_metadata (const SmartPtr<MetaData>& data)
{
    _metadata_list.push_back (data);
    return true;
}
 
bool
VideoBuffer::remove_metadata (const SmartPtr<MetaData>& data)
{
    for (MetaDataList::iterator iter = _metadata_list.begin ();
            iter != _metadata_list.end (); ++iter) {
        SmartPtr<MetaData>& current = *iter;
        if (current.ptr () == data.ptr ()) {
            _metadata_list.erase (iter);
            return true;
        }
    }
 
    //not found
    return false;
}
 
void
VideoBuffer::clear_all_metadata ()
{
    _metadata_list.clear ();
}
 
};