⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 info.c

📁 vlc源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * info.c : CD digital audio input information routines ***************************************************************************** * Copyright (C) 2004, 2005 the VideoLAN team * $Id$ * * Authors: Rocky Bernstein <rocky@panix.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include "callback.h"      /* FIXME - reorganize callback.h, cdda.h better */#include "cdda.h"          /* private structures. Also #includes vlc things */#warning playlist code must not be used here.#include <vlc_playlist.h>  /* Has to come *after* cdda.h */#include <cdio/cdio.h>#include <cdio/cdtext.h>#include <cdio/logging.h>#include <cdio/cd_types.h>#include "info.h"#ifdef HAVE_ERRNO_H#   include <errno.h>#endifstatic char *CDDAFormatStr( const access_t *p_access, cdda_data_t *p_cdda,                const char format_str[], const char *psz_mrl,                track_t i_track);static char *CDDAFormatMRL( const access_t *p_access, track_t i_track );#ifdef HAVE_LIBCDDB#define free_and_dup(var, val) \  if (var) free(var);          \  if (val) var=strdup(val);/* Saves CDDB information about CD-DA via libcddb. */static voidGetCDDBInfo( access_t *p_access, cdda_data_t *p_cdda ){    int i, i_matches;    cddb_conn_t  *conn = cddb_new();    const CdIo_t *p_cdio = p_cdda->p_cdio;    dbg_print( (INPUT_DBG_CALL), "" );#ifdef FIXME_NOW    cddb_log_set_handler (uninit_log_handler);#endif    if (!conn)    {        msg_Warn( p_access, "Unable to initialize libcddb" );        goto cddb_destroy;    }    char* psz_email = config_GetPsz( p_access, MODULE_STRING "-cddb-email");    char* psz_srv_name = config_GetPsz( p_access, MODULE_STRING "-cddb-server");    cddb_set_email_address( conn, psz_email );    cddb_set_server_name( conn, psz_srv_name );    cddb_set_server_port(conn,                         config_GetInt( p_access,                                        MODULE_STRING "-cddb-port") );    free( psz_email );    free( psz_srv_name );  /* Set the location of the local CDDB cache directory.     The default location of this directory is */    if (!config_GetInt( p_access, MODULE_STRING "-cddb-enable-cache" ))        cddb_cache_disable(conn);    char* psz_cache = config_GetPsz( p_access, MODULE_STRING "-cddb-cachedir");    cddb_cache_set_dir(conn, psz_cache );    free( psz_cache );    cddb_set_timeout(conn,                   config_GetInt( p_access, MODULE_STRING "-cddb-timeout") );    if (config_GetInt( p_access, MODULE_STRING "-cddb-httpd" ) )    {        cddb_http_enable(conn);    }    else    {        cddb_http_disable(conn);    }    p_cdda->cddb.disc = cddb_disc_new();    if (!p_cdda->cddb.disc)    {        msg_Err( p_access, "Unable to create CDDB disc structure." );        goto cddb_end;    }    for(i = 0; i < p_cdda->i_tracks; i++)    {        track_t i_track =  p_cdda->i_first_track + i;        cddb_track_t *t = cddb_track_new();    cddb_track_set_frame_offset(t,                    cdio_get_track_lba(p_cdio, i_track));        cddb_disc_add_track(p_cdda->cddb.disc, t);    }    cddb_disc_set_length(p_cdda->cddb.disc,             cdio_get_track_lba(p_cdio, CDIO_CDROM_LEADOUT_TRACK)             / CDIO_CD_FRAMES_PER_SEC);    if (!cddb_disc_calc_discid(p_cdda->cddb.disc))    {        msg_Err( p_access, "CDDB disc ID calculation failed" );        goto cddb_destroy;    }    i_matches = cddb_query(conn, p_cdda->cddb.disc);    if (i_matches > 0)    {        if (i_matches > 1)             msg_Warn( p_access, "Found %d matches in CDDB. Using first one.",                                 i_matches);        cddb_read(conn, p_cdda->cddb.disc);        if (p_cdda->i_debug & INPUT_DBG_CDDB)            cddb_disc_print(p_cdda->cddb.disc);    }    else    {        msg_Warn( p_access, "CDDB error: %s", cddb_error_str(errno));    }cddb_destroy:    cddb_destroy(conn);cddb_end: ;}#endif /*HAVE_LIBCDDB*/#define add_meta_val(VLC_META, VAL)                           \  if ( p_cdda->p_meta && VAL) {                               \    /*vlc_meta_Add( p_cdda->p_meta, VLC_META, VAL );*/        \    dbg_print( INPUT_DBG_META, "field %s: %s\n",              \            input_MetaTypeToLocalizedString(VLC_META), VAL ); \  }                                                           \#define add_cddb_meta(FIELD, VLC_META)                            \  add_meta_val(VLC_META, cddb_disc_get_##FIELD(p_cdda->cddb.disc));#define add_cddb_meta_fmt(FIELD, FORMAT_SPEC, VLC_META)                 \  {                                                                     \    char psz_buf[100];                                                  \    snprintf( psz_buf, sizeof(psz_buf)-1, FORMAT_SPEC,                  \              cddb_disc_get_##FIELD(p_cdda->cddb.disc));                               \    psz_buf[sizeof(psz_buf)-1] = '\0';                                  \    add_meta_val(VLC_META, psz_buf);                    \  }/* Adds a string-valued entry to the stream and media information if   the string is not null or the null string. */#define add_info_str(CATEGORY, TITLE, FIELD)                      \  if (FIELD && strlen(FIELD)) {                                   \    input_Control( p_cdda->p_input, INPUT_ADD_INFO, CATEGORY,     \                   _(TITLE), "%s", FIELD );                       \  }/* Adds a numeric-valued entry to the stream and media information   if the number is not zero. */#define add_info_val(CATEGORY, TITLE, FMT, FIELD)                 \  if (FIELD) {                                                    \    input_Control( p_cdda->p_input, INPUT_ADD_INFO, CATEGORY,     \                   _(TITLE), FMT, FIELD );                        \  }/* Adds a CDDB string-valued entry to the stream and media information   under category "Disc" if the string is not null or the null string. */#define add_cddb_disc_info_str(TITLE, FIELD)                    \  add_info_str("Disc", TITLE, cddb_disc_get_##FIELD(p_cdda->cddb.disc))/* Adds a CDDB numeric-valued entry to the stream and media information   under category "Disc" if the string is not null or the null string. */#define add_cddb_disc_info_val(TITLE, FMT, FIELD)               \  add_info_val("Disc", TITLE, FMT, cddb_disc_get_##FIELD(p_cdda->cddb.disc))/* Adds a CD-Text string-valued entry to the stream and media information   under category "Disc" if the string is not null or the null string. */#define add_cdtext_info_str(CATEGORY, TITLE, INDEX, FIELD)              \    add_info_str(CATEGORY, TITLE, p_cdda->p_cdtext[INDEX]->field[FIELD])/* Adds a CD-Text string-valued entry to the stream and media information   under category "Disc" if the string is not null or the null string. */#define add_cdtext_disc_info_str(TITLE, FIELD) \  add_cdtext_info_str("Disc", TITLE, 0, FIELD)/*  Saves Meta Information about the CD-DA.  Meta information used in "stream and media info" or in playlist  info. The intialization of CD-Text or CDDB is done here though.  Therefore, this should be called before CDDAMetaInfo is called. */voidCDDAMetaInfoInit( access_t *p_access ){    cdda_data_t *p_cdda   = (cdda_data_t *) p_access->p_sys;    if ( ! p_cdda ) return;    dbg_print( (INPUT_DBG_CALL), "p_cdda->i_tracks %d",           p_cdda->i_tracks );    p_cdda->psz_mcn = cdio_get_mcn(p_cdda->p_cdio);#if 0    p_cdda->p_meta = vlc_meta_New();#endif#ifdef HAVE_LIBCDDB    if ( p_cdda->b_cddb_enabled )    {        GetCDDBInfo(p_access, p_cdda);    }#endif /*HAVE_LIBCDDB*/ #define TITLE_MAX 30    {        track_t i_track;        for( i_track = 0 ; i_track < p_cdda->i_tracks ; i_track++ )        {            p_cdda->p_cdtext[i_track] =            cdio_get_cdtext(p_cdda->p_cdio, i_track);        }    }}/* In the Control routine, we handle Meta Information requests and basically copy what was saved in CDDAMetaInfoInit. If i_track is CDIO_INVALID_TRACK we are probably asking about the entire CD. */voidCDDAMetaInfo( access_t *p_access, track_t i_track ){    cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;    char *psz_meta_title = CDDAFormatMRL( p_access, i_track );    char *psz_meta_artist = NULL;    if ( ! p_cdda ) return;    dbg_print( (INPUT_DBG_CALL), "i_track %d", i_track );#ifdef HAVE_LIBCDDB    /* Set up for Meta and name for CDDB access. */    if ( p_cdda->b_cddb_enabled &&  p_cdda->cddb.disc )    {        if( CDIO_INVALID_TRACK == i_track )        {            psz_meta_title  = (char *)cddb_disc_get_title(p_cdda->cddb.disc);            psz_meta_artist = (char *)cddb_disc_get_artist(p_cdda->cddb.disc);            if ( cddb_disc_get_genre(p_cdda->cddb.disc) &&                strlen(cddb_disc_get_genre(p_cdda->cddb.disc)) )                add_cddb_meta(genre, vlc_meta_Genre);            if ( 0 != cddb_disc_get_year(p_cdda->cddb.disc))                add_cddb_meta_fmt(year, "%d", vlc_meta_Date );        }        else        {            cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc, i_track-1);            if (t != NULL )            {                if( cddb_track_get_title(t) != NULL && ! p_cdda->b_nav_mode )                {                    add_meta_val( vlc_meta_Title, cddb_track_get_title(t) );                }                if( cddb_track_get_artist(t) != NULL )                {                    add_meta_val( vlc_meta_Artist, cddb_track_get_artist(t) );                }            }        }    }#endif /*HAVE_LIBCDDB*/#define TITLE_MAX 30    {        track_t i = p_cdda->i_tracks;        const int i_first_track = p_cdda->i_first_track;        char psz_buffer[MSTRTIME_MAX_SIZE];        unsigned int i_track_frames =        cdio_get_track_lba(p_cdda->p_cdio, CDIO_CDROM_LEADOUT_TRACK);        mtime_t i_duration = i_track_frames / CDIO_CD_FRAMES_PER_SEC;        dbg_print( INPUT_DBG_META, "Duration %ld, tracks %d",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -