diff options
author | 2009-08-07 22:37:32 +0200 | |
---|---|---|
committer | 2009-08-07 22:37:32 +0200 | |
commit | 4fa0d0375913a45ae93103ce6f006f8fa134357b (patch) | |
tree | ae8621292e93fefe963c433d191384daa1a36668 | |
parent | 403128abb088f8db7d64ef00b965198192194e4a (diff) |
added flac vorbiscomment metadata support
-rw-r--r-- | cflac.c | 60 | ||||
-rw-r--r-- | cmp3.c | 6 | ||||
-rw-r--r-- | gtkplaylist.c | 2 | ||||
-rw-r--r-- | palsa.c | 14 | ||||
-rw-r--r-- | playlist.c | 29 |
5 files changed, 90 insertions, 21 deletions
@@ -177,8 +177,41 @@ cflac_init_write_callback (const FLAC__StreamDecoder *decoder, const FLAC__Frame void cflac_init_metadata_callback(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { - int *psr = (int *)client_data; - *psr = metadata->data.stream_info.sample_rate; + playItem_t *it = (playItem_t *)client_data; + it->tracknum = 0; + if (metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) { + const FLAC__StreamMetadata_VorbisComment *vc = &metadata->data.vorbis_comment; + for (int i = 0; i < vc->num_comments; i++) { + const FLAC__StreamMetadata_VorbisComment_Entry *c = &vc->comments[i]; + if (c->length > 0) { + char s[c->length+1]; + s[c->length] = 0; + memcpy (s, c->entry, c->length); + if (!strncmp (s, "ARTIST=", 7)) { + ps_add_meta (it, "artist", s + 7); + } + else if (!strncmp (s, "TITLE=", 6)) { + ps_add_meta (it, "title", s + 6); + } + else if (!strncmp (s, "ALBUM=", 6)) { + ps_add_meta (it, "album", s + 6); + } + else if (!strncmp (s, "TRACKNUMBER=", 12)) { + ps_add_meta (it, "track", s + 12); + } + else if (!strncmp (s, "DATE=", 5)) { + ps_add_meta (it, "date", s + 5); + } + } + } + +// ps_add_meta (it, "artist", performer); +// ps_add_meta (it, "album", albumtitle); +// ps_add_meta (it, "track", track); +// ps_add_meta (it, "title", title); + } +// int *psr = (int *)client_data; +// *psr = metadata->data.stream_info.sample_rate; } playItem_t * @@ -208,29 +241,34 @@ cflac_insert (playItem_t *after, const char *fname) { printf ("FLAC__stream_decoder_new failed\n"); return NULL; } + FLAC__stream_decoder_set_metadata_respond_all (decoder); FLAC__stream_decoder_set_md5_checking(decoder, 0); int samplerate = -1; - status = FLAC__stream_decoder_init_file(decoder, fname, cflac_init_write_callback, cflac_init_metadata_callback, cflac_error_callback, &samplerate); + playItem_t *it = malloc (sizeof (playItem_t)); + memset (it, 0, sizeof (playItem_t)); + it->codec = &cflac; + it->fname = strdup (fname); + it->tracknum = 0; + it->timestart = 0; + it->timeend = 0; + it->tracknum = -1; + status = FLAC__stream_decoder_init_file(decoder, fname, cflac_init_write_callback, cflac_init_metadata_callback, cflac_error_callback, it); if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { FLAC__stream_decoder_delete(decoder); + ps_item_free (it); return NULL; } if (!FLAC__stream_decoder_process_until_end_of_metadata (decoder)) { FLAC__stream_decoder_delete(decoder); + ps_item_free (it); return NULL; } - if (samplerate == -1) { // not a FLAC stream + if (it->tracknum == -1) { // not a FLAC stream FLAC__stream_decoder_delete(decoder); + ps_item_free (it); return NULL; } FLAC__stream_decoder_delete(decoder); - playItem_t *it = malloc (sizeof (playItem_t)); - memset (it, 0, sizeof (playItem_t)); - it->codec = &cflac; - it->fname = strdup (fname); - it->tracknum = 0; - it->timestart = 0; - it->timeend = 0; after = ps_insert_item (after, it); return after; } @@ -753,6 +753,7 @@ cmp3_read_id3v1 (playItem_t *it, FILE *fp) { int cmp3_read_id3v2 (playItem_t *it, FILE *fp) { + int title_added = 0; if (!it || !fp) { printf ("bad call to cmp3_read_id3v2!\n"); return -1; @@ -872,6 +873,7 @@ cmp3_read_id3v2 (playItem_t *it, FILE *fp) { memcpy (str, readptr, sz); str[sz] = 0; ps_add_meta (it, "title", convstr (str, sz)); + title_added = 1; } readptr += sz; } @@ -910,10 +912,14 @@ cmp3_read_id3v2 (playItem_t *it, FILE *fp) { memcpy (str, readptr, sz); str[sz] = 0; ps_add_meta (it, "title", convstr (str, sz)); + title_added = 1; } readptr += sz; } } + if (!title_added) { + ps_add_meta (it, "title", NULL); + } return 0; } diff --git a/gtkplaylist.c b/gtkplaylist.c index 433973ec..06828026 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -48,7 +48,7 @@ int refit_header[ncolumns] = { const char *colnames[ncolumns] = { "Playing Status", - "Album / Title", + "Artist / Album", "Track №", "Title / Track Artist", "Duration" @@ -250,14 +250,16 @@ palsa_thread (uintptr_t context) { // usleep (1000); // continue; // } - snd_pcm_wait (audio, 1000); -#if 0 - if ((err = ) < 0) { - mutex_unlock (mutex); + ; + if ((err = snd_pcm_wait (audio, 1000)) < 0 && state == 1) { fprintf (stderr, "alsa poll failed (%s)\n", strerror (errno)); -// continue; + if ((err = snd_pcm_prepare (audio)) < 0) { + fprintf (stderr, "cannot prepare audio interface for use (%s)\n", + snd_strerror (err)); + } + mutex_unlock (mutex); + continue; } -#endif /* find out how much space is available for playback data */ @@ -213,8 +213,10 @@ ps_insert_cue (playItem_t *after, const char *cuename) { it->timestart = tstart; it->timeend = -1; // will be filled by next read, or by codec after = ps_insert_item (after, it); -// ps_append_item (it); -// printf ("added item %x\n", it); + ps_add_meta (it, "artist", performer); + ps_add_meta (it, "album", albumtitle); + ps_add_meta (it, "track", track); + ps_add_meta (it, "title", title); prev = it; track[0] = 0; } @@ -748,8 +750,29 @@ ps_start_current (void) { void ps_add_meta (playItem_t *it, const char *key, const char *value) { + char str[256]; if (!value || !*value) { - value = "?"; + if (!strcmp (key, "title")) { + int len = 256; + // cut filename without path and extension + const char *pext = it->fname + strlen (it->fname) - 1; + while (pext >= it->fname && *pext != '.') { + pext--; + } + const char *pname = pext; + while (pname >= it->fname && *pname != '/') { + pname--; + } + if (*pname == '/') { + pname++; + } + strncpy (str, pname, pext-pname); + str[pext-pname] = 0; + value = str; + } + else { + value = "?"; + } } metaInfo_t *m = malloc (sizeof (metaInfo_t)); m->key = key; |