本文整理汇总了C++中BarUiMsg函数的典型用法代码示例。如果您正苦于以下问题:C++ BarUiMsg函数的具体用法?C++ BarUiMsg怎么用?C++ BarUiMsg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BarUiMsg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BarMainGetInitialStation
/* get initial station from autostart setting or user input
*/
static void BarMainGetInitialStation (BarApp_t *app) {
/* try to get autostart station */
if (app->settings.autostartStation != NULL) {
app->curStation = PianoFindStationById (app->ph.stations,
app->settings.autostartStation);
if (app->curStation == NULL) {
BarUiMsg (&app->settings, MSG_ERR,
"Error: Autostart station not found.\n");
}
}
/* no autostart? ask the user */
if (app->curStation == NULL) {
app->curStation = BarUiSelectStation (app, "Select station: ", NULL);
}
if (app->curStation != NULL) {
BarUiPrintStation (&app->settings, app->curStation);
}
}
示例2: BarUiPrintSong
/* Print song infos (artist, title, album, loved)
* @param pianobar settings
* @param the song
* @param alternative station info (show real station for quickmix, e.g.)
*/
void BarUiPrintSong (const BarSettings_t *settings,
const PianoSong_t *song, const PianoStation_t *station) {
char outstr[512];
const char *vals[] = {song->title, song->artist, song->album,
(song->rating == PIANO_RATE_LOVE) ? settings->loveIcon : "",
station != NULL ? settings->atIcon : "",
station != NULL ? station->name : "",
song->detailUrl};
BarUiCustomFormat (outstr, sizeof (outstr), settings->npSongFormat,
"[email protected]", vals);
BarUiAppendNewline (outstr, sizeof (outstr));
BarUiMsg (settings, MSG_PLAYING, "%s", outstr);
BarUiCustomFormat(outstr, sizeof(outstr), settings->titleFormat,
"[email protected]", vals);
BarConsoleSetTitle(outstr);
}
示例3: BarMainStartPlayback
/* start new player thread
*/
static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
assert (app != NULL);
assert (playerThread != NULL);
const PianoSong_t * const curSong = app->playlist;
assert (curSong != NULL);
BarUiPrintSong (&app->settings, curSong, app->curStation->isQuickMix ?
PianoFindStationById (app->ph.stations,
curSong->stationId) : NULL);
static const char httpPrefix[] = "http://";
/* avoid playing local files */
if (curSong->audioUrl == NULL ||
strncmp (curSong->audioUrl, httpPrefix, strlen (httpPrefix)) != 0) {
BarUiMsg (&app->settings, MSG_ERR, "Invalid song url.\n");
} else {
/* setup player */
memset (&app->player, 0, sizeof (app->player));
app->player.url = curSong->audioUrl;
app->player.gain = curSong->fileGain;
app->player.settings = &app->settings;
app->player.songDuration = curSong->length;
pthread_mutex_init (&app->player.pauseMutex, NULL);
pthread_cond_init (&app->player.pauseCond, NULL);
assert (interrupted == &app->doQuit);
interrupted = &app->player.interrupted;
/* throw event */
BarUiStartEventCmd (&app->settings, "songstart",
app->curStation, curSong, &app->player, app->ph.stations,
PIANO_RET_OK, CURLE_OK);
/* prevent race condition, mode must _not_ be DEAD if
* thread has been started */
app->player.mode = PLAYER_WAITING;
/* start player */
pthread_create (playerThread, NULL, BarPlayerThread,
&app->player);
}
}
示例4: BarMainStartPlayback
/* start new player thread
*/
static void BarMainStartPlayback (BarApp_t *app, pthread_t *playerThread) {
BarUiPrintSong (&app->settings, app->playlist, app->curStation->isQuickMix ?
PianoFindStationById (app->ph.stations,
app->playlist->stationId) : NULL);
if (app->playlist->audioUrl == NULL) {
BarUiMsg (&app->settings, MSG_ERR, "Invalid song url.\n");
} else {
/* setup player */
memset (&app->player, 0, sizeof (app->player));
WaitressInit (&app->player.waith);
WaitressSetUrl (&app->player.waith, app->playlist->audioUrl);
/* set up global proxy, player is NULLed on songfinish */
if (app->settings.proxy != NULL) {
WaitressSetProxy (&app->player.waith, app->settings.proxy);
}
app->player.gain = app->playlist->fileGain;
if ( !app->mute ) {
app->player.scale = BarPlayerCalcScale (app->player.gain + app->settings.volume);
}
app->player.audioFormat = app->playlist->audioFormat;
app->player.settings = &app->settings;
pthread_mutex_init (&app->player.pauseMutex, NULL);
pthread_cond_init (&app->player.pauseCond, NULL);
/* throw event */
BarUiStartEventCmd (&app->settings, "songstart",
app->curStation, app->playlist, &app->player, app->ph.stations,
PIANO_RET_OK, WAITRESS_RET_OK);
BarDownloadStart(app);
/* prevent race condition, mode must _not_ be FREED if
* thread has been started */
app->player.mode = PLAYER_STARTING;
/* start player */
pthread_create (playerThread, NULL, BarPlayerThread,
&app->player);
}
}
示例5: openDevice
/* setup libao
*/
static bool openDevice (player_t * const player) {
AVCodecContext * const cctx = player->st->codec;
ao_sample_format aoFmt;
memset (&aoFmt, 0, sizeof (aoFmt));
aoFmt.bits = av_get_bytes_per_sample (avformat) * 8;
assert (aoFmt.bits > 0);
aoFmt.channels = cctx->channels;
aoFmt.rate = cctx->sample_rate;
aoFmt.byte_format = AO_FMT_NATIVE;
int driver = ao_default_driver_id ();
if ((player->aoDev = ao_open_live (driver, &aoFmt, NULL)) == NULL) {
BarUiMsg (player->settings, MSG_ERR, "Cannot open audio device.\n");
return false;
}
return true;
}
示例6: _BarFlyTagFetchCover
static int _BarFlyTagFetchCover(uint8_t** cover_art, size_t* cover_size,
char const* url, BarSettings_t const* settings)
{
int exit_status = 0;
int status;
uint8_t* tmp_cover_art = NULL;
size_t tmp_cover_size;
assert(cover_art != NULL);
assert(cover_size != NULL);
assert(url != NULL);
assert(settings != NULL);
/*
* Fetch the cover art.
*/
status = _BarFlyFetchURL(url, &tmp_cover_art, &tmp_cover_size, settings);
if (status != 0) {
BarUiMsg(settings, MSG_ERR, "Could not get the cover art.\n");
goto error;
}
*cover_art = tmp_cover_art;
tmp_cover_art = NULL;
*cover_size = tmp_cover_size;
goto end;
error:
exit_status = -1;
end:
if (tmp_cover_art != NULL) {
free(tmp_cover_art);
}
return exit_status;
}
示例7: memset
/* let user pick one song
* @param pianobar settings
* @param song list
* @param input fds
* @return pointer to selected item in song list or NULL
*/
PianoSong_t *BarUiSelectSong (const BarSettings_t *settings,
PianoSong_t *startSong, BarReadlineFds_t *input) {
PianoSong_t *tmpSong = NULL;
char buf[100];
memset (buf, 0, sizeof (buf));
do {
BarUiListSongs (settings, startSong, buf);
BarUiMsg (settings, MSG_QUESTION, "Select song: ");
if (BarReadlineStr (buf, sizeof (buf), input, BAR_RL_DEFAULT) == 0) {
return NULL;
}
if (isnumeric (buf)) {
unsigned long i = strtoul (buf, NULL, 0);
tmpSong = PianoListGetP (startSong, i);
}
} while (tmpSong == NULL);
return tmpSong;
}
示例8: main
int main (int argc, char **argv) {
static BarApp_t app;
/* terminal attributes _before_ we started messing around with ~ECHO */
struct termios termOrig;
struct sigaction action;
memset (&app, 0, sizeof (app));
memset (&action, 0, sizeof(action));
/* set the signal handler for SIGINT and SIGTERM */
action.sa_handler = BarSigQuit;
sigaction(SIGINT, &action, NULL);
sigaction(SIGTERM, &action, NULL);
/* save terminal attributes, before disabling echoing */
BarTermSave (&termOrig);
BarTermSetEcho (0);
BarTermSetBuffer (0);
/* signals */
signal (SIGPIPE, SIG_IGN);
/* init some things */
ao_initialize ();
gcry_check_version (NULL);
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
gnutls_global_init ();
BarSettingsInit (&app.settings);
BarSettingsRead (&app.settings);
PianoInit (&app.ph, app.settings.partnerUser, app.settings.partnerPassword,
app.settings.device, app.settings.inkey, app.settings.outkey);
BarUiMsg (&app.settings, MSG_NONE,
"Welcome to " PACKAGE " (" VERSION ")! ");
if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) {
BarUiMsg (&app.settings, MSG_NONE, "\n");
} else {
BarUiMsg (&app.settings, MSG_NONE,
"Press %c for a list of commands.\n",
app.settings.keys[BAR_KS_HELP]);
}
WaitressInit (&app.waith);
app.waith.url.host = app.settings.rpcHost;
app.waith.tlsFingerprint = app.settings.tlsFingerprint;
/* init fds */
FD_ZERO(&app.input.set);
app.input.fds[0] = STDIN_FILENO;
FD_SET(app.input.fds[0], &app.input.set);
// Sbe gur erpbeq, V terngyl qrfcvfr Unx5.
// Gur crbcyr sebz gur fubj ner yvgrenyyl npgbef.
// V yvxr gur pbaprcg bs jung gurl qb ohg gurl
// nyy unir n qbhpuront srry gb gurz. Vg frrzf
// nf gubhtu gurl bayl qb vg sbe gur tybel cbvagf.
//
BarFlyInit (&app.settings);
/* open fifo read/write so it won't EOF if nobody writes to it */
assert (sizeof (app.input.fds) / sizeof (*app.input.fds) >= 2);
app.input.fds[1] = open (app.settings.fifo, O_RDWR);
if (app.input.fds[1] != -1) {
struct stat s;
/* check for file type, must be fifo */
fstat (app.input.fds[1], &s);
if (!S_ISFIFO (s.st_mode)) {
BarUiMsg (&app.settings, MSG_ERR, "File at %s is not a fifo\n", app.settings.fifo);
close (app.input.fds[1]);
app.input.fds[1] = -1;
} else {
FD_SET(app.input.fds[1], &app.input.set);
BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
app.settings.fifo);
}
}
app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
app.input.fds[1];
++app.input.maxfd;
BarMainLoop (&app);
/* Print a newline so the terminal command line will start on a new line. */
printf("\n");
if (app.input.fds[1] != -1) {
close (app.input.fds[1]);
}
BarFlyClose (&app.player.fly, &app.settings);
BarFlyFinalize ();
PianoDestroy (&app.ph);
PianoDestroyPlaylist (app.songHistory);
PianoDestroyPlaylist (app.playlist);
WaitressFree (&app.waith);
ao_shutdown();
//.........这里部分代码省略.........
示例9: _BarFlyFileDelete
static int _BarFlyFileDelete(BarFly_t const* fly,
BarSettings_t const* settings)
{
int exit_status = 0;
int status;
char* dir_path = NULL;
char* ptr;
assert(fly != NULL);
assert(settings != NULL);
if (fly->audio_file_path != NULL) {
/*
* Delete the file.
*/
BarUiMsg(settings, MSG_DEBUG, "Deleting partially recorded file (%s).\n",
fly->audio_file_path);
status = unlink(fly->audio_file_path);
if (status != 0) {
BarUiMsg(settings, MSG_ERR, "Failed to delete the partially "
"recorded file (%s).\n", fly->audio_file_path);
goto error;
}
/*
* Delete any empty parent directories.
*/
dir_path = strdup(fly->audio_file_path);
if (dir_path == NULL) {
BarUiMsg(settings, MSG_ERR,
"Error copying the file path (%s) (%d:%s).\n",
fly->audio_file_path, errno, strerror(errno));
goto error;
}
ptr = strrchr(dir_path, '/');
while (ptr != NULL) {
*ptr = '\0';
status = rmdir(dir_path);
if ((status != 0) && (errno != ENOTEMPTY) && (errno != EEXIST)) {
BarUiMsg(settings, MSG_ERR,
"Failed to delete the empty artist directory "
"(%s) (%d:%s).\n", dir_path, errno, strerror);
goto error;
}
ptr = strrchr(dir_path, '/');
}
}
goto end;
error:
exit_status = -1;
end:
if (dir_path != NULL) {
free(dir_path);
}
return exit_status;
}
示例10: BarStationFromGenre
/* browse genre stations and create shared station
* @param app handle
*/
void BarStationFromGenre (BarApp_t *app) {
PianoReturn_t pRet;
WaitressReturn_t wRet;
PianoGenreCategory_t *curCat;
PianoGenre_t *curGenre;
int i;
/* receive genre stations list if not yet available */
if (app->ph.genreStations == NULL) {
BarUiMsg (&app->settings, MSG_INFO, "Receiving genre stations... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_GENRE_STATIONS, NULL,
&pRet, &wRet)) {
return;
}
}
/* print all available categories */
curCat = app->ph.genreStations;
i = 0;
while (curCat != NULL) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curCat->name);
i++;
curCat = curCat->next;
}
do {
/* select category or exit */
BarUiMsg (&app->settings, MSG_QUESTION, "Select category: ");
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
curCat = app->ph.genreStations;
while (curCat != NULL && i > 0) {
curCat = curCat->next;
i--;
}
} while (curCat == NULL);
/* print all available stations */
curGenre = curCat->genres;
i = 0;
while (curGenre != NULL) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %s\n", i, curGenre->name);
i++;
curGenre = curGenre->next;
}
do {
BarUiMsg (&app->settings, MSG_QUESTION, "Select genre: ");
if (BarReadlineInt (&i, &app->input) == 0) {
return;
}
curGenre = curCat->genres;
while (curGenre != NULL && i > 0) {
curGenre = curGenre->next;
i--;
}
} while (curGenre == NULL);
/* create station */
PianoRequestDataCreateStation_t reqData;
reqData.token = curGenre->musicId;
reqData.type = PIANO_MUSICTYPE_INVALID;
BarUiMsg (&app->settings, MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, &reqData, &pRet, &wRet);
}
示例11: BarUiMsg
/* let user pick one station
* @param app handle
* @param stations that should be listed
* @param prompt string
* @param called if input was not a number
* @param auto-select if only one station remains after filtering
* @return pointer to selected station or NULL
*/
PianoStation_t *BarUiSelectStation (BarApp_t *app, PianoStation_t *stations,
const char *prompt, BarUiSelectStationCallback_t callback,
bool autoselect) {
PianoStation_t **sortedStations = NULL, *retStation = NULL;
size_t stationCount, i, lastDisplayed, displayCount;
char buf[100];
if (stations == NULL) {
BarUiMsg (&app->settings, MSG_ERR, "No station available.\n");
return NULL;
}
memset (buf, 0, sizeof (buf));
/* sort and print stations */
sortedStations = BarSortedStations (stations, &stationCount,
app->settings.sortOrder);
do {
displayCount = 0;
for (i = 0; i < stationCount; i++) {
const PianoStation_t *currStation = sortedStations[i];
/* filter stations */
if (BarStrCaseStr (currStation->name, buf) != NULL) {
BarUiMsg (&app->settings, MSG_LIST, "%2i) %c%c%c %s\n", i,
currStation->useQuickMix ? 'q' : ' ',
currStation->isQuickMix ? 'Q' : ' ',
!currStation->isCreator ? 'S' : ' ',
currStation->name);
++displayCount;
lastDisplayed = i;
}
}
BarUiMsg (&app->settings, MSG_QUESTION, prompt);
if (autoselect && displayCount == 1 && stationCount != 1) {
/* auto-select last remaining station */
BarUiMsg (&app->settings, MSG_NONE, "%i\n", lastDisplayed);
retStation = sortedStations[lastDisplayed];
} else {
if (BarReadlineStr (buf, sizeof (buf), &app->input,
BAR_RL_DEFAULT) == 0) {
break;
}
if (isnumeric (buf)) {
unsigned long selected = strtoul (buf, NULL, 0);
if (selected < stationCount) {
retStation = sortedStations[selected];
}
}
/* hand over buffer to external function if it was not a station number */
if (retStation == NULL && callback != NULL) {
callback (app, buf);
}
}
} while (retStation == NULL);
free (sortedStations);
return retStation;
}
示例12: BarMainGetLoginCredentials
/* ask for username/password if none were provided in settings
*/
static bool BarMainGetLoginCredentials (BarSettings_t *settings,
BarReadlineFds_t *input) {
bool usernameFromConfig = true;
if (settings->username == NULL) {
char nameBuf[100];
BarUiMsg (settings, MSG_QUESTION, "No User name in config? Email: ");
BarReadlineStr (nameBuf, sizeof (nameBuf), input, BAR_RL_DEFAULT);
settings->username = strdup (nameBuf);
usernameFromConfig = false;
}
if (settings->password == NULL) {
char passBuf[100];
if (usernameFromConfig) {
BarUiMsg (settings, MSG_QUESTION, "Got username Email: %s\n", settings->username);
}
if (settings->passwordCmd == NULL) {
BarUiMsg (settings, MSG_QUESTION, "Password: ");
BarReadlineStr (passBuf, sizeof (passBuf), input, BAR_RL_NOECHO);
/* write missing newline */
puts ("");
settings->password = strdup (passBuf);
} else {
pid_t chld;
int pipeFd[2];
BarUiMsg (settings, MSG_INFO, "Requesting password from external helper... ");
if (pipe (pipeFd) == -1) {
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
return false;
}
chld = fork ();
if (chld == 0) {
/* child */
close (pipeFd[0]);
dup2 (pipeFd[1], fileno (stdout));
execl ("/bin/sh", "/bin/sh", "-c", settings->passwordCmd, (char *) NULL);
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
close (pipeFd[1]);
exit (1);
} else if (chld == -1) {
BarUiMsg (settings, MSG_NONE, "Error: %s\n", strerror (errno));
return false;
} else {
/* parent */
int status;
close (pipeFd[1]);
memset (passBuf, 0, sizeof (passBuf));
read (pipeFd[0], passBuf, sizeof (passBuf)-1);
close (pipeFd[0]);
/* drop trailing newlines */
ssize_t len = strlen (passBuf)-1;
while (len >= 0 && passBuf[len] == '\n') {
passBuf[len] = '\0';
--len;
}
waitpid (chld, &status, 0);
if (WEXITSTATUS (status) == 0) {
settings->password = strdup (passBuf);
BarUiMsg (settings, MSG_NONE, "Ok.\n");
} else {
BarUiMsg (settings, MSG_NONE, "Error: Exit status %i.\n", WEXITSTATUS (status));
return false;
}
}
} /* end else passwordCmd */
}
return true;
}
示例13: main
int main (int argc, char **argv) {
static BarApp_t app;
/* terminal attributes _before_ we started messing around with ~ECHO */
struct termios termOrig;
memset (&app, 0, sizeof (app));
/* save terminal attributes, before disabling echoing */
BarTermSave (&termOrig);
BarTermSetEcho (0);
BarTermSetBuffer (0);
/* signals */
signal (SIGPIPE, SIG_IGN);
/* init some things */
ao_initialize ();
gcry_check_version (NULL);
gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
gnutls_global_init ();
BarSettingsInit (&app.settings);
BarSettingsRead (&app.settings);
PianoInit (&app.ph, app.settings.partnerUser, app.settings.partnerPassword,
app.settings.device, app.settings.inkey, app.settings.outkey);
BarUiMsg (&app.settings, MSG_NONE,
"Welcome to " PACKAGE " (" VERSION ")! ");
if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) {
BarUiMsg (&app.settings, MSG_NONE, "\n");
} else {
BarUiMsg (&app.settings, MSG_NONE,
"Press %c for a list of commands.\n",
app.settings.keys[BAR_KS_HELP]);
}
WaitressInit (&app.waith);
app.waith.url.host = app.settings.rpcHost;
app.waith.tlsFingerprint = app.settings.tlsFingerprint;
/* init fds */
FD_ZERO(&app.input.set);
app.input.fds[0] = STDIN_FILENO;
FD_SET(app.input.fds[0], &app.input.set);
/* open fifo read/write so it won't EOF if nobody writes to it */
assert (sizeof (app.input.fds) / sizeof (*app.input.fds) >= 2);
app.input.fds[1] = open (app.settings.fifo, O_RDWR);
if (app.input.fds[1] != -1) {
struct stat s;
/* check for file type, must be fifo */
fstat (app.input.fds[1], &s);
if (!S_ISFIFO (s.st_mode)) {
BarUiMsg (&app.settings, MSG_ERR, "File at %s is not a fifo\n", app.settings.fifo);
close (app.input.fds[1]);
app.input.fds[1] = -1;
} else {
FD_SET(app.input.fds[1], &app.input.set);
BarUiMsg (&app.settings, MSG_INFO, "Control fifo at %s opened\n",
app.settings.fifo);
}
}
app.input.maxfd = app.input.fds[0] > app.input.fds[1] ? app.input.fds[0] :
app.input.fds[1];
++app.input.maxfd;
BarMainLoop (&app);
if (app.input.fds[1] != -1) {
close (app.input.fds[1]);
}
PianoDestroy (&app.ph);
PianoDestroyPlaylist (app.songHistory);
PianoDestroyPlaylist (app.playlist);
WaitressFree (&app.waith);
ao_shutdown();
gnutls_global_deinit ();
BarSettingsDestroy (&app.settings);
/* restore terminal attributes, zsh doesn't need this, bash does... */
BarTermRestore (&termOrig);
return 0;
}
示例14: BarPlayerMp3Cb
/* mp3 playback callback
*/
static WaitressCbReturn_t BarPlayerMp3Cb (void *ptr, size_t size,
void *stream) {
const char *data = ptr;
struct audioPlayer *player = stream;
size_t i;
QUIT_PAUSE_CHECK;
if (!BarPlayerBufferFill (player, data, size)) {
return WAITRESS_CB_RET_ERR;
}
/* some "prebuffering" */
if (player->mode < PLAYER_RECV_DATA &&
player->bufferFilled < BAR_PLAYER_BUFSIZE / 2) {
return WAITRESS_CB_RET_OK;
}
mad_stream_buffer (&player->mp3Stream, player->buffer,
player->bufferFilled);
player->mp3Stream.error = 0;
do {
/* channels * max samples, found in mad.h */
signed short int madDecoded[2*1152], *madPtr = madDecoded;
if (mad_frame_decode (&player->mp3Frame, &player->mp3Stream) != 0) {
if (player->mp3Stream.error != MAD_ERROR_BUFLEN) {
BarUiMsg (player->settings, MSG_ERR,
"mp3 decoding error: %s\n",
mad_stream_errorstr (&player->mp3Stream));
return WAITRESS_CB_RET_ERR;
} else {
/* rebuffering required => exit loop */
break;
}
}
mad_synth_frame (&player->mp3Synth, &player->mp3Frame);
for (i = 0; i < player->mp3Synth.pcm.length; i++) {
/* left channel */
*(madPtr++) = applyReplayGain (BarPlayerMadToShort (
player->mp3Synth.pcm.samples[0][i]), player->scale);
/* right channel */
*(madPtr++) = applyReplayGain (BarPlayerMadToShort (
player->mp3Synth.pcm.samples[1][i]), player->scale);
}
if (player->mode < PLAYER_AUDIO_INITIALIZED) {
ao_sample_format format;
int audioOutDriver;
player->channels = player->mp3Synth.pcm.channels;
player->samplerate = player->mp3Synth.pcm.samplerate;
audioOutDriver = ao_default_driver_id();
memset (&format, 0, sizeof (format));
format.bits = 16;
format.channels = player->channels;
format.rate = player->samplerate;
format.byte_format = AO_FMT_NATIVE;
if ((player->audioOutDevice = ao_open_live (audioOutDriver,
&format, NULL)) == NULL) {
player->aoError = 1;
BarUiMsg (player->settings, MSG_ERR,
"Cannot open audio device\n");
return WAITRESS_CB_RET_ERR;
}
/* calc song length using the framerate of the first decoded frame */
player->songDuration = (unsigned long long int) player->waith.request.contentLength /
((unsigned long long int) player->mp3Frame.header.bitrate /
(unsigned long long int) BAR_PLAYER_MS_TO_S_FACTOR / 8LL);
/* must be > PLAYER_SAMPLESIZE_INITIALIZED, otherwise time won't
* be visible to user (ugly, but mp3 decoding != aac decoding) */
player->mode = PLAYER_RECV_DATA;
}
/* samples * length * channels */
ao_play (player->audioOutDevice, (char *) madDecoded,
player->mp3Synth.pcm.length * 2 * 2);
/* avoid division by 0 */
if (player->mode == PLAYER_RECV_DATA) {
/* same calculation as in aac player; don't need to divide by
* channels, length is number of samples for _one_ channel */
player->songPlayed += (unsigned long long int) player->mp3Synth.pcm.length *
(unsigned long long int) BAR_PLAYER_MS_TO_S_FACTOR /
(unsigned long long int) player->samplerate;
}
QUIT_PAUSE_CHECK;
} while (player->mp3Stream.error != MAD_ERROR_BUFLEN);
player->bufferRead += player->mp3Stream.next_frame - player->buffer;
BarPlayerBufferMove (player);
return WAITRESS_CB_RET_OK;
}
示例15: _BarFlyParseTrackDisc
static int _BarFlyParseTrackDisc(char const* title, char const* album_xml,
short unsigned* track_num, short unsigned* disc_num,
BarSettings_t const* settings)
{
size_t const MATCH_COUNT = 3;
size_t const ERROR_MSG_SIZE = 100;
int exit_status = 0;
int status;
char* regex_string = NULL;
regex_t regex_track;
regmatch_t match[MATCH_COUNT];
char error_msg[ERROR_MSG_SIZE];
char regex_title[BAR_FLY_NAME_LENGTH];
int index;
int index2;
short unsigned track;
short unsigned disc;
assert(title != NULL);
assert(album_xml != NULL);
assert(track_num != NULL);
assert(disc_num != NULL);
assert(settings != NULL);
memset(®ex_track, 0, sizeof(regex_track));
/*
* Create the regular expression string.
*
* The title needs to have all potential regular expresion metacharacters
* fixed. The real correct way to do this would be to escape all of them
* with '\'. But the easy way to it is simply replace them with '.'.
*
* Additionally Pandora excludes some characters from the titles in the
* xml page. These characters are ignored.
*/
index2 = 0;
for (index = 0; title[index] != '\0'; index++) {
if (title[index] == '^' ||
title[index] == '$' ||
title[index] == '(' ||
title[index] == ')' ||
title[index] == '>' ||
title[index] == '<' ||
title[index] == '[' ||
title[index] == '{' ||
title[index] == '\\' ||
title[index] == '|' ||
title[index] == '.' ||
title[index] == '*' ||
title[index] == '+' ||
title[index] == '&') {
regex_title[index2] = '.';
index2++;
} else if (title[index] == '?' ) {
/*
* Skip these characters.
*/
} else {
regex_title[index2] = title[index];
index2++;
}
}
regex_title[index2] = '\0';
status = BarFlyasprintf(®ex_string,
"songTitle *= *\"%s\"[^>]+"
"discNum *= *\"([0-9]+)\"[^>]+"
"trackNum *= *\"([0-9]+)\"", regex_title);
if (status == -1) {
BarUiMsg(settings, MSG_ERR, "Failed to create the regex string to get "
"the track and disc numbers (%d:%s).\n", errno,
strerror(errno));
goto error;
}
/*
* Compile and execute the regular expression to get the track and disc
* numbers.
*/
status = regcomp(®ex_track, regex_string, REG_EXTENDED);
if (status != 0) {
regerror(status, ®ex_track, error_msg, ERROR_MSG_SIZE);
BarUiMsg(settings, MSG_ERR, "Failed to compile the regex to get the "
"track and disc numbers (%d:%s).\n", status, error_msg);
goto error;
}
memset(match, 0, sizeof(match));
status = regexec(®ex_track, album_xml, MATCH_COUNT, match, 0);
if (status != 0) {
regerror(status, ®ex_track, error_msg, ERROR_MSG_SIZE);
BarUiMsg(settings, MSG_DEBUG, "The track and disc numbers were not "
"included in the album explorer page (%d:%s).\n", status,
error_msg);
goto error;
}
/*
//.........这里部分代码省略.........