1 /* GStreamer H.265 Parser
2  * Copyright (C) 2013 Intel Corporation
3  *   Contact: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef __GST_H265_PARSE_H__
22 #define __GST_H265_PARSE_H__
23 
24 #include <gst/gst.h>
25 #include <gst/base/gstbaseparse.h>
26 #include <gst/codecparsers/gsth265parser.h>
27 
28 G_BEGIN_DECLS
29 
30 #define GST_TYPE_H265_PARSE \
31   (gst_h265_parse_get_type())
32 #define GST_H265_PARSE(obj) \
33   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_H265_PARSE,GstH265Parse))
34 #define GST_H265_PARSE_CLASS(klass) \
35   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_H265_PARSE,GstH265ParseClass))
36 #define GST_IS_H265_PARSE(obj) \
37   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_H265_PARSE))
38 #define GST_IS_H265_PARSE_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_H265_PARSE))
40 
41 GType gst_h265_parse_get_type (void);
42 
43 typedef struct _GstH265Parse GstH265Parse;
44 typedef struct _GstH265ParseClass GstH265ParseClass;
45 
46 struct _GstH265Parse
47 {
48   GstBaseParse baseparse;
49 
50   /* stream */
51   gint width, height;
52   gint fps_num, fps_den;
53   gint upstream_par_n, upstream_par_d;
54   gint parsed_par_n, parsed_par_d;
55   gint parsed_fps_n, parsed_fps_d;
56   /* current codec_data in output caps, if any */
57   GstBuffer *codec_data;
58   /* input codec_data, if any */
59   GstBuffer *codec_data_in;
60   guint nal_length_size;
61   gboolean packetized;
62   gboolean split_packetized;
63   gboolean transform;
64 
65   /* state */
66   GstH265Parser *nalparser;
67   guint state;
68   guint align;
69   guint format;
70   gint current_off;
71 
72   GstClockTime last_report;
73   gboolean push_codec;
74   /* The following variables have a meaning in context of "have
75    * VPS/SPS/PPS to push downstream", e.g. to update caps */
76   gboolean have_vps;
77   gboolean have_sps;
78   gboolean have_pps;
79 
80   /* per frame vps/sps/pps check for periodic push codec decision */
81   gboolean have_vps_in_frame;
82   gboolean have_sps_in_frame;
83   gboolean have_pps_in_frame;
84 
85   /* collected SPS and PPS NALUs */
86   GstBuffer *vps_nals[GST_H265_MAX_VPS_COUNT];
87   GstBuffer *sps_nals[GST_H265_MAX_SPS_COUNT];
88   GstBuffer *pps_nals[GST_H265_MAX_PPS_COUNT];
89 
90   /* Infos we need to keep track of */
91   guint8 sei_pic_struct;
92 
93   /* Collected TimeCode SEI */
94   GstH265TimeCode time_code;
95 
96   gboolean discont;
97 
98   /* frame parsing */
99   gint idr_pos, sei_pos;
100   gboolean update_caps;
101   GstAdapter *frame_out;
102   gboolean keyframe;
103   gboolean header;
104   /* AU state */
105   gboolean picture_start;
106 
107   /* props */
108   gint interval;
109 
110   gboolean sent_codec_tag;
111 
112   GstClockTime pending_key_unit_ts;
113   GstEvent *force_key_unit_event;
114 };
115 
116 struct _GstH265ParseClass
117 {
118   GstBaseParseClass parent_class;
119 };
120 
121 G_END_DECLS
122 #endif
123