Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 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 | |
Wind Yuan | 8810a79 | 2015-01-22 15:20:23 +0800 | [diff] [blame] | 24 | #include "xcam_utils.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 25 | #include "video_buffer.h" |
| 26 | #include "smartptr.h" |
| 27 | #include <linux/videodev2.h> |
| 28 | |
| 29 | namespace XCam { |
| 30 | |
| 31 | class V4l2Device; |
| 32 | |
| 33 | class V4l2Buffer { |
| 34 | public: |
| 35 | explicit V4l2Buffer (const struct v4l2_buffer &buf, const struct v4l2_format &format); |
| 36 | virtual ~V4l2Buffer (); |
| 37 | |
| 38 | const struct v4l2_buffer & get_buf () const { |
| 39 | return _buf; |
| 40 | } |
| 41 | |
| 42 | void set_timestamp (const struct timeval &time) { |
| 43 | _buf.timestamp = time; |
| 44 | } |
| 45 | |
| 46 | void set_timecode (const struct v4l2_timecode &code) { |
| 47 | _buf.timecode = code; |
| 48 | } |
| 49 | |
| 50 | void set_sequence (const uint32_t sequence) { |
| 51 | _buf.sequence = sequence; |
| 52 | } |
| 53 | |
| 54 | void set_length (const uint32_t value) { |
| 55 | _buf.length = value; |
| 56 | } |
| 57 | |
| 58 | void reset () { |
| 59 | xcam_mem_clear (&_buf.timestamp); |
| 60 | xcam_mem_clear (&_buf.timecode); |
| 61 | _buf.sequence = 0; |
| 62 | //_buf.length = 0; |
| 63 | } |
| 64 | |
| 65 | const struct v4l2_format & get_format () const { |
| 66 | return _format; |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | XCAM_DEAD_COPY (V4l2Buffer); |
| 71 | |
| 72 | private: |
| 73 | struct v4l2_buffer _buf; |
| 74 | struct v4l2_format _format; |
| 75 | }; |
| 76 | |
| 77 | class V4l2BufferProxy |
| 78 | : public VideoBuffer |
| 79 | { |
| 80 | public: |
| 81 | explicit V4l2BufferProxy (SmartPtr<V4l2Buffer> &buf, SmartPtr<V4l2Device> &device); |
| 82 | |
| 83 | ~V4l2BufferProxy (); |
| 84 | |
| 85 | int get_v4l2_buf_index () { |
| 86 | return get_v4l2_buf().index; |
| 87 | } |
| 88 | |
Wind Yuan | e9cc968 | 2015-02-10 17:39:48 +0800 | [diff] [blame] | 89 | enum v4l2_memory get_v4l2_mem_type () { |
| 90 | return (enum v4l2_memory)(get_v4l2_buf().memory); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | int get_v4l2_buf_length () { |
| 94 | return get_v4l2_buf().length; |
| 95 | } |
| 96 | |
| 97 | int get_v4l2_dma_fd () { |
| 98 | return get_v4l2_buf().m.fd; |
| 99 | } |
| 100 | |
| 101 | uintptr_t get_v4l2_userptr () { |
| 102 | return get_v4l2_buf().m.userptr; |
| 103 | } |
| 104 | |
| 105 | virtual uint8_t *map (); |
| 106 | virtual bool unmap (); |
| 107 | |
| 108 | private: |
| 109 | const struct v4l2_buffer & get_v4l2_buf () const; |
| 110 | |
| 111 | void v4l2_format_to_video_info ( |
| 112 | const struct v4l2_format &format, VideoBufferInfo &info); |
| 113 | |
| 114 | XCAM_DEAD_COPY (V4l2BufferProxy); |
| 115 | |
| 116 | private: |
| 117 | SmartPtr<V4l2Buffer> _buf; |
| 118 | SmartPtr<V4l2Device> _device; |
| 119 | }; |
| 120 | }; |
| 121 | |
| 122 | #endif //XCAM_V4L2_BUFFER_PROXY_H |