FFmpeg  4.1.9
rpi_sand_fns.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2018 Raspberry Pi (Trading) Ltd.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the copyright holder nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 Authors: John Cox
28 */
29 
30 #ifndef AVUTIL_RPI_SAND_FNS
31 #define AVUTIL_RPI_SAND_FNS
32 
33 #include "libavutil/frame.h"
34 
35 // For all these fns _x & _w are measured as coord * PW
36 // For the C fns coords are in chroma pels (so luma / 2)
37 // Strides are in bytes
38 
39 void av_rpi_sand_to_planar_y8(uint8_t * dst, const unsigned int dst_stride,
40  const uint8_t * src,
41  unsigned int stride1, unsigned int stride2,
42  unsigned int _x, unsigned int y,
43  unsigned int _w, unsigned int h);
44 void av_rpi_sand_to_planar_y16(uint8_t * dst, const unsigned int dst_stride,
45  const uint8_t * src,
46  unsigned int stride1, unsigned int stride2,
47  unsigned int _x, unsigned int y,
48  unsigned int _w, unsigned int h);
49 
50 void av_rpi_sand_to_planar_c8(uint8_t * dst_u, const unsigned int dst_stride_u,
51  uint8_t * dst_v, const unsigned int dst_stride_v,
52  const uint8_t * src,
53  unsigned int stride1, unsigned int stride2,
54  unsigned int _x, unsigned int y,
55  unsigned int _w, unsigned int h);
56 void av_rpi_sand_to_planar_c16(uint8_t * dst_u, const unsigned int dst_stride_u,
57  uint8_t * dst_v, const unsigned int dst_stride_v,
58  const uint8_t * src,
59  unsigned int stride1, unsigned int stride2,
60  unsigned int _x, unsigned int y,
61  unsigned int _w, unsigned int h);
62 
63 void av_rpi_planar_to_sand_c8(uint8_t * dst_c,
64  unsigned int stride1, unsigned int stride2,
65  const uint8_t * src_u, const unsigned int src_stride_u,
66  const uint8_t * src_v, const unsigned int src_stride_v,
67  unsigned int _x, unsigned int y,
68  unsigned int _w, unsigned int h);
69 void av_rpi_planar_to_sand_c16(uint8_t * dst_c,
70  unsigned int stride1, unsigned int stride2,
71  const uint8_t * src_u, const unsigned int src_stride_u,
72  const uint8_t * src_v, const unsigned int src_stride_v,
73  unsigned int _x, unsigned int y,
74  unsigned int _w, unsigned int h);
75 
76 void av_rpi_sand30_to_planar_y16(uint8_t * dst, const unsigned int dst_stride,
77  const uint8_t * src,
78  unsigned int stride1, unsigned int stride2,
79  unsigned int _x, unsigned int y,
80  unsigned int _w, unsigned int h);
81 void av_rpi_sand30_to_planar_c16(uint8_t * dst_u, const unsigned int dst_stride_u,
82  uint8_t * dst_v, const unsigned int dst_stride_v,
83  const uint8_t * src,
84  unsigned int stride1, unsigned int stride2,
85  unsigned int _x, unsigned int y,
86  unsigned int _w, unsigned int h);
87 
88 
89 // w/h in pixels
90 void av_rpi_sand16_to_sand8(uint8_t * dst, const unsigned int dst_stride1, const unsigned int dst_stride2,
91  const uint8_t * src, const unsigned int src_stride1, const unsigned int src_stride2,
92  unsigned int w, unsigned int h, const unsigned int shr);
93 
94 
95 // dst must contain required pixel format & allocated data buffers
96 // Cropping on the src buffer will be honoured and dst crop will be set to zero
97 int av_rpi_sand_to_planar_frame(AVFrame * const dst, const AVFrame * const src);
98 
99 
100 static inline unsigned int av_rpi_sand_frame_stride1(const AVFrame * const frame)
101 {
102 #ifdef RPI_ZC_SAND128_ONLY
103  // If we are sure we only only support 128 byte sand formats replace the
104  // var with a constant which should allow for better optimisation
105  return 128;
106 #else
107  return frame->linesize[0];
108 #endif
109 }
110 
111 static inline unsigned int av_rpi_sand_frame_stride2(const AVFrame * const frame)
112 {
113  return frame->linesize[3];
114 }
115 
116 
117 static inline int av_rpi_is_sand_format(const int format)
118 {
119  return (format >= AV_PIX_FMT_SAND128 && format <= AV_PIX_FMT_RPI4_10);
120 }
121 
122 static inline int av_rpi_is_sand_frame(const AVFrame * const frame)
123 {
124  return av_rpi_is_sand_format(frame->format);
125 }
126 
127 static inline int av_rpi_is_sand8_frame(const AVFrame * const frame)
128 {
129  return (frame->format == AV_PIX_FMT_SAND128 || frame->format == AV_PIX_FMT_RPI4_8);
130 }
131 
132 static inline int av_rpi_is_sand16_frame(const AVFrame * const frame)
133 {
134  return (frame->format >= AV_PIX_FMT_SAND64_10 && frame->format <= AV_PIX_FMT_SAND64_16);
135 }
136 
137 static inline int av_rpi_is_sand30_frame(const AVFrame * const frame)
138 {
139  return (frame->format == AV_PIX_FMT_RPI4_10);
140 }
141 
142 static inline int av_rpi_sand_frame_xshl(const AVFrame * const frame)
143 {
144  return av_rpi_is_sand8_frame(frame) ? 0 : 1;
145 }
146 
147 // If x is measured in bytes (not pixels) then this works for sand64_16 as
148 // well as sand128 - but in the general case we work that out
149 
150 static inline unsigned int av_rpi_sand_frame_off_y(const AVFrame * const frame, const unsigned int x_y, const unsigned int y)
151 {
152  const unsigned int stride1 = av_rpi_sand_frame_stride1(frame);
153  const unsigned int stride2 = av_rpi_sand_frame_stride2(frame);
154  const unsigned int x = x_y << av_rpi_sand_frame_xshl(frame);
155  const unsigned int x1 = x & (stride1 - 1);
156  const unsigned int x2 = x ^ x1;
157 
158  return x1 + stride1 * y + stride2 * x2;
159 }
160 
161 static inline unsigned int av_rpi_sand_frame_off_c(const AVFrame * const frame, const unsigned int x_c, const unsigned int y_c)
162 {
163  const unsigned int stride1 = av_rpi_sand_frame_stride1(frame);
164  const unsigned int stride2 = av_rpi_sand_frame_stride2(frame);
165  const unsigned int x = x_c << (av_rpi_sand_frame_xshl(frame) + 1);
166  const unsigned int x1 = x & (stride1 - 1);
167  const unsigned int x2 = x ^ x1;
168 
169  return x1 + stride1 * y_c + stride2 * x2;
170 }
171 
172 static inline uint8_t * av_rpi_sand_frame_pos_y(const AVFrame * const frame, const unsigned int x, const unsigned int y)
173 {
174  return frame->data[0] + av_rpi_sand_frame_off_y(frame, x, y);
175 }
176 
177 static inline uint8_t * av_rpi_sand_frame_pos_c(const AVFrame * const frame, const unsigned int x, const unsigned int y)
178 {
179  return frame->data[1] + av_rpi_sand_frame_off_c(frame, x, y);
180 }
181 
182 #endif
183 
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
int av_rpi_sand_to_planar_frame(AVFrame *const dst, const AVFrame *const src)
static unsigned int av_rpi_sand_frame_stride1(const AVFrame *const frame)
Definition: rpi_sand_fns.h:100
4:2:0 10-bit 64x*Y stripe, 32x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:350
static int av_rpi_is_sand_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:122
4:2:0 16-bit 64x*Y stripe, 32x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:351
void av_rpi_sand_to_planar_c16(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static AVFrame * frame
static unsigned int av_rpi_sand_frame_off_y(const AVFrame *const frame, const unsigned int x_y, const unsigned int y)
Definition: rpi_sand_fns.h:150
static int av_rpi_is_sand_format(const int format)
Definition: rpi_sand_fns.h:117
void av_rpi_sand30_to_planar_c16(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static uint8_t * av_rpi_sand_frame_pos_y(const AVFrame *const frame, const unsigned int x, const unsigned int y)
Definition: rpi_sand_fns.h:172
void av_rpi_sand16_to_sand8(uint8_t *dst, const unsigned int dst_stride1, const unsigned int dst_stride2, const uint8_t *src, const unsigned int src_stride1, const unsigned int src_stride2, unsigned int w, unsigned int h, const unsigned int shr)
reference-counted frame API
void av_rpi_sand_to_planar_c8(uint8_t *dst_u, const unsigned int dst_stride_u, uint8_t *dst_v, const unsigned int dst_stride_v, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_sand_to_planar_y8(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static int av_rpi_is_sand30_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:137
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:299
static unsigned int av_rpi_sand_frame_off_c(const AVFrame *const frame, const unsigned int x_c, const unsigned int y_c)
Definition: rpi_sand_fns.h:161
static int av_rpi_sand_frame_xshl(const AVFrame *const frame)
Definition: rpi_sand_fns.h:142
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
void av_rpi_planar_to_sand_c8(uint8_t *dst_c, unsigned int stride1, unsigned int stride2, const uint8_t *src_u, const unsigned int src_stride_u, const uint8_t *src_v, const unsigned int src_stride_v, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static int av_rpi_is_sand8_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:127
static int av_rpi_is_sand16_frame(const AVFrame *const frame)
Definition: rpi_sand_fns.h:132
static unsigned int av_rpi_sand_frame_stride2(const AVFrame *const frame)
Definition: rpi_sand_fns.h:111
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
void av_rpi_sand30_to_planar_y16(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
4:2:0 8-bit 128x*Y stripe, 64x*UV stripe, then next x stripe, mysterious padding
Definition: pixfmt.h:349
void av_rpi_sand_to_planar_y16(uint8_t *dst, const unsigned int dst_stride, const uint8_t *src, unsigned int stride1, unsigned int stride2, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
void av_rpi_planar_to_sand_c16(uint8_t *dst_c, unsigned int stride1, unsigned int stride2, const uint8_t *src_u, const unsigned int src_stride_u, const uint8_t *src_v, const unsigned int src_stride_v, unsigned int _x, unsigned int y, unsigned int _w, unsigned int h)
static uint8_t * av_rpi_sand_frame_pos_c(const AVFrame *const frame, const unsigned int x, const unsigned int y)
Definition: rpi_sand_fns.h:177