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:mixvideoinitparams
11 * @short_description: VideoInit parameters
12 *
13 * A data object which stores videoinit specific parameters.
14 */
15
16 #include "mixvideoinitparams.h"
17
18 #define SAFE_FREE(p) if(p) { g_free(p); p = NULL; }
19
20 static GType _mix_videoinitparams_type = 0;
21 static MixParamsClass *parent_class = NULL;
22
23 #define _do_init { _mix_videoinitparams_type = g_define_type_id; }
24
25 gboolean mix_videoinitparams_copy(MixParams * target, const MixParams * src);
26 MixParams *mix_videoinitparams_dup(const MixParams * obj);
27 gboolean mix_videoinitparams_equal(MixParams * first, MixParams * second);
28 static void mix_videoinitparams_finalize(MixParams * obj);
29
30 G_DEFINE_TYPE_WITH_CODE (MixVideoInitParams, mix_videoinitparams,
31 MIX_TYPE_PARAMS, _do_init);
32
mix_videoinitparams_init(MixVideoInitParams * self)33 static void mix_videoinitparams_init(MixVideoInitParams * self) {
34
35 /* Initialize member varibles */
36 self->display = NULL;
37 self->reserved1 = NULL;
38 self->reserved2 = NULL;
39 self->reserved3 = NULL;
40 self->reserved4 = NULL;
41 }
42
mix_videoinitparams_class_init(MixVideoInitParamsClass * klass)43 static void mix_videoinitparams_class_init(MixVideoInitParamsClass * klass) {
44 MixParamsClass *mixparams_class = MIX_PARAMS_CLASS(klass);
45
46 /* setup static parent class */
47 parent_class = (MixParamsClass *) g_type_class_peek_parent(klass);
48
49 mixparams_class->finalize = mix_videoinitparams_finalize;
50 mixparams_class->copy = (MixParamsCopyFunction) mix_videoinitparams_copy;
51 mixparams_class->dup = (MixParamsDupFunction) mix_videoinitparams_dup;
52 mixparams_class->equal = (MixParamsEqualFunction) mix_videoinitparams_equal;
53 }
54
55 MixVideoInitParams *
mix_videoinitparams_new(void)56 mix_videoinitparams_new(void) {
57 MixVideoInitParams *ret = (MixVideoInitParams *) g_type_create_instance(
58 MIX_TYPE_VIDEOINITPARAMS);
59
60 return ret;
61 }
62
mix_videoinitparams_finalize(MixParams * obj)63 void mix_videoinitparams_finalize(MixParams * obj) {
64 /* clean up here. */
65
66 MixVideoInitParams *self = MIX_VIDEOINITPARAMS(obj);
67
68 /* unref display */
69 if (self->display) {
70 mix_display_unref(self->display);
71 self->display = NULL;
72 }
73
74 /* Chain up parent */
75 if (parent_class->finalize) {
76 parent_class->finalize(obj);
77 }
78 }
79
80 MixVideoInitParams *
mix_videoinitparams_ref(MixVideoInitParams * mix)81 mix_videoinitparams_ref(MixVideoInitParams * mix) {
82 return (MixVideoInitParams *) mix_params_ref(MIX_PARAMS(mix));
83 }
84
85 /**
86 * mix_videoinitparams_dup:
87 * @obj: a #MixVideoInitParams object
88 * @returns: a newly allocated duplicate of the object.
89 *
90 * Copy duplicate of the object.
91 */
92 MixParams *
mix_videoinitparams_dup(const MixParams * obj)93 mix_videoinitparams_dup(const MixParams * obj) {
94 MixParams *ret = NULL;
95 if (MIX_IS_VIDEOINITPARAMS(obj)) {
96 MixVideoInitParams *duplicate = mix_videoinitparams_new();
97 if (mix_videoinitparams_copy(MIX_PARAMS(duplicate), MIX_PARAMS(obj))) {
98 ret = MIX_PARAMS(duplicate);
99 } else {
100 mix_videoinitparams_unref(duplicate);
101 }
102 }
103 return ret;
104 }
105
106 /**
107 * mix_videoinitparams_copy:
108 * @target: copy to target
109 * @src: copy from src
110 * @returns: boolean indicates if copy is successful.
111 *
112 * Copy instance data from @src to @target.
113 */
mix_videoinitparams_copy(MixParams * target,const MixParams * src)114 gboolean mix_videoinitparams_copy(MixParams * target, const MixParams * src) {
115 MixVideoInitParams *this_target, *this_src;
116 if (MIX_IS_VIDEOINITPARAMS(target) && MIX_IS_VIDEOINITPARAMS(src)) {
117 /* Cast the base object to this child object */
118 this_target = MIX_VIDEOINITPARAMS(target);
119 this_src = MIX_VIDEOINITPARAMS(src);
120 /* Copy properties from source to target. */
121
122 /* duplicate display */
123
124 this_target->display = mix_display_dup(this_src->display);
125
126 /* Now chainup base class */
127 if (parent_class->copy) {
128 return parent_class->copy(MIX_PARAMS_CAST(target), MIX_PARAMS_CAST(
129 src));
130 } else {
131 return TRUE;
132 }
133 }
134 return FALSE;
135 }
136
137 /**
138 * mix_videoinitparams_equal:
139 * @first: first object to compare
140 * @second: seond object to compare
141 * @returns: boolean indicates if instance are equal.
142 *
143 * Copy instance data from @src to @target.
144 */
mix_videoinitparams_equal(MixParams * first,MixParams * second)145 gboolean mix_videoinitparams_equal(MixParams * first, MixParams * second) {
146 gboolean ret = FALSE;
147 MixVideoInitParams *this_first, *this_second;
148 this_first = MIX_VIDEOINITPARAMS(first);
149 this_second = MIX_VIDEOINITPARAMS(second);
150 if (MIX_IS_VIDEOINITPARAMS(first) && MIX_IS_VIDEOINITPARAMS(second)) {
151 // Compare member variables
152 if (!this_first->display && !this_second->display) {
153 ret = TRUE;
154 } else if (this_first->display && this_second->display) {
155
156 /* compare MixDisplay */
157 ret = mix_display_equal(this_first->display, this_second->display);
158 }
159
160 if (ret == FALSE) {
161 return FALSE;
162 }
163 // members within this scope equal. chaining up.
164 MixParamsClass *klass = MIX_PARAMS_CLASS(parent_class);
165 if (klass->equal)
166 ret = parent_class->equal(first, second);
167 else
168 ret = TRUE;
169 }
170 return ret;
171 }
172
173 #define MIX_VIDEOINITPARAMS_SETTER_CHECK_INPUT(obj) \
174 if(!obj) return MIX_RESULT_NULL_PTR; \
175 if(!MIX_IS_VIDEOINITPARAMS(obj)) return MIX_RESULT_FAIL; \
176
177 #define MIX_VIDEOINITPARAMS_GETTER_CHECK_INPUT(obj, prop) \
178 if(!obj || !prop) return MIX_RESULT_NULL_PTR; \
179 if(!MIX_IS_VIDEOINITPARAMS(obj)) return MIX_RESULT_FAIL; \
180
mix_videoinitparams_set_display(MixVideoInitParams * obj,MixDisplay * display)181 MIX_RESULT mix_videoinitparams_set_display(MixVideoInitParams * obj,
182 MixDisplay * display) {
183 MIX_VIDEOINITPARAMS_SETTER_CHECK_INPUT (obj);
184
185 if(obj->display) {
186 mix_display_unref(obj->display);
187 }
188 obj->display = NULL;
189
190 if(display) {
191 /* obj->display = mix_display_dup(display);
192 if(!obj->display) {
193 return MIX_RESULT_NO_MEMORY;
194 }*/
195
196 obj->display = mix_display_ref(display);
197 }
198
199 return MIX_RESULT_SUCCESS;
200 }
201
202 /*
203 Caller is responsible to use g_free to free the memory
204 */
mix_videoinitparams_get_display(MixVideoInitParams * obj,MixDisplay ** display)205 MIX_RESULT mix_videoinitparams_get_display(MixVideoInitParams * obj,
206 MixDisplay ** display) {
207 MIX_VIDEOINITPARAMS_GETTER_CHECK_INPUT (obj, display);
208
209 *display = NULL;
210 if(obj->display) {
211 /* *display = mix_display_dup(obj->display);
212 if(!*display) {
213 return MIX_RESULT_NO_MEMORY;
214 }*/
215 *display = mix_display_ref(obj->display);
216 }
217
218 return MIX_RESULT_SUCCESS;
219 }
220