hc
2024-08-12 233ab1bd4c5697f5cdec94e60206e8c6ac609b4c
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
/*
 * video_buffer.h - 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>
 */
 
#ifndef XCAM_VIDEO_BUFFER_H
#define XCAM_VIDEO_BUFFER_H
 
#include <xcam_std.h>
#include <meta_data.h>
#include <base/xcam_buffer.h>
#include <list>
 
namespace XCam {
 
class VideoBuffer;
typedef std::list<SmartPtr<VideoBuffer>>  VideoBufferList;
 
struct VideoBufferPlanarInfo
    : XCamVideoBufferPlanarInfo
{
    VideoBufferPlanarInfo ();
};
 
struct VideoBufferInfo
    : XCamVideoBufferInfo
{
    VideoBufferInfo ();
    bool init (
        uint32_t format,
        uint32_t width, uint32_t height,
        uint32_t aligned_width = 0, uint32_t aligned_height = 0, uint32_t size = 0, bool compacted = false);
 
    bool fill (const XCamVideoBufferInfo &info);
 
    bool get_planar_info (
        VideoBufferPlanarInfo &planar, const uint32_t index = 0) const;
 
    bool is_valid () const;
};
 
class VideoBuffer {
public:
    explicit VideoBuffer (int64_t timestamp = InvalidTimestamp)
        : _timestamp (timestamp), _buf_type(0)
    {}
    explicit VideoBuffer (const VideoBufferInfo &info, int64_t timestamp = InvalidTimestamp)
        : _videoinfo (info)
        , _timestamp (timestamp)
    {}
    virtual ~VideoBuffer ();
 
    void set_parent (const SmartPtr<VideoBuffer> &parent) {
        _parent = parent;
    }
 
    virtual uint8_t *map () = 0;
    virtual bool unmap () = 0;
    virtual int get_fd () = 0;
 
    const VideoBufferInfo & get_video_info () const {
        return _videoinfo;
    }
    int64_t get_timestamp () const {
        return _timestamp;
    }
 
    void set_video_info (const VideoBufferInfo &info) {
        _videoinfo = info;
    }
 
    void set_timestamp (int64_t timestamp) {
        _timestamp = timestamp;
    }
 
    uint32_t get_size () const {
        return _videoinfo.size;
    }
 
    void set_sequence (uint32_t sequence) {
        _sequence = sequence;
    }
 
    uint32_t get_sequence () const {
        return _sequence;
    }
 
    bool attach_buffer (const SmartPtr<VideoBuffer>& buf);
    bool detach_buffer (const SmartPtr<VideoBuffer>& buf);
    bool copy_attaches (const SmartPtr<VideoBuffer>& buf);
    void clear_attached_buffers ();
 
    template <typename BufType>
    SmartPtr<BufType> find_typed_attach ();
 
    bool add_metadata (const SmartPtr<MetaData>& data);
    bool remove_metadata (const SmartPtr<MetaData>& data);
    void clear_all_metadata ();
 
    template <typename MetaType>
    SmartPtr<MetaType> find_typed_metadata ();
    int _buf_type;
private:
    XCAM_DEAD_COPY (VideoBuffer);
 
protected:
    VideoBufferList           _attached_bufs;
    MetaDataList              _metadata_list;
 
private:
    VideoBufferInfo           _videoinfo;
    int64_t                   _timestamp; // in microseconds
    uint32_t                  _sequence;
 
    SmartPtr<VideoBuffer>     _parent;
};
 
template <typename BufType>
SmartPtr<BufType> VideoBuffer::find_typed_attach ()
{
    for (VideoBufferList::iterator iter = _attached_bufs.begin ();
            iter != _attached_bufs.end (); ++iter) {
        SmartPtr<BufType> buf = (*iter).dynamic_cast_ptr<BufType> ();
        if (buf.ptr ())
            return buf;
    }
 
    return NULL;
}
 
template <typename MetaType>
SmartPtr<MetaType> VideoBuffer::find_typed_metadata ()
{
    for (MetaDataList::iterator iter = _metadata_list.begin ();
            iter != _metadata_list.end (); ++iter) {
        SmartPtr<MetaType> buf = (*iter).dynamic_cast_ptr<MetaType> ();
        if (buf.ptr ())
            return buf;
    }
 
    return NULL;
}
 
XCamVideoBuffer *convert_to_external_buffer (const SmartPtr<VideoBuffer> &buf);
 
};
 
#endif //XCAM_VIDEO_BUFFER_H