1 /* GStreamer H.264 Parser 2 * Copyright (C) <2010> Collabora ltd 3 * Copyright (C) <2010> Nokia Corporation 4 * Copyright (C) <2011> Intel Corporation 5 * 6 * Copyright (C) <2010> Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk> 7 * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com> 8 * 9 * This library is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Library General Public 11 * License as published by the Free Software Foundation; either 12 * version 2 of the License, or (at your option) any later version. 13 * 14 * This library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Library General Public License for more details. 18 * 19 * You should have received a copy of the GNU Library General Public 20 * License along with this library; if not, write to the 21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 22 * Boston, MA 02110-1301, USA. 23 */ 24 25 #ifndef __GST_H264_PARSE_H__ 26 #define __GST_H264_PARSE_H__ 27 28 #include <gst/gst.h> 29 #include <gst/base/gstbaseparse.h> 30 #include <gst/codecparsers/gsth264parser.h> 31 #include <gst/video/video.h> 32 #include "gstvideoparseutils.h" 33 34 G_BEGIN_DECLS 35 36 typedef struct _H264Params H264Params; 37 38 #define GST_TYPE_H264_PARSE \ 39 (gst_h264_parse_get_type()) 40 #define GST_H264_PARSE(obj) \ 41 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_H264_PARSE,GstH264Parse)) 42 #define GST_H264_PARSE_CLASS(klass) \ 43 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_H264_PARSE,GstH264ParseClass)) 44 #define GST_IS_H264_PARSE(obj) \ 45 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_H264_PARSE)) 46 #define GST_IS_H264_PARSE_CLASS(klass) \ 47 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_H264_PARSE)) 48 49 GType gst_h264_parse_get_type (void); 50 51 typedef struct _GstH264Parse GstH264Parse; 52 typedef struct _GstH264ParseClass GstH264ParseClass; 53 54 struct _GstH264Parse 55 { 56 GstBaseParse baseparse; 57 58 /* stream */ 59 gint width, height; 60 gint fps_num, fps_den; 61 gint upstream_par_n, upstream_par_d; 62 gint parsed_par_n, parsed_par_d; 63 gint parsed_fps_n, parsed_fps_d; 64 GstVideoColorimetry parsed_colorimetry; 65 /* current codec_data in output caps, if any */ 66 GstBuffer *codec_data; 67 /* input codec_data, if any */ 68 GstBuffer *codec_data_in; 69 guint nal_length_size; 70 gboolean packetized; 71 gboolean split_packetized; 72 gboolean transform; 73 74 /* state */ 75 GstH264NalParser *nalparser; 76 guint state; 77 guint in_align; 78 guint align; 79 guint format; 80 gint current_off; 81 /* True if input format and alignment match negotiated output */ 82 gboolean can_passthrough; 83 84 GstClockTime last_report; 85 gboolean push_codec; 86 /* The following variables have a meaning in context of "have 87 * SPS/PPS to push downstream", e.g. to update caps */ 88 gboolean have_sps; 89 gboolean have_pps; 90 91 /* per frame sps/pps check for periodic push codec decision */ 92 gboolean have_sps_in_frame; 93 gboolean have_pps_in_frame; 94 95 /* per frame AU Delimiter check used when in_format == avc or avc3 */ 96 gboolean have_aud_in_frame; 97 98 /* tracing state whether h264parse needs to insert AUD or not. 99 * Used when in_format == byte-stream */ 100 gboolean aud_needed; 101 102 /* For insertion of AU Delimiter */ 103 gboolean aud_insert; 104 105 gboolean first_frame; 106 107 /* collected SPS and PPS NALUs */ 108 GstBuffer *sps_nals[GST_H264_MAX_SPS_COUNT]; 109 GstBuffer *pps_nals[GST_H264_MAX_PPS_COUNT]; 110 111 /* collected SEI timestamps */ 112 guint num_clock_timestamp; 113 GstH264PicTiming pic_timing_sei; 114 115 /* Infos we need to keep track of */ 116 guint32 sei_cpb_removal_delay; 117 guint8 sei_pic_struct; 118 guint8 sei_pic_struct_pres_flag; 119 guint field_pic_flag; 120 121 /* cached timestamps */ 122 /* (trying to) track upstream dts and interpolate */ 123 GstClockTime dts; 124 /* dts at start of last buffering period */ 125 GstClockTime ts_trn_nb; 126 gboolean do_ts; 127 128 gboolean discont; 129 gboolean marker; 130 131 /* frame parsing */ 132 /*guint last_nal_pos;*/ 133 /*guint next_sc_pos;*/ 134 gint idr_pos, sei_pos; 135 gint pic_timing_sei_pos; 136 gint pic_timing_sei_size; 137 gboolean update_caps; 138 GstAdapter *frame_out; 139 gboolean keyframe; 140 gboolean predicted; 141 gboolean bidirectional; 142 gboolean header; 143 gboolean frame_start; 144 /* AU state */ 145 gboolean picture_start; 146 147 /* props */ 148 gint interval; 149 gboolean update_timecode; 150 151 GstClockTime pending_key_unit_ts; 152 GstEvent *force_key_unit_event; 153 154 /* Stereo / multiview info */ 155 GstVideoMultiviewMode multiview_mode; 156 GstVideoMultiviewFlags multiview_flags; 157 gboolean first_in_bundle; 158 159 GstVideoParseUserData user_data; 160 161 GstVideoMasteringDisplayInfo mastering_display_info; 162 guint mastering_display_info_state; 163 164 GstVideoContentLightLevel content_light_level; 165 guint content_light_level_state; 166 167 /* For forward predicted trickmode */ 168 gboolean discard_bidirectional; 169 }; 170 171 struct _GstH264ParseClass 172 { 173 GstBaseParseClass parent_class; 174 }; 175 176 G_END_DECLS 177 #endif 178