RAPICAM_3-15-2015
RaspiTex.h
1 /*
2 Copyright (c) 2013, Broadcom Europe Ltd
3 Copyright (c) 2013, Tim Gover
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8  * Redistributions of source code must retain the above copyright
9  notice, this list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright
11  notice, this list of conditions and the following disclaimer in the
12  documentation and/or other materials provided with the distribution.
13  * Neither the name of the copyright holder nor the
14  names of its contributors may be used to endorse or promote products
15  derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 
29 #ifndef RASPITEX_H_
30 #define RASPITEX_H_
31 
32 #include <stdio.h>
33 #include <EGL/egl.h>
34 #include <EGL/eglext.h>
35 #include <GLES/gl.h>
36 #include <GLES/glext.h>
37 #include "interface/khronos/include/EGL/eglext_brcm.h"
38 #include "interface/mmal/mmal.h"
39 
40 #define RASPITEX_VERSION_MAJOR 1
41 #define RASPITEX_VERSION_MINOR 0
42 
43 typedef enum {
44  RASPITEX_SCENE_SQUARE = 0,
45  RASPITEX_SCENE_MIRROR,
46  RASPITEX_SCENE_TEAPOT,
47  RASPITEX_SCENE_YUV,
48  RASPITEX_SCENE_SOBEL,
49 
50 } RASPITEX_SCENE_T;
51 
52 struct RASPITEX_STATE;
53 
54 typedef struct RASPITEX_SCENE_OPS
55 {
58  int (*create_native_window)(struct RASPITEX_STATE *state);
59 
61  int (*gl_init)(struct RASPITEX_STATE *state);
62 
65  int (*update_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf);
66 
69  int (*update_y_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf);
70 
73  int (*update_u_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf);
74 
77  int (*update_v_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf);
78 
80  int (*update_model)(struct RASPITEX_STATE *state);
81 
83  int (*redraw)(struct RASPITEX_STATE *state);
84 
87  int (*capture)(struct RASPITEX_STATE *state,
88  uint8_t **buffer, size_t *buffer_size);
89 
91  void (*gl_term)(struct RASPITEX_STATE *state);
92 
94  void (*destroy_native_window)(struct RASPITEX_STATE *state);
95 
97  void (*close)(struct RASPITEX_STATE *state);
99 
100 typedef struct RASPITEX_CAPTURE
101 {
103  VCOS_SEMAPHORE_T start_sem;
104 
106  VCOS_SEMAPHORE_T completed_sem;
107 
109  uint8_t *buffer;
110 
112  size_t size;
113 
116  int request;
118 
123 typedef struct RASPITEX_STATE
124 {
125  int version_major;
127  MMAL_PORT_T *preview_port;
128  MMAL_POOL_T *preview_pool;
129  MMAL_QUEUE_T *preview_queue;
130  VCOS_THREAD_T preview_thread;
131  uint32_t preview_stop;
132 
133  /* Copy of preview window params */
134  int32_t preview_x;
135  int32_t preview_y;
136  int32_t preview_width;
137  int32_t preview_height;
138 
139  /* Display rectangle for the native window */
140  int32_t x;
141  int32_t y;
142  int32_t width;
143  int32_t height;
144  int opacity;
146 
147  /* DispmanX info. This might be unused if a custom create_native_window
148  * does something else. */
149  DISPMANX_DISPLAY_HANDLE_T disp;
150  EGL_DISPMANX_WINDOW_T win;
151 
152  EGLNativeWindowType* native_window;
153  EGLDisplay display;
154  EGLSurface surface;
155  EGLContext context;
156  const EGLint *egl_config_attribs;
157 
158  GLuint texture;
159  EGLImageKHR egl_image;
160 
161  GLuint y_texture;
162  EGLImageKHR y_egl_image;
163  GLuint u_texture;
164  EGLImageKHR u_egl_image;
165  GLuint v_texture;
166  EGLImageKHR v_egl_image;
167 
168  MMAL_BUFFER_HEADER_T *preview_buf;
169 
170  RASPITEX_SCENE_T scene_id;
172  void *scene_state;
173  int verbose;
174 
176 
178 
179 int raspitex_init(RASPITEX_STATE *state);
180 void raspitex_destroy(RASPITEX_STATE *state);
181 int raspitex_start(RASPITEX_STATE *state);
182 void raspitex_stop(RASPITEX_STATE *state);
183 void raspitex_set_defaults(RASPITEX_STATE *state);
184 int raspitex_configure_preview_port(RASPITEX_STATE *state,
185  MMAL_PORT_T *preview_port);
186 void raspitex_display_help();
188  const char *arg1, const char *arg2);
189 int raspitex_capture(RASPITEX_STATE *state, FILE* output_file);
190 
191 #endif /* RASPITEX_H_ */
Definition: RaspiTex.h:54
void(* close)(struct RASPITEX_STATE *state)
Called when the scene is unloaded.
Definition: RaspiTex.h:97
int version_minor
For binary compatibility.
Definition: RaspiTex.h:126
void(* destroy_native_window)(struct RASPITEX_STATE *state)
Destroys the native window.
Definition: RaspiTex.h:94
EGLNativeWindowType * native_window
Dispmanx handle for preview surface.
Definition: RaspiTex.h:152
int opacity
height in pixels
Definition: RaspiTex.h:144
int(* update_model)(struct RASPITEX_STATE *state)
Advance to the next animation step.
Definition: RaspiTex.h:80
RASPITEX_SCENE_OPS ops
Id of the scene to load.
Definition: RaspiTex.h:171
EGLSurface surface
The current EGL display.
Definition: RaspiTex.h:154
int raspitex_start(RASPITEX_STATE *state)
Definition: RaspiTex.c:683
int(* gl_init)(struct RASPITEX_STATE *state)
Creates EGL surface for native window.
Definition: RaspiTex.h:61
GLuint u_texture
EGL image for Y plane texture.
Definition: RaspiTex.h:163
uint8_t * buffer
The RGB capture buffer.
Definition: RaspiTex.h:109
EGLImageKHR u_egl_image
The U plane texture.
Definition: RaspiTex.h:164
int32_t height
width in pixels
Definition: RaspiTex.h:143
GLuint v_texture
EGL image for U plane texture.
Definition: RaspiTex.h:165
int raspitex_capture(RASPITEX_STATE *state, FILE *output_file)
Definition: RaspiTex.c:705
int(* update_v_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf)
Definition: RaspiTex.h:77
int(* update_u_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf)
Definition: RaspiTex.h:73
int32_t x
preview y-plane height in pixels
Definition: RaspiTex.h:140
GLuint y_texture
The current preview EGL image.
Definition: RaspiTex.h:161
RASPITEX_SCENE_T scene_id
MMAL buffer currently bound to texture(s)
Definition: RaspiTex.h:170
VCOS_SEMAPHORE_T start_sem
Wait for previous capture to complete.
Definition: RaspiTex.h:103
MMAL_QUEUE_T * preview_queue
Pool for storing opaque buffer handles.
Definition: RaspiTex.h:129
int(* update_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf)
Definition: RaspiTex.h:65
const EGLint * egl_config_attribs
The current EGL context.
Definition: RaspiTex.h:156
VCOS_THREAD_T preview_thread
Queue preview buffers to display in order.
Definition: RaspiTex.h:130
int(* update_y_texture)(struct RASPITEX_STATE *state, EGLClientBuffer mm_buf)
Definition: RaspiTex.h:69
int raspitex_parse_cmdline(RASPITEX_STATE *state, const char *arg1, const char *arg2)
Definition: RaspiTex.c:112
int32_t preview_height
preview y-plane width in pixels
Definition: RaspiTex.h:137
RASPITEX_CAPTURE capture
Log FPS.
Definition: RaspiTex.h:175
size_t size
Size of the captured buffer in bytes.
Definition: RaspiTex.h:112
MMAL_POOL_T * preview_pool
Source port for preview opaque buffers.
Definition: RaspiTex.h:128
MMAL_BUFFER_HEADER_T * preview_buf
EGL image for V plane texture.
Definition: RaspiTex.h:168
int(* capture)(struct RASPITEX_STATE *state, uint8_t **buffer, size_t *buffer_size)
Definition: RaspiTex.h:87
EGLDisplay display
Native window used for EGL surface.
Definition: RaspiTex.h:153
void * scene_state
The interface for the current scene.
Definition: RaspiTex.h:172
MMAL_PORT_T * preview_port
Incremented for new features.
Definition: RaspiTex.h:127
EGLImageKHR y_egl_image
The Y plane texture.
Definition: RaspiTex.h:162
uint32_t preview_stop
Preview worker / GL rendering thread.
Definition: RaspiTex.h:131
VCOS_SEMAPHORE_T completed_sem
Posted once the capture is complete.
Definition: RaspiTex.h:106
int request
Definition: RaspiTex.h:116
int gl_win_defined
Alpha value for display element.
Definition: RaspiTex.h:145
int32_t y
x-offset in pixels
Definition: RaspiTex.h:141
void(* gl_term)(struct RASPITEX_STATE *state)
Creates EGL surface for native window.
Definition: RaspiTex.h:91
int32_t preview_x
If zero the worker can continue.
Definition: RaspiTex.h:134
GLuint texture
GL scenes preferred EGL configuration.
Definition: RaspiTex.h:158
int(* create_native_window)(struct RASPITEX_STATE *state)
Definition: RaspiTex.h:58
int32_t width
y-offset in pixels
Definition: RaspiTex.h:142
EGLImageKHR egl_image
Name for the preview texture.
Definition: RaspiTex.h:159
EGLContext context
The current EGL surface.
Definition: RaspiTex.h:155
int verbose
Pointer to scene specific data.
Definition: RaspiTex.h:173
DISPMANX_DISPLAY_HANDLE_T disp
Use rect from –glwin instead of preview.
Definition: RaspiTex.h:149
Definition: RaspiTex.h:123
int32_t preview_y
x-offset of preview window
Definition: RaspiTex.h:135
Definition: RaspiTex.h:100
int32_t preview_width
y-offset of preview window
Definition: RaspiTex.h:136
EGLImageKHR v_egl_image
The V plane texture.
Definition: RaspiTex.h:166
EGL_DISPMANX_WINDOW_T win
Dispmanx display for GL preview.
Definition: RaspiTex.h:150
int(* redraw)(struct RASPITEX_STATE *state)
Draw the scene - called after update_model.
Definition: RaspiTex.h:83
void raspitex_display_help()
Definition: RaspiTex.c:175