FFmpeg  n2.7-dev-20500-gb515f38688
rpi_zc.h
Go to the documentation of this file.
1 #ifndef LIBAVCODEC_RPI_ZC_H
2 #define LIBAVCODEC_RPI_ZC_H
3 
4 // Zero-Copy frame code for RPi
5 // RPi needs Y/U/V planes to be contiguous for display. By default
6 // ffmpeg will allocate separated planes so a memcpy is needed before
7 // display. This code provides a method a making ffmpeg allocate a single
8 // bit of memory for the frame when can then be reference counted until
9 // display has finished with it.
10 
11 // Frame buffer number in which to stuff an 8-bit copy of a 16-bit frame
12 // 0 disables
13 // *** This option still in development
14 // Only works if SAO active
15 // Allocates buffers that are twice the required size
16 #define RPI_ZC_SAND_8_IN_10_BUF 0
17 
18 struct AVBufferRef;
19 struct AVFrame;
20 struct AVCodecContext;
21 enum AVPixelFormat;
22 
23 // "Opaque" pointer to whatever we are using as a buffer reference
24 typedef struct AVBufferRef * AVRpiZcRefPtr;
25 
26 struct AVZcEnv;
27 typedef struct AVZcEnv * AVZcEnvPtr;
28 
29 typedef struct AVRpiZcFrameGeometry
30 {
31  unsigned int stride_y; // Luma stride (bytes)
32  unsigned int height_y; // Luma height (lines)
33  unsigned int stride_c; // Chroma stride (bytes)
34  unsigned int height_c; // Chroma stride (lines)
35  unsigned int planes_c; // Chroma plane count (U, V = 2, interleaved = 1)
36  unsigned int stripes; // Number of stripes (sand)
37  unsigned int bytes_per_pel;
39 
40 
42  const int format,
43  const unsigned int video_width, const unsigned int video_height);
44 
45 // Replacement fn for avctx->get_buffer2
46 // Should be set before calling avcodec_decode_open2
47 //
48 // N.B. in addition to to setting avctx->get_buffer2, avctx->refcounted_frames
49 // must be set to 1 as otherwise the buffer info is killed before being returned
50 // by avcodec_decode_video2. Note also that this means that the AVFrame that is
51 // returned must be manually derefed with av_frame_unref. This should be done
52 // after av_rpi_zc_ref has been called.
53 int av_rpi_zc_get_buffer2(struct AVCodecContext *s, AVFrame *frame, int flags);
54 
55 // Generate a ZC reference to the buffer(s) in this frame
56 // If the buffer doesn't appear to be one allocated by _get_buffer_2
57 // then the behaviour depends on maycopy:
58 // If maycopy=0 then return NULL
59 // If maycopy=1 && the src frame is in a form where we can easily copy
60 // the data, then allocate a new buffer and copy the data into it
61 // Otherwise return NULL
62 AVRpiZcRefPtr av_rpi_zc_ref(struct AVCodecContext * const s,
63  const struct AVFrame * const frame, const enum AVPixelFormat expected_format, const int maycopy);
64 
65 // Get the vc_handle from the frame ref
66 // Returns -1 if ref doesn't look valid
67 int av_rpi_zc_vc_handle(const AVRpiZcRefPtr fr_ref);
68 // Get offset from the start of the memory referenced
69 // by the vc_handle to valid data
70 int av_rpi_zc_offset(const AVRpiZcRefPtr fr_ref);
71 // Length of buffer data
72 int av_rpi_zc_length(const AVRpiZcRefPtr fr_ref);
73 // Get the number of bytes allocated from the frame ref
74 // Returns 0 if ref doesn't look valid
75 int av_rpi_zc_numbytes(const AVRpiZcRefPtr fr_ref);
76 
77 // Unreference the buffer refed/allocated by _zc_ref
78 // If fr_ref is NULL then this will NOP
79 void av_rpi_zc_unref(AVRpiZcRefPtr fr_ref);
80 
81 // Allocate an environment for the buffer pool used by the ZC code
82 // This should be put in avctx->get_buffer_context so it can be found by
83 // av_rpi_zc_get_buffer2 when it is called from ffmpeg
85 
86 // Allocate the environment used by the ZC code
88 
89 // Test to see if the context is using zc (checks get_buffer2)
90 int av_rpi_zc_in_use(const struct AVCodecContext * const s);
91 
92 // Init ZC into a context
93 // There is nothing magic in this fn - it just packages setting
94 // get_buffer2 & get_buffer_context
95 int av_rpi_zc_init(struct AVCodecContext * const s);
96 
97 // Free ZC from a context
98 // There is nothing magic in this fn - it just packages unsetting
99 // get_buffer2 & get_buffer_context
100 void av_rpi_zc_uninit(struct AVCodecContext * const s);
101 
102 
103 
104 #endif
105 
unsigned int planes_c
Definition: rpi_zc.h:35
unsigned int stripes
Definition: rpi_zc.h:36
int av_rpi_zc_get_buffer2(struct AVCodecContext *s, AVFrame *frame, int flags)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:218
int av_rpi_zc_vc_handle(const AVRpiZcRefPtr fr_ref)
void av_rpi_zc_env_free(AVZcEnvPtr)
static AVFrame * frame
unsigned int height_y
Definition: rpi_zc.h:32
int av_rpi_zc_length(const AVRpiZcRefPtr fr_ref)
AVRpiZcFrameGeometry av_rpi_zc_frame_geometry(const int format, const unsigned int video_width, const unsigned int video_height)
void av_rpi_zc_uninit(struct AVCodecContext *const s)
int av_rpi_zc_offset(const AVRpiZcRefPtr fr_ref)
unsigned int bytes_per_pel
Definition: rpi_zc.h:37
main external API structure.
Definition: avcodec.h:1520
struct AVZcEnv * AVZcEnvPtr
Definition: rpi_zc.h:27
unsigned int stride_y
Definition: rpi_zc.h:31
unsigned int height_c
Definition: rpi_zc.h:34
A reference to a data buffer.
Definition: buffer.h:81
unsigned int stride_c
Definition: rpi_zc.h:33
int av_rpi_zc_numbytes(const AVRpiZcRefPtr fr_ref)
int av_rpi_zc_in_use(const struct AVCodecContext *const s)
int av_rpi_zc_init(struct AVCodecContext *const s)
AVZcEnvPtr av_rpi_zc_env_alloc(void)
AVRpiZcRefPtr av_rpi_zc_ref(struct AVCodecContext *const s, const struct AVFrame *const frame, const enum AVPixelFormat expected_format, const int maycopy)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
void av_rpi_zc_unref(AVRpiZcRefPtr fr_ref)