• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* VP8
2  * Copyright (C) 2006 David Schleef <ds@schleef.org>
3  * Copyright (C) 2010 Entropy Wave Inc
4  * Copyright (C) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 #ifndef __GST_VPX_ENC_H__
23 #define __GST_VPX_ENC_H__
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #if defined(HAVE_VP8_ENCODER) || defined(HAVE_VP9_ENCODER)
30 
31 #include <gst/gst.h>
32 #include <gst/video/gstvideoencoder.h>
33 
34 /* FIXME: Undef HAVE_CONFIG_H because vpx_codec.h uses it,
35  * which causes compilation failures */
36 #ifdef HAVE_CONFIG_H
37 #undef HAVE_CONFIG_H
38 #endif
39 
40 #include <vpx/vpx_encoder.h>
41 #include <vpx/vp8cx.h>
42 
43 G_BEGIN_DECLS
44 
45 #define GST_TYPE_VPX_ENC \
46   (gst_vpx_enc_get_type())
47 #define GST_VPX_ENC(obj) \
48   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VPX_ENC,GstVPXEnc))
49 #define GST_VPX_ENC_CLASS(klass) \
50   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VPX_ENC,GstVPXEncClass))
51 #define GST_IS_VPX_ENC(obj) \
52   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VPX_ENC))
53 #define GST_IS_VPX_ENC_CLASS(obj) \
54   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VPX_ENC))
55 #define GST_VPX_ENC_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_VPX_ENC, GstVPXEncClass))
56 
57 typedef struct _GstVPXEnc GstVPXEnc;
58 typedef struct _GstVPXEncClass GstVPXEncClass;
59 
60 struct _GstVPXEnc
61 {
62   GstVideoEncoder base_video_encoder;
63 
64   /* < protected > */
65   vpx_codec_ctx_t encoder;
66   GMutex encoder_lock;
67 
68   /* properties */
69   vpx_codec_enc_cfg_t cfg;
70   gboolean have_default_config;
71   gboolean rc_target_bitrate_auto;
72   gint n_ts_target_bitrate;
73   gint n_ts_rate_decimator;
74   gint n_ts_layer_id;
75   gint n_ts_layer_flags;
76   gint *ts_layer_flags;
77   gint n_ts_layer_sync_flags;
78   gboolean *ts_layer_sync_flags;
79   /* Global two-pass options */
80   gchar *multipass_cache_file;
81   gchar *multipass_cache_prefix;
82   guint multipass_cache_idx;
83   GByteArray *first_pass_cache_content;
84 
85   /* Encode parameter */
86   gint64 deadline;
87 
88   /* Controls */
89   VPX_SCALING_MODE h_scaling_mode;
90   VPX_SCALING_MODE v_scaling_mode;
91   int cpu_used;
92   gboolean enable_auto_alt_ref;
93   unsigned int noise_sensitivity;
94   unsigned int sharpness;
95   unsigned int static_threshold;
96   vp8e_token_partitions token_partitions;
97   unsigned int arnr_maxframes;
98   unsigned int arnr_strength;
99   unsigned int arnr_type;
100   vp8e_tuning tuning;
101   unsigned int cq_level;
102   unsigned int max_intra_bitrate_pct;
103   /* Timebase - a value of 0 will use the framerate */
104   unsigned int timebase_n;
105   unsigned int timebase_d;
106 
107   /* Bits per Pixel */
108   gfloat bits_per_pixel;
109 
110   /* state */
111   gboolean inited;
112   guint8 tl0picidx;
113   gboolean prev_was_keyframe;
114 
115   vpx_image_t image;
116 
117   GstClockTime last_pts;
118 
119   GstVideoCodecState *input_state;
120 };
121 
122 struct _GstVPXEncClass
123 {
124   GstVideoEncoderClass base_video_encoder_class;
125   /*virtual function to get supported algo*/
126   vpx_codec_iface_t* (*get_algo) (GstVPXEnc *enc);
127   /*enabled scaling*/
128   gboolean (*enable_scaling) (GstVPXEnc *enc);
129   /*called from set_format with lock taken*/
130   gboolean (*configure_encoder) (GstVPXEnc *enc, GstVideoCodecState *state);
131   /*set image format info*/
132   void (*set_image_format) (GstVPXEnc *enc, vpx_image_t *image);
133   /*get new simple caps*/
134   GstCaps* (*get_new_vpx_caps) (GstVPXEnc *enc);
135   /*set stream info*/
136   void (*set_stream_info) (GstVPXEnc *enc, GstCaps *caps, GstVideoInfo *info);
137   /*process user data*/
138   void* (*process_frame_user_data) (GstVPXEnc *enc, GstVideoCodecFrame* frame);
139   /*set frame user data*/
140   void (*set_frame_user_data) (GstVPXEnc *enc, GstVideoCodecFrame* frame,
141       vpx_image_t *image);
142   /*Handle invisible frame*/
143   GstFlowReturn (*handle_invisible_frame_buffer) (GstVPXEnc *enc,
144       void* user_data, GstBuffer* buffer);
145   /*apply temporal settings -- called with encoder lock*/
146   void (*apply_frame_temporal_settings) (GstVPXEnc *enc,
147       GstVideoCodecFrame* frame, guint layer_id, guint8 tl0picidx,
148       gboolean layer_sync);
149   /*get temporal settings*/
150   void (*get_frame_temporal_settings) (GstVPXEnc *enc,
151       GstVideoCodecFrame *frame, guint * layer_id, guint8 *tl0picidx,
152       gboolean *layer_sync);
153   /* preflight buffer */
154   void (*preflight_buffer) (GstVPXEnc *enc,
155       GstVideoCodecFrame *frame, GstBuffer *buffer,
156       gboolean layer_sync, guint layer_id, guint8 tl0picidx);
157 };
158 
159 GType gst_vpx_enc_get_type (void);
160 
161 G_DEFINE_AUTOPTR_CLEANUP_FUNC (GstVPXEnc, gst_object_unref)
162 
163 G_END_DECLS
164 
165 #endif
166 
167 #endif /* __GST_VPX_ENC_H__ */
168