6a79ac5240d9b8a81bba15f792eaa2ae7f825456
[platform/upstream/gstreamer.git] / sys / rpicamsrc / RaspiCapture.h
1 /*
2  * GStreamer
3  * Copyright (C) 2013-2015 Jan Schmidt <jan@centricular.com>
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Alternatively, the contents of this file may be used under the
24  * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
25  * which case the following provisions apply instead of the ones
26  * mentioned above:
27  *
28  * This library is free software; you can redistribute it and/or
29  * modify it under the terms of the GNU Library General Public
30  * License as published by the Free Software Foundation; either
31  * version 2 of the License, or (at your option) any later version.
32  *
33  * This library is distributed in the hope that it will be useful,
34  * but WITHOUT ANY WARRANTY; without even the implied warranty of
35  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
36  * Library General Public License for more details.
37  *
38  * You should have received a copy of the GNU Library General Public
39  * License along with this library; if not, write to the
40  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41  * Boston, MA 02111-1307, USA.
42  */
43
44 #ifndef __RASPICAPTURE_H__
45 #define __RASPICAPTURE_H__
46
47 #include <glib.h>
48 #include <inttypes.h>
49
50 #include "interface/mmal/mmal_common.h"
51 #include "interface/mmal/mmal_types.h"
52 #include "interface/mmal/mmal_parameters_camera.h"
53 #include "interface/mmal/mmal_component.h"
54 #include "RaspiCamControl.h"
55 #include "RaspiPreview.h"
56
57 GST_DEBUG_CATEGORY_EXTERN (gst_rpi_cam_src_debug);
58 #define GST_CAT_DEFAULT gst_rpi_cam_src_debug
59
60 #undef fprintf
61 #define fprintf(f,...) GST_LOG(__VA_ARGS__)
62 #undef vcos_log_error
63 #define vcos_log_error GST_ERROR
64 #undef vcos_log_warn
65 #define vcos_log_warn GST_WARNING
66
67 G_BEGIN_DECLS
68
69 typedef enum
70 {
71   PROP_CHANGE_ENCODING          = (1 << 0), /* BITRATE or QUANT or KEY Interval, intra refresh */
72   PROP_CHANGE_PREVIEW           = (1 << 1), /* Preview opacity or fullscreen */
73   PROP_CHANGE_COLOURBALANCE     = (1 << 2),
74   PROP_CHANGE_SENSOR_SETTINGS   = (1 << 3), /* ISO, EXPOSURE, SHUTTER, DRC, Sensor Mode */
75   PROP_CHANGE_VIDEO_STABILISATION = (1 << 4),
76   PROP_CHANGE_AWB               = (1 << 5),
77   PROP_CHANGE_IMAGE_COLOUR_EFFECT = (1 << 6),
78   PROP_CHANGE_ORIENTATION       = (1 << 7),
79   PROP_CHANGE_ROI               = (1 << 8),
80   PROP_CHANGE_ANNOTATION        = (1 << 9)
81 } RpiPropChangeFlags;
82
83 /** Structure containing all state information for the current run
84  */
85 typedef struct
86 {
87    RpiPropChangeFlags change_flags;
88
89    int verbose; /// !0 if want detailed run information
90
91    int timeout;                        /// Time taken before frame is grabbed and app then shuts down. Units are milliseconds
92    int width;                          /// Requested width of image
93    int height;                         /// requested height of image
94    int bitrate;                        /// Requested bitrate
95    int fps_n;                      /// Requested frame rate (fps) numerator
96    int fps_d;                      /// Requested frame rate (fps) denominator
97    int intraperiod;                    /// Intra-refresh period (key frame rate)
98    int quantisationParameter;          /// Quantisation parameter - quality. Set bitrate 0 and set this for variable bitrate
99    int bInlineHeaders;                  /// Insert inline headers to stream (SPS, PPS)
100    int demoMode;                       /// Run app in demo mode
101    int demoInterval;                   /// Interval between camera settings changes
102    int immutableInput;                 /// Flag to specify whether encoder works in place or creates a new buffer. Result is preview can display either
103                                        /// the camera output or the encoder output (with compression artifacts)
104    int profile;                        /// H264 profile to use for encoding
105    RASPIPREVIEW_PARAMETERS preview_parameters;   /// Preview setup parameters
106    RASPICAM_CAMERA_PARAMETERS camera_parameters; /// Camera setup parameters
107
108    int inlineMotionVectors;             /// Encoder outputs inline Motion Vectors
109
110    int cameraNum;                       /// Camera number
111    int settings;                        /// Request settings from the camera
112    int sensor_mode;                     /// Sensor mode. 0=auto. Check docs/forum for modes selected by other values.
113    int intra_refresh_type;              /// What intra refresh type to use. -1 to not set.
114
115    MMAL_FOURCC_T encoding;              // Which encoding to use
116
117    int jpegQuality;
118    int jpegRestartInterval;
119 } RASPIVID_CONFIG;
120
121 typedef struct RASPIVID_STATE_T RASPIVID_STATE;
122
123 void raspicapture_init();
124 void raspicapture_default_config(RASPIVID_CONFIG *config);
125 RASPIVID_STATE *raspi_capture_setup(RASPIVID_CONFIG *config);
126 gboolean raspi_capture_start(RASPIVID_STATE *state);
127 void raspi_capture_update_config (RASPIVID_STATE *state,
128     RASPIVID_CONFIG *config, gboolean dynamic);
129 GstFlowReturn raspi_capture_fill_buffer(RASPIVID_STATE *state, GstBuffer **buf,
130     GstClock *clock, GstClockTime base_time);
131 void raspi_capture_stop(RASPIVID_STATE *state);
132 void raspi_capture_free(RASPIVID_STATE *state);
133 gboolean raspi_capture_request_i_frame(RASPIVID_STATE *state);
134
135 G_END_DECLS
136
137 #endif