Skip to content

Commit

Permalink
Code cleaning and minor refactoring prior to further work.
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.daper.net/moc/trunk@2429 910807d9-36e0-0310-a014-e9ea483e2ba4
  • Loading branch information
jcf committed Jul 8, 2012
1 parent c32e408 commit e89da1c
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 124 deletions.
90 changes: 44 additions & 46 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,8 @@ static void go_to_another_file ()
if (plist_count(&queue) && go_next) {
logit ("Playing file from queue");

if (!before_queue_fname && curr_playing_fname) {
if (!before_queue_fname && curr_playing_fname)
before_queue_fname = xstrdup (curr_playing_fname);
}

curr_plist = &queue;
curr_playing = plist_next (&queue, -1);
Expand Down Expand Up @@ -816,34 +815,29 @@ int audio_send_pcm (const char *buf, const size_t size)
char *softmixed = NULL;
char *equalized = NULL;

if(equalizer_is_active())
if (equalizer_is_active ())
{
equalized = xmalloc(size);
memcpy(equalized, buf, size);
equalized = xmalloc (size);
memcpy (equalized, buf, size);

equalizer_process_buffer(equalized, size, &driver_sound_params);
equalizer_process_buffer (equalized, size, &driver_sound_params);

buf = equalized;
}

if(softmixer_is_active())
if (softmixer_is_active ())
{
if(equalized)
if (equalized)
{
softmixed = equalized;
}
else
{
softmixed = xmalloc(size);
memcpy(softmixed, buf, size);
softmixed = xmalloc (size);
memcpy (softmixed, buf, size);
}

softmixer_process_buffer
(
softmixed
, size
, &driver_sound_params
);
softmixer_process_buffer (softmixed, size, &driver_sound_params);

buf = softmixed;
}
Expand All @@ -855,11 +849,11 @@ int audio_send_pcm (const char *buf, const size_t size)
if (played == 0)
fatal ("Audio output error!");

if(softmixed && !equalized)
free(softmixed);
if (softmixed && !equalized)
free (softmixed);

if(equalized)
free(equalized);
if (equalized)
free (equalized);

return played;
}
Expand Down Expand Up @@ -1100,23 +1094,23 @@ char *audio_get_sname ()

int audio_get_mixer ()
{
if(current_mixer==2)
return softmixer_get_value();
if (current_mixer == 2)
return softmixer_get_value ();

return hw.read_mixer ();
return hw.read_mixer ();
}

void audio_set_mixer (const int val)
{
if (val >= 0 && val <= 100)
{
if(current_mixer==2)
softmixer_set_value(val);
else
hw.set_mixer (val);
}
else
if (val < 0 || val > 100) {
logit ("Tried to set mixer to volume out of range.");
return;
}

if (current_mixer == 2)
softmixer_set_value (val);
else
hw.set_mixer (val);
}

void audio_plist_delete (const char *file)
Expand Down Expand Up @@ -1151,18 +1145,22 @@ int audio_get_ftime (const char *file)
{
int i;
int time;
time_t mtime = get_mtime (file);
time_t mtime;

mtime = get_mtime (file);

LOCK (plist_mut);
if ((i = plist_find_fname(&playlist, file)) != -1
&& (time = get_item_time(&playlist, i)) != -1) {
if (playlist.items[i].mtime == mtime) {
debug ("Found time for %s", file);
UNLOCK (plist_mut);
return time;
}
else
i = plist_find_fname (&playlist, file);
if (i != -1) {
time = get_item_time (&playlist, i);
if (time != -1) {
if (playlist.items[i].mtime == mtime) {
debug ("Found time for %s", file);
UNLOCK (plist_mut);
return time;
}
logit ("mtime for %s has changed", file);
}
}
UNLOCK (plist_mut);

Expand Down Expand Up @@ -1249,15 +1247,15 @@ struct file_tags *audio_get_curr_tags ()

char *audio_get_mixer_channel_name ()
{
if(current_mixer==2)
return softmixer_name();
if (current_mixer == 2)
return softmixer_name ();

return hw.get_mixer_channel_name ();
return hw.get_mixer_channel_name ();
}

void audio_toggle_mixer_channel ()
{
current_mixer=(current_mixer+1)%3;
if(current_mixer<2)
hw.toggle_mixer_channel ();
current_mixer = (current_mixer + 1) % 3;
if (current_mixer < 2)
hw.toggle_mixer_channel ();
}
25 changes: 18 additions & 7 deletions decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,28 +661,39 @@ void decoder_init (int debug_info)
load_preferences ();
}

void decoder_cleanup ()
static void cleanup_decoders ()
{
int i;
decoder_t_preference *pref, *next;
int ix;

for (i = 0; i < plugins_num; i++) {
if (plugins[i].decoder->destroy)
plugins[i].decoder->destroy ();
free (plugins[i].name);
for (ix = 0; ix < plugins_num; ix++) {
if (plugins[ix].decoder->destroy)
plugins[ix].decoder->destroy ();
free (plugins[ix].name);
}

if (lt_dlexit ())
logit ("lt_exit() failed: %s", lt_dlerror ());
}

static void cleanup_preferences ()
{
decoder_t_preference *pref, *next;

pref = preferences;
for (pref = preferences; pref; pref = next) {
next = pref->next;
free (pref);
}

preferences = NULL;
}

void decoder_cleanup ()
{
cleanup_decoders ();
cleanup_preferences ();
}

/* Fill the error structure with an error of a given type and message.
* strerror(add_errno) is appended at the end of the message if add_errno != 0.
* The old error message is free()ed.
Expand Down
10 changes: 2 additions & 8 deletions decoder_plugins/flac/flac.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,10 @@ static void *flac_open_internal (const char *file, const int buffered)
return data;
}

data->ok = 1;

#ifdef LEGACY_FLAC
if (!(data->decoder = FLAC__seekable_stream_decoder_new())) {
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__seekable_stream_decoder_new() failed");
data->ok = 0;
return data;
}

Expand Down Expand Up @@ -361,7 +358,6 @@ static void *flac_open_internal (const char *file, const int buffered)
!= FLAC__SEEKABLE_STREAM_DECODER_OK) {
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__seekable_stream_decoder_init() failed");
data->ok = 0;
return data;
}

Expand All @@ -370,14 +366,12 @@ static void *flac_open_internal (const char *file, const int buffered)
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__seekable_stream_decoder_process_until_end_of_metadata()"
" failed.");
data->ok = 0;
return data;
}
#else
if (!(data->decoder = FLAC__stream_decoder_new())) {
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__stream_decoder_new() failed");
data->ok = 0;
return data;
}

Expand All @@ -391,18 +385,18 @@ static void *flac_open_internal (const char *file, const int buffered)
!= FLAC__STREAM_DECODER_INIT_STATUS_OK) {
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__stream_decoder_init() failed");
data->ok = 0;
return data;
}

if (!FLAC__stream_decoder_process_until_end_of_metadata(data->decoder)) {
decoder_error (&data->error, ERROR_FATAL, 0,
"FLAC__stream_decoder_process_until_end_of_metadata()"
" failed.");
data->ok = 0;
return data;
}
#endif

data->ok = 1;
data->avg_bitrate = (data->bits_per_sample) * data->sample_rate;

return data;
Expand Down
14 changes: 7 additions & 7 deletions decoder_plugins/speex/speex.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ static void *spx_open (const char *file)
struct spx_data *data;

stream = io_open (file, 1);
if (io_ok(stream))
if (io_ok (stream))
data = spx_open_internal (stream);
else {
data = (struct spx_data *)xmalloc (sizeof(struct spx_data));
Expand Down Expand Up @@ -437,7 +437,7 @@ static void spx_info (const char *file_name, struct file_tags *tags,
struct io_stream *s;

s = io_open (file_name, 0);
if (io_ok(s)) {
if (io_ok (s)) {
struct spx_data *data = spx_open_internal (s);

if (data->ok) {
Expand Down Expand Up @@ -559,10 +559,9 @@ static int spx_decode (void *prv_data, char *sound_buf, int nbytes,
/* First see if there is anything left in the output buffer and
* empty it out */
if (data->output_left > 0) {
int to_copy = nbytes / 2;
int to_copy = nbytes / sizeof(int16_t);

to_copy = data->output_left < to_copy
? data->output_left : to_copy;
to_copy = MIN(data->output_left, to_copy);

memcpy (out, data->output + data->output_start,
to_copy * sizeof(int16_t));
Expand All @@ -571,8 +570,9 @@ static int spx_decode (void *prv_data, char *sound_buf, int nbytes,
data->output_start += to_copy;
data->output_left -= to_copy;

nbytes -= to_copy * 2;
} else if (ogg_stream_packetout(&data->os, &data->op) == 1) {
nbytes -= to_copy * sizeof(int16_t);
}
else if (ogg_stream_packetout (&data->os, &data->op) == 1) {
int16_t *temp_output = data->output;

/* Decode some more samples */
Expand Down
33 changes: 13 additions & 20 deletions files.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,46 +305,39 @@ void resolve_path (char *buf, const int size, const char *file)
* If some tags are already present, don't read them.
* If present_tags is NULL, allocate new tags. */
struct file_tags *read_file_tags (const char *file,
struct file_tags *present_tags, const int tags_sel)
struct file_tags *tags, const int tags_sel)
{
struct file_tags *tags;
struct decoder *df;
int needed_tags;

assert (file != NULL);

if (present_tags) {
tags = present_tags;
needed_tags = ~tags->filled & tags_sel;
}
else {
if (tags == NULL)
tags = tags_new ();
needed_tags = tags_sel;
}

if (file_type(file) == F_URL)
if (file_type (file) == F_URL)
return tags;

df = get_decoder (file);
needed_tags = ~tags->filled & tags_sel;
if (!needed_tags) {
debug ("No need to read any tags");
return tags;
}

df = get_decoder (file);
if (!df) {
logit ("Can't find decoder functions for %s", file);
return tags;
}

if (needed_tags) {

/* This makes sure that we don't cause a memory leak */
assert (!((needed_tags & TAGS_COMMENTS) &&
/* This makes sure that we don't cause a memory leak */
assert (!((needed_tags & TAGS_COMMENTS) &&
(tags->title
|| tags->artist
|| tags->album)));

df->info (file, tags, needed_tags);
tags->filled |= tags_sel;
}
else
debug ("No need to read any tags");
df->info (file, tags, needed_tags);
tags->filled |= tags_sel;

return tags;
}
Expand Down
3 changes: 2 additions & 1 deletion interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,9 @@ static char *get_curr_file ()

static void update_mixer_value ()
{
int val = get_mixer_value ();
int val;

val = get_mixer_value ();
iface_set_mixer_value MAX(val, 0);
}

Expand Down
2 changes: 0 additions & 2 deletions keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
#include "log.h"
#include "files.h"

#define CTRL_KEY_CODE 0x1F

/* ^c version of c */
#ifndef CTRL
# define CTRL(c) ((c) & CTRL_KEY_CODE)
Expand Down
1 change: 1 addition & 0 deletions keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ enum key_context
#endif

#define META_KEY_FLAG 0x80
#define CTRL_KEY_CODE 0x1F

struct iface_key;
enum key_cmd get_key_cmd (const enum key_context context, const struct iface_key *key);
Expand Down
Loading

0 comments on commit e89da1c

Please sign in to comment.