+
+#ifdef HAVE_LIBCDDB
+static void GetCDDBInfo( access_t *p_access, int i_titles, int *p_sectors )
+{
+ int i, i_matches;
+ int64_t i_length = 0, i_size = 0;
+ cddb_conn_t *p_cddb = cddb_new();
+
+// cddb_log_set_handler( CDDBLogHandler );
+
+ if( !p_cddb )
+ {
+ msg_Warn( p_access, "unable to use CDDB" );
+ goto cddb_destroy;
+ }
+
+ cddb_set_email_address( p_cddb, "vlc@videolan.org" );
+ cddb_set_server_name( p_cddb, config_GetPsz( p_access, "cddb-server" ) );
+ cddb_set_server_port( p_cddb, config_GetInt( p_access, "cddb-port" ) );
+
+ /// \todo
+ cddb_cache_disable( p_cddb );
+
+// cddb_cache_set_dir( p_cddb,
+// config_GetPsz( p_access,
+// MODULE_STRING "-cddb-cachedir") );
+
+ cddb_set_timeout( p_cddb, 10 );
+
+ /// \todo
+ cddb_http_disable( p_cddb);
+
+ p_access->p_sys->p_disc = cddb_disc_new();
+
+ if(! p_access->p_sys->p_disc )
+ {
+ msg_Err( p_access, "Unable to create CDDB disc structure." );
+ goto cddb_end;
+ }
+
+ for(i = 0; i < i_titles ; i++ )
+ {
+ cddb_track_t *t = cddb_track_new();
+ cddb_track_set_frame_offset(t, p_sectors[i] );
+ cddb_disc_add_track( p_access->p_sys->p_disc, t );
+ i_size = ( p_sectors[i+1] - p_sectors[i] ) *
+ (int64_t)CDDA_DATA_SIZE;
+ i_length += I64C(1000000) * i_size / 44100 / 4 ;
+ }
+
+ cddb_disc_set_length( p_access->p_sys->p_disc, (int)(i_length/1000000) );
+
+ if (!cddb_disc_calc_discid(p_access->p_sys->p_disc ))
+ {
+ msg_Err( p_access, "CDDB disc ID calculation failed" );
+ goto cddb_destroy;
+ }
+
+ i_matches = cddb_query( p_cddb, p_access->p_sys->p_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( p_cddb, p_access->p_sys->p_disc );
+
+// cddb_disc_print( p_access->p_sys->p_disc );
+ }
+ else
+ {
+ msg_Warn( p_access, "CDDB error: %s", cddb_error_str(errno));
+ }
+
+cddb_destroy:
+ cddb_destroy( p_cddb);
+
+cddb_end: ;
+}
+#endif /*HAVE_LIBCDDB*/