summaryrefslogtreecommitdiff
path: root/ytstenut/video-profile/yts-vp-playable-proxy.c
blob: 8b6d9a5f4fe22e8f694b0ea202722bcf88da912a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * Copyright © 2011 Intel Corp.
 *
 * This  library is free  software; you can  redistribute it and/or
 * modify it  under  the terms  of the  GNU Lesser  General  Public
 * License  as published  by the Free  Software  Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed  in the hope that it will be useful,
 * but  WITHOUT ANY WARRANTY; without even  the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authored by: Rob Staudinger <robsta@linux.intel.com>
 */

#include <math.h>

#include "yts-vp-playable.h"
#include "yts-vp-playable-proxy.h"
#include "config.h"

static void
_playable_interface_init (YtsVPPlayableInterface *interface);

G_DEFINE_TYPE_WITH_CODE (YtsVPPlayableProxy,
                         yts_vp_playable_proxy,
                         G_TYPE_OBJECT,
                         G_IMPLEMENT_INTERFACE (YTS_VP_TYPE_PLAYABLE,
                                                _playable_interface_init))

#define GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), YTS_VP_TYPE_PLAYABLE_PROXY, YtsVPPlayableProxyPrivate))

typedef struct {
  double       duration;
  GHashTable  *metadata;
  double       position;
  char        *thumbnail;
  char        *title;
  char        *uri;
} YtsVPPlayableProxyPrivate;

/*
 * YtsVPPlayable implementation
 */

static void
_playable_interface_init (YtsVPPlayableInterface *interface)
{
}

/*
 * YtsVPPlayableProxy
 */

enum {
  PROP_0,
  PROP_PLAYABLE_DURATION,
  PROP_PLAYABLE_METADATA,
  PROP_PLAYABLE_POSITION,
  PROP_PLAYABLE_THUMBNAIL,
  PROP_PLAYABLE_TITLE,
  PROP_PLAYABLE_URI
};

static void
_get_property (GObject    *object,
               unsigned    property_id,
               GValue     *value,
               GParamSpec *pspec)
{
  YtsVPPlayableProxyPrivate *priv = GET_PRIVATE (object);

  switch (property_id) {
    case PROP_PLAYABLE_DURATION:
      g_value_set_double (value, priv->duration);
      break;
    case PROP_PLAYABLE_METADATA:
      g_value_set_boxed (value, priv->metadata);
      break;
    case PROP_PLAYABLE_POSITION:
      g_value_set_double (value, priv->position);
      break;
    case PROP_PLAYABLE_THUMBNAIL:
      g_value_set_string (value, priv->thumbnail);
      break;
    case PROP_PLAYABLE_TITLE:
      g_value_set_string (value, priv->title);
      break;
    case PROP_PLAYABLE_URI:
      g_value_set_string (value, priv->uri);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  }
}

static void
_set_property (GObject      *object,
               unsigned      property_id,
               const GValue *value,
               GParamSpec   *pspec)
{
  YtsVPPlayableProxyPrivate *priv = GET_PRIVATE (object);

  switch (property_id) {
    case PROP_PLAYABLE_POSITION: {
      double position = g_value_get_double (value);
      if (0.001 < fabs (position - priv->position)) {
        priv->position = position;
        g_object_notify (object, "postion");
        /* TODO send home etc */
      }
    } break;
  default:
    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
  }
}

static void
_dispose (GObject *object)
{
  YtsVPPlayableProxyPrivate *priv = GET_PRIVATE (object);

  if (priv->metadata) {
    g_hash_table_unref (priv->metadata);
    priv->metadata = NULL;
  }

  if (priv->thumbnail) {
    g_free (priv->thumbnail);
    priv->thumbnail = NULL;
  }

  if (priv->uri) {
    g_free (priv->uri);
    priv->uri = NULL;
  }

  G_OBJECT_CLASS (yts_vp_playable_proxy_parent_class)->dispose (object);
}

static void
yts_vp_playable_proxy_class_init (YtsVPPlayableProxyClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  g_type_class_add_private (klass, sizeof (YtsVPPlayableProxyPrivate));

  object_class->get_property = _get_property;
  object_class->set_property = _set_property;
  object_class->dispose = _dispose;

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_DURATION,
                                    "duration");

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_METADATA,
                                    "metadata");

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_POSITION,
                                    "position");

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_THUMBNAIL,
                                    "thumbnail");

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_TITLE,
                                    "title");

  g_object_class_override_property (object_class,
                                    PROP_PLAYABLE_URI,
                                    "uri");
}

static void
yts_vp_playable_proxy_init (YtsVPPlayableProxy *self)
{
}

YtsVPPlayableProxy *
yts_vp_playable_proxy_new (double       duration,
                            GHashTable  *metadata,
                            double       position,
                            char const  *thumbnail,
                            char const  *title,
                            char const  *uri)
{
  return g_object_new (YTS_VP_TYPE_PLAYABLE_PROXY,
                       "duration",  duration,
                       "metadata",  metadata,
                       "position",  position,
                       "title",     title,
                       "uri",       uri,
                       NULL);
}