1 /*
2  * GStreamer
3  * Copyright (C) 2010 Texas Instruments, Inc
4  * Copyright (C) 2011 Thiago Santos <thiago.sousa.santos@collabora.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 
23 #ifndef __GST_BASE_CAMERA_SRC_H__
24 #define __GST_BASE_CAMERA_SRC_H__
25 
26 #ifndef GST_USE_UNSTABLE_API
27 #warning "GstBaseCameraSrc is unstable API and may change in future."
28 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
29 #endif
30 
31 #include <gst/gst.h>
32 #include <gst/gstbin.h>
33 #include "basecamerabinsrc-prelude.h"
34 #include "gstcamerabin-enum.h"
35 #include "gstcamerabinpreview.h"
36 
37 G_BEGIN_DECLS
38 
39 #define GST_TYPE_BASE_CAMERA_SRC \
40   (gst_base_camera_src_get_type())
41 #define GST_BASE_CAMERA_SRC(obj) \
42   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_CAMERA_SRC,GstBaseCameraSrc))
43 #define GST_BASE_CAMERA_SRC_GET_CLASS(obj) \
44   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_CAMERA_SRC, GstBaseCameraSrcClass))
45 #define GST_BASE_CAMERA_SRC_CLASS(klass) \
46   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_CAMERA_SRC,GstBaseCameraSrcClass))
47 #define GST_IS_BASE_CAMERA_SRC(obj) \
48   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_CAMERA_SRC))
49 #define GST_IS_BASE_CAMERA_SRC_CLASS(klass) \
50   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_CAMERA_SRC))
51 #define GST_BASE_CAMERA_SRC_CAST(obj) \
52   ((GstBaseCameraSrc *) (obj))
53 GST_BASE_CAMERA_BIN_SRC_API
54 GType gst_base_camera_src_get_type (void);
55 
56 typedef struct _GstBaseCameraSrc GstBaseCameraSrc;
57 typedef struct _GstBaseCameraSrcClass GstBaseCameraSrcClass;
58 
59 #define GST_BASE_CAMERA_SRC_VIEWFINDER_PAD_NAME "vfsrc"
60 #define GST_BASE_CAMERA_SRC_IMAGE_PAD_NAME "imgsrc"
61 #define GST_BASE_CAMERA_SRC_VIDEO_PAD_NAME "vidsrc"
62 
63 #define GST_BASE_CAMERA_SRC_PREVIEW_MESSAGE_NAME "preview-image"
64 
65 /**
66  * GstBaseCameraSrc:
67  */
68 struct _GstBaseCameraSrc
69 {
70   GstBin parent;
71 
72   GstCameraBinMode mode;
73 
74   gboolean auto_start;
75   gboolean capturing;
76   GMutex capturing_mutex;
77 
78   /* Preview convert pipeline */
79   GstCaps *preview_caps;
80   gboolean post_preview;
81   GstElement *preview_filter;
82   GstCameraBinPreviewPipelineData *preview_pipeline;
83 
84   /* Resolution of the buffers configured to camerabin */
85   gint width;
86   gint height;
87 
88   gfloat zoom;
89   gfloat max_zoom;
90 
91   gpointer _gst_reserved[GST_PADDING_LARGE];
92 };
93 
94 
95 /**
96  * GstBaseCameraSrcClass:
97  * @construct_pipeline: construct pipeline
98  * @setup_pipeline: configure pipeline for the chosen settings
99  * @set_zoom: set the zoom
100  * @set_mode: set the mode
101  */
102 struct _GstBaseCameraSrcClass
103 {
104   GstBinClass parent;
105 
106   /* Construct pipeline. (called in GST_STATE_CHANGE_NULL_TO_READY) Optional. */
107   gboolean    (*construct_pipeline)  (GstBaseCameraSrc *self);
108 
109   /* (called in GST_STATE_CHANGE_READY_TO_PAUSED). Optional. */
110   gboolean    (*setup_pipeline)      (GstBaseCameraSrc *self);
111 
112   /* Set the zoom. If set, called when changing 'zoom' property. Optional. */
113   void        (*set_zoom)            (GstBaseCameraSrc *self, gfloat zoom);
114 
115   /* Set the mode. If set, called when changing 'mode' property. Optional. */
116   gboolean    (*set_mode)            (GstBaseCameraSrc *self,
117                                       GstCameraBinMode mode);
118 
119   /* Set preview caps. If set, called called when setting new 'preview-caps'. Optional. */
120   gboolean    (*set_preview)         (GstBaseCameraSrc *self,
121                                       GstCaps *preview_caps);
122 
123   /* Called by the handler for 'start-capture'. Mandatory. */
124   gboolean (*start_capture) (GstBaseCameraSrc * src);
125 
126   /* Called by the handler for 'stop-capture'. Mandatory. */
127   void (*stop_capture) (GstBaseCameraSrc * src);
128 
129   gpointer _gst_reserved[GST_PADDING_LARGE];
130 };
131 
132 
133 #define MIN_ZOOM 1.0f
134 #define MAX_ZOOM 10.0f
135 #define ZOOM_1X MIN_ZOOM
136 
137 GST_BASE_CAMERA_BIN_SRC_API
138 gboolean gst_base_camera_src_set_mode (GstBaseCameraSrc *self, GstCameraBinMode mode);
139 
140 GST_BASE_CAMERA_BIN_SRC_API
141 void gst_base_camera_src_setup_zoom (GstBaseCameraSrc * self);
142 
143 GST_BASE_CAMERA_BIN_SRC_API
144 void gst_base_camera_src_setup_preview (GstBaseCameraSrc * self, GstCaps * preview_caps);
145 
146 GST_BASE_CAMERA_BIN_SRC_API
147 void gst_base_camera_src_finish_capture (GstBaseCameraSrc *self);
148 
149 
150 GST_BASE_CAMERA_BIN_SRC_API
151 void gst_base_camera_src_post_preview (GstBaseCameraSrc *self, GstSample * sample);
152 // XXX add methods to get/set img capture and vid capture caps..
153 
154 G_END_DECLS
155 
156 #endif /* __GST_BASE_CAMERA_SRC_H__ */
157