static void mlp_hook_playback_begin(gpointer hook_data, gpointer user_data) { gint playlist = mlp_playlist_get_playing(); gint pos = mlp_playlist_get_position(playlist); if (mlp_playlist_entry_get_length (playlist, pos, FALSE) < 30) { AUDDBG(" *** not submitting due to entry->length < 30"); return; } gchar * filename = mlp_playlist_entry_get_filename (playlist, pos); if (ishttp (filename)) { AUDDBG(" *** not submitting due to HTTP source"); str_unref (filename); return; } str_unref (filename); sc_idle(m_scrobbler); if (submit_tuple) tuple_unref (submit_tuple); submit_tuple = mlp_playlist_entry_get_tuple (playlist, pos, FALSE); if (! submit_tuple) return; sc_addentry(m_scrobbler, submit_tuple, tuple_get_int(submit_tuple, FIELD_LENGTH, NULL) / 1000); if (!track_timeout) track_timeout = g_timeout_add_seconds(1, sc_timeout, NULL); }
static void pulse_drain(void) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 0); if (!(o = pa_stream_drain(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_drain() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_drain() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
void metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { callback_info *info = (callback_info*) client_data; gsize size; if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { info->stream.samples = metadata->data.stream_info.total_samples; AUDDBG("total_samples=%lld\n", (long long) metadata->data.stream_info.total_samples); info->stream.bits_per_sample = metadata->data.stream_info.bits_per_sample; AUDDBG("bits_per_sample=%d\n", metadata->data.stream_info.bits_per_sample); info->stream.channels = metadata->data.stream_info.channels; AUDDBG("channels=%d\n", metadata->data.stream_info.channels); info->stream.samplerate = metadata->data.stream_info.sample_rate; AUDDBG("sample_rate=%d\n", metadata->data.stream_info.sample_rate); size = vfs_fsize(info->fd); if (size == -1 || info->stream.samples == 0) info->bitrate = 0; else info->bitrate = 8 * size * (gint64) info->stream.samplerate / info->stream.samples; AUDDBG("bitrate=%d\n", info->bitrate); info->metadata_changed = TRUE; } }
static AVInputFormat * get_format_by_extension (const gchar * name) { const gchar * ext0, * sub; uri_parse (name, NULL, & ext0, & sub, NULL); if (ext0 == sub) return NULL; gchar * ext = g_ascii_strdown (ext0 + 1, sub - ext0 - 1); AUDDBG ("Get format by extension: %s\n", name); pthread_mutex_lock (& data_mutex); if (! extension_dict) extension_dict = create_extension_dict (); AVInputFormat * f = g_hash_table_lookup (extension_dict, ext); pthread_mutex_unlock (& data_mutex); if (f) AUDDBG ("Format %s.\n", f->name); else AUDDBG ("Format unknown.\n"); g_free (ext); return f; }
static void start_single (int type) { PluginHandle * p; if ((p = find_enabled (type)) != NULL) { AUDDBG ("Starting selected %s plugin %s.\n", table[type].name, plugin_get_name (p)); if (table[type].u.s.set_current (p)) return; AUDDBG ("%s failed to start.\n", plugin_get_name (p)); plugin_set_enabled (p, FALSE); } AUDDBG ("Probing for %s plugin.\n", table[type].name); if ((p = table[type].u.s.probe ()) == NULL) { fprintf (stderr, "FATAL: No %s plugin found.\n", table[type].name); exit (EXIT_FAILURE); } AUDDBG ("Starting %s.\n", plugin_get_name (p)); plugin_set_enabled (p, TRUE); if (! table[type].u.s.set_current (p)) { fprintf (stderr, "FATAL: %s failed to start.\n", plugin_get_name (p)); plugin_set_enabled (p, FALSE); exit (EXIT_FAILURE); } }
static bool_t set_format(int format, int rate, int channels) { int param; AUDDBG("Audio format: %s, sample rate: %dHz, number of channels: %d.\n", oss_format_to_text(format), rate, channels); /* Enable/disable format conversions made by the OSS software */ param = aud_get_bool("oss4", "cookedmode"); CHECK(ioctl, oss_data->fd, SNDCTL_DSP_COOKEDMODE, ¶m); AUDDBG("%s format conversions made by the OSS software.\n", param ? "Enabled" : "Disabled"); param = format; CHECK_NOISY(ioctl, oss_data->fd, SNDCTL_DSP_SETFMT, ¶m); CHECK_VAL(param == format, ERROR_NOISY, "Selected audio format is not supported by the device.\n"); param = rate; CHECK_NOISY(ioctl, oss_data->fd, SNDCTL_DSP_SPEED, ¶m); CHECK_VAL(param >= rate * 9 / 10 && param <= rate * 11 / 10, ERROR_NOISY, "Selected sample rate is not supported by the device.\n"); param = channels; CHECK_NOISY(ioctl, oss_data->fd, SNDCTL_DSP_CHANNELS, ¶m); CHECK_VAL(param == channels, ERROR_NOISY, "Selected number of channels is not supported by the device.\n"); oss_data->format = format; oss_data->rate = rate; oss_data->channels = channels; oss_data->bits_per_sample = oss_format_to_bits(oss_data->format); return TRUE; FAILED: return FALSE; }
//called from scrobbler_init() @ scrobbler.c bool_t scrobbler_communication_init() { CURLcode curl_requests_result = curl_global_init(CURL_GLOBAL_DEFAULT); if (curl_requests_result != CURLE_OK) { AUDDBG("Could not initialize libCURL: %s.\n", curl_easy_strerror(curl_requests_result)); return FALSE; } curlHandle = curl_easy_init(); if (curlHandle == NULL) { AUDDBG("Could not initialize libCURL.\n"); return FALSE; } curl_requests_result = curl_easy_setopt(curlHandle, CURLOPT_URL, SCROBBLER_URL); if (curl_requests_result != CURLE_OK) { AUDDBG("Could not define scrobbler destination URL: %s.\n", curl_easy_strerror(curl_requests_result)); return FALSE; } curl_requests_result = curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, result_callback); if (curl_requests_result != CURLE_OK) { AUDDBG("Could not register scrobbler callback function: %s.\n", curl_easy_strerror(curl_requests_result)); return FALSE; } return TRUE; }
static void general_load (PluginHandle * plugin) { GList * node = g_list_find_custom (loaded_general_plugins, plugin, (GCompareFunc) general_find_cb); if (node != NULL) return; AUDDBG ("Loading %s.\n", plugin_get_name (plugin)); GeneralPlugin * gp = plugin_get_header (plugin); g_return_if_fail (gp != NULL); LoadedGeneral * general = g_slice_new (LoadedGeneral); general->plugin = plugin; general->gp = gp; general->widget = NULL; if (gp->get_widget != NULL) general->widget = gp->get_widget (); if (general->widget != NULL) { AUDDBG ("Adding %s to interface.\n", plugin_get_name (plugin)); g_signal_connect (general->widget, "destroy", (GCallback) gtk_widget_destroyed, & general->widget); interface_add_plugin_widget (plugin, general->widget); } loaded_general_plugins = g_list_prepend (loaded_general_plugins, general); }
static Tuple * wv_probe_for_tuple(const char * filename, VFSFile * fd) { WavpackContext *ctx; Tuple *tu; char error[1024]; ctx = WavpackOpenFileInputEx(&wv_readers, fd, NULL, error, OPEN_TAGS, 0); if (ctx == NULL) return NULL; AUDDBG("starting probe of %p\n", (void *) fd); vfs_rewind(fd); tu = tuple_new_from_filename(filename); vfs_rewind(fd); tag_tuple_read(tu, fd); tuple_set_int(tu, FIELD_LENGTH, NULL, ((uint64_t) WavpackGetNumSamples(ctx) * 1000) / (uint64_t) WavpackGetSampleRate(ctx)); tuple_set_str(tu, FIELD_CODEC, NULL, "WavPack"); char * quality = wv_get_quality (ctx); tuple_set_str (tu, FIELD_QUALITY, NULL, quality); str_unref (quality); WavpackCloseFile(ctx); AUDDBG("returning tuple %p for file %p\n", (void *) tu, (void *) fd); return tu; }
void start(void) { sc_going = 1; gchar * username = mlp_get_string ("audioscrobbler", "username"); gchar * password = mlp_get_string ("audioscrobbler", "password"); gchar * sc_url = mlp_get_string ("audioscrobbler", "sc_url"); if ((!username || !password) || (!*username || !*password)) { AUDDBG("username/password not found - not starting last.fm support"); sc_going = 0; } else sc_init(username, password, sc_url); g_free (username); g_free (password); g_free (sc_url); m_scrobbler = g_mutex_new(); hook_associate("playback begin", mlp_hook_playback_begin, NULL); hook_associate("playback stop", mlp_hook_playback_end, NULL); AUDDBG("plugin started"); sc_idle(m_scrobbler); }
static void pulse_flush(int time) { pa_operation *o = NULL; int success = 0; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); written = time * (int64_t) bytes_per_second / 1000; flush_time = time; if (!(o = pa_stream_flush(stream, stream_success_cb, &success))) { AUDDBG("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } while (pa_operation_get_state(o) != PA_OPERATION_DONE) { CHECK_DEAD_GOTO(fail, 1); pa_threaded_mainloop_wait(mainloop); } if (!success) AUDDBG("pa_stream_flush() failed: %s", pa_strerror(pa_context_errno(context))); fail: if (o) pa_operation_unref(o); pa_threaded_mainloop_unlock(mainloop); }
static void delete_lines_from_scrobble_log (GSList **lines_to_remove_ptr, gchar *queuepath) { GSList *lines_to_remove = *lines_to_remove_ptr; gchar *contents = NULL; gchar **lines = NULL; gchar **finallines = g_malloc_n(1, sizeof(gchar *)); int n_finallines; if (lines_to_remove == NULL) { return; } lines_to_remove = g_slist_reverse(lines_to_remove); pthread_mutex_lock(&log_access_mutex); gboolean success = g_file_get_contents(queuepath, &contents, NULL, NULL); if (!success) { AUDDBG("Could not read scrobbler.log contents.\n"); } else { lines = g_strsplit(contents, "\n", 0); n_finallines = 0; for (int i = 0 ; lines[i] != NULL && strlen(lines[i]) > 0; i++) { if (lines_to_remove != NULL && *((int *) (lines_to_remove->data)) == i) { //this line is to remove lines_to_remove = g_slist_next(lines_to_remove); } else { //keep this line n_finallines++; finallines = g_realloc_n(finallines, n_finallines, sizeof(gchar *)); finallines[n_finallines-1] = g_strdup(lines[i]); } } finallines = g_realloc_n(finallines, n_finallines+2, sizeof(gchar *)); finallines[n_finallines] = g_strdup(""); finallines[n_finallines+1] = NULL; g_free(contents); contents = g_strjoinv("\n", finallines); success = g_file_set_contents(queuepath, contents, -1, NULL); if (!success) { AUDDBG("Could not write to scrobbler.log!\n"); } } pthread_mutex_unlock(&log_access_mutex); g_strfreev(finallines); g_strfreev(lines); g_free(contents); }
//returns: // FALSE if there was a network problem. // TRUE otherwise (scrobbling_enabled must be checked) //sets scrobbling_enabled to TRUE if the session is OK //sets session_key to NULL if it is invalid static bool_t scrobbler_test_connection() { if (session_key == NULL || strlen(session_key) == 0) { scrobbling_enabled = FALSE; return TRUE; } gchar *testmsg = create_message_to_lastfm("user.getRecommendedArtists", 3, "limit", "1", "api_key", SCROBBLER_API_KEY, "sk", session_key ); bool_t success = send_message_to_lastfm(testmsg); g_free(testmsg); if (success == FALSE) { AUDDBG("Network problems. Will not scrobble any tracks.\n"); scrobbling_enabled = FALSE; if (permission_check_requested) { perm_result = PERMISSION_NONET; } return FALSE; } gchar *error_code = NULL; gchar *error_detail = NULL; if (read_authentication_test_result(&error_code, &error_detail) == FALSE) { AUDDBG("Error code: %s. Detail: %s.\n", error_code, error_detail); if (error_code != NULL && ( g_strcmp0(error_code, "4") == 0 || //error code 4: Authentication Failed - You do not have permissions to access the service g_strcmp0(error_code, "9") == 0 //error code 9: Invalid session key - Please re-authenticate )) { g_free(error_code); g_free(error_detail); g_free(session_key); session_key = NULL; aud_set_string("scrobbler", "session_key", ""); scrobbling_enabled = FALSE; return TRUE; } else { //network problem. scrobbling_enabled = FALSE; AUDDBG("Connection NOT OK. Scrobbling disabled\n"); return FALSE; } } else { //THIS IS THE ONLY PLACE WHERE SCROBBLING IS SET TO ENABLED IN RUN-TIME scrobbling_enabled = TRUE; AUDDBG("Connection OK. Scrobbling enabled.\n"); return TRUE; } }
static bool_t start_multi_cb (PluginHandle * p, void * type) { AUDDBG ("Starting %s.\n", plugin_get_name (p)); if (! table[GPOINTER_TO_INT (type)].u.m.start (p)) { AUDDBG ("%s failed to start; disabling.\n", plugin_get_name (p)); plugin_set_enabled (p, FALSE); } return TRUE; }
static bool_t send_message_to_lastfm(gchar *data) { AUDDBG("This message will be sent to last.fm:\n%s\n%%%%End of message%%%%\n", data);//Enter?\n", data); curl_easy_setopt(curlHandle, CURLOPT_POSTFIELDS, data); CURLcode curl_requests_result = curl_easy_perform(curlHandle); if (curl_requests_result != CURLE_OK) { AUDDBG("Could not communicate with last.fm: %s.\n", curl_easy_strerror(curl_requests_result)); return FALSE; } return TRUE; }
gchar *archive_decompress(const gchar *filename) { gchar *tmpdir, *cmd, *escaped_filename; ArchiveType type; #ifndef HAVE_MKDTEMP #ifdef S_IRGRP mode_t mode755 = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; #else mode_t mode755 = S_IRWXU; #endif #endif if ((type = archive_get_type(filename)) <= ARCHIVE_DIR) return NULL; #ifdef HAVE_MKDTEMP tmpdir = g_build_filename(g_get_tmp_dir(), "audacious.XXXXXXXX", NULL); if (!mkdtemp(tmpdir)) { g_free(tmpdir); AUDDBG("Unable to load skin: Failed to create temporary " "directory: %s\n", g_strerror(errno)); return NULL; } #else tmpdir = g_strdup_printf("%s/audacious.%ld", g_get_tmp_dir(), (long)rand()); make_directory(tmpdir, mode755); #endif escaped_filename = escape_shell_chars(filename); cmd = archive_extract_funcs[type] (escaped_filename, tmpdir); g_free(escaped_filename); if (!cmd) { AUDDBG("extraction function is NULL!\n"); g_free(tmpdir); return NULL; } AUDDBG("Attempt to execute \"%s\"\n", cmd); if (system(cmd) != 0) { AUDDBG("could not execute cmd %s\n", cmd); g_free(cmd); return NULL; } g_free(cmd); return tmpdir; }
bool_t flac_get_image(const char *filename, VFSFile *fd, void **data, int64_t *length) { AUDDBG("Probe for song image.\n"); FLAC__Metadata_Iterator *iter; FLAC__Metadata_Chain *chain; FLAC__StreamMetadata *metadata = NULL; FLAC__Metadata_ChainStatus status; bool_t has_image = FALSE; chain = FLAC__metadata_chain_new(); if (!FLAC__metadata_chain_read_with_callbacks(chain, fd, io_callbacks)) goto ERR; iter = FLAC__metadata_iterator_new(); FLAC__metadata_iterator_init(iter, chain); while (FLAC__metadata_iterator_next(iter)) if (FLAC__metadata_iterator_get_block_type(iter) == FLAC__METADATA_TYPE_PICTURE) break; if (FLAC__metadata_iterator_get_block_type(iter) == FLAC__METADATA_TYPE_PICTURE) { metadata = FLAC__metadata_iterator_get_block(iter); if (metadata->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER) { AUDDBG("FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER found."); * data = malloc (metadata->data.picture.data_length); * length = metadata->data.picture.data_length; memcpy (* data, metadata->data.picture.data, * length); has_image = TRUE; } } FLAC__metadata_iterator_delete(iter); FLAC__metadata_chain_delete(chain); return has_image; ERR: status = FLAC__metadata_chain_status(chain); FLAC__metadata_chain_delete(chain); FLACNG_ERROR("An error occured: %s\n", FLAC__Metadata_ChainStatusString[status]); return FALSE; }
static void mp3_close(void) { if (output_file) { int imp3, encout; /* write remaining mp3 data */ encout = lame_encode_flush_nogap(gfp, encbuffer, LAME_MAXMP3BUFFER); write_output(encbuffer, encout); /* set gfp->num_samples for valid TLEN tag */ lame_set_num_samples(gfp, numsamples); /* append v1 tag */ imp3 = lame_get_id3v1_tag(gfp, encbuffer, sizeof(encbuffer)); if (imp3 > 0) write_output(encbuffer, imp3); /* update v2 tag */ imp3 = lame_get_id3v2_tag(gfp, encbuffer, sizeof(encbuffer)); if (imp3 > 0) { if (vfs_fseek(output_file, 0, SEEK_SET) != 0) { AUDDBG("can't rewind\n"); } else { write_output(encbuffer, imp3); } } /* update lame tag */ if (id3v2_size) { if (vfs_fseek(output_file, id3v2_size, SEEK_SET) != 0) { AUDDBG("fatal error: can't update LAME-tag frame!\n"); } else { imp3 = lame_get_lametag_frame(gfp, encbuffer, sizeof(encbuffer)); write_output(encbuffer, imp3); } } } g_free (write_buffer); lame_close(gfp); AUDDBG("lame_close() done\n"); free_lameid3(&lameid3); numsamples = 0; }
int sdlout_open_audio (int format, int rate, int chan) { if (format != FMT_S16_NE) { sdlout_error ("Only signed 16-bit, native endian audio is supported.\n"); return 0; } AUDDBG ("Opening audio for %d channels, %d Hz.\n", chan, rate); sdlout_chan = chan; sdlout_rate = rate; buffer_size = 2 * chan * (aud_get_int (NULL, "output_buffer_size") * rate / 1000); buffer = g_malloc (buffer_size); buffer_data_start = 0; buffer_data_len = 0; frames_written = 0; prebuffer_flag = 1; paused_flag = 0; SDL_AudioSpec spec = { .freq = rate, .format = AUDIO_S16, .channels = chan, .samples = 4096, .callback = callback, .userdata = NULL}; if (SDL_OpenAudio (& spec, NULL) < 0) { sdlout_error ("Failed to open audio stream: %s.\n", SDL_GetError ()); g_free (buffer); buffer = NULL; return 0; } return 1; } void sdlout_close_audio (void) { AUDDBG ("Closing audio.\n"); SDL_CloseAudio (); g_free (buffer); buffer = NULL; }
static size_t read_cb(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle) { size_t read; if (handle == NULL) { FLACNG_ERROR("Trying to read data from an uninitialized file!\n"); return -1; } read = vfs_fread(ptr, size, nmemb, handle); switch (read) { case -1: FLACNG_ERROR("Error while reading from stream!\n"); return -1; case 0: AUDDBG("Stream reached EOF\n"); return 0; default: return read; } }
bool_t read_metadata(FLAC__StreamDecoder *decoder, callback_info *info) { FLAC__StreamDecoderState ret; reset_info(info); /* Reset the decoder */ if (FLAC__stream_decoder_reset(decoder) == false) { FLACNG_ERROR("Could not reset the decoder!\n"); return FALSE; } /* Try to decode the metadata */ if (FLAC__stream_decoder_process_until_end_of_metadata(decoder) == false) { ret = FLAC__stream_decoder_get_state(decoder); AUDDBG("Could not read the metadata: %s(%d)!\n", FLAC__StreamDecoderStateString[ret], ret); reset_info(info); return FALSE; } return TRUE; }
callback_info *init_callback_info(void) { callback_info *info; if ((info = malloc (sizeof (callback_info))) == NULL) { FLACNG_ERROR("Could not allocate memory for callback structure!"); return NULL; } memset (info, 0, sizeof (callback_info)); if ((info->output_buffer = malloc (BUFFER_SIZE_BYTE)) == NULL) { FLACNG_ERROR("Could not allocate memory for output buffer!"); free (info); return NULL; } reset_info(info); AUDDBG("Playback buffer allocated for %d samples, %d bytes\n", BUFFER_SIZE_SAMP, BUFFER_SIZE_BYTE); return info; }
static GHashTable * dictionary_from_vorbis_comment (vorbis_comment * vc) { gint i; GHashTable * dict = g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) str_unref, (GDestroyNotify) str_unref); for (i = 0; i < vc->comments; i++) { gchar **frags; AUDDBG("%s\n", vc->user_comments[i]); frags = g_strsplit(vc->user_comments[i], "=", 2); if (frags[0] && frags[1]) { gchar * key = g_ascii_strdown (frags[0], -1); g_hash_table_insert (dict, str_get (key), str_get (frags[1])); g_free (key); } g_strfreev(frags); /* Don't use g_free() for string lists! --eugene */ } return dict; }
void init_dbus() { GError *error = NULL; DBusConnection *local_conn; main_thread = g_thread_self(); info_mutex = g_mutex_new(); info_cond = g_cond_new(); AUDDBG ("Trying to initialize D-Bus.\n"); dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (dbus_conn == NULL) { g_warning("Unable to connect to dbus: %s", error->message); g_error_free(error); return; } g_type_init(); g_object_new(audacious_rc_get_type(), NULL); g_object_new(mpris_root_get_type(), NULL); mpris = g_object_new(mpris_player_get_type(), NULL); g_object_new(mpris_tracklist_get_type(), NULL); local_conn = dbus_g_connection_get_connection(dbus_conn); dbus_connection_set_exit_on_disconnect(local_conn, FALSE); }
//returns: // FALSE if there was a network problem // TRUE otherwise (request_token must be checked) static bool_t scrobbler_request_token() { gchar *tokenmsg = create_message_to_lastfm("auth.getToken", 1, "api_key", SCROBBLER_API_KEY ); if (send_message_to_lastfm(tokenmsg) == FALSE) { AUDDBG("Could not send token request to last.fm.\n"); g_free(tokenmsg); return FALSE; } gchar *error_code = NULL; gchar *error_detail = NULL; if (read_token(&error_code, &error_detail) == FALSE) { if (error_code != NULL && g_strcmp0(error_code, "8")) { //error code 8: There was an error granting the request token. Please try again later request_token = NULL; return FALSE; } return FALSE; } return TRUE; }
void plugin_load (const char * filename) { GModule *module; Plugin * (* func) (AudAPITable * table); AUDDBG ("Loading plugin: %s.\n", filename); if (!(module = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL))) { printf("Failed to load plugin (%s): %s\n", filename, g_module_error()); return; } /* v2 plugin loading */ if (g_module_symbol (module, "get_plugin_info", (void *) & func)) { Plugin * header = func (& api_table); g_return_if_fail (header != NULL); plugin2_process(header, module, filename); return; } printf("Invalid plugin (%s)\n", filename); g_module_close(module); }
static bool_t update_session_key() { bool_t result = TRUE; gchar *error_code = NULL; gchar *error_detail = NULL; if (read_session_key(&error_code, &error_detail) == FALSE) { if (error_code != NULL && ( g_strcmp0(error_code, "4") == 0 || //invalid token g_strcmp0(error_code, "14") == 0 || //token not authorized g_strcmp0(error_code, "15") == 0 //token expired )) { AUDDBG("error code CAUGHT: %s\n", error_code); g_free(session_key); session_key = NULL; result = TRUE; } else { result= FALSE; } } if (session_key == NULL) { aud_set_string("scrobbler", "session_key", ""); } else { aud_set_string("scrobbler", "session_key", session_key); } return result; }
static int open_device(void) { int res = -1; int flags = O_WRONLY; char *device = aud_get_string("oss4", "device"); char *alt_device = aud_get_string("oss4", "alt_device"); if (aud_get_bool("oss4", "exclusive")) { AUDDBG("Enabled exclusive mode.\n"); flags |= O_EXCL; } if (aud_get_bool("oss4", "use_alt_device") && alt_device != NULL) res = open(alt_device, flags); else if (device != NULL) res = open(device, flags); else res = open(DEFAULT_DSP, flags); free(device); free(alt_device); return res; }
EXPORT void audgui_simple_message (GtkWidget * * widget, GtkMessageType type, const char * title, const char * text) { AUDDBG ("%s\n", text); if (* widget) { const char * old = NULL; g_object_get ((GObject *) * widget, "text", & old, NULL); g_return_if_fail (old); int messages = GPOINTER_TO_INT (g_object_get_data ((GObject *) * widget, "messages")); if (messages > 10) text = _("\n(Further messages have been hidden.)"); if (! strstr (old, text)) { SCONCAT3 (both, old, "\n", text); g_object_set ((GObject *) * widget, "text", both, NULL); g_object_set_data ((GObject *) * widget, "messages", GINT_TO_POINTER (messages + 1)); } gtk_window_present ((GtkWindow *) * widget); } else { GtkWidget * button = audgui_button_new (_("Close"), "window-close", NULL, NULL); * widget = audgui_dialog_new (type, title, text, button, NULL); g_object_set_data ((GObject *) * widget, "messages", GINT_TO_POINTER (1)); g_signal_connect (* widget, "destroy", (GCallback) gtk_widget_destroyed, widget); gtk_widget_show_all (* widget); } }
static void pulse_write(void* ptr, int length) { int writeoffs, remain, writable; CHECK_CONNECTED(); pa_threaded_mainloop_lock(mainloop); CHECK_DEAD_GOTO(fail, 1); /* break large fragments into smaller fragments. --nenolod */ for (writeoffs = 0, remain = length; writeoffs < length; writeoffs += writable, remain -= writable) { void * pptr = (char *) ptr + writeoffs; writable = length - writeoffs; size_t fragsize = pa_stream_writable_size(stream); /* don't write more than what PA is willing to handle right now. */ if (writable > fragsize) writable = fragsize; if (pa_stream_write(stream, pptr, writable, NULL, PA_SEEK_RELATIVE, 0) < 0) { AUDDBG("pa_stream_write() failed: %s", pa_strerror(pa_context_errno(context))); goto fail; } } do_trigger = 0; written += length; fail: pa_threaded_mainloop_unlock(mainloop); }