Permalink
Browse files

- fixed crash when ID3 Metadata are corrupted or inclomplete

  • Loading branch information...
1 parent 4973899 commit 9906dd4669e22764f7976d24efe28ef2abcca06d @jan-lugfl committed Jan 26, 2012
Showing with 27 additions and 7 deletions.
  1. +18 −7 src/mpgdecoder.cpp
  2. +9 −0 src/mpgdecoder.h
View
@@ -20,10 +20,6 @@
***************************************************************************/
#include "mpgdecoder.h"
-#ifdef HAVE_ID3TAG
-#include <id3tag.h>
-#endif
-
mpgDecoder::mpgDecoder(FILE* File, QObject *parent )
: fileDecoder(File, parent )
{
@@ -338,10 +334,25 @@ void mpgDecoder::readMetaFromFile( playListItem * pli )
id3_file* id3f = id3_file_open( pli->getFile().toAscii(), ID3_FILE_MODE_READONLY );
id3_tag* id3 = id3_file_tag( id3f );
- pli->setArtist( (char*)id3_ucs4_utf8duplicate(id3_field_getstrings( id3_frame_field( id3_tag_findframe( id3, ID3_FRAME_ARTIST, 0 ), 1 ), 0 ) ) );
- pli->setTitle( (char*)id3_ucs4_utf8duplicate(id3_field_getstrings( id3_frame_field( id3_tag_findframe( id3, ID3_FRAME_TITLE, 0 ), 1 ), 0 ) ) );
- pli->setGenre( (char*)id3_ucs4_utf8duplicate(id3_field_getstrings( id3_frame_field( id3_tag_findframe( id3, ID3_FRAME_GENRE, 0 ), 1 ), 0 ) ) );
+ pli->setArtist( getID3String(id3, ID3_FRAME_ARTIST) );
+ pli->setTitle( getID3String(id3, ID3_FRAME_TITLE) );
+ pli->setGenre( getID3String(id3, ID3_FRAME_GENRE) );
id3_file_close( id3f );
#endif
}
+
+#ifdef HAVE_ID3TAG
+QString mpgDecoder::getID3String( id3_tag* idtag, const char* field_frame )
+{
+ QString str;
+ id3_frame* frame = id3_tag_findframe( idtag, ID3_FRAME_ARTIST, 0 );
+ if(frame)
+ {
+ id3_field* field = id3_frame_field(frame, 1);
+ if(field)
+ str = (char*)id3_ucs4_utf8duplicate(id3_field_getstrings(field, 0));
+ }
+ return str;
+}
+#endif
View
@@ -29,6 +29,10 @@
// Includes libMAD for MPEG decoding
#include <mad.h>
+#ifdef HAVE_ID3TAG
+#include <id3tag.h>
+#endif
+
/**
MPEG Decoder Class for decodeung MPEG 1 and 2 Layer I,II and II with libmad..
@@ -56,6 +60,11 @@ Q_OBJECT
static void readMetaFromFile( playListItem * pli );
+private:
+#ifdef HAVE_ID3TAG
+ static QString getID3String( id3_tag* idtag, const char* field_frame );
+#endif
+
protected:
QFile* madFile;
mad_stream* madStream;

0 comments on commit 9906dd4

Please sign in to comment.