Main Page   Data Structures   File List   Data Fields   Globals  

libdaisy.c File Reference

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>
#include "libdaisy.h"
#include "control.h"
#include "common.h"
#include "snprintf/snprintf.h"
#include "audio.h"
#include "report.h"

Go to the source code of this file.

Data Structures

struct  struct_daisyplayer_t

Defines

#define DAISYPLAYER_MAGIC_NUMBER   0xC729A4BF

Functions

void local_cb_daisy_audio_done (daisyplayer_t daisy)
audio_data_t start_audio (daisyplayer_t daisy, void(*done)(daisyplayer_t), void(*error)(void *data, enum daisy_status, const char *), void(*progress)(void *data, long int progress_ms))
void stop_audio (daisyplayer_t daisy, audio_data_t data)
audio_data_t start_audio (daisyplayer_t daisy, void(*done)(daisyplayer_t d), void(*error)(void *data, enum daisy_status, const char *daisy_error_msg), void(*progress)(void *data, long int progress_ms))
daisyplayer_t daisy_init (void *data, void(*l_cb_daisy_audio_done)(void *), void(*l_cb_daisy_audio_next)(void *, unsigned long int), void(*l_cb_daisy_text)(void *, void *), void(*l_cb_daisy_id)(void *, void *), void(*l_cb_daisy_error)(void *, enum daisy_status, const char *), void(*l_cb_daisy_progress)(void *, long int))
void daisy_term (daisyplayer_t daisy)
int daisy_load (daisyplayer_t daisy, char *path)
int daisy_play (daisyplayer_t daisy)
int daisy_seek (daisyplayer_t daisy, int seek_option)
daisy_positiondaisy_get_position (daisyplayer_t daisy)
int daisy_goto_position (daisyplayer_t daisy, daisy_position *position)
int daisy_stop (daisyplayer_t daisy)
int daisy_pause (daisyplayer_t daisy)
char * daisy_get_info (daisyplayer_t daisy, int value)
int daisy_get_chapter_count (daisyplayer_t daisy)
char * daisy_get_chapter_info (daisyplayer_t daisy, int num, int option)


Define Documentation

#define DAISYPLAYER_MAGIC_NUMBER   0xC729A4BF
 

Definition at line 44 of file libdaisy.c.

Referenced by daisy_init().


Function Documentation

int daisy_get_chapter_count daisyplayer_t    daisy
 

Retrieves the number of chapters in in the loaded Daisy DTB.

Parameters:
daisy  - the daisy struct which must be passed along with all the API functions.
Returns:
the number of chapters, or -1 in case of error.

Definition at line 618 of file libdaisy.c.

References struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, daisyplayer_t, struct_daisyplayer_t::data, SmilNode::next, DaisyData::smilHead, and DaisyData::smilTail.

char* daisy_get_chapter_info daisyplayer_t    daisy,
int    num,
int    option
 

Retrieves information about a given chapter.

Parameters:
daisy  - the daisy struct which must be passed along with all the API functions.
num  - the chapter number to retrive information from (use daisy_get_chapter_count to get the number of chapters available).
option  - a daisy_chapter_info which states what information to retrieve.
Returns:
a pointer to a string containing the information, or NULL in case of error.
See also:
daisy_chapter_info , daisy_get_chapter_count

Definition at line 653 of file libdaisy.c.

References struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_CHAPTER_TITLE, DAISY_CHAPTER_WEIGHT, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, daisyplayer_t, struct_daisyplayer_t::data, SmilNode::header, SmilNode::next, DaisyData::smilHead, and DaisyData::smilTail.

char* daisy_get_info daisyplayer_t    daisy,
int    value
 

Retrieves book meta information.

Parameters:
daisy  - the daisy struct which must be passed along with all the API functions.
value  - a daisy_bookinfo_option value which states what information to retrieve.
Returns:
the string if found, otherwise NULL. The string must be deallocated by the caller.
See also:
daisy_bookinfo_option

Definition at line 566 of file libdaisy.c.

References DaisyData::bookInfo, struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_BOOKINFO_TITLEIMAGE, DAISY_BOOKINFO_TITLETEXT, DAISY_BOOKINFO_TOTALTIME, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, daisyplayer_t, struct_daisyplayer_t::data, SmilNode::next, DaisyData::smilHead, DaisyData::smilTail, BookInfo::titleImage, BookInfo::titleText, and BookInfo::totalTime.

daisy_position* daisy_get_position daisyplayer_t    daisy
 

Retrieves the current playback position.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
Returns:
a pointer to a daisy_position struct containing the chapter and passage positions, or NULL in case of error. The struct must be deallocated by the caller.
See also:
daisy_position , daisy_goto_position

Definition at line 435 of file libdaisy.c.

References struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, daisyplayer_t, struct_daisyplayer_t::data, getNodePos(), getSmilPos(), SmilNode::next, daisy_position::nodepos, REP_DEBUG, report(), DaisyData::smilHead, daisy_position::smilpos, and DaisyData::smilTail.

int daisy_goto_position daisyplayer_t    daisy,
daisy_position   position
 

Seeks to a playback position (bookmark) and continue playback from there.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
position  - a pointer to a daisy_position struct with the chapter and passage position.
Returns:
1 in case of success and -1 in case of error.
See also:
daisy_position , daisy_get_position

Definition at line 473 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, audio_get_state(), AUDIO_STATE_STOP, audio_state_t, audio_stop(), struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, struct_daisyplayer_t::daisy_mutex, daisy_play(), daisyplayer_t, struct_daisyplayer_t::data, gotoNodePosition(), gotoSmilPosition(), SmilNode::next, daisy_position::nodepos, REP_DEBUG, report(), DaisyData::smilHead, daisy_position::smilpos, and DaisyData::smilTail.

daisyplayer_t daisy_init void *    data,
void(*    l_cb_daisy_audio_done)(void *),
void(*    l_cb_daisy_audio_next)(void *, unsigned long int),
void(*    l_cb_daisy_text)(void *, void *),
void(*    l_cb_daisy_id)(void *, void *),
void(*    l_cb_daisy_error)(void *, enum daisy_status, const char *),
void(*    l_cb_daisy_progress)(void *, long int)
 

Initializes the daisy library. It should be called before any atempt to use the daisy functionality.

Parameters:
data  - a void pointer to any object or datastructure you may need in the callback functions. This data pointer will be availible in all callback functions. You can e.g. pass along a GUI object in c++ so that you can output the text from the callbackfunctions in the GUI. Set this parameter to NULL if you don't need it.
l_cb_daisy_audio_done  - a pointer to the function which will be called when an audio segment is done playing.
l_cb_daisy_audio_next  - a pointer to the function which will be called when an new audio segment starts playing, supplying the duration of the segment in ms.
l_cb_daisy_text  - a pointer to the function which will be called when an new audio segment starts playing, supplying the text corresponding to the audio.
l_cb_daisy_id  - a pointer to the function which will be called when an new audio segment starts playing, supplying the id of the text passage in the xml file.
l_cb_daisy_error  - a pointer to the function which will be called when an engine error occures.
l_cb_daisy_progress  - a pointer to the function which will be called during playback, supplying the progress in ms.
Returns:
daisyplayer_t - the daisy data struct which must be passed along with all the API functions.

Definition at line 216 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, struct_daisyplayer_t::cb_daisy_audio_done, struct_daisyplayer_t::cb_daisy_audio_next, struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::cb_daisy_id, struct_daisyplayer_t::cb_daisy_progress, struct_daisyplayer_t::cb_daisy_text, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_MISC_INIT_MUTEX, struct_daisyplayer_t::daisy_mutex, daisy_status, DAISYPLAYER_MAGIC_NUMBER, daisyplayer_t, struct_daisyplayer_t::data, local_cb_daisy_audio_done(), struct_daisyplayer_t::magic, parseInit(), REP_ERROR, report(), and start_audio().

int daisy_load daisyplayer_t    daisy,
char *    path
 

Loades a new daisy book.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
path  - a full path to the daisy dtb (ncc.* | *.ncx) to open.
Returns:
1 in case of success and -1 in case of error.

Definition at line 279 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::cb_daisy_progress, struct_daisyplayer_t::daisy_book_data, DAISY_SEEK_NEXT_PASSAGE, daisyplayer_t, local_cb_daisy_audio_done(), parse(), REP_DEBUG, report(), seek(), start_audio(), and stop_audio().

int daisy_pause daisyplayer_t    daisy
 

Toggle pause. Pauses playback if state is playing and continues playing of state is paused.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
Returns:
1 in case of success and -1 in case of error.

Definition at line 552 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, audio_pause(), daisyplayer_t, REP_DEBUG, and report().

int daisy_play daisyplayer_t    daisy
 

Starts playback if a book i loaded.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
Returns:
1 in case of success and -1 in case of error.

Definition at line 301 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, audio_play(), Node::audiofilename, Node::audioStartPos, Node::audioStopPos, struct_daisyplayer_t::cb_daisy_audio_next, struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::cb_daisy_id, struct_daisyplayer_t::cb_daisy_text, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_PLAYBACK_NO_AUDIO_IN_SEGMENT, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, DAISY_ERROR_PLAYBACK_NO_TEXT_IN_SEGMENT, daisyplayer_t, struct_daisyplayer_t::data, Node::fragmentIdentifier, SmilNode::next, DaisyData::nodePos, DaisyData::path, REP_DEBUG, report(), DaisyData::smilHead, DaisyData::smilTail, STRLEN, and Node::textPassage.

Referenced by daisy_goto_position(), and daisy_seek().

int daisy_seek daisyplayer_t    daisy,
int    seek_option
 

Seek operations which can be performed when a book is loaded.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
seek_option  - a daisy_seek_option.
Returns:
0 if end_of_book, 1 in case of success and -1 in case of error.
See also:
daisy_seek_option

Definition at line 351 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, audio_get_state(), AUDIO_STATE_STOP, audio_state_t, audio_stop(), struct_daisyplayer_t::cb_daisy_error, struct_daisyplayer_t::daisy_book_data, DAISY_ERROR_PLAYBACK_NO_DTB_LOADED, struct_daisyplayer_t::daisy_mutex, daisy_play(), daisyplayer_t, struct_daisyplayer_t::data, SmilNode::next, REP_DEBUG, report(), seek(), DaisyData::smilHead, and DaisyData::smilTail.

Referenced by local_cb_daisy_audio_done().

int daisy_stop daisyplayer_t    daisy
 

Stops playback.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.
Returns:
1 in case of success. Has no other return values at this point.

Definition at line 535 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, audio_stop(), struct_daisyplayer_t::daisy_mutex, daisyplayer_t, REP_DEBUG, and report().

void daisy_term daisyplayer_t    daisy
 

Terminates the daisy library and frees memory used by it. It should be called when daisy are no longer needed.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.

Definition at line 259 of file libdaisy.c.

References struct_daisyplayer_t::audio_data, struct_daisyplayer_t::daisy_book_data, daisyplayer_t, struct_daisyplayer_t::magic, parseTerminate(), REP_DEBUG, report(), and stop_audio().

void local_cb_daisy_audio_done daisyplayer_t    daisy [static]
 

Internal callback function. Will be called each time the audio engine is done playing the supplied segment. Feeds the audio engine with the next audio segment and signals the the front end that an segment is done playing.

Parameters:
daisy  - the daisy data struct which must be passed along with all the API functions.

Definition at line 122 of file libdaisy.c.

References struct_daisyplayer_t::cb_daisy_audio_done, struct_daisyplayer_t::cb_daisy_error, DAISY_END_OF_BOOK, DAISY_ERROR_PLAYBACK_SEEK_FAILED, daisy_seek(), DAISY_SEEK_NEXT_PASSAGE, daisyplayer_t, and struct_daisyplayer_t::data.

Referenced by daisy_init(), and daisy_load().

audio_data_t start_audio daisyplayer_t    daisy,
void(*    done)(daisyplayer_t d),
void(*    error)(void *data, enum daisy_status, const char *daisy_error_msg),
void(*    progress)(void *data, long int progress_ms)
[static]
 

Starts the audio thread. The audio playback is run as a separate thread with callback functions.

Parameters:
daisy  - a pointer to the daisy data struct returned from daisy_init ().
done  - a void pointer to a function which will be called when a audio passage is done playing with the daisy data struct as parameter.
error  - a void pointer to a function which will be called when an error occurs in the audio thread with the audio data struct, the status of the audio thread and the error message as parameters.
progress  - a void pointer to a function which will be called continuously with the progress in ms as an parameter.
Returns:
audio_data_t to the audio data struct or NULL on fail.

Definition at line 157 of file libdaisy.c.

References audio_data_t, audio_initiate(), struct_daisyplayer_t::daisy_book_data, daisy_status, daisyplayer_t, REP_CRITICAL, REP_DEBUG, report(), and DaisyData::thread_audio.

Referenced by daisy_init(), and daisy_load().

audio_data_t start_audio daisyplayer_t    daisy,
void(*    done)(daisyplayer_t),
void(*    error)(void *data, enum daisy_status, const char *),
void(*    progress)(void *data, long int progress_ms)
[static]
 

Starts the audio thread. The audio playback is run as a separate thread with callback functions.

Parameters:
daisy  - the daisy data struct returned from daisy_init ().
done  - a void pointer to a function which will be called when a audio passage is done playing with the daisy data struct as parameter.
error  - a void pointer to a function which will be called when an error occurs in the audio thread with the audio data struct, the status of the audio thread and the error message as parameters.
progress  - a void pointer to a function which will be called continuously with the progress in ms as an parameter.
Returns:
audio_data_t to the audio data struct or NULL on fail.

void stop_audio daisyplayer_t    daisy,
audio_data_t    data
[static]
 

Stops the audio thread.

Parameters:
daisy  - a pointer the daisy data struct returned from daisy_init ().
data  - a pointer to the audio data struct.

Definition at line 187 of file libdaisy.c.

References audio_data_t, audio_terminate(), struct_daisyplayer_t::daisy_book_data, daisyplayer_t, and DaisyData::thread_audio.

Referenced by daisy_load(), and daisy_term().


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