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:mixvideoconfigparams
11 * @short_description: VideoConfig parameters
12 *
13 * A data object which stores videoconfig specific parameters.
14 */
15
16#include <string.h>
17#include "mixvideolog.h"
18#include "mixvideoconfigparamsdec.h"
19
20static GType _mix_videoconfigparamsdec_type = 0;
21static MixVideoConfigParamsClass *parent_class = NULL;
22
23#define _do_init { _mix_videoconfigparamsdec_type = g_define_type_id; }
24
25gboolean mix_videoconfigparamsdec_copy(MixParams * target, const MixParams * src);
26MixParams *mix_videoconfigparamsdec_dup(const MixParams * obj);
27gboolean mix_videoconfigparamsdec_equal(MixParams * first, MixParams * second);
28static void mix_videoconfigparamsdec_finalize(MixParams * obj);
29
30G_DEFINE_TYPE_WITH_CODE (MixVideoConfigParamsDec, mix_videoconfigparamsdec,
31		MIX_TYPE_VIDEOCONFIGPARAMS, _do_init);
32
33static void mix_videoconfigparamsdec_init(MixVideoConfigParamsDec * self) {
34
35	/* initialize properties here */
36
37	self->frame_order_mode = MIX_FRAMEORDER_MODE_DISPLAYORDER;
38	memset(&self->header, 0, sizeof(self->header));
39
40	self->mime_type = NULL;
41
42	self->frame_rate_num = 0;
43	self->frame_rate_denom = 0;
44
45	self->picture_width = 0;
46	self->picture_height = 0;
47
48	self->raw_format = 0;
49	self->rate_control = 0;
50	self->mixbuffer_pool_size = 0;
51	self->extra_surface_allocation = 0;
52
53	/* TODO: initialize other properties */
54	self->reserved1 = NULL;
55	self->reserved2 = NULL;
56	self->reserved3 = NULL;
57	self->reserved4 = NULL;
58}
59
60static void mix_videoconfigparamsdec_class_init(MixVideoConfigParamsDecClass * klass) {
61	MixParamsClass *mixparams_class = MIX_PARAMS_CLASS(klass);
62
63	/* setup static parent class */
64	parent_class = (MixVideoConfigParamsClass *) g_type_class_peek_parent(klass);
65
66	mixparams_class->finalize = mix_videoconfigparamsdec_finalize;
67	mixparams_class->copy = (MixParamsCopyFunction) mix_videoconfigparamsdec_copy;
68	mixparams_class->dup = (MixParamsDupFunction) mix_videoconfigparamsdec_dup;
69	mixparams_class->equal
70			= (MixParamsEqualFunction) mix_videoconfigparamsdec_equal;
71}
72
73MixVideoConfigParamsDec *
74mix_videoconfigparamsdec_new(void) {
75	MixVideoConfigParamsDec *ret =
76			(MixVideoConfigParamsDec *) g_type_create_instance(
77					MIX_TYPE_VIDEOCONFIGPARAMSDEC);
78
79	return ret;
80}
81
82void mix_videoconfigparamsdec_finalize(MixParams * obj) {
83
84	/* clean up here. */
85	MixVideoConfigParamsDec *self = MIX_VIDEOCONFIGPARAMSDEC(obj);
86	MixParamsClass *root_class = MIX_PARAMS_CLASS(parent_class);
87
88
89	/* free header */
90	if (self->header.data) {
91		g_free(self->header.data);
92		memset(&self->header, 0, sizeof(self->header));
93	}
94
95	/* free mime_type */
96	if (self->mime_type->str)
97		g_string_free(self->mime_type, TRUE);
98	else
99		g_string_free(self->mime_type, FALSE);
100
101	/* Chain up parent */
102	if (root_class->finalize) {
103		root_class->finalize(obj);
104	}
105}
106
107MixVideoConfigParamsDec *
108mix_videoconfigparamsdec_ref(MixVideoConfigParamsDec * mix) {
109	return (MixVideoConfigParamsDec *) mix_params_ref(MIX_PARAMS(mix));
110}
111
112/**
113 * mix_videoconfigparamsdec_dup:
114 * @obj: a #MixVideoConfigParamsDec object
115 * @returns: a newly allocated duplicate of the object.
116 *
117 * Copy duplicate of the object.
118 */
119MixParams *
120mix_videoconfigparamsdec_dup(const MixParams * obj) {
121	MixParams *ret = NULL;
122
123	if (MIX_IS_VIDEOCONFIGPARAMSDEC(obj)) {
124		MixVideoConfigParamsDec *duplicate = mix_videoconfigparamsdec_new();
125		if (mix_videoconfigparamsdec_copy(MIX_PARAMS(duplicate), MIX_PARAMS(obj))) {
126			ret = MIX_PARAMS(duplicate);
127		} else {
128			mix_videoconfigparamsdec_unref(duplicate);
129		}
130	}
131
132	return ret;
133}
134
135/**
136 * mix_videoconfigparamsdec_copy:
137 * @target: copy to target
138 * @src: copy from src
139 * @returns: boolean indicates if copy is successful.
140 *
141 * Copy instance data from @src to @target.
142 */
143gboolean mix_videoconfigparamsdec_copy(MixParams * target, const MixParams * src) {
144
145	MixVideoConfigParamsDec *this_target, *this_src;
146	MIX_RESULT mix_result = MIX_RESULT_FAIL;
147	MixParamsClass *root_class = MIX_PARAMS_CLASS(parent_class);
148
149	LOG_V( "Begin\n");
150
151	if (MIX_IS_VIDEOCONFIGPARAMSDEC(target) && MIX_IS_VIDEOCONFIGPARAMSDEC(src)) {
152
153		/* Cast the base object to this child object */
154		this_target = MIX_VIDEOCONFIGPARAMSDEC(target);
155		this_src = MIX_VIDEOCONFIGPARAMSDEC(src);
156
157		/* copy properties of primitive type */
158
159		this_target->frame_rate_num = this_src->frame_rate_num;
160		this_target->frame_rate_denom = this_src->frame_rate_denom;
161		this_target->picture_width = this_src->picture_width;
162		this_target->picture_height = this_src->picture_height;
163		this_target->raw_format = this_src->raw_format;
164		this_target->rate_control = this_src->rate_control;
165		this_target->mixbuffer_pool_size = this_src->mixbuffer_pool_size;
166		this_target->extra_surface_allocation = this_src->extra_surface_allocation;
167
168		/* copy properties of non-primitive */
169
170		/* copy header */
171		mix_result = mix_videoconfigparamsdec_set_header(this_target,
172				&this_src->header);
173
174		if (mix_result != MIX_RESULT_SUCCESS) {
175
176			LOG_E( "set_header failed: mix_result = 0x%x\n", mix_result);
177			return FALSE;
178		}
179
180		/* copy mime_type */
181		if (this_src->mime_type) {
182
183			mix_result = mix_videoconfigparamsdec_set_mime_type(this_target,
184					this_src->mime_type->str);
185		} else {
186			mix_result = mix_videoconfigparamsdec_set_mime_type(this_target, NULL);
187		}
188
189		if (mix_result != MIX_RESULT_SUCCESS) {
190			LOG_E( "set_mime_type failed: mix_result = 0x%x\n", mix_result);
191			return FALSE;
192		}
193
194		/* TODO: copy other properties if there's any */
195
196		/* Now chainup base class */
197		if (root_class->copy) {
198			LOG_V( "root_class->copy != NULL\n");
199			return root_class->copy(MIX_PARAMS_CAST(target), MIX_PARAMS_CAST(
200					src));
201		} else {
202			LOG_E( "root_class->copy == NULL\n");
203			return TRUE;
204		}
205	}
206
207	LOG_V( "End\n");
208
209	return FALSE;
210}
211
212/**
213 * mix_videoconfigparamsdec_:
214 * @first: first object to compare
215 * @second: seond object to compare
216 * @returns: boolean indicates if instance are equal.
217 *
218 * Copy instance data from @src to @target.
219 */
220gboolean mix_videoconfigparamsdec_equal(MixParams * first, MixParams * second) {
221
222	gboolean ret = FALSE;
223
224	MixVideoConfigParamsDec *this_first, *this_second;
225	MixParamsClass *root_class = MIX_PARAMS_CLASS(parent_class);
226
227
228	if (MIX_IS_VIDEOCONFIGPARAMSDEC(first) && MIX_IS_VIDEOCONFIGPARAMSDEC(second)) {
229
230		// Deep compare
231		// Cast the base object to this child object
232		this_first = MIX_VIDEOCONFIGPARAMSDEC(first);
233		this_second = MIX_VIDEOCONFIGPARAMSDEC(second);
234
235		/* check the equalitiy of the primitive type properties */
236		if (this_first->frame_order_mode != this_second->frame_order_mode) {
237			goto not_equal;
238		}
239
240		if (this_first->frame_rate_num != this_second->frame_rate_num
241				&& this_first->frame_rate_denom
242						!= this_second->frame_rate_denom) {
243			goto not_equal;
244		}
245
246		if (this_first->picture_width != this_second->picture_width
247				&& this_first->picture_height != this_second->picture_height) {
248			goto not_equal;
249		}
250
251		if (this_first->raw_format != this_second->raw_format) {
252			goto not_equal;
253		}
254
255		if (this_first->rate_control != this_second->rate_control) {
256			goto not_equal;
257		}
258
259		if (this_first->mixbuffer_pool_size != this_second->mixbuffer_pool_size) {
260			goto not_equal;
261		}
262
263		if (this_first->extra_surface_allocation != this_second->extra_surface_allocation) {
264			goto not_equal;
265		}
266
267		/* check the equalitiy of the none-primitive type properties */
268
269		/* MixIOVec header */
270
271		if (this_first->header.data_size != this_second->header.data_size) {
272			goto not_equal;
273		}
274
275		if (this_first->header.buffer_size != this_second->header.buffer_size) {
276			goto not_equal;
277		}
278
279		if (this_first->header.data && this_second->header.data) {
280			if (memcmp(this_first->header.data, this_second->header.data,
281					this_first->header.data_size) != 0) {
282				goto not_equal;
283			}
284		} else if (!(!this_first->header.data && !this_second->header.data)) {
285			goto not_equal;
286		}
287
288		/* compare mime_type */
289
290		if (this_first->mime_type && this_second->mime_type) {
291			if (g_string_equal(this_first->mime_type, this_second->mime_type)
292					!= TRUE) {
293				goto not_equal;
294			}
295		} else if (!(!this_first->mime_type && !this_second->mime_type)) {
296			goto not_equal;
297		}
298
299		ret = TRUE;
300
301		not_equal:
302
303		if (ret != TRUE) {
304			return ret;
305		}
306
307		/* chaining up. */
308		if (root_class->equal)
309			ret = root_class->equal(first, second);
310		else
311			ret = TRUE;
312	}
313
314	return ret;
315}
316
317#define MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT(obj) \
318	if(!obj) return MIX_RESULT_NULL_PTR; \
319	if(!MIX_IS_VIDEOCONFIGPARAMSDEC(obj)) return MIX_RESULT_FAIL; \
320
321#define MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT(obj, prop) \
322	if(!obj || !prop) return MIX_RESULT_NULL_PTR; \
323	if(!MIX_IS_VIDEOCONFIGPARAMSDEC(obj)) return MIX_RESULT_FAIL; \
324
325#define MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT_PAIR(obj, prop, prop2) \
326	if(!obj || !prop || !prop2 ) return MIX_RESULT_NULL_PTR; \
327	if(!MIX_IS_VIDEOCONFIGPARAMSDEC(obj)) return MIX_RESULT_FAIL; \
328
329/* TODO: Add getters and setters for other properties. The following is incomplete */
330
331MIX_RESULT mix_videoconfigparamsdec_set_frame_order_mode(
332		MixVideoConfigParamsDec * obj, MixFrameOrderMode frame_order_mode) {
333	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
334	obj->frame_order_mode = frame_order_mode;
335	return MIX_RESULT_SUCCESS;
336}
337
338MIX_RESULT mix_videoconfigparamsdec_get_frame_order_mode(
339		MixVideoConfigParamsDec * obj, MixFrameOrderMode * frame_order_mode) {
340	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, frame_order_mode);
341	*frame_order_mode = obj->frame_order_mode;
342	return MIX_RESULT_SUCCESS;
343}
344
345MIX_RESULT mix_videoconfigparamsdec_set_header(MixVideoConfigParamsDec * obj,
346		MixIOVec * header) {
347
348	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
349
350	if (!header) {
351		return MIX_RESULT_NULL_PTR;
352	}
353
354	if (header->data && header->buffer_size) {
355		obj->header.data = g_memdup(header->data, header->buffer_size);
356		if (!obj->header.data) {
357			return MIX_RESULT_NO_MEMORY;
358		}
359		obj->header.buffer_size = header->buffer_size;
360		obj->header.data_size = header->data_size;
361	}
362	return MIX_RESULT_SUCCESS;
363}
364
365MIX_RESULT mix_videoconfigparamsdec_get_header(MixVideoConfigParamsDec * obj,
366		MixIOVec ** header) {
367
368	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, header);
369
370	if (obj->header.data && obj->header.buffer_size) {
371
372		*header = g_malloc(sizeof(MixIOVec));
373
374		if (*header == NULL) {
375			return MIX_RESULT_NO_MEMORY;
376		}
377
378		(*header)->data = g_memdup(obj->header.data, obj->header.buffer_size);
379		(*header)->buffer_size = obj->header.buffer_size;
380		(*header)->data_size = obj->header.data_size;
381
382	} else {
383		*header = NULL;
384	}
385	return MIX_RESULT_SUCCESS;
386
387}
388
389MIX_RESULT mix_videoconfigparamsdec_set_mime_type(MixVideoConfigParamsDec * obj,
390		const gchar * mime_type) {
391
392	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
393
394	if (!mime_type) {
395		return MIX_RESULT_NULL_PTR;
396	}
397
398	if (obj->mime_type) {
399		if (obj->mime_type->str)
400			g_string_free(obj->mime_type, TRUE);
401		else
402			g_string_free(obj->mime_type, FALSE);
403	}
404
405	obj->mime_type = g_string_new(mime_type);
406	if (!obj->mime_type) {
407		return MIX_RESULT_NO_MEMORY;
408	}
409
410	return MIX_RESULT_SUCCESS;
411}
412
413MIX_RESULT mix_videoconfigparamsdec_get_mime_type(MixVideoConfigParamsDec * obj,
414		gchar ** mime_type) {
415	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, mime_type);
416
417	if (!obj->mime_type) {
418		*mime_type = NULL;
419		return MIX_RESULT_SUCCESS;
420	}
421	*mime_type = g_strdup(obj->mime_type->str);
422	if (!*mime_type) {
423		return MIX_RESULT_NO_MEMORY;
424	}
425
426	return MIX_RESULT_SUCCESS;
427}
428
429MIX_RESULT mix_videoconfigparamsdec_set_frame_rate(MixVideoConfigParamsDec * obj,
430		guint frame_rate_num, guint frame_rate_denom) {
431	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
432	obj->frame_rate_num = frame_rate_num;
433	obj->frame_rate_denom = frame_rate_denom;
434	return MIX_RESULT_SUCCESS;
435}
436
437MIX_RESULT mix_videoconfigparamsdec_get_frame_rate(MixVideoConfigParamsDec * obj,
438		guint * frame_rate_num, guint * frame_rate_denom) {
439	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT_PAIR (obj, frame_rate_num, frame_rate_denom);
440	*frame_rate_num = obj->frame_rate_num;
441	*frame_rate_denom = obj->frame_rate_denom;
442	return MIX_RESULT_SUCCESS;
443}
444
445MIX_RESULT mix_videoconfigparamsdec_set_picture_res(MixVideoConfigParamsDec * obj,
446		guint picture_width, guint picture_height) {
447	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
448	obj->picture_width = picture_width;
449	obj->picture_height = picture_height;
450	return MIX_RESULT_SUCCESS;
451}
452
453MIX_RESULT mix_videoconfigparamsdec_get_picture_res(MixVideoConfigParamsDec * obj,
454		guint * picture_width, guint * picture_height) {
455	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT_PAIR (obj, picture_width, picture_height);
456	*picture_width = obj->picture_width;
457	*picture_height = obj->picture_height;
458	return MIX_RESULT_SUCCESS;
459}
460
461MIX_RESULT mix_videoconfigparamsdec_set_raw_format(MixVideoConfigParamsDec * obj,
462		guint raw_format) {
463	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
464
465	/* TODO: check if the value of raw_format is valid */
466	obj->raw_format = raw_format;
467	return MIX_RESULT_SUCCESS;
468}
469
470MIX_RESULT mix_videoconfigparamsdec_get_raw_format(MixVideoConfigParamsDec * obj,
471		guint *raw_format) {
472	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, raw_format);
473	*raw_format = obj->raw_format;
474	return MIX_RESULT_SUCCESS;
475}
476
477MIX_RESULT mix_videoconfigparamsdec_set_rate_control(MixVideoConfigParamsDec * obj,
478		guint rate_control) {
479	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
480
481	/* TODO: check if the value of rate_control is valid */
482	obj->rate_control = rate_control;
483	return MIX_RESULT_SUCCESS;
484}
485
486MIX_RESULT mix_videoconfigparamsdec_get_rate_control(MixVideoConfigParamsDec * obj,
487		guint *rate_control) {
488	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, rate_control);
489	*rate_control = obj->rate_control;
490	return MIX_RESULT_SUCCESS;
491}
492
493MIX_RESULT mix_videoconfigparamsdec_set_buffer_pool_size(
494		MixVideoConfigParamsDec * obj, guint bufpoolsize) {
495
496	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
497
498	obj->mixbuffer_pool_size = bufpoolsize;
499	return MIX_RESULT_SUCCESS;
500
501}
502
503MIX_RESULT mix_videoconfigparamsdec_get_buffer_pool_size(
504		MixVideoConfigParamsDec * obj, guint *bufpoolsize) {
505
506	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, bufpoolsize);
507	*bufpoolsize = obj->mixbuffer_pool_size;
508	return MIX_RESULT_SUCCESS;
509}
510
511MIX_RESULT mix_videoconfigparamsdec_set_extra_surface_allocation(
512		MixVideoConfigParamsDec * obj,
513                guint extra_surface_allocation) {
514
515	MIX_VIDEOCONFIGPARAMSDEC_SETTER_CHECK_INPUT (obj);
516
517	obj->extra_surface_allocation = extra_surface_allocation;
518	return MIX_RESULT_SUCCESS;
519
520}
521
522MIX_RESULT mix_videoconfigparamsdec_get_extra_surface_allocation(
523		MixVideoConfigParamsDec * obj,
524                guint *extra_surface_allocation) {
525
526	MIX_VIDEOCONFIGPARAMSDEC_GETTER_CHECK_INPUT (obj, extra_surface_allocation);
527	*extra_surface_allocation = obj->extra_surface_allocation;
528	return MIX_RESULT_SUCCESS;
529
530}
531
532
533
534
535