• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * v4l2_buffer_proxy.h - v4l2 buffer proxy
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 #ifndef XCAM_V4L2_BUFFER_PROXY_H
22 #define XCAM_V4L2_BUFFER_PROXY_H
23 
24 #include <xcam_std.h>
25 #include <buffer_pool.h>
26 #include <linux/videodev2.h>
27 
28 namespace XCam {
29 
30 class V4l2Device;
31 
32 class V4l2Buffer
33     : public BufferData
34 {
35 public:
36     explicit V4l2Buffer (const struct v4l2_buffer &buf, const struct v4l2_format &format);
37     virtual ~V4l2Buffer ();
38 
get_buf()39     const struct v4l2_buffer & get_buf () const {
40         return _buf;
41     }
42 
set_timestamp(const struct timeval & time)43     void set_timestamp (const struct timeval &time) {
44         _buf.timestamp = time;
45     }
46 
set_timecode(const struct v4l2_timecode & code)47     void set_timecode (const struct v4l2_timecode &code) {
48         _buf.timecode = code;
49     }
50 
set_sequence(const uint32_t sequence)51     void set_sequence (const uint32_t sequence) {
52         _buf.sequence = sequence;
53     }
54 
set_length(const uint32_t value)55     void set_length (const uint32_t value) {
56         _buf.length = value;
57     }
58 
reset()59     void reset () {
60         xcam_mem_clear (_buf.timestamp);
61         xcam_mem_clear (_buf.timecode);
62         _buf.sequence = 0;
63         //_buf.length = 0;
64     }
65 
get_format()66     const struct v4l2_format & get_format () const {
67         return _format;
68     }
69 
70     // derived from BufferData
71     virtual uint8_t *map ();
72     virtual bool unmap ();
73     virtual int get_fd ();
74 
75 private:
76     XCAM_DEAD_COPY (V4l2Buffer);
77 
78 private:
79     struct v4l2_buffer  _buf;
80     struct v4l2_format  _format;
81 };
82 
83 class V4l2BufferProxy
84     : public BufferProxy
85 {
86 public:
87     explicit V4l2BufferProxy (SmartPtr<V4l2Buffer> &buf, SmartPtr<V4l2Device> &device);
88 
89     ~V4l2BufferProxy ();
90 
get_v4l2_buf_index()91     int get_v4l2_buf_index () {
92         return get_v4l2_buf().index;
93     }
94 
get_v4l2_mem_type()95     enum v4l2_memory get_v4l2_mem_type () {
96         return (enum v4l2_memory)(get_v4l2_buf().memory);
97     }
98 
get_v4l2_buf_length()99     int get_v4l2_buf_length () {
100         return get_v4l2_buf().length;
101     }
102 
get_v4l2_dma_fd()103     int get_v4l2_dma_fd () {
104         return get_v4l2_buf().m.fd;
105     }
106 
get_v4l2_userptr()107     uintptr_t get_v4l2_userptr () {
108         return get_v4l2_buf().m.userptr;
109     }
110 
111 private:
112     const struct v4l2_buffer & get_v4l2_buf ();
113 
114     void v4l2_format_to_video_info (
115         const struct v4l2_format &format, VideoBufferInfo &info);
116 
117     XCAM_DEAD_COPY (V4l2BufferProxy);
118 
119 private:
120     SmartPtr<V4l2Device>  _device;
121 };
122 };
123 
124 #endif //XCAM_V4L2_BUFFER_PROXY_H
125