1 /*
2 INTEL CONFIDENTIAL
3 Copyright 2009 Intel Corporation All Rights Reserved.
4 The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
5 
6 No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
7 */
8 
9 /**
10 * SECTION:mixvideoconfigparamsenc_h264
11 * @short_description: VideoConfig parameters
12 *
13 * A data object which stores videoconfig specific parameters.
14 */
15 
16 #include "mixvideolog.h"
17 #include "mixvideoconfigparamsenc_h264.h"
18 
19 #define MDEBUG
20 
21 
22 static GType _mix_videoconfigparamsenc_h264_type = 0;
23 static MixVideoConfigParamsEncClass *parent_class = NULL;
24 
25 #define _do_init { _mix_videoconfigparamsenc_h264_type = g_define_type_id; }
26 
27 gboolean mix_videoconfigparamsenc_h264_copy (MixParams * target,
28 					  const MixParams * src);
29 MixParams *mix_videoconfigparamsenc_h264_dup (const MixParams * obj);
30 gboolean mix_videoconfigparamsencenc_h264_equal (MixParams * first,
31 					   MixParams * second);
32 static void mix_videoconfigparamsenc_h264_finalize (MixParams * obj);
33 
34 G_DEFINE_TYPE_WITH_CODE (MixVideoConfigParamsEncH264,	/* The name of the new type, in Camel case */
35 			 mix_videoconfigparamsenc_h264,	/* The name of the new type in lowercase */
36 			 MIX_TYPE_VIDEOCONFIGPARAMSENC,	/* The GType of the parent type */
37 			 _do_init);
38 
39 void
_mix_videoconfigparamsenc_h264_initialize(void)40 _mix_videoconfigparamsenc_h264_initialize (void)
41 {
42   /* the MixParams types need to be class_ref'd once before it can be
43    * done from multiple threads;
44    * see http://bugzilla.gnome.org/show_bug.cgi?id=304551 */
45   g_type_class_ref (mix_videoconfigparamsenc_h264_get_type ());
46 }
47 
48 static void
mix_videoconfigparamsenc_h264_init(MixVideoConfigParamsEncH264 * self)49 mix_videoconfigparamsenc_h264_init (MixVideoConfigParamsEncH264 * self)
50 {
51   /* initialize properties here */
52   /* TODO: initialize properties */
53   self->basic_unit_size = 0;
54   self->slice_num = 1;
55   self->disable_deblocking_filter_idc = 0;
56 
57   self->delimiter_type = MIX_DELIMITER_LENGTHPREFIX;
58 
59   self->reserved1 = NULL;
60   self->reserved2 = NULL;
61   self->reserved3 = NULL;
62   self->reserved4 = NULL;
63 }
64 
65 static void
mix_videoconfigparamsenc_h264_class_init(MixVideoConfigParamsEncH264Class * klass)66 mix_videoconfigparamsenc_h264_class_init (MixVideoConfigParamsEncH264Class * klass)
67 {
68   MixVideoConfigParamsEncClass *this_parent_class =
69     MIX_VIDEOCONFIGPARAMSENC_CLASS (klass);
70   MixParamsClass *this_root_class = MIX_PARAMS_CLASS (this_parent_class);
71 
72   /* setup static parent class */
73   parent_class =
74     (MixVideoConfigParamsEncClass *) g_type_class_peek_parent (klass);
75 
76   this_root_class->finalize = mix_videoconfigparamsenc_h264_finalize;
77   this_root_class->copy =
78     (MixParamsCopyFunction) mix_videoconfigparamsenc_h264_copy;
79   this_root_class->dup =
80     (MixParamsDupFunction) mix_videoconfigparamsenc_h264_dup;
81   this_root_class->equal =
82     (MixParamsEqualFunction) mix_videoconfigparamsencenc_h264_equal;
83 }
84 
85 MixVideoConfigParamsEncH264 *
mix_videoconfigparamsenc_h264_new(void)86 mix_videoconfigparamsenc_h264_new (void)
87 {
88   MixVideoConfigParamsEncH264 *ret = (MixVideoConfigParamsEncH264 *)
89     g_type_create_instance (MIX_TYPE_VIDEOCONFIGPARAMSENC_H264);
90 
91   return ret;
92 }
93 
94 void
mix_videoconfigparamsenc_h264_finalize(MixParams * obj)95 mix_videoconfigparamsenc_h264_finalize (MixParams * obj)
96 {
97   /* MixVideoConfigParamsEncH264 *this_obj = MIX_VIDEOCONFIGPARAMSENC_H264 (obj); */
98   MixParamsClass *root_class = MIX_PARAMS_CLASS (parent_class);
99 
100   /* TODO: cleanup resources allocated */
101 
102   /* Chain up parent */
103 
104   if (root_class->finalize)
105     {
106       root_class->finalize (obj);
107     }
108 }
109 
110 MixVideoConfigParamsEncH264
mix_videoconfigparamsenc_h264_ref(MixVideoConfigParamsEncH264 * mix)111   * mix_videoconfigparamsenc_h264_ref (MixVideoConfigParamsEncH264 * mix)
112 {
113   return (MixVideoConfigParamsEncH264 *) mix_params_ref (MIX_PARAMS (mix));
114 }
115 
116 /**
117 * mix_videoconfigparamsenc_h264_dup:
118 * @obj: a #MixVideoConfigParams object
119 * @returns: a newly allocated duplicate of the object.
120 *
121 * Copy duplicate of the object.
122 */
123 MixParams *
mix_videoconfigparamsenc_h264_dup(const MixParams * obj)124 mix_videoconfigparamsenc_h264_dup (const MixParams * obj)
125 {
126   MixParams *ret = NULL;
127 
128   if (MIX_IS_VIDEOCONFIGPARAMSENC_H264 (obj))
129     {
130       MixVideoConfigParamsEncH264 *duplicate = mix_videoconfigparamsenc_h264_new ();
131       if (mix_videoconfigparamsenc_h264_copy
132 	  (MIX_PARAMS (duplicate), MIX_PARAMS (obj)))
133 	{
134 	  ret = MIX_PARAMS (duplicate);
135 	}
136       else
137 	{
138 	  mix_videoconfigparamsenc_h264_unref (duplicate);
139 	}
140     }
141   return ret;
142 }
143 
144 /**
145 * mix_videoconfigparamsenc_h264_copy:
146 * @target: copy to target
147 * @src: copy from src
148 * @returns: boolean indicates if copy is successful.
149 *
150 * Copy instance data from @src to @target.
151 */
152 gboolean
mix_videoconfigparamsenc_h264_copy(MixParams * target,const MixParams * src)153 mix_videoconfigparamsenc_h264_copy (MixParams * target, const MixParams * src)
154 {
155     MixVideoConfigParamsEncH264 *this_target, *this_src;
156     MixParamsClass *root_class;
157 
158     LOG_V( "Begin\n");
159 
160     if (MIX_IS_VIDEOCONFIGPARAMSENC_H264 (target)
161       && MIX_IS_VIDEOCONFIGPARAMSENC_H264 (src))
162     {
163       // Cast the base object to this child object
164       this_target = MIX_VIDEOCONFIGPARAMSENC_H264 (target);
165       this_src = MIX_VIDEOCONFIGPARAMSENC_H264 (src);
166 
167       //add properties
168       this_target->basic_unit_size = this_src->basic_unit_size;
169       this_target->slice_num = this_src->slice_num;
170       this_target->disable_deblocking_filter_idc = this_src->disable_deblocking_filter_idc;
171       this_target->delimiter_type = this_src->delimiter_type;
172 
173 
174       // Now chainup base class
175       root_class = MIX_PARAMS_CLASS (parent_class);
176 
177       if (root_class->copy)
178 	{
179 	  return root_class->copy (MIX_PARAMS_CAST (target),
180 				   MIX_PARAMS_CAST (src));
181 	}
182       else
183 	{
184 	  return TRUE;
185 	}
186     }
187   return FALSE;
188 }
189 
190 /**
191 * mix_videoconfigparamsenc_h264:
192 * @first: first object to compare
193 * @second: seond object to compare
194 * @returns: boolean indicates if instance are equal.
195 *
196 * Copy instance data from @src to @target.
197 */
198 gboolean
mix_videoconfigparamsencenc_h264_equal(MixParams * first,MixParams * second)199 mix_videoconfigparamsencenc_h264_equal (MixParams * first, MixParams * second)
200 {
201   gboolean ret = FALSE;
202   MixVideoConfigParamsEncH264 *this_first, *this_second;
203 
204   if (MIX_IS_VIDEOCONFIGPARAMSENC_H264 (first)
205       && MIX_IS_VIDEOCONFIGPARAMSENC_H264 (second))
206     {
207       // Cast the base object to this child object
208 
209       this_first = MIX_VIDEOCONFIGPARAMSENC_H264 (first);
210       this_second = MIX_VIDEOCONFIGPARAMSENC_H264 (second);
211 
212       if (this_first->basic_unit_size != this_second->basic_unit_size) {
213 	  	goto not_equal;
214 	}
215 
216       if (this_first->slice_num != this_second->slice_num) {
217 	  	goto not_equal;
218 	}
219 
220       if (this_first->disable_deblocking_filter_idc != this_second->disable_deblocking_filter_idc) {
221 	  	goto not_equal;
222 	}
223 
224       if (this_first->delimiter_type != this_second->delimiter_type) {
225 	  	goto not_equal;
226 	}
227 
228 
229 	ret = TRUE;
230 
231 	not_equal:
232 
233 	if (ret != TRUE) {
234 		return ret;
235 	}
236 
237       /* TODO: add comparison for properties */
238       {
239 	// members within this scope equal. chaining up.
240 	MixParamsClass *klass = MIX_PARAMS_CLASS (parent_class);
241 	if (klass->equal)
242 	  {
243 	    ret = klass->equal (first, second);
244 	  }
245 	else
246 	  {
247 	    ret = TRUE;
248 	  }
249       }
250     }
251 
252   return ret;
253 }
254 
255 /* TODO: Add getters and setters for properties if any */
256 
257 #define MIX_VIDEOCONFIGPARAMSENC_H264_SETTER_CHECK_INPUT(obj) \
258 	if(!obj) return MIX_RESULT_NULL_PTR; \
259 	if(!MIX_IS_VIDEOCONFIGPARAMSENC_H264(obj)) return MIX_RESULT_FAIL; \
260 
261 #define MIX_VIDEOCONFIGPARAMSENC_H264_GETTER_CHECK_INPUT(obj, prop) \
262 	if(!obj || !prop) return MIX_RESULT_NULL_PTR; \
263 	if(!MIX_IS_VIDEOCONFIGPARAMSENC_H264(obj)) return MIX_RESULT_FAIL; \
264 
265 
mix_videoconfigparamsenc_h264_set_bus(MixVideoConfigParamsEncH264 * obj,guint basic_unit_size)266 MIX_RESULT mix_videoconfigparamsenc_h264_set_bus (MixVideoConfigParamsEncH264 * obj,
267 		guint basic_unit_size) {
268 	MIX_VIDEOCONFIGPARAMSENC_H264_SETTER_CHECK_INPUT (obj);
269 	obj->basic_unit_size = basic_unit_size;
270 	return MIX_RESULT_SUCCESS;
271 }
272 
mix_videoconfigparamsenc_h264_get_bus(MixVideoConfigParamsEncH264 * obj,guint * basic_unit_size)273 MIX_RESULT mix_videoconfigparamsenc_h264_get_bus (MixVideoConfigParamsEncH264 * obj,
274 		guint * basic_unit_size) {
275 	MIX_VIDEOCONFIGPARAMSENC_H264_GETTER_CHECK_INPUT (obj, basic_unit_size);
276 	*basic_unit_size = obj->basic_unit_size;
277 	return MIX_RESULT_SUCCESS;
278 }
279 
280 
mix_videoconfigparamsenc_h264_set_dlk(MixVideoConfigParamsEncH264 * obj,guint disable_deblocking_filter_idc)281 MIX_RESULT mix_videoconfigparamsenc_h264_set_dlk (MixVideoConfigParamsEncH264 * obj,
282 		guint disable_deblocking_filter_idc) {
283 	MIX_VIDEOCONFIGPARAMSENC_H264_SETTER_CHECK_INPUT (obj);
284 	obj->disable_deblocking_filter_idc = disable_deblocking_filter_idc;
285 	return MIX_RESULT_SUCCESS;
286 }
287 
mix_videoconfigparamsenc_h264_get_dlk(MixVideoConfigParamsEncH264 * obj,guint * disable_deblocking_filter_idc)288 MIX_RESULT mix_videoconfigparamsenc_h264_get_dlk (MixVideoConfigParamsEncH264 * obj,
289 		guint * disable_deblocking_filter_idc) {
290 	MIX_VIDEOCONFIGPARAMSENC_H264_GETTER_CHECK_INPUT (obj, disable_deblocking_filter_idc);
291 	*disable_deblocking_filter_idc = obj->disable_deblocking_filter_idc;
292 	return MIX_RESULT_SUCCESS;
293 }
294 
295 
mix_videoconfigparamsenc_h264_set_slice_num(MixVideoConfigParamsEncH264 * obj,guint slice_num)296 MIX_RESULT mix_videoconfigparamsenc_h264_set_slice_num(MixVideoConfigParamsEncH264 * obj,
297 		guint slice_num) {
298 	MIX_VIDEOCONFIGPARAMSENC_H264_SETTER_CHECK_INPUT (obj);
299 	obj->slice_num = slice_num;
300 	return MIX_RESULT_SUCCESS;
301 }
302 
mix_videoconfigparamsenc_h264_get_slice_num(MixVideoConfigParamsEncH264 * obj,guint * slice_num)303 MIX_RESULT mix_videoconfigparamsenc_h264_get_slice_num(MixVideoConfigParamsEncH264 * obj,
304 		guint * slice_num) {
305 	MIX_VIDEOCONFIGPARAMSENC_H264_GETTER_CHECK_INPUT (obj, slice_num);
306 	*slice_num = obj->slice_num;
307 	return MIX_RESULT_SUCCESS;
308 }
309 
mix_videoconfigparamsenc_h264_set_delimiter_type(MixVideoConfigParamsEncH264 * obj,MixDelimiterType delimiter_type)310 MIX_RESULT mix_videoconfigparamsenc_h264_set_delimiter_type (MixVideoConfigParamsEncH264 * obj,
311 		MixDelimiterType delimiter_type) {
312 	MIX_VIDEOCONFIGPARAMSENC_H264_SETTER_CHECK_INPUT (obj);
313 	obj->delimiter_type = delimiter_type;
314 	return MIX_RESULT_SUCCESS;
315 }
316 
mix_videoconfigparamsenc_h264_get_delimiter_type(MixVideoConfigParamsEncH264 * obj,MixDelimiterType * delimiter_type)317 MIX_RESULT mix_videoconfigparamsenc_h264_get_delimiter_type (MixVideoConfigParamsEncH264 * obj,
318 		MixDelimiterType * delimiter_type) {
319 	MIX_VIDEOCONFIGPARAMSENC_H264_GETTER_CHECK_INPUT (obj, delimiter_type);
320 	*delimiter_type = obj->delimiter_type;
321 	return MIX_RESULT_SUCCESS;
322 }
323