mpg123 duration fix (bug #4907):
authorOzkan Sezer
Fri, 20 Dec 2019 11:50:05 +0300
changeset 110291dc8a87aaee
parent 1101 2e69576079bd
child 1103 4e1c2282e6f1
mpg123 duration fix (bug #4907):

mpg123 backend reported -1 duration for multiple mp3s for me.
The failure was because we skipping the tags unconditionally
since changeset 503ad6c93c50. If libmpg123 sees the ID3v2 tags,
it does properly report duration for those files. Therefore,
let music_mp3123 to keep the ID3v2 tags.
src/codecs/mp3utils.c
src/codecs/mp3utils.h
src/codecs/music_mad.c
src/codecs/music_mpg123.c
     1.1 --- a/src/codecs/mp3utils.c	Fri Dec 20 11:50:05 2019 +0300
     1.2 +++ b/src/codecs/mp3utils.c	Fri Dec 20 11:50:05 2019 +0300
     1.3 @@ -279,7 +279,7 @@
     1.4      return len + 256; /* header is present. */
     1.5  }
     1.6  
     1.7 -int mp3_skiptags(struct mp3file_t *fil)
     1.8 +int mp3_skiptags(struct mp3file_t *fil, SDL_bool keep_id3v2)
     1.9  {
    1.10      unsigned char buf[128];
    1.11      long len; size_t readsize;
    1.12 @@ -292,8 +292,10 @@
    1.13      if (is_id3v2(buf, readsize)) {
    1.14          len = get_id3v2_len(buf, (long)readsize);
    1.15          if (len >= fil->length) goto fail;
    1.16 -        fil->start += len;
    1.17 -        fil->length -= len;
    1.18 +        if (! keep_id3v2)  {
    1.19 +            fil->start  += len;
    1.20 +            fil->length -= len;
    1.21 +        }
    1.22      }
    1.23      /* APE tag _might_ be at the start (discouraged
    1.24       * but not forbidden, either.)  read the header. */
     2.1 --- a/src/codecs/mp3utils.h	Fri Dec 20 11:50:05 2019 +0300
     2.2 +++ b/src/codecs/mp3utils.h	Fri Dec 20 11:50:05 2019 +0300
     2.3 @@ -27,7 +27,7 @@
     2.4      Sint64 start, length, pos;
     2.5  };
     2.6  
     2.7 -extern int  mp3_skiptags(struct mp3file_t *fil);
     2.8 +extern int  mp3_skiptags(struct mp3file_t *fil, SDL_bool keep_id3v2);
     2.9  extern size_t MP3_RWread(struct mp3file_t *fil, void *ptr, size_t size, size_t maxnum);
    2.10  extern Sint64 MP3_RWseek(struct mp3file_t *fil, Sint64 offset, int whence);
    2.11  
     3.1 --- a/src/codecs/music_mad.c	Fri Dec 20 11:50:05 2019 +0300
     3.2 +++ b/src/codecs/music_mad.c	Fri Dec 20 11:50:05 2019 +0300
     3.3 @@ -167,7 +167,7 @@
     3.4      music->volume = MIX_MAX_VOLUME;
     3.5  
     3.6      music->mp3file.length = SDL_RWsize(src);
     3.7 -    if (mp3_skiptags(&music->mp3file) < 0) {
     3.8 +    if (mp3_skiptags(&music->mp3file, SDL_FALSE) < 0) {
     3.9          SDL_free(music);
    3.10          Mix_SetError("music_mad: corrupt mp3 file (bad tags.)");
    3.11          return NULL;
     4.1 --- a/src/codecs/music_mpg123.c	Fri Dec 20 11:50:05 2019 +0300
     4.2 +++ b/src/codecs/music_mpg123.c	Fri Dec 20 11:50:05 2019 +0300
     4.3 @@ -231,7 +231,7 @@
     4.4      music->volume = MIX_MAX_VOLUME;
     4.5  
     4.6      music->mp3file.length = SDL_RWsize(src);
     4.7 -    if (mp3_skiptags(&music->mp3file) < 0) {
     4.8 +    if (mp3_skiptags(&music->mp3file, SDL_TRUE) < 0) {
     4.9          SDL_free(music);
    4.10          Mix_SetError("music_mpg123: corrupt mp3 file (bad tags.)");
    4.11          return NULL;