SCTC
the soundcloud.com terminal client
Macros | Functions | Variables
sound.c File Reference
#include "_hard_config.h"
#include "sound.h"
#include <ao/ao.h>
#include <mpg123.h>
#include "cache.h"
#include "helper.h"
#include "http.h"
#include "log.h"
#include "network/network.h"
#include "soundcloud.h"
#include "track.h"
#include "tui.h"
#include "state.h"
Include dependency graph for sound.c:

Macros

#define BUFFER_SIZE   256 * 1024 * 1024
 
#define SEEKPOS_NONE   ((unsigned int) ~0)
 
#define SEM_SET_TO_ZERO(S)   {int sval; while(!sem_getvalue(&S, &sval) && sval) {sem_wait(&S);}}
 

Functions

static char * ao_strerror (int err)
 
static mpg123_handle * mpg123_reinit (mpg123_handle *mh)
 Reinitialize libmpg123. More...
 
static void * _thread_io_function (void *unused)
 main function for IO thread. More...
 
static void * _thread_play_function (void *unused)
 main function for playback thread. More...
 
bool sound_init (void(*_time_callback)(int))
 Global initialization of sound. More...
 
bool sound_finalize ()
 
bool sound_stop ()
 Stop playback of current track. More...
 
unsigned int sound_get_current_pos ()
 
void sound_seek (unsigned int pos)
 
bool sound_play (struct track *_track)
 Start playback of track. More...
 

Variables

static sem_t sem_io
 
static sem_t sem_play
 
static sem_t sem_stopped
 
static pthread_t thread_io
 
static pthread_t thread_play
 
static sem_t sem_data_available
 
static mpg123_handle * mh = NULL
 
static volatile int buffer_pos = 0
 
static volatile char * buffer = NULL
 
static volatile struct tracktrack = NULL
 
static volatile unsigned int current_pos = 0
 
static volatile unsigned int seek_to_pos = SEEKPOS_NONE
 
static volatile size_t track_size = 0
 
static volatile bool stopped = false
 
static volatile bool terminate = false
 
static void(* time_callback )(int)
 

Macro Definition Documentation

#define BUFFER_SIZE   256 * 1024 * 1024
#define SEEKPOS_NONE   ((unsigned int) ~0)
#define SEM_SET_TO_ZERO (   S)    {int sval; while(!sem_getvalue(&S, &sval) && sval) {sem_wait(&S);}}

Function Documentation

static void* _thread_io_function ( void *  unused)
static

main function for IO thread.

Parameters
unusedUnused parameter (never read), required due to pthread interface
Returns
NULL Unused return value, required due to pthread interface

Here is the call graph for this function:

Here is the caller graph for this function:

static void* _thread_play_function ( void *  unused)
static

main function for playback thread.

Parameters
unusedUnused parameter (never read), required due to pthread interface
Returns
NULL Unused return value, required due to pthread interface
Todo:
'quiet' is not quiet at all...

Here is the call graph for this function:

Here is the caller graph for this function:

static char* ao_strerror ( int  err)
static

Here is the caller graph for this function:

static mpg123_handle* mpg123_reinit ( mpg123_handle *  mh)
static

Reinitialize libmpg123.

Parameters
mhThe old handle to close (may be NULL)
Returns
A pointer to the new handle (or NULL in case of failure)

Here is the caller graph for this function:

bool sound_finalize ( )

Here is the caller graph for this function:

unsigned int sound_get_current_pos ( )

Here is the caller graph for this function:

bool sound_init ( void(*)(int)  time_callback)

Global initialization of sound.

This function is required to be called prior to the first call sound_play() and does several internal initializations.

Parameters
time_callbackcallback function receiving the elapsed seconds as parameter
Returns
true in case of success, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

bool sound_play ( struct track track)

Start playback of track.

This function is required to be called prior to the first call sound_play() and does several internal initializations.

Parameters
trackthe track to play
Returns
true in case of success, false otherwise

Here is the caller graph for this function:

void sound_seek ( unsigned int  pos)

Here is the caller graph for this function:

bool sound_stop ( )

Stop playback of current track.

Returns
true in case of success, false otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

volatile char* buffer = NULL
static
volatile int buffer_pos = 0
static
volatile unsigned int current_pos = 0
static
mpg123_handle* mh = NULL
static
volatile unsigned int seek_to_pos = SEEKPOS_NONE
static
sem_t sem_data_available
static
sem_t sem_io
static
sem_t sem_play
static
sem_t sem_stopped
static
volatile bool stopped = false
static
volatile bool terminate = false
static
pthread_t thread_io
static
pthread_t thread_play
static
void(* time_callback) (int)
static
volatile struct track* track = NULL
static
volatile size_t track_size = 0
static

The amount of data for the whole track. As soon as we reach this position during playback the end of track has been reached