1 /*
2  *  Copyright (C) 2003 Jorn Baayen <jorn@nl.linux.org>
3  *  Copyright (C) 2003 Colin Walters <walters@verbum.org>
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  The Rhythmbox authors hereby grant permission for non-GPL compatible
11  *  GStreamer plugins to be used and distributed together with GStreamer
12  *  and Rhythmbox. This permission is above and beyond the permissions granted
13  *  by the GPL license by which Rhythmbox is covered. If you modify this code
14  *  you may extend this exception to your version of the code, but you are not
15  *  obligated to do so. If you do not wish to do so, delete this exception
16  *  statement from your version.
17  *
18  *  This program is distributed in the hope that it will be useful,
19  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  *  GNU General Public License for more details.
22  *
23  *  You should have received a copy of the GNU General Public License
24  *  along with this program; if not, write to the Free Software
25  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
26  *
27  */
28 
29 #ifndef __RB_PLAYER_H
30 #define __RB_PLAYER_H
31 
32 #include <glib-object.h>
33 #include <gdk-pixbuf/gdk-pixbuf.h>
34 #include <metadata/rb-metadata.h>
35 
36 G_BEGIN_DECLS
37 
38 typedef enum
39 {
40 	RB_PLAYER_PLAY_REPLACE,
41 	RB_PLAYER_PLAY_AFTER_EOS,
42 	RB_PLAYER_PLAY_CROSSFADE
43 } RBPlayerPlayType;
44 
45 GType rb_player_play_type_get_type (void);
46 #define RB_TYPE_PLAYER_PLAY_TYPE (rb_player_play_type_get_type())
47 
48 typedef enum
49 {
50 	RB_PLAYER_ERROR_NO_AUDIO,
51 	RB_PLAYER_ERROR_GENERAL,
52 	RB_PLAYER_ERROR_INTERNAL,
53 	RB_PLAYER_ERROR_NOT_FOUND
54 } RBPlayerError;
55 
56 GType rb_player_error_get_type (void);
57 #define RB_TYPE_PLAYER_ERROR	(rb_player_error_get_type())
58 GQuark rb_player_error_quark (void);
59 #define RB_PLAYER_ERROR rb_player_error_quark ()
60 
61 #define RB_PLAYER_SECOND	(G_USEC_PER_SEC * 1000)
62 
63 #define RB_TYPE_PLAYER         (rb_player_get_type ())
64 #define RB_PLAYER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), RB_TYPE_PLAYER, RBPlayer))
65 #define RB_IS_PLAYER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), RB_TYPE_PLAYER))
66 #define RB_PLAYER_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE ((o), RB_TYPE_PLAYER, RBPlayerIface))
67 
68 typedef struct _RBPlayer RBPlayer;
69 typedef struct _RBPlayerIface RBPlayerIface;
70 
71 typedef gboolean (*RBPlayerFeatureFunc) (RBPlayer *player);
72 
73 struct _RBPlayerIface
74 {
75 	GTypeInterface	g_iface;
76 
77 	/* virtual functions */
78 	gboolean        (*open)			(RBPlayer *player,
79 						 const char *uri,
80 						 gpointer stream_data,
81 						 GDestroyNotify stream_data_destroy,
82 						 GError **error);
83 	gboolean	(*opened)		(RBPlayer *player);
84 	gboolean        (*close)		(RBPlayer *player,
85 						 const char *uri,
86 						 GError **error);
87 
88 	gboolean	(*play)			(RBPlayer *player,
89 						 RBPlayerPlayType play_type,
90 						 gint64 crossfade,
91 						 GError **error);
92 	void		(*pause)		(RBPlayer *player);
93 	gboolean	(*playing)		(RBPlayer *player);
94 
95 	void		(*set_volume)		(RBPlayer *player,
96 						 float volume);
97 	float		(*get_volume)		(RBPlayer *player);
98 
99 	gboolean	(*seekable)		(RBPlayer *player);
100 	void		(*set_time)		(RBPlayer *player,
101 						 gint64 newtime);
102 	gint64		(*get_time)		(RBPlayer *player);
103 	gboolean	(*multiple_open)	(RBPlayer *player);
104 
105 
106 	/* signals */
107 	void		(*playing_stream)	(RBPlayer *player,
108 						 gpointer stream_data);
109 	void		(*eos)			(RBPlayer *player,
110 						 gpointer stream_data,
111 						 gboolean early);
112 	void		(*info)			(RBPlayer *player,
113 						 gpointer stream_data,
114 						 RBMetaDataField field,
115 						 GValue *value);
116 	void		(*buffering)		(RBPlayer *player,
117 						 gpointer stream_data,
118 						 guint progress);
119 	void		(*error)           	(RBPlayer *player,
120 						 gpointer stream_data,
121 						 GError *error);
122 	void		(*tick)            	(RBPlayer *player,
123 						 gpointer stream_data,
124 						 gint64 elapsed,
125 						 gint64 duration);
126 	void		(*event)		(RBPlayer *player,
127 						 gpointer stream_data,
128 						 gpointer data);
129 	void		(*volume_changed)	(RBPlayer *player,
130 						 float volume);
131 	void		(*image)		(RBPlayer *player,
132 						 gpointer stream_data,
133 						 GdkPixbuf *image);
134 	void		(*redirect)		(RBPlayer *player,
135 						 gpointer stream_data,
136 						 const gchar *uri);
137 };
138 
139 GType		rb_player_get_type   (void);
140 RBPlayer *	rb_player_new        (gboolean want_crossfade,
141 				      GError **error);
142 
143 gboolean        rb_player_open       (RBPlayer *player,
144 				      const char *uri,
145 				      gpointer stream_data,
146 				      GDestroyNotify stream_data_destroy,
147 				      GError **error);
148 gboolean	rb_player_opened     (RBPlayer *player);
149 gboolean        rb_player_close      (RBPlayer *player,
150 				      const char *uri,
151 				      GError **error);
152 
153 gboolean	rb_player_play       (RBPlayer *player,
154 				      RBPlayerPlayType play_type,
155 				      gint64 crossfade,
156 				      GError **error);
157 void		rb_player_pause      (RBPlayer *player);
158 gboolean	rb_player_playing    (RBPlayer *player);
159 
160 void		rb_player_set_volume (RBPlayer *player, float volume);
161 float		rb_player_get_volume (RBPlayer *player);
162 
163 gboolean	rb_player_seekable   (RBPlayer *player);
164 void		rb_player_set_time   (RBPlayer *player, gint64 newtime);
165 gint64		rb_player_get_time   (RBPlayer *player);
166 
167 gboolean	rb_player_multiple_open (RBPlayer *player);
168 
169 /* only to be used by subclasses */
170 void	_rb_player_emit_eos (RBPlayer *player, gpointer stream_data, gboolean early);
171 void	_rb_player_emit_info (RBPlayer *player, gpointer stream_data, RBMetaDataField field, GValue *value);
172 void	_rb_player_emit_buffering (RBPlayer *player, gpointer stream_data, guint progress);
173 void	_rb_player_emit_error (RBPlayer *player, gpointer stream_data, GError *error);
174 void	_rb_player_emit_tick (RBPlayer *player, gpointer stream_data, gint64 elapsed, gint64 duration);
175 void	_rb_player_emit_event (RBPlayer *player, gpointer stream_data, const char *name, gpointer data);
176 void	_rb_player_emit_playing_stream (RBPlayer *player, gpointer stream_data);
177 void	_rb_player_emit_volume_changed (RBPlayer *player, float volume);
178 void	_rb_player_emit_image (RBPlayer *player, gpointer stream_data, GdkPixbuf *image);
179 void	_rb_player_emit_redirect (RBPlayer *player, gpointer stream_data, const char *uri);
180 
181 G_END_DECLS
182 
183 #endif /* __RB_PLAYER_H */
184