1 /* 2 * xcam_buffer.h - video buffer standard version 3 * 4 * Copyright (c) 2016 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 (at) intel.com> 19 */ 20 21 #ifndef C_XCAM_BUFFER_H 22 #define C_XCAM_BUFFER_H 23 24 #include <base/xcam_common.h> 25 26 XCAM_BEGIN_DECLARE 27 #include <linux/videodev2.h> 28 29 #ifndef V4L2_PIX_FMT_XBGR32 30 #define V4L2_PIX_FMT_XBGR32 v4l2_fourcc('X', 'R', '2', '4') 31 #endif 32 33 #ifndef V4L2_PIX_FMT_ABGR32 34 #define V4L2_PIX_FMT_ABGR32 v4l2_fourcc('A', 'R', '2', '4') 35 #endif 36 37 #ifndef V4L2_PIX_FMT_XRGB32 38 #define V4L2_PIX_FMT_XRGB32 v4l2_fourcc('B', 'X', '2', '4') 39 #endif 40 41 #ifndef V4L2_PIX_FMT_ARGB32 42 #define V4L2_PIX_FMT_ARGB32 v4l2_fourcc('B', 'A', '2', '4') 43 #endif 44 45 #ifndef V4L2_PIX_FMT_RGBA32 46 #define V4L2_PIX_FMT_RGBA32 v4l2_fourcc('A', 'B', '2', '4') 47 #endif 48 49 /* 50 * Define special format for 16 bit color 51 * every format start with 'X' 52 * 53 * XCAM_PIX_FMT_RGB48: RGB with color-bits = 16 54 * XCAM_PIX_FMT_RGBA64, RGBA with color-bits = 16 55 * XCAM_PIX_FMT_SGRBG16, Bayer, with color-bits = 16 56 */ 57 58 #define XCAM_PIX_FMT_RGB48 v4l2_fourcc('w', 'R', 'G', 'B') 59 #define XCAM_PIX_FMT_RGBA64 v4l2_fourcc('w', 'R', 'G', 'a') 60 #define XCAM_PIX_FMT_SGRBG16 v4l2_fourcc('w', 'B', 'A', '0') 61 #define XCAM_PIX_FMT_LAB v4l2_fourcc('h', 'L', 'a', 'b') 62 #define XCAM_PIX_FMT_RGB48_planar v4l2_fourcc('n', 'R', 'G', 0x48) 63 #define XCAM_PIX_FMT_RGB24_planar v4l2_fourcc('n', 'R', 'G', 0x24) 64 #define XCAM_PIX_FMT_SGRBG16_planar v4l2_fourcc('n', 'B', 'A', '0') 65 #define XCAM_PIX_FMT_SGRBG8_planar v4l2_fourcc('n', 'B', 'A', '8') 66 67 #define XCAM_VIDEO_MAX_COMPONENTS 4 68 69 70 typedef struct _XCamVideoBufferPlanarInfo XCamVideoBufferPlanarInfo; 71 struct _XCamVideoBufferPlanarInfo { 72 uint32_t width; 73 uint32_t height; 74 uint32_t pixel_bytes; 75 }; 76 77 typedef struct _XCamVideoBufferInfo XCamVideoBufferInfo; 78 struct _XCamVideoBufferInfo { 79 uint32_t format; // v4l2 fourcc 80 uint32_t color_bits; 81 uint32_t width; 82 uint32_t height; 83 uint32_t aligned_width; 84 uint32_t aligned_height; 85 uint32_t size; 86 uint32_t components; 87 uint32_t strides [XCAM_VIDEO_MAX_COMPONENTS]; 88 uint32_t offsets [XCAM_VIDEO_MAX_COMPONENTS]; 89 }; 90 91 typedef enum { 92 XCAM_MEM_TYPE_CPU, 93 XCAM_MEM_TYPE_GPU, 94 XCAM_MEM_TYPE_PRIVATE = 0x8000, 95 XCAM_MEM_TYPE_PRIVATE_BO, 96 } XCamMemType; 97 98 typedef struct _XCamVideoBuffer XCamVideoBuffer; 99 100 struct _XCamVideoBuffer { 101 XCamVideoBufferInfo info; 102 uint32_t mem_type; 103 int64_t timestamp; 104 105 void (*ref) (XCamVideoBuffer *); 106 void (*unref) (XCamVideoBuffer *); 107 uint8_t *(*map) (XCamVideoBuffer *); 108 void (*unmap) (XCamVideoBuffer *); 109 int (*get_fd) (XCamVideoBuffer *); 110 }; 111 112 typedef struct _XCamVideoBufferIntel XCamVideoBufferIntel; 113 struct _XCamVideoBufferIntel { 114 XCamVideoBuffer base; 115 116 void *(*get_bo) (XCamVideoBufferIntel *); 117 }; 118 119 #define xcam_video_buffer_ref(buf) (buf)->ref(buf) 120 #define xcam_video_buffer_unref(buf) (buf)->unref(buf) 121 #define xcam_video_buffer_map(buf) (buf)->map(buf) 122 #define xcam_video_buffer_unmap(buf) (buf)->unmap(buf) 123 #define xcam_video_buffer_get_fd(buf) (buf)->get_fd(buf) 124 #define xcam_video_buffer_intel_get_bo(buf) (buf)->get_bo(buf) 125 126 XCamReturn 127 xcam_video_buffer_info_reset ( 128 XCamVideoBufferInfo *info, 129 uint32_t format, uint32_t width, uint32_t height, 130 uint32_t aligned_width, uint32_t aligned_height, uint32_t size); 131 132 XCamReturn 133 xcam_video_buffer_get_planar_info ( 134 const XCamVideoBufferInfo *buf_info, XCamVideoBufferPlanarInfo *planar_info, const uint32_t index); 135 136 137 XCAM_END_DECLARE 138 139 #endif // C_XCAM_BUFFER_H 140