summaryrefslogtreecommitdiff
path: root/ytstenut/video-profile/yts-vp-player.c
blob: a9f6fc43577d7133732833d617c94ee099386823 (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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
 * 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 "yts-capability.h"
#include "yts-marshal.h"
#include "yts-vp-playable.h"
#include "yts-vp-player.h"
#include "config.h"

G_DEFINE_INTERFACE (YtsVPPlayer,
                    yts_vp_player,
                    YTS_TYPE_CAPABILITY)

enum {
  SIG_NEXT_RESPONSE,
  SIG_PREV_RESPONSE,
  N_SIGNALS
};

static unsigned _signals[N_SIGNALS] = { 0, };

static void
_play (YtsVPPlayer *self)
{
  g_critical ("%s : Method YtsVPPlayer.play() not implemented by %s",
              G_STRLOC,
              G_OBJECT_TYPE_NAME (self));
}

static void
_pause (YtsVPPlayer *self)
{
  g_critical ("%s : Method YtsVPPlayer.pause() not implemented by %s",
              G_STRLOC,
              G_OBJECT_TYPE_NAME (self));
}

static void
_next (YtsVPPlayer *self,
       char const   *invocation_id)
{
  g_critical ("%s : Method YtsVPPlayer.next() not implemented by %s",
              G_STRLOC,
              G_OBJECT_TYPE_NAME (self));
}

static void
_prev (YtsVPPlayer *self,
       char const   *invocation_id)
{
  g_critical ("%s : Method YtsVPPlayer.prev() not implemented by %s",
              G_STRLOC,
              G_OBJECT_TYPE_NAME (self));
}

static void
yts_vp_player_default_init (YtsVPPlayerInterface *interface)
{
  GParamSpec *pspec;

  interface->play = _play;
  interface->pause = _pause;
  interface->next = _next;
  interface->prev = _prev;

  pspec = g_param_spec_object ("playable", "", "",
                               YTS_VP_TYPE_PLAYABLE,
                               G_PARAM_READWRITE |
                               G_PARAM_STATIC_STRINGS);
  g_object_interface_install_property (interface, pspec);

  pspec = g_param_spec_boolean ("playing", "", "",
                                false,
                                G_PARAM_READWRITE |
                                G_PARAM_STATIC_STRINGS);
  g_object_interface_install_property (interface, pspec);

  pspec = g_param_spec_double ("volume", "", "",
                               0.0, 1.0, 0.5,
                               G_PARAM_READWRITE |
                               G_PARAM_STATIC_STRINGS);
  g_object_interface_install_property (interface, pspec);

  pspec = g_param_spec_string ("playable-uri", "", "",
                               NULL,
                               G_PARAM_READWRITE |
                               G_PARAM_STATIC_STRINGS);
  g_object_interface_install_property (interface, pspec);

  /* Signals */

  _signals[SIG_NEXT_RESPONSE] = g_signal_new ("next-response",
                                              YTS_VP_TYPE_PLAYER,
                                              G_SIGNAL_RUN_LAST,
                                              0, NULL, NULL,
                                              yts_marshal_VOID__STRING_BOOLEAN,
                                              G_TYPE_NONE,
                                              2, G_TYPE_STRING, G_TYPE_BOOLEAN);

  _signals[SIG_PREV_RESPONSE] = g_signal_new ("prev-response",
                                               YTS_VP_TYPE_PLAYER,
                                               G_SIGNAL_RUN_LAST,
                                               0, NULL, NULL,
                                               yts_marshal_VOID__STRING_BOOLEAN,
                                               G_TYPE_NONE,
                                               2, G_TYPE_STRING, G_TYPE_BOOLEAN);
}

YtsVPPlayable *
yts_vp_player_get_playable (YtsVPPlayer *self)
{
  YtsVPPlayable *playable;

  g_return_val_if_fail (YTS_VP_IS_PLAYER (self), NULL);

  playable = NULL;
  g_object_get (G_OBJECT (self), "playable", &playable, NULL);
  return playable;
}

void
yts_vp_player_set_playable (YtsVPPlayer   *self,
                             YtsVPPlayable *playable)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_object_set (G_OBJECT (self), "playable", playable, NULL);
}

bool
yts_vp_player_get_playing (YtsVPPlayer *self)
{
  bool playing;

  g_return_val_if_fail (YTS_VP_IS_PLAYER (self), false);

  playing = false;
  g_object_get (G_OBJECT (self), "playing", &playing, NULL);
  return playing;
}

void
yts_vp_player_set_playing (YtsVPPlayer *self,
                            bool          playing)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_object_set (G_OBJECT (self), "playing", playing, NULL);
}

double
yts_vp_player_get_volume (YtsVPPlayer *self)
{
  double volume;

  g_return_val_if_fail (YTS_VP_IS_PLAYER (self), 0.0);

  volume = 0.0;
  g_object_get (G_OBJECT (self), "volume", &volume, NULL);
  return volume;
}

void
yts_vp_player_set_volume (YtsVPPlayer *self,
                           double        volume)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_object_set (G_OBJECT (self), "volume", volume, NULL);
}

char *
yts_vp_player_get_playable_uri (YtsVPPlayer *self)
{
  char *playable_uri;

  g_return_val_if_fail (YTS_VP_IS_PLAYER (self), NULL);

  playable_uri = NULL;
  g_object_get (G_OBJECT (self), "playable-uri", &playable_uri, NULL);
  return playable_uri;
}

void
yts_vp_player_set_playable_uri (YtsVPPlayer *self,
                                 char const   *playable_uri)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_object_set (G_OBJECT (self), "playable-uri", playable_uri, NULL);
}

void
yts_vp_player_play (YtsVPPlayer *self)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  YTS_VP_PLAYER_GET_INTERFACE (self)->play (self);
}

void
yts_vp_player_pause (YtsVPPlayer *self)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  YTS_VP_PLAYER_GET_INTERFACE (self)->pause (self);
}

void
yts_vp_player_next (YtsVPPlayer *self,
                     char const   *invocation_id)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  YTS_VP_PLAYER_GET_INTERFACE (self)->next (self, invocation_id);
}

void
yts_vp_player_next_return (YtsVPPlayer  *self,
                            char const    *invocation_id,
                            bool           response)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_signal_emit (self, _signals[SIG_NEXT_RESPONSE], 0,
                 invocation_id, response);
}

void
yts_vp_player_prev (YtsVPPlayer *self,
                     char const   *invocation_id)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  YTS_VP_PLAYER_GET_INTERFACE (self)->prev (self, invocation_id);
}

void
yts_vp_player_prev_return (YtsVPPlayer  *self,
                            char const    *invocation_id,
                            bool           response)
{
  g_return_if_fail (YTS_VP_IS_PLAYER (self));

  g_signal_emit (self, _signals[SIG_PREV_RESPONSE], 0,
                 invocation_id, response);
}