1
mirror of https://github.com/mpv-player/mpv synced 2024-08-04 14:59:58 +02:00

stream_cdda: print CDTEXT if available

The per-CD info will be printed on playback start, per-track info when
a track is played. (This is not a technical restriction, and just goes
along with the existing code.)

The following fields are not included in output, because these are
supposedly binary: CDTEXT_DISCID, CDTEXT_GENRE, CDTEXT_SIZE_INFO,
CDTEXT_TOC_INFO, CDTEXT_TOC_INFO2.
This commit is contained in:
wm4 2012-03-14 06:36:46 +01:00
parent 0a4beb49f6
commit fd4759c8e6

View File

@ -19,8 +19,11 @@
#include "config.h"
#include <cdio/cdda.h>
#include <cdio/paranoia.h>
#include <cdio/cdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "talloc.h"
@ -112,6 +115,49 @@ const m_option_t cdda_opts[] = {
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static const char *cdtext_name[] = {
[CDTEXT_ARRANGER] = "Arranger",
[CDTEXT_COMPOSER] = "Composer",
[CDTEXT_MESSAGE] = "Message",
[CDTEXT_ISRC] = "ISRC",
[CDTEXT_PERFORMER] = "Performer",
[CDTEXT_SONGWRITER] = "Songwriter",
[CDTEXT_TITLE] = "Title",
[CDTEXT_UPC_EAN] = "UPC_EAN",
};
static bool print_cdtext(stream_t *s, int track)
{
cdda_priv* p = (cdda_priv*)s->priv;
cdtext_t *text = cdio_get_cdtext(p->cd->p_cdio, track);
if (text) {
mp_msg(MSGT_SEEK, MSGL_INFO, "CD-Text (%s):\n", track ? "track" : "CD");
for (int i = 0; i < sizeof(cdtext_name) / sizeof(cdtext_name[0]); i++) {
const char *name = cdtext_name[i];
const char *value = cdtext_get_const(i, text);
if (name && value)
mp_msg(MSGT_SEEK, MSGL_INFO, " %s: '%s'\n", name, value);
}
return true;
}
return false;
}
static void print_track_info(stream_t *s, int track)
{
cdda_priv* p = (cdda_priv*)s->priv;
cd_track_t *cd_track = cd_info_get_track(p->cd_info, track);
if( cd_track!=NULL ) {
mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n",
cd_track->track_nb);
}
if (print_cdtext(s, track)) {
// hack for term OSD overwriting the last line of CDTEXT
mp_msg(MSGT_SEEK, MSGL_INFO, "\n");
}
}
static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function)
{
}
@ -119,7 +165,6 @@ static void cdparanoia_callback(long int inpos, paranoia_cb_mode_t function)
static int fill_buffer(stream_t *s, char *buffer, int max_len)
{
cdda_priv *p = (cdda_priv *)s->priv;
cd_track_t *cd_track;
int16_t *buf;
int i;
@ -142,12 +187,7 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len)
for (i = 0; i < p->cd->tracks; i++) {
if (p->cd->disc_toc[i].dwStartSector == p->sector - 1) {
cd_track = cd_info_get_track(p->cd_info, i + 1);
if (cd_track != NULL) {
mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n",
cd_track->track_nb);
}
print_track_info(s, i + 1);
break;
}
}
@ -158,7 +198,6 @@ static int fill_buffer(stream_t *s, char *buffer, int max_len)
static int seek(stream_t *s, off_t newpos)
{
cdda_priv *p = (cdda_priv *)s->priv;
cd_track_t *cd_track;
int sec;
int current_track = 0, seeked_track = 0;
int seek_to_track = 0;
@ -183,15 +222,8 @@ static int seek(stream_t *s, off_t newpos)
seek_to_track = sec == p->cd->disc_toc[i].dwStartSector;
}
}
if (current_track != seeked_track && !seek_to_track) {
cd_track = cd_info_get_track(p->cd_info, seeked_track + 1);
if (cd_track != NULL) {
mp_msg(MSGT_SEEK, MSGL_INFO, "\n%s\n", cd_track->name);
mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CDDA_TRACK=%d\n",
cd_track->track_nb);
}
}
if (current_track != seeked_track && !seek_to_track)
print_track_info(s, seeked_track + 1);
p->sector = sec;
@ -441,6 +473,8 @@ static int open_cdda(stream_t *st, int m, void *opts, int *file_format)
m_struct_free(&stream_opts, opts);
print_cdtext(st, 0);
return STREAM_OK;
}