1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON 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
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef MMAL_BUFFER_PRIVATE_H
29#define MMAL_BUFFER_PRIVATE_H
30
31/** Typedef for the private area the framework reserves for the driver / communication layer */
32typedef struct MMAL_DRIVER_BUFFER_T MMAL_DRIVER_BUFFER_T;
33
34/** Size of the private area the framework reserves for the driver / communication layer */
35#define MMAL_DRIVER_BUFFER_SIZE 32
36
37/** Typedef for the framework's private area in the buffer header */
38typedef struct MMAL_BUFFER_HEADER_PRIVATE_T
39{
40 /** Callback invoked just prior to actually releasing the buffer header. Returns TRUE if
41 * release should be delayed. */
42 MMAL_BH_PRE_RELEASE_CB_T pf_pre_release;
43 void *pre_release_userdata;
44
45 /** Callback used to release / recycle the buffer header. This needs to be set by
46 * whoever allocates the buffer header. */
47 void (*pf_release)(struct MMAL_BUFFER_HEADER_T *header);
48 void *owner; /**< Context set by the allocator of the buffer header and passed
49 during the release callback */
50
51 int32_t refcount; /**< Reference count of the buffer header. When it reaches 0,
52 the release callback will be called. */
53
54 MMAL_BUFFER_HEADER_T *reference; /**< Reference to another acquired buffer header. */
55
56 /** Callback used to free the payload associated with this buffer header. This is only
57 * used if the buffer header was created by MMAL with a payload associated with it. */
58 void (*pf_payload_free)(void *payload_context, void *payload);
59 void *payload; /**< Pointer / handle to the allocated payload buffer */
60 void *payload_context; /**< Pointer to the context of the payload allocator */
61 uint32_t payload_size; /**< Allocated size in bytes of payload buffer */
62
63 void *component_data; /**< Field reserved for use by the component */
64 void *payload_handle; /**< Field reserved for mmal_buffer_header_mem_lock */
65
66 uint8_t driver_area[MMAL_DRIVER_BUFFER_SIZE];
67
68} MMAL_BUFFER_HEADER_PRIVATE_T;
69
70/** Get the size in bytes of a fully initialised MMAL_BUFFER_HEADER_T */
71unsigned int mmal_buffer_header_size(MMAL_BUFFER_HEADER_T *header);
72
73/** Initialise a MMAL_BUFFER_HEADER_T */
74MMAL_BUFFER_HEADER_T *mmal_buffer_header_initialise(void *mem, unsigned int length);
75
76/** Return a pointer to the area reserved for the driver.
77 */
78MMAL_DRIVER_BUFFER_T *mmal_buffer_header_driver_data(MMAL_BUFFER_HEADER_T *);
79
80/** Return a pointer to a referenced buffer header.
81 * It is the caller's responsibility to ensure that the reference is still
82 * valid when using it.
83 */
84MMAL_BUFFER_HEADER_T *mmal_buffer_header_reference(MMAL_BUFFER_HEADER_T *header);
85
86#endif /* MMAL_BUFFER_PRIVATE_H */
87