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 }