XMMS2
mediainfo.c
Go to the documentation of this file.
1 /* XMMS2 - X Music Multiplexer System
2  * Copyright (C) 2003-2009 XMMS2 Team
3  *
4  * PLUGINS ARE NOT CONSIDERED TO BE DERIVED WORK !!!
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  */
16 
17 
18 
19 
20 /** @file
21  * This file controls the mediainfo reader thread.
22  *
23  */
24 
25 #include <stdlib.h>
26 
27 #include "xmms/xmms_log.h"
28 #include "xmms/xmms_ipc.h"
30 #include "xmmspriv/xmms_medialib.h"
31 #include "xmmspriv/xmms_xform.h"
32 
33 
34 #include <glib.h>
35 
36 /** @defgroup MediaInfoReader MediaInfoReader
37  * @ingroup XMMSServer
38  * @brief The mediainfo reader.
39  *
40  * When a item is added to the playlist the mediainfo reader will
41  * start extracting the information from this entry and update it
42  * if additional information is found.
43  * @{
44  */
45 
46 struct xmms_mediainfo_reader_St {
47  xmms_object_t object;
48 
49  GThread *thread;
50  GMutex *mutex;
51  GCond *cond;
52 
53  gboolean running;
54 };
55 
56 static void xmms_mediainfo_reader_stop (xmms_object_t *o);
57 static gpointer xmms_mediainfo_reader_thread (gpointer data);
58 
59 
60 /**
61  * Start a new mediainfo reader thread
62  */
63 
66 {
68 
70  xmms_mediainfo_reader_stop);
71 
73  XMMS_OBJECT (mrt));
74 
79 
80  mrt->mutex = g_mutex_new ();
81  mrt->cond = g_cond_new ();
82  mrt->running = TRUE;
83  mrt->thread = g_thread_create (xmms_mediainfo_reader_thread, mrt, TRUE, NULL);
84 
85  return mrt;
86 }
87 
88 /**
89  * Kill the mediainfo reader thread
90  */
91 
92 static void
93 xmms_mediainfo_reader_stop (xmms_object_t *o)
94 {
96 
97  g_mutex_lock (mir->mutex);
98  mir->running = FALSE;
99  g_cond_signal (mir->cond);
100  g_mutex_unlock (mir->mutex);
101 
105 
106  g_thread_join (mir->thread);
107 
108  g_cond_free (mir->cond);
109  g_mutex_free (mir->mutex);
110 }
111 
112 /**
113  * Wake the reader thread and start process the entries.
114  */
115 
116 void
118 {
119  g_return_if_fail (mr);
120 
121  g_mutex_lock (mr->mutex);
122  g_cond_signal (mr->cond);
123  g_mutex_unlock (mr->mutex);
124 }
125 
126 /** @} */
127 
128 static gpointer
129 xmms_mediainfo_reader_thread (gpointer data)
130 {
131  GList *goal_format;
132  GTimeVal timeval;
134  guint num = 0;
135 
137 
142 
143 
144  f = _xmms_stream_type_new (NULL,
146  "audio/pcm",
148  goal_format = g_list_prepend (NULL, f);
149 
150  while (mrt->running) {
151  xmms_medialib_session_t *session;
152  xmmsc_medialib_entry_status_t prev_status;
153  guint lmod = 0;
154  xmms_medialib_entry_t entry;
155  xmms_xform_t *xform;
156 
157  session = xmms_medialib_begin_write ();
158  entry = xmms_medialib_entry_not_resolved_get (session);
159  XMMS_DBG ("got %d as not resolved", entry);
160 
161  if (!entry) {
162  xmms_medialib_end (session);
163 
168 
169  g_mutex_lock (mrt->mutex);
170  g_cond_wait (mrt->cond, mrt->mutex);
171  g_mutex_unlock (mrt->mutex);
172 
173  num = 0;
174 
179  continue;
180  }
181 
184 
186 
187  if (num == 0) {
192  num = 10;
193  } else {
194  num--;
195  }
196 
197  xmms_medialib_end (session);
198  xform = xmms_xform_chain_setup (entry, goal_format, TRUE);
199 
200  if (!xform) {
201  if (prev_status == XMMS_MEDIALIB_ENTRY_STATUS_NEW) {
203  } else {
204  session = xmms_medialib_begin_write ();
206  xmms_medialib_end (session);
208  }
209  continue;
210  }
211 
212  xmms_object_unref (xform);
213  g_get_current_time (&timeval);
214 
215  session = xmms_medialib_begin_write ();
217  xmms_medialib_entry_property_set_int (session, entry,
219  timeval.tv_sec);
220  xmms_medialib_end (session);
222 
223  }
224 
225  g_list_free (goal_format);
226  xmms_object_unref (f);
227 
228  return NULL;
229 }
xmms_mediainfo_reader_t * xmms_mediainfo_reader_start(void)
Start a new mediainfo reader thread.
Definition: mediainfo.c:65
G_BEGIN_DECLS typedef gint32 xmms_medialib_entry_t
Definition: xmms_medialib.h:86
struct xmms_mediainfo_reader_St xmms_mediainfo_reader_t
#define XMMS_OBJECT(p)
Definition: xmms_object.h:84
#define xmms_object_unref(obj)
Definition: xmms_object.h:193
xmms_xform_t * xmms_xform_chain_setup(xmms_medialib_entry_t entry, GList *goal_formats, gboolean rehash)
Definition: xform.c:1500
gint xmms_medialib_entry_property_get_int(xmms_medialib_session_t *session, xmms_medialib_entry_t entry, const gchar *property)
Retrieve a property as a int from a entry.
Definition: medialib.c:588
struct xmms_stream_type_St xmms_stream_type_t
xmmsc_medialib_entry_status_t
void xmms_ipc_broadcast_register(xmms_object_t *object, xmms_ipc_signals_t signalid)
Register a broadcast signal.
Definition: ipc.c:694
struct xmms_xform_St xmms_xform_t
void xmms_ipc_signal_register(xmms_object_t *object, xmms_ipc_signals_t signalid)
Register a signal.
Definition: ipc.c:726
void xmms_object_emit_f(xmms_object_t *object, guint32 signalid, xmmsv_type_t type,...)
Emits a signal on the current object.
Definition: object.c:257
#define XMMS_MEDIALIB_ENTRY_PROPERTY_LMOD
Definition: xmms_medialib.h:44
#define XMMS_MEDIALIB_ENTRY_PROPERTY_ADDED
Definition: xmms_medialib.h:54
void xmms_mediainfo_reader_wakeup(xmms_mediainfo_reader_t *mr)
Wake the reader thread and start process the entries.
Definition: mediainfo.c:117
#define XMMS_MEDIALIB_ENTRY_PROPERTY_STATUS
Definition: xmms_medialib.h:67
void xmms_ipc_signal_unregister(xmms_ipc_signals_t signalid)
Unregister a signal.
Definition: ipc.c:740
void xmms_ipc_object_unregister(xmms_ipc_objects_t objectid)
Remove a object from the IPC core.
Definition: ipc.c:769
xmms_stream_type_t * _xmms_stream_type_new(void *dumb,...)
Definition: streamtype.c:362
struct xmms_medialib_session_St xmms_medialib_session_t
Definition: xmms_medialib.h:87
void xmms_medialib_entry_send_update(xmms_medialib_entry_t entry)
Trigger a update signal to the client.
Definition: medialib.c:719
#define XMMS_DBG(fmt,...)
Definition: xmms_log.h:32
#define xmms_medialib_begin_write()
void xmms_ipc_broadcast_unregister(xmms_ipc_signals_t signalid)
Unregister a broadcast signal.
Definition: ipc.c:709
#define xmms_object_new(objtype, destroyfunc)
Definition: xmms_object.h:199
#define xmms_medialib_entry_status_set(session, e, st)
guint xmms_medialib_num_not_resolved(xmms_medialib_session_t *session)
Definition: medialib.c:1500
gboolean xmms_medialib_entry_property_set_int(xmms_medialib_session_t *session, xmms_medialib_entry_t entry, const gchar *property, gint value)
Set a entry property to a new value, overwriting the old value.
Definition: medialib.c:616
void xmms_ipc_object_register(xmms_ipc_objects_t objectid, xmms_object_t *object)
Register a object to the IPC core.
Definition: ipc.c:758
void xmms_medialib_entry_remove(xmms_medialib_entry_t entry)
Remove a medialib entry from the database.
Definition: medialib.c:754
void xmms_medialib_end(xmms_medialib_session_t *session)
Definition: medialib.c:470
xmms_medialib_entry_t xmms_medialib_entry_not_resolved_get(xmms_medialib_session_t *session)
Definition: medialib.c:1482