Bug Summary

File:build-analysis/../src/plugins/ofa/ofa.c
Warning:line 124, column 2
Value stored to 'entry' is never read

Annotated Source Code

1/* XMMS2 - X Music Multiplexer System
2 * Copyright (C) 2003-2017 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 * @file
19 * Ofa
20 */
21
22#include <xmms/xmms_xformplugin.h>
23#include <xmms/xmms_log.h>
24
25#include <glib.h>
26
27#include "ofa1/ofa.h"
28
29typedef enum xmms_ofa_thread_state_E {
30 XMMS_OFA_WAIT = 0,
31 XMMS_OFA_CALCULATE,
32 XMMS_OFA_DONE,
33 XMMS_OFA_ABORT,
34} xmms_ofa_thread_state_t;
35
36typedef struct xmms_ofa_data_St {
37 unsigned char *buf;
38 int bytes_to_read;
39 int pos;
40
41 gboolean run_ofa;
42 gboolean done;
43
44 GMutex mutex;
45 GCond cond;
46 GThread *thread;
47 xmms_ofa_thread_state_t thread_state;
48
49 char *fp;
50} xmms_ofa_data_t;
51
52static gboolean xmms_ofa_plugin_setup (xmms_xform_plugin_t *xform_plugin);
53static gboolean xmms_ofa_init (xmms_xform_t *xform);
54static void xmms_ofa_destroy (xmms_xform_t *xform);
55static gint xmms_ofa_read (xmms_xform_t *xform, xmms_sample_t *buf,
56 gint len, xmms_error_t *error);
57static gint64 xmms_ofa_seek (xmms_xform_t *xform, gint64 samples,
58 xmms_xform_seek_mode_t whence,
59 xmms_error_t *error);
60
61static gpointer xmms_ofa_thread (gpointer arg);
62
63/*
64 * Plugin header
65 */
66
67XMMS_XFORM_PLUGIN_DEFINE ("ofa",xmms_plugin_desc_t __attribute__((visibility ("default"))) XMMS_PLUGIN_DESC
= { XMMS_PLUGIN_TYPE_XFORM, 7, "ofa", "Open Fingerprint Architecture"
, "clang-analysis", "Open Fingerprint calculator", (gboolean (
*)(gpointer))xmms_ofa_plugin_setup };
68 "Open Fingerprint Architecture",xmms_plugin_desc_t __attribute__((visibility ("default"))) XMMS_PLUGIN_DESC
= { XMMS_PLUGIN_TYPE_XFORM, 7, "ofa", "Open Fingerprint Architecture"
, "clang-analysis", "Open Fingerprint calculator", (gboolean (
*)(gpointer))xmms_ofa_plugin_setup };
69 XMMS_VERSION,xmms_plugin_desc_t __attribute__((visibility ("default"))) XMMS_PLUGIN_DESC
= { XMMS_PLUGIN_TYPE_XFORM, 7, "ofa", "Open Fingerprint Architecture"
, "clang-analysis", "Open Fingerprint calculator", (gboolean (
*)(gpointer))xmms_ofa_plugin_setup };
70 "Open Fingerprint calculator",xmms_plugin_desc_t __attribute__((visibility ("default"))) XMMS_PLUGIN_DESC
= { XMMS_PLUGIN_TYPE_XFORM, 7, "ofa", "Open Fingerprint Architecture"
, "clang-analysis", "Open Fingerprint calculator", (gboolean (
*)(gpointer))xmms_ofa_plugin_setup };
71 xmms_ofa_plugin_setup)xmms_plugin_desc_t __attribute__((visibility ("default"))) XMMS_PLUGIN_DESC
= { XMMS_PLUGIN_TYPE_XFORM, 7, "ofa", "Open Fingerprint Architecture"
, "clang-analysis", "Open Fingerprint calculator", (gboolean (
*)(gpointer))xmms_ofa_plugin_setup };
;
72
73static gboolean
74xmms_ofa_plugin_setup (xmms_xform_plugin_t *xform_plugin)
75{
76 xmms_xform_methods_t methods;
77
78 XMMS_XFORM_METHODS_INIT (methods)memset (&methods, 0, sizeof (xmms_xform_methods_t));
79
80 methods.init = xmms_ofa_init;
81 methods.destroy = xmms_ofa_destroy;
82 methods.read = xmms_ofa_read;
83 methods.seek = xmms_ofa_seek;
84
85 xmms_xform_plugin_methods_set (xform_plugin, &methods);
86
87 xmms_xform_plugin_indata_add (xform_plugin,
88 XMMS_STREAM_TYPE_MIMETYPE,
89 "audio/pcm",
90 XMMS_STREAM_TYPE_FMT_FORMAT,
91 XMMS_SAMPLE_FORMAT_S16,
92 XMMS_STREAM_TYPE_FMT_CHANNELS,
93 2,
94 XMMS_STREAM_TYPE_FMT_SAMPLERATE,
95 44100,
96 XMMS_STREAM_TYPE_END);
97
98 return TRUE(!(0));
99}
100
101static gboolean
102xmms_ofa_init (xmms_xform_t *xform)
103{
104 xmms_ofa_data_t *data;
105 xmms_medialib_entry_t entry;
106 char *fp;
107
108 g_return_val_if_fail (xform, FALSE)do{ if (xform) { } else { g_return_if_fail_warning (((gchar*)
0), ((const char*) (__func__)), "xform"); return ((0)); }; }
while (0)
;
109
110 data = g_new0 (xmms_ofa_data_t, 1)((xmms_ofa_data_t *) g_malloc0_n ((1), sizeof (xmms_ofa_data_t
)))
;
111 g_return_val_if_fail (data, FALSE)do{ if (data) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "data"); return ((0)); }; }while
(0)
;
112
113 data->thread = g_thread_new ("x2 ofa calc", xmms_ofa_thread, data);
114 if (!data->thread) {
115 g_free (data);
116 return FALSE(0);
117 }
118
119 g_mutex_init (&data->mutex);
120 g_cond_init (&data->cond);
121
122 data->bytes_to_read = 44100 * 135 * 4;
123 data->buf = g_malloc (data->bytes_to_read);
124 entry = xmms_xform_entry_get (xform);
Value stored to 'entry' is never read
125
126 /* TODO: #2482
127 fp = xmms_medialib_entry_property_get_str (entry, "ofa_fingerprint");
128 */
129 fp = NULL((void*)0);
130 if (fp) {
131 XMMS_DBG ("Entry already has ofa_fingerprint, not recalculating")g_debug ("../src/plugins/ofa/ofa.c" ":" "131" ": " "Entry already has ofa_fingerprint, not recalculating"
)
;
132 /* keep it! */
133 xmms_xform_metadata_set_str (xform, "ofa_fingerprint", fp);
134 g_free (fp);
135 } else {
136 data->run_ofa = TRUE(!(0));
137 }
138
139 xmms_xform_private_data_set (xform, data);
140
141 xmms_xform_outdata_type_copy (xform);
142
143 return TRUE(!(0));
144}
145
146static void
147xmms_ofa_destroy (xmms_xform_t *xform)
148{
149 xmms_ofa_data_t *data;
150 g_return_if_fail (xform)do{ if (xform) { } else { g_return_if_fail_warning (((gchar*)
0), ((const char*) (__func__)), "xform"); return; }; }while (
0)
;
151
152 data = xmms_xform_private_data_get (xform);
153
154 g_mutex_lock (&data->mutex);
155 data->thread_state = XMMS_OFA_ABORT;
156 g_cond_signal (&data->cond);
157 g_mutex_unlock (&data->mutex);
158
159 g_thread_join (data->thread);
160 g_cond_clear (&data->cond);
161 g_mutex_clear (&data->mutex);
162
163 if (data->fp)
164 g_free (data->fp);
165 g_free (data->buf);
166 g_free (data);
167}
168
169static gint
170xmms_ofa_read (xmms_xform_t *xform, xmms_sample_t *buf, gint len,
171 xmms_error_t *error)
172{
173 xmms_ofa_data_t *data;
174 gint read;
175
176 g_return_val_if_fail (xform, -1)do{ if (xform) { } else { g_return_if_fail_warning (((gchar*)
0), ((const char*) (__func__)), "xform"); return (-1); }; }while
(0)
;
177
178 data = xmms_xform_private_data_get (xform);
179 g_return_val_if_fail (data, -1)do{ if (data) { } else { g_return_if_fail_warning (((gchar*) 0
), ((const char*) (__func__)), "data"); return (-1); }; }while
(0)
;
180
181 read = xmms_xform_read (xform, buf, len, error);
182
183 if (data->run_ofa && read > 0 && data->pos < data->bytes_to_read) {
184 int l = MIN (data->bytes_to_read - data->pos, read)(((data->bytes_to_read - data->pos) < (read)) ? (data
->bytes_to_read - data->pos) : (read))
;
185 memcpy (data->buf + data->pos, buf, l);
186 data->pos += l;
187 if (data->pos == data->bytes_to_read) {
188 g_mutex_lock (&data->mutex);
189 data->thread_state = XMMS_OFA_CALCULATE;
190 g_cond_signal (&data->cond);
191 g_mutex_unlock (&data->mutex);
192 data->run_ofa = FALSE(0);
193 }
194 } else if (data->pos == data->bytes_to_read){
195 if (!data->done) {
196 g_mutex_lock (&data->mutex);
197 if (data->thread_state == XMMS_OFA_DONE) {
198 xmms_xform_metadata_set_str (xform,
199 "ofa_fingerprint",
200 data->fp);
201 data->done = TRUE(!(0));
202 }
203 g_mutex_unlock (&data->mutex);
204 }
205 }
206
207 return read;
208}
209
210static gint64
211xmms_ofa_seek (xmms_xform_t *xform, gint64 samples,
212 xmms_xform_seek_mode_t whence, xmms_error_t *error)
213{
214 xmms_ofa_data_t *data;
215
216 data = xmms_xform_private_data_get (xform);
217
218 if (data->run_ofa) {
219 xmms_log_info ("Seeking requested, disabling ofa calculation!")g_message ("../src/plugins/ofa/ofa.c" ":" "219" ": " "Seeking requested, disabling ofa calculation!"
)
;
220 data->run_ofa = FALSE(0);
221 }
222 return xmms_xform_seek (xform, samples, whence, error);
223}
224
225static gpointer
226xmms_ofa_thread (gpointer arg)
227{
228 xmms_ofa_data_t *data = (xmms_ofa_data_t *)arg;
229 const char *fp;
230
231 g_mutex_lock (&data->mutex);
232 while (data->thread_state == XMMS_OFA_WAIT) {
233 g_cond_wait (&data->cond, &data->mutex);
234 }
235 if (data->thread_state == XMMS_OFA_ABORT) {
236 g_mutex_unlock (&data->mutex);
237 return NULL((void*)0);
238 }
239 g_mutex_unlock (&data->mutex);
240
241 XMMS_DBG ("Calculating fingerprint... (will consume CPU)")g_debug ("../src/plugins/ofa/ofa.c" ":" "241" ": " "Calculating fingerprint... (will consume CPU)"
)
;
242
243 fp = ofa_create_print (data->buf,
244#if G_BYTE_ORDER1234 == G_BIG_ENDIAN4321
245 OFA_BIG_ENDIAN(1),
246#else
247 OFA_LITTLE_ENDIAN(0),
248#endif
249 data->bytes_to_read/2,
250 44100,
251 1);
252
253 g_mutex_lock (&data->mutex);
254 data->thread_state = XMMS_OFA_DONE;
255 data->fp = g_strdup (fp);
256 g_mutex_unlock (&data->mutex);
257
258 XMMS_DBG ("Fingerprint calculated: %s", fp)g_debug ("../src/plugins/ofa/ofa.c" ":" "258" ": " "Fingerprint calculated: %s"
, fp)
;
259 return NULL((void*)0);
260}