1/*
2INTEL CONFIDENTIAL
3Copyright 2009 Intel Corporation All Rights Reserved.
4The 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
6No 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:mixvideocaps
11* @short_description: VideoConfig parameters
12*
13* A data object which stores videoconfig specific parameters.
14*/
15
16#include "mixvideocaps.h"
17
18#define SAFE_FREE(p) if(p) { g_free(p); p = NULL; }
19
20static GType _mix_videocaps_type = 0;
21static MixParamsClass *parent_class = NULL;
22
23#define _do_init { _mix_videocaps_type = g_define_type_id; }
24
25gboolean mix_videocaps_copy (MixParams * target, const MixParams * src);
26MixParams *mix_videocaps_dup (const MixParams * obj);
27gboolean mix_videocaps_equal (MixParams * first, MixParams * second);
28static void mix_videocaps_finalize (MixParams * obj);
29
30G_DEFINE_TYPE_WITH_CODE (MixVideoCaps, mix_videocaps, MIX_TYPE_PARAMS,
31			 _do_init);
32
33static void
34mix_videocaps_init (MixVideoCaps * self)
35{
36  /* initialize properties here */
37  self->mix_caps = NULL;
38  self->video_hw_caps = NULL;
39
40  self->reserved1 = NULL;
41  self->reserved2 = NULL;
42  self->reserved3 = NULL;
43  self->reserved4 = NULL;
44
45}
46
47static void
48mix_videocaps_class_init (MixVideoCapsClass * klass)
49{
50  MixParamsClass *mixparams_class = MIX_PARAMS_CLASS (klass);
51
52  /* setup static parent class */
53  parent_class = (MixParamsClass *) g_type_class_peek_parent (klass);
54
55  mixparams_class->finalize = mix_videocaps_finalize;
56  mixparams_class->copy = (MixParamsCopyFunction) mix_videocaps_copy;
57  mixparams_class->dup = (MixParamsDupFunction) mix_videocaps_dup;
58  mixparams_class->equal = (MixParamsEqualFunction) mix_videocaps_equal;
59}
60
61MixVideoCaps *
62mix_videocaps_new (void)
63{
64  MixVideoCaps *ret =
65    (MixVideoCaps *) g_type_create_instance (MIX_TYPE_VIDEOCAPS);
66  return ret;
67}
68
69void
70mix_videocaps_finalize (MixParams * obj)
71{
72  /* clean up here. */
73
74  MixVideoCaps *self = MIX_VIDEOCAPS (obj);
75  SAFE_FREE (self->mix_caps);
76  SAFE_FREE (self->video_hw_caps);
77
78  /* Chain up parent */
79  if (parent_class->finalize)
80    {
81      parent_class->finalize (obj);
82    }
83}
84
85MixVideoCaps *
86mix_videocaps_ref (MixVideoCaps * mix)
87{
88  return (MixVideoCaps *) mix_params_ref (MIX_PARAMS (mix));
89}
90
91/**
92* mix_videocaps_dup:
93* @obj: a #MixVideoCaps object
94* @returns: a newly allocated duplicate of the object.
95*
96* Copy duplicate of the object.
97*/
98MixParams *
99mix_videocaps_dup (const MixParams * obj)
100{
101  MixParams *ret = NULL;
102
103  if (MIX_IS_VIDEOCAPS (obj))
104    {
105      MixVideoCaps *duplicate = mix_videocaps_new ();
106      if (mix_videocaps_copy (MIX_PARAMS (duplicate), MIX_PARAMS (obj)))
107	{
108	  ret = MIX_PARAMS (duplicate);
109	}
110      else
111	{
112	  mix_videocaps_unref (duplicate);
113	}
114    }
115  return ret;
116}
117
118/**
119* mix_videocaps_copy:
120* @target: copy to target
121* @src: copy from src
122* @returns: boolean indicates if copy is successful.
123*
124* Copy instance data from @src to @target.
125*/
126gboolean
127mix_videocaps_copy (MixParams * target, const MixParams * src)
128{
129  MixVideoCaps *this_target, *this_src;
130
131  if (MIX_IS_VIDEOCAPS (target) && MIX_IS_VIDEOCAPS (src))
132    {
133      // Cast the base object to this child object
134      this_target = MIX_VIDEOCAPS (target);
135      this_src = MIX_VIDEOCAPS (src);
136
137      // Free the existing properties
138      SAFE_FREE (this_target->mix_caps);
139      SAFE_FREE (this_target->video_hw_caps);
140
141      // Duplicate string
142      this_target->mix_caps = g_strdup (this_src->mix_caps);
143      this_target->video_hw_caps = g_strdup (this_src->video_hw_caps);
144
145      // Now chainup base class
146      if (parent_class->copy)
147	{
148	  return parent_class->copy (MIX_PARAMS_CAST (target),
149				     MIX_PARAMS_CAST (src));
150	}
151      else
152	{
153	  return TRUE;
154	}
155    }
156  return FALSE;
157}
158
159/**
160* mix_videocaps_:
161* @first: first object to compare
162* @second: seond object to compare
163* @returns: boolean indicates if instance are equal.
164*
165* Copy instance data from @src to @target.
166*/
167gboolean
168mix_videocaps_equal (MixParams * first, MixParams * second)
169{
170  gboolean ret = FALSE;
171  MixVideoCaps *this_first, *this_second;
172
173  if (MIX_IS_VIDEOCAPS (first) && MIX_IS_VIDEOCAPS (second))
174    {
175      // Deep compare
176      // Cast the base object to this child object
177
178      this_first = MIX_VIDEOCAPS (first);
179      this_second = MIX_VIDEOCAPS (second);
180
181      /* TODO: add comparison for other properties */
182      if (g_strcmp0 (this_first->mix_caps, this_second->mix_caps) == 0
183	  && g_strcmp0 (this_first->video_hw_caps,
184			this_second->video_hw_caps) == 0)
185	{
186	  // members within this scope equal. chaining up.
187	  MixParamsClass *klass = MIX_PARAMS_CLASS (parent_class);
188	  if (klass->equal)
189	    ret = klass->equal (first, second);
190	  else
191	    ret = TRUE;
192	}
193    }
194
195  return ret;
196}
197
198#define MIX_VIDEOCAPS_SETTER_CHECK_INPUT(obj) \
199	if(!obj) return MIX_RESULT_NULL_PTR; \
200	if(!MIX_IS_VIDEOCAPS(obj)) return MIX_RESULT_FAIL; \
201
202#define MIX_VIDEOCAPS_GETTER_CHECK_INPUT(obj, prop) \
203	if(!obj || !prop) return MIX_RESULT_NULL_PTR; \
204	if(!MIX_IS_VIDEOCAPS(obj)) return MIX_RESULT_FAIL; \
205
206
207/* TODO: Add getters and setters for other properties. The following is just an exmaple, not implemented yet. */
208MIX_RESULT
209mix_videocaps_set_mix_caps (MixVideoCaps * obj, gchar * mix_caps)
210{
211  MIX_VIDEOCAPS_SETTER_CHECK_INPUT (obj);
212
213  SAFE_FREE (obj->mix_caps);
214  obj->mix_caps = g_strdup (mix_caps);
215  if (mix_caps != NULL && obj->mix_caps == NULL)
216    {
217      return MIX_RESULT_NO_MEMORY;
218    }
219
220  return MIX_RESULT_SUCCESS;
221}
222
223MIX_RESULT
224mix_videocaps_get_mix_caps (MixVideoCaps * obj, gchar ** mix_caps)
225{
226  MIX_VIDEOCAPS_GETTER_CHECK_INPUT (obj, mix_caps);
227  *mix_caps = g_strdup (obj->mix_caps);
228  if (*mix_caps == NULL && obj->mix_caps)
229    {
230      return MIX_RESULT_NO_MEMORY;
231    }
232  return MIX_RESULT_SUCCESS;
233}
234
235MIX_RESULT
236mix_videocaps_set_video_hw_caps (MixVideoCaps * obj, gchar * video_hw_caps)
237{
238  MIX_VIDEOCAPS_SETTER_CHECK_INPUT (obj);
239
240  SAFE_FREE (obj->video_hw_caps);
241  obj->video_hw_caps = g_strdup (video_hw_caps);
242  if (video_hw_caps != NULL && obj->video_hw_caps == NULL)
243    {
244      return MIX_RESULT_NO_MEMORY;
245    }
246
247  return MIX_RESULT_SUCCESS;
248}
249
250MIX_RESULT
251mix_videocaps_get_video_hw_caps (MixVideoCaps * obj, gchar ** video_hw_caps)
252{
253  MIX_VIDEOCAPS_GETTER_CHECK_INPUT (obj, video_hw_caps);
254
255  *video_hw_caps = g_strdup (obj->video_hw_caps);
256  if (*video_hw_caps == NULL && obj->video_hw_caps)
257    {
258      return MIX_RESULT_NO_MEMORY;
259    }
260  return MIX_RESULT_SUCCESS;
261}
262