1 /*
2  * GStreamer
3  *
4  * Copyright (C) 2012 Cisco Systems, Inc.
5  *   Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef __GST_UVC_H264_SRC_H__
25 #define __GST_UVC_H264_SRC_H__
26 
27 #ifdef HAVE_CONFIG_H
28 #  include <config.h>
29 #endif
30 
31 #include <gst/gst.h>
32 #include <gst/basecamerabinsrc/gstbasecamerasrc.h>
33 #include <libusb.h>
34 
35 #include "uvc_h264.h"
36 
37 G_BEGIN_DECLS
38 
39 #define GST_TYPE_UVC_H264_SRC                   \
40   (gst_uvc_h264_src_get_type())
41 #define GST_UVC_H264_SRC(obj)                                           \
42   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_UVC_H264_SRC, GstUvcH264Src))
43 #define GST_UVC_H264_SRC_CLASS(klass)                                   \
44   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_UVC_H264_SRC, GstUvcH264SrcClass))
45 #define GST_IS_UVC_H264_SRC(obj)                                \
46   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_UVC_H264_SRC))
47 #define GST_IS_UVC_H264_SRC_CLASS(klass)                        \
48   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_UVC_H264_SRC))
49     GType gst_uvc_h264_src_get_type (void);
50 
51 typedef struct _GstUvcH264Src GstUvcH264Src;
52 typedef struct _GstUvcH264SrcClass GstUvcH264SrcClass;
53 
54 enum GstVideoRecordingStatus {
55   GST_VIDEO_RECORDING_STATUS_DONE,
56   GST_VIDEO_RECORDING_STATUS_STARTING,
57   GST_VIDEO_RECORDING_STATUS_RUNNING,
58   GST_VIDEO_RECORDING_STATUS_FINISHING
59 };
60 
61 enum  {
62   QP_I_FRAME = 0,
63   QP_P_FRAME,
64   QP_B_FRAME,
65   QP_FRAMES
66 };
67 
68 typedef enum {
69   UVC_H264_SRC_FORMAT_NONE,
70   UVC_H264_SRC_FORMAT_JPG,
71   UVC_H264_SRC_FORMAT_H264,
72   UVC_H264_SRC_FORMAT_RAW
73 } GstUvcH264SrcFormat;
74 
75 /**
76  * GstUcH264Src:
77  *
78  */
79 struct _GstUvcH264Src
80 {
81   GstBaseCameraSrc parent;
82 
83   GstPad *vfsrc;
84   GstPad *imgsrc;
85   GstPad *vidsrc;
86 
87   /* source elements */
88   GstElement *v4l2_src;
89   GstElement *mjpg_demux;
90   GstElement *jpeg_dec;
91   GstElement *vid_colorspace;
92   GstElement *vf_colorspace;
93 
94   GstUvcH264SrcFormat main_format;
95   guint16 main_width;
96   guint16 main_height;
97   guint32 main_frame_interval;
98   UvcH264StreamFormat main_stream_format;
99   guint16 main_profile;
100   GstUvcH264SrcFormat secondary_format;
101   guint16 secondary_width;
102   guint16 secondary_height;
103   guint32 secondary_frame_interval;
104 
105   int v4l2_fd;
106   guint8 h264_unit_id;
107   libusb_context *usb_ctx;
108 
109   GstPadEventFunction srcpad_event_func;
110   GstEvent *key_unit_event;
111   GstSegment segment;
112 
113   gboolean started;
114 
115   /* When restarting the source */
116   gboolean reconfiguring;
117   gboolean vid_newseg;
118   gboolean vf_newseg;
119 
120   gchar *colorspace_name;
121   gchar *jpeg_decoder_name;
122   int num_clock_samples;
123 
124   /* v4l2src proxied properties */
125   guint32 num_buffers;
126   gchar *device;
127 
128   /* Static controls */
129   guint32 initial_bitrate;
130   guint16 slice_units;
131   UvcH264SliceMode slice_mode;
132   guint16 iframe_period;
133   UvcH264UsageType usage_type;
134   UvcH264Entropy entropy;
135   gboolean enable_sei;
136   guint8 num_reorder_frames;
137   gboolean preview_flipped;
138   guint16 leaky_bucket_size;
139 
140   /* Dynamic controls */
141   UvcH264RateControl rate_control;
142   gboolean fixed_framerate;
143   guint8 level_idc;
144   guint32 peak_bitrate;
145   guint32 average_bitrate;
146   gint8 min_qp[QP_FRAMES];
147   gint8 max_qp[QP_FRAMES];
148   guint8 ltr_buffer_size;
149   guint8 ltr_encoder_control;
150 };
151 
152 
153 /**
154  * GstUvcH264SrcClass:
155  *
156  */
157 struct _GstUvcH264SrcClass
158 {
159   GstBaseCameraSrcClass parent;
160 };
161 
162 G_END_DECLS
163 
164 #endif /* __GST_UVC_H264_SRC_H__ */
165