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 34 #include "uvc_h264.h" 35 36 G_BEGIN_DECLS 37 38 #define GST_TYPE_UVC_H264_SRC \ 39 (gst_uvc_h264_src_get_type()) 40 #define GST_UVC_H264_SRC(obj) \ 41 (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_UVC_H264_SRC, GstUvcH264Src)) 42 #define GST_UVC_H264_SRC_CLASS(klass) \ 43 (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_UVC_H264_SRC, GstUvcH264SrcClass)) 44 #define GST_IS_UVC_H264_SRC(obj) \ 45 (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_UVC_H264_SRC)) 46 #define GST_IS_UVC_H264_SRC_CLASS(klass) \ 47 (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_UVC_H264_SRC)) 48 GType gst_uvc_h264_src_get_type (void); 49 50 typedef struct _GstUvcH264Src GstUvcH264Src; 51 typedef struct _GstUvcH264SrcClass GstUvcH264SrcClass; 52 53 enum GstVideoRecordingStatus { 54 GST_VIDEO_RECORDING_STATUS_DONE, 55 GST_VIDEO_RECORDING_STATUS_STARTING, 56 GST_VIDEO_RECORDING_STATUS_RUNNING, 57 GST_VIDEO_RECORDING_STATUS_FINISHING 58 }; 59 60 enum { 61 QP_I_FRAME = 0, 62 QP_P_FRAME, 63 QP_B_FRAME, 64 QP_FRAMES 65 }; 66 67 typedef enum { 68 UVC_H264_SRC_FORMAT_NONE, 69 UVC_H264_SRC_FORMAT_JPG, 70 UVC_H264_SRC_FORMAT_H264, 71 UVC_H264_SRC_FORMAT_RAW 72 } GstUvcH264SrcFormat; 73 74 /** 75 * GstUcH264Src: 76 * 77 */ 78 struct _GstUvcH264Src 79 { 80 GstBaseCameraSrc parent; 81 82 GstPad *vfsrc; 83 GstPad *imgsrc; 84 GstPad *vidsrc; 85 86 /* source elements */ 87 GstElement *v4l2_src; 88 GstElement *mjpg_demux; 89 GstElement *jpeg_dec; 90 GstElement *vid_colorspace; 91 GstElement *vf_colorspace; 92 93 GstUvcH264SrcFormat main_format; 94 guint16 main_width; 95 guint16 main_height; 96 guint32 main_frame_interval; 97 UvcH264StreamFormat main_stream_format; 98 guint16 main_profile; 99 GstUvcH264SrcFormat secondary_format; 100 guint16 secondary_width; 101 guint16 secondary_height; 102 guint32 secondary_frame_interval; 103 104 int v4l2_fd; 105 guint8 h264_unit_id; 106 libusb_context *usb_ctx; 107 108 GstPadEventFunction srcpad_event_func; 109 GstEvent *key_unit_event; 110 GstSegment segment; 111 112 gboolean started; 113 114 /* When restarting the source */ 115 gboolean reconfiguring; 116 gboolean vid_newseg; 117 gboolean vf_newseg; 118 119 gchar *colorspace_name; 120 gchar *jpeg_decoder_name; 121 int num_clock_samples; 122 123 /* v4l2src proxied properties */ 124 guint32 num_buffers; 125 gchar *device; 126 127 /* Static controls */ 128 guint32 initial_bitrate; 129 guint16 slice_units; 130 UvcH264SliceMode slice_mode; 131 guint16 iframe_period; 132 UvcH264UsageType usage_type; 133 UvcH264Entropy entropy; 134 gboolean enable_sei; 135 guint8 num_reorder_frames; 136 gboolean preview_flipped; 137 guint16 leaky_bucket_size; 138 139 /* Dynamic controls */ 140 UvcH264RateControl rate_control; 141 gboolean fixed_framerate; 142 guint8 level_idc; 143 guint32 peak_bitrate; 144 guint32 average_bitrate; 145 gint8 min_qp[QP_FRAMES]; 146 gint8 max_qp[QP_FRAMES]; 147 guint8 ltr_buffer_size; 148 guint8 ltr_encoder_control; 149 }; 150 151 152 /** 153 * GstUvcH264SrcClass: 154 * 155 */ 156 struct _GstUvcH264SrcClass 157 { 158 GstBaseCameraSrcClass parent; 159 }; 160 161 GST_ELEMENT_REGISTER_DECLARE (uvch264src); 162 163 G_END_DECLS 164 165 #endif /* __GST_UVC_H264_SRC_H__ */ 166