add properties in gsth264encode; profile, level,bitrate, intra-period, init-qp
[profile/ivi/gstreamer-vaapi.git] / gst / vaapiencode / h264encoder.h
1
2 #ifndef _GST_H264_ENCODER_H_
3 #define _GST_H264_ENCODER_H_
4
5 #include <stdio.h>
6 #include <stdint.h>
7
8 #include "gst/gstbuffer.h"
9 #include "gst/vaapi/gstvaapidisplay.h"
10 #include "gst/vaapi/gstvaapisurfacepool.h"
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifdef DEBUG
17 #include <assert.h>
18 #define H264_ASSERT(exp) assert(exp)
19 #else
20 #define H264_ASSERT(exp)
21 #endif
22
23 #define H264_NO_ERROR       0
24 #define H264_MEM_ERR       -1
25 #define H264_DISPLAY_ERR   -2
26 #define H264_CONFIG_ERR    -3
27 #define H264_CONTEXT_ERR    -3
28 #define H264_STATE_ERR     -4
29 #define H264_ENC_RES_ERR   -5
30 #define H264_PICTURE_ERR   -6
31 #define H264_SURFACE_ERR   -7
32 #define H264_QUERY_STATUS_ERR -8
33 #define H264_DATA_NOT_READY   -9
34 #define H264_DATA_ERR      -10
35 #define H264_PROFILE_ERR   -11
36 #define H264_PARAMETER_ERR -12
37
38
39 #define H264_LOG_ERROR(...) fprintf(stdout, ## __VA_ARGS__)
40 #define H264_LOG_DEBUG(...) fprintf(stdout, ## __VA_ARGS__)
41 #define H264_LOG_INFO(...)  fprintf(stdout, ## __VA_ARGS__)
42
43
44 typedef int                                 H264Status;
45 typedef struct _GstH264Encoder              GstH264Encoder;
46 typedef struct _GstH264EncoderPrivate       GstH264EncoderPrivate;
47 typedef struct _GstH264EncoderClass         GstH264EncoderClass;
48
49
50 #define GST_TYPE_H264_ENCODER             (gst_h264_encoder_get_type())
51 #define GST_IS_H264_ENCODER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_H264_ENCODER))
52 #define GST_IS_H264_ENCODER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_H264_ENCODER))
53 #define GST_H264_ENCODER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_H264_ENCODER, GstH264EncoderClass))
54 #define GST_H264_ENCODER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_H264_ENCODER, GstH264Encoder))
55 #define GST_H264_ENCODER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_H264_ENCODER, GstH264EncoderClass))
56 #define GST_H264_ENCODER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GST_TYPE_H264_ENCODER,GstH264EncoderPrivate))
57
58 typedef enum {
59   H264_ENC_NULL,
60   H264_ENC_INIT,
61   H264_ENC_OPENED,
62   H264_ENC_ENCODING,
63 } H264_Encode_State;
64
65 typedef enum {
66   H264_PROFILE_BASELINE = 66,
67   H264_PROFILE_MAIN     = 77,
68   H264_PROFILE_EXTENDED = 88,
69   H264_PROFILE_HIGH    = 100,
70   H264_PROFILE_HIGH10  = 110,
71   H264_PROFILE_HIGH422 = 122,
72   H264_PROFILE_HIGH444 = 144,
73   H264_PROFILE_HIGH444_PREDICTIVE = 244,
74 } H264_Profile;
75
76 typedef enum {
77   H264_LEVEL_10 = 10,  /* QCIF format, < 380160 samples/sec */
78   H264_LEVEL_11 = 11,  /* CIF format,   < 768000 samples/sec */
79   H264_LEVEL_12 = 12,  /* CIF format,   < 1536000  samples/sec */
80   H264_LEVEL_13 = 13,  /* CIF format,   < 3041280  samples/sec */
81   H264_LEVEL_20 = 20,  /* CIF format,   < 3041280  samples/sec */
82   H264_LEVEL_21 = 21,  /* HHR format,  < 5068800  samples/sec */
83   H264_LEVEL_22 = 22,  /* SD/4CIF format,     < 5184000      samples/sec */
84   H264_LEVEL_30 = 30,  /* SD/4CIF format,     < 10368000    samples/sec */
85   H264_LEVEL_31 = 31,  /* 720pHD format,      < 27648000    samples/sec */
86   H264_LEVEL_32 = 32,  /* SXGA  format,         < 55296000    samples/sec */
87   H264_LEVEL_40 = 40,  /* 2Kx1K format,         < 62914560    samples/sec */
88   H264_LEVEL_41 = 41,  /* 2Kx1K format,         < 62914560    samples/sec */
89   H264_LEVEL_42 = 42,  /* 2Kx1K format,         < 125829120  samples/sec */
90   H264_LEVEL_50 = 50,  /* 3672x1536 format,  < 150994944  samples/sec */
91   H264_LEVEL_51 = 51,  /* 4096x2304 format,  < 251658240  samples/sec */
92 } H264_Level;
93
94 #define H264_DEFAULT_PROFILE      H264_PROFILE_BASELINE
95 #define H264_DEFAULT_LEVEL        H264_LEVEL_30
96 #define H264_DEFAULT_INIT_QP      24
97 #define H264_DEFAULT_BITRATE      800*1000   /*800k*/
98 #define H264_DEFAULT_INTRA_PERIOD 30
99 #define H264_DEFAULT_FPS          30
100
101
102 struct _GstH264Encoder {
103   GObject parent;   /*based on gobject*/
104
105   uint32_t profile;
106   uint32_t level;
107   uint32_t width;
108   uint32_t height;
109   uint32_t frame_rate;
110   uint32_t bitrate;
111   uint32_t intra_period;
112   int32_t  init_qp;  /*default 26*/
113   /* private data; */
114 };
115
116 struct _GstH264EncoderClass {
117     GObjectClass parent_class;
118 };
119
120
121 GType    gst_h264_encoder_get_type(void);
122
123 GstH264Encoder *gst_h264_encoder_new(void);
124 static inline void gst_h264_encoder_unref (GstH264Encoder * encoder)
125 {
126   g_object_unref (encoder);
127 }
128
129 void     gst_h264_encoder_set_input_format(GstH264Encoder* encoder, uint32_t format);
130 void     gst_h264_encoder_set_es_flag(GstH264Encoder* encoder, gboolean es);
131 gboolean gst_h264_encoder_set_display(GstH264Encoder* encoder, GstVaapiDisplay *display);
132 GstVaapiDisplay *gst_h264_encoder_get_display(GstH264Encoder* encoder);
133
134
135 H264Status gst_h264_encoder_initialize(GstH264Encoder* encoder);
136 H264Status gst_h264_encoder_uninitialize(GstH264Encoder* encoder);
137
138 /*
139  set attributes here
140 */
141 void       gst_h264_encoder_set_default_values(GstH264Encoder* encoder);
142
143
144 /**/
145 #ifdef _MRST_
146 H264Status gst_h264_encoder_open(GstH264Encoder* encoder, GstVaapiSurfacePool *surfaces_pool);
147 #else
148 H264Status gst_h264_encoder_open(GstH264Encoder* encoder);
149 #endif
150
151 H264Status gst_h264_encoder_close(GstH264Encoder* encoder);
152
153
154 H264Status gst_h264_encoder_encode(GstH264Encoder* encoder, GstBuffer *raw_pic, GList **coded_pics);
155 H264Status gst_h264_encoder_flush(GstH264Encoder* encoder, GList *coded_pics);
156
157 H264_Encode_State gst_h264_encoder_get_state(GstH264Encoder* encoder);
158
159 /*other functions*/
160 char      *h264_dump_bytes(const uint8_t *buf, uint32_t num);
161 H264Status gst_h264_encoder_get_avcC_codec_data(GstH264Encoder* encoder, GstBuffer **buffer);
162 H264Status gst_h264_encoder_get_nal_codec_data(GstH264Encoder* encoder, GstBuffer **buffer);
163
164
165 #ifdef __cplusplus
166 }
167 #endif
168
169 #endif /*_GST_H264_ENCODER_H_ */
170