Main Page   Data Structures   File List   Data Fields   Globals  

audio.c File Reference

#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <assert.h>
#include <stdbool.h>
#include <sys/time.h>
#include "common.h"
#include "audio.h"
#include "mp3.h"
#include "parsetime.h"
#include "report.h"
#include "snprintf/snprintf.h"

Go to the source code of this file.

Defines

#define AUDIO_MAGIC_NUMBER   0x6B2F6EEF

Functions

bool open_file (struct_audio_data_t *data, const char *fname)
audio_file_t get_file_type (const char *file)
bool is_new_file (struct_audio_data_t *data)
void * audio_decoder (void *)
void * audio_decoder (audio_data_t _data)
unsigned long int audio_play (audio_data_t _data, const char *fname, const char *start, const char *stop)
int audio_pause (audio_data_t _data)
int audio_stop (audio_data_t _data)
int callback (audio_data_t _data, long int progress_ms)
void audio_terminate (audio_data_t _data)
audio_data_t audio_initiate (daisyplayer_t _daisy, void(*done)(daisyplayer_t d), void(*error)(void *data, enum daisy_status status, const char *daisy_status_msg), void(*progress)(void *data, long int progress_ms))
void * audio_thread (void *_data)
audio_state_t audio_get_state (audio_data_t _data)


Define Documentation

#define AUDIO_MAGIC_NUMBER   0x6B2F6EEF
 

Includes

Definition at line 57 of file audio.c.

Referenced by audio_decoder(), audio_initiate(), audio_pause(), audio_play(), audio_stop(), audio_terminate(), audio_thread(), callback(), is_new_file(), and open_file().


Function Documentation

void* audio_decoder audio_data_t    _data [static]
 

Finds out the type of file and starts the aproporiate decoder.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.

Definition at line 222 of file audio.c.

References aac_initiate(), aac_play(), aac_terminate(), audio_data_t, AUDIO_FILE_AAC, AUDIO_FILE_MP3, AUDIO_MAGIC_NUMBER, AUDIO_STATE_STOP, audio_state_t, struct_audio_data_t::do_callback_done, struct_audio_data_t::file_name, get_file_type(), is_new_file(), struct_audio_data_t::is_playing, struct_audio_data_t::magic, mp3_close(), mp3_init(), mp3_play(), struct_audio_data_t::mutex, struct_audio_data_t::prev_file_type, REP_DEBUG, REP_MESSAGE, report(), and struct_audio_data_t::state.

void* audio_decoder void *    [static]
 

Referenced by audio_thread().

audio_state_t audio_get_state audio_data_t    _data
 

Returns the current state of the audio engine.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
Returns:
the currant state of the audio engine

Definition at line 717 of file audio.c.

References audio_data_t, audio_state_t, struct_audio_data_t::mutex, and struct_audio_data_t::state.

Referenced by audio_terminate(), daisy_goto_position(), and daisy_seek().

audio_data_t audio_initiate daisyplayer_t    _daisy,
void(*    done)(daisyplayer_t d),
void(*    error)(void *data, enum daisy_status status, const char *daisy_status_msg),
void(*    progress)(void *data, long int progress_ms)
 

Initiate the audio engine. This is called when the program wants us to start and prepare for audio playback This should allocate the basic resources needed by the audio engine.

Parameters:
-  daisy the daisy struct
-  done the callback function that will be called once a segment have been played.
-  error the callback function that will be called when errors occur.
-  progress the callback function that will be called during playback.

Definition at line 569 of file audio.c.

References audio_data_t, AUDIO_FILE_UNKNOWN, AUDIO_MAGIC_NUMBER, AUDIO_STATE_STOP, struct_audio_data_t::cb_error, struct_audio_data_t::cb_playing_done, struct_audio_data_t::cb_progress, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_INITIATE_DATA, daisy_status, daisyplayer_t, struct_audio_data_t::do_callback_done, error(), struct_audio_data_t::fd, struct_audio_data_t::fdm, struct_audio_data_t::file_name, struct_audio_data_t::file_type, struct_audio_data_t::is_playing, struct_audio_data_t::magic, struct_audio_data_t::mp3_dither, struct_audio_data_t::mutex, struct_audio_data_t::prev_file_name, struct_audio_data_t::prev_file_type, REP_DEBUG, REP_ERROR, report(), struct_audio_data_t::state, and struct_audio_data_t::unpause_cond.

int audio_pause audio_data_t    _data
 

Pause audio. Sets the audio engine state to pause.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
Returns:
1 on success, -1 on fail.

Definition at line 357 of file audio.c.

References audio_data_t, AUDIO_MAGIC_NUMBER, AUDIO_STATE_NOOP, AUDIO_STATE_PAUSE, AUDIO_STATE_PLAY, audio_state_t, struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_PAUSED_WHILE_NOT_PLAYING, struct_audio_data_t::is_playing, struct_audio_data_t::magic, struct_audio_data_t::mutex, REP_DEBUG, report(), struct_audio_data_t::state, and struct_audio_data_t::unpause_cond.

Referenced by daisy_pause().

unsigned long int audio_play audio_data_t    _data,
const char *    fname,
const char *    start,
const char *    stop
 

Plays a file from start to stop.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
const  char *fname - the filename.
const  char *start - the start time as a string in a DAISY compliant format.
const  char *stop - the stop time as a string in a DAISY compliant format.
Returns:
the duration in milliseconds or -1 if fail.

Definition at line 314 of file audio.c.

References audio_data_t, AUDIO_MAGIC_NUMBER, AUDIO_STATE_PLAY, AUDIO_STATE_STOP, struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_NOT_STOPPED, DAISY_ERROR_AUDIO_OPEN, struct_audio_data_t::magic, struct_audio_data_t::mutex, open_file(), parse_time_get_dur(), parse_time_mad_time_t(), struct_audio_data_t::progress, REP_ERROR, REP_WARNING, report(), struct_audio_data_t::start, struct_audio_data_t::state, struct_audio_data_t::stop, and STRLEN.

Referenced by daisy_play().

int audio_stop audio_data_t    _data
 

Stops audio. Sets the state to stop and blocks to make sure that audio has actually stopped.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
Returns:
1 on success, -1 on fail.

Definition at line 402 of file audio.c.

References audio_data_t, AUDIO_MAGIC_NUMBER, AUDIO_STATE_PLAY, AUDIO_STATE_STOP, struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_DATA_IS_NULL, DAISY_ERROR_AUDIO_STOPPED_WHILE_NOT_PLAYING, daisy_status, struct_audio_data_t::is_playing, struct_audio_data_t::magic, struct_audio_data_t::mutex, REP_DEBUG, report(), and struct_audio_data_t::state.

Referenced by audio_terminate(), daisy_goto_position(), daisy_seek(), and daisy_stop().

void audio_terminate audio_data_t    _data
 

Stops and frees audio engine resources. This is called when the user wants us to terminate.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.

Definition at line 494 of file audio.c.

References aac_terminate(), audio_data_t, audio_get_state(), AUDIO_MAGIC_NUMBER, AUDIO_STATE_STOP, audio_stop(), struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_FREE_MMAP, struct_audio_data_t::fd, struct_audio_data_t::fdm, struct_audio_data_t::file_name, struct_audio_data_t::file_type, struct_audio_data_t::magic, mp3_close(), struct_audio_data_t::mp3_dither, struct_audio_data_t::mutex, REP_MESSAGE, report(), and struct_audio_data_t::stat.

Referenced by stop_audio().

void* audio_thread void *    _data
 

Audio thread. This is run as a thread from daisyplayer.c and keeps the audio-engine alive. audio_initiate MUST be called before this function. audio_terminate MUST be called once you are done using the audio engine.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.

Definition at line 635 of file audio.c.

References audio_decoder(), AUDIO_MAGIC_NUMBER, AUDIO_STATE_PLAY, AUDIO_STATE_STOP, audio_state_t, struct_audio_data_t::cb_playing_done, struct_audio_data_t::daisy, daisyplayer_t, struct_audio_data_t::do_callback_done, struct_audio_data_t::is_playing, struct_audio_data_t::magic, struct_audio_data_t::mutex, REP_DEBUG, report(), and struct_audio_data_t::state.

int callback audio_data_t    _data,
long int    progress_ms
 

callback is called by the decoder loop.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
-  progress_ms the progress (so far) in the current segment. value is in milliseconds.
Returns:
0 to continue or -1 to stop decoding.

Definition at line 461 of file audio.c.

References audio_data_t, AUDIO_MAGIC_NUMBER, AUDIO_STATE_PAUSE, AUDIO_STATE_STOP, struct_audio_data_t::cb_progress, struct_audio_data_t::daisy, struct_audio_data_t::magic, struct_audio_data_t::mutex, REP_DEBUG, report(), struct_audio_data_t::state, and struct_audio_data_t::unpause_cond.

Referenced by header().

audio_file_t get_file_type const char *    fname [static]
 

Returns the filetype based on const char *fname. This is used by audio_decoder to start the apropriate audio decoder.

Parameters:
const  char *fname - the filename of the file we want to query. NOTE: This file returns AUDIO_FILE_MP3 regardless of input. This MUST be changed if another audio decoder are to be implemented.

Definition at line 183 of file audio.c.

References AUDIO_FILE_MP3, audio_file_t, REP_DEBUG, and report().

Referenced by audio_decoder(), and open_file().

bool is_new_file struct_audio_data_t   data [static]
 

Checks if this file is new.

Returns:
true if the current file is difrent from the previous file. NOTE: data struct MUST be under mutex lock when this function is called!

Definition at line 196 of file audio.c.

References AUDIO_MAGIC_NUMBER, struct_audio_data_t::file_name, struct_audio_data_t::magic, and struct_audio_data_t::prev_file_name.

Referenced by audio_decoder().

bool open_file struct_audio_data_t   data,
const char *    fname
[static]
 

Opens an audio file (if it's not already opened). This function will load a file if it's not already loaded. The freeing and generating of mmaps are handled here.

Parameters:
audio_data_t  _data - the struct_audio_data_t that is passed to almost all functions in the audio module.
const  char *fname - the filename.
Returns:
false on error, true on success. NOTE: data must be mutex locked when this function is called!

Definition at line 90 of file audio.c.

References AUDIO_MAGIC_NUMBER, struct_audio_data_t::cb_error, struct_audio_data_t::daisy, DAISY_ERROR_AUDIO_CREATE_MMAP, DAISY_ERROR_AUDIO_FREE_MMAP, DAISY_ERROR_AUDIO_FSTAT, DAISY_ERROR_AUDIO_MALLOC, DAISY_ERROR_AUDIO_OPEN, struct_audio_data_t::fd, struct_audio_data_t::fdm, struct_audio_data_t::file_name, struct_audio_data_t::file_type, get_file_type(), struct_audio_data_t::magic, struct_audio_data_t::prev_file_type, REP_DEBUG, REP_ERROR, REP_WARNING, report(), struct_audio_data_t::stat, and STRLEN.

Referenced by audio_play().


Generated on Tue Sep 5 12:14:08 2006 for libdaisy by doxygen1.2.15