VLC does not retrieve the cddb information for some CDs. I did a little digging with gdb and discovered that vlc calculates an incorrect cddb disc ID - the parts generated from the disc length and number of tracks is correct, but the part generated from track offsets is wrong. But other tools do calculate the disc id and retrieve track information from freedb.
The problem seems to be vlc treating the first track as if it starts from an offset of zero and not 150 frames (the initial pregap).
Breaking inside cdda.c:GetCDDBInfo()
gdb) print i_titles
$1 = 13
(gdb) print p_sectors[0]
$2 = 0
(gdb) print p_sectors[1]
$3 = 17435
(gdb) print p_sectors[2]
$4 = 31076
...
(gdb) print p_sectors[12]
$14 = 193574
...
(gdb) s
cddb_disc_calc_discid (disc=0x7fffd8022060) at cddb_disc.c:501
cddb_query uses libcdio to read the TOC and uses cdte_format = CDROM_MSF, whereas vlc does it in modules/access/vcd/cdrom.c and uses cdte_format = CDROM_LBA. Could that be the difference?
I'm not entirely clear, but I've read some definitions of LBA that ignore the pregap. libcdio seems to use LSN as a frame offset that is pregap-aware. But sometimes the difference seems a bit muddled.
Sorry for my later mistake, now I am editing this comment only to correctly state that Function "GetCDDBInfo()" is not really part of libcddb, but is part of VLC source code, like Get_Tracks() the routine that calls it, both of which are definied into VLC "modules/access/cdda.c" source file.
Of course, GetCDDBInfo() does make use of data structures declared into "cddb/cddb.h" and makes calls to CDDB related functions which are all dynamically linked to libcddb (
http://libcddb.sourceforge.net/tutorial.html ).
For example, one of this libcddb functions,namely "cddb_disc_calc_discid()", is precisely responsable for calculating the discid that is used, along with the frame offsets of every CD track, for querying the CDDB...
The apparently inexact match returned by the CDDB server, is caused ( as oliverhenshaw found out and fisrt explained in this bug tracking report ) by a missing pregap in all track frame offsets that VLC is passing to libcddb functions responsable for the query, like libcddb:cddb_query :
cdda.c:GetTracks -> cdda.c:GetCDDBInfo( access_t *p_access, int i_titles, int *p_sectors ) -> libcddb:cddb_query( p_cddb, p_disc )
The reason why ( as oliverhenshaw further explained earlier ) the starting frame numbers in all tracks of the "*p_sectors" data structure are missing these 150 frames ( equivalent to the 2 seconds pregap ) is because of always using macro "MSF_TO_LBA2" ( which explicitly subtracts this gap ) instead of macro "MSF_TO_LBA" ( which does not alter the values provided by Native OS API functions, like "DeviceIoControl_()" in the case of MS Windows OSes family ).
Doing a bit more of research, it shows that prior to calling GetCDDBInfo(), the CD Table of Contents, named "cdrom_toc" ( structure of typedef CDROM_TOC ) is initiallized in this call sequence :
cdda.c:GetTracks -> cdrom.c:ioctl_GetTracksMap -> Native API funtion call
-- OS Dependant function that retrieves CD TOC depending on ARCHITECTURE ( for APPLE: CDTOCGetDescriptorCount(), WIN32: DeviceIOControl() , OS2: DosDevIOCtl() , etc. )
So, after this OS-dependant API call, made under modules/access/vcd/cdrom.c:ioctl_GetTracksMap() implementation , an array of elements representing all tracks in the CD is dynamically created and pointed by "pp_sectors":
This macro, MSF_TO_LBA2 , receives CD track data in the format Minutes, Seconds and Frames, and then calculates the total frame offset by using a formula similar to macro MSF_TO_LBA, but also explicitly subtracting the 2 seconds pregap!!!...
I really dont understand yet why , but just suppose that the choice of macro "MSF_TO_LBA2" instead of "MSF_TO_LBA" ( which does not subtract the pregap ) was made because of being more convenient for VCD, o maybe for controlling CD playback or seek functions... After all, this macro call is made from "modules/access/vcd/cdrom.c" ... I think we need to carefully understand this prior to propose any changes to VLC source code, that maybe could fix CDDB support but at the same time, create a new bug with VCD playback!
As you see, I will take away the "-2" term in MSF_TO_LBA2 macro definition, and then proceed to compile ( in fact, crosscompile Win32 version of VLC under linux ).
Then I will report back if CDDB support is finally working properly or not...
But, of course, as I said earlier, I dont think this would be a proper way to fix CDDB without potencially introducing some new bug related with VCD or even CDDA playback ...
I would like to share the way I have found to ( hopefully ) fix this bug preventing VLC from correctly retrieving Audio CD info from any HTTP CDDB Server, that is caused by this missing pregap when building the CDDB database query ( cgi cmd line via http protocol )...
The best fix I could figure out consist on modifying two existing code lines inside "modules/access/cdda.c", part of VLC source code:
Current line 648 of "cdda.c" source:
/* in order to properly calculate the discid value and also to get the cgi CDDB query correctly built, for every track starting sector, we need to add 150 frames, that comes from the 2 seconds pregap at the begining of every audio CD, and were previuosly substracted while convertings track starting times ( Minutes:Seconds:Frames ) to Logical Block Addresses ( LBA ), using macro MSF_TO_LBA2, defined in <vcd/cdrom.h> and <vcd/cdrom_internals.h> */ cddb_track_set_frame_offset( t, p_sectors[i] + 150 ); /* adding 150,for the pregap, to every track frame offset */
And finally at current line 665 of "cdda.c" source:
cddb_disc_set_length( p_disc, (int)(i_length/1000000 + 2 ) ); /* here we add the 2 seconds pregap to the total Audio CD length, in order to get the discid calculated right */
With only these two code lines modified, every track start frame and total CD length passed to the following calls to libcddb functions via structure "p_cddb" are now correct, so the discid calculation and then the query http cmd line will truely reflect the Audio CD track structure, matching that existing on the internet server database ( like freedb.org or musicbrainz.org ).
This is all that is needed to fix this bug, at least if building VLC for linux platforms...
If you want to be able to successfully use the VLC CDDB feature on Windows, then you will also need to fix this other somehow related ( but not dependant ) bug : #13465 (closed) ( https://trac.videolan.org/vlc/ticket/13465 )
Hi, Congrats! Just checked the 03-Ene-2015 nightly build and now the bug seems solved!
Only one suggestion about the msg_Debug() added in commit ab0080f6: to display the discid in the right format (an 8 digit hexa number, as used in search engines like http://www.freedb.org/freedb_discid_check.php ) it should be:
CDDB: display CDDB ID in the right formatAka a 8 digit hexa number, as used in search engines likehttp://www.freedb.org/freedb_discid_check.phpRef [#4370](https://code.videolan.org/videolan/vlc/-/issues/4370)