Bug#677958: mediatomb: fails to build against current version of libmp4v2

Matthias Heinz matthias.heinz at uweschneider.de
Thu Jul 25 12:41:29 UTC 2013


Hello,

since the original patch has some serious flaws, I'm sending in this 
patch, which fixes hopefully all of them.


Regards,
-- 
Matthias Heinz
Uwe Schneider GmbH
Heegwaldring 12
63694 Limeshain
Tel.: +49 / 6047 / 98 65 21
FAX.: +49 / 6047 / 98 73 96
E-Mail: matthias.heinz at UweSchneider.de

Uwe Schneider Gesellschaft für innovative
Produkte der Computertechnik mbH
Sitz der Gesellschaft: Limeshain
Registergericht: Friedberg HRB 5895
Geschäftsführer: Uwe Schneider
-------------- next part --------------
--- mediatomb-0.12.1/src/metadata/libmp4v2_handler.cc	2010-03-25 14:58:10.000000000 +0000
+++ mediatomb-0.12.1~/src/metadata/libmp4v2_handler.cc	2013-07-25 00:14:11.527935064 +0000
@@ -66,60 +66,48 @@
 {
     String value;
     char*  mp4_retval = NULL;
-    u_int16_t track;
-    u_int16_t total_tracks;
- 
     Ref<StringConverter> sc = StringConverter::i2i();
-    
+
+    const MP4Tags* tags = MP4TagsAlloc();
+    MP4TagsFetch( tags, mp4 );
+
     switch (field)
     {
         case M_TITLE:
-            MP4GetMetadataName(mp4, &mp4_retval);
+            value =  tags->name;
             break;
         case M_ARTIST:
-            MP4GetMetadataArtist(mp4, &mp4_retval);
+            value = tags->artist;
             break;
         case M_ALBUM:
-            MP4GetMetadataAlbum(mp4, &mp4_retval);
+            value = tags->album;
             break;
         case M_DATE:
-            MP4GetMetadataYear(mp4, &mp4_retval);
-            if (mp4_retval)
-            {
-                value = mp4_retval;
-                free(mp4_retval);
-                if (string_ok(value))
-                    value = value + "-01-01";
-                else
-                    return;
-            }
+            value = tags->releaseDate;
+            if (string_ok(value))
+              value = value + "-01-01";
             break;
         case M_GENRE:
-            MP4GetMetadataGenre(mp4, &mp4_retval);
+            value = tags->genre;
             break;
         case M_DESCRIPTION:
-            MP4GetMetadataComment(mp4, &mp4_retval);
+            value = tags->description;
             break;
         case M_TRACKNUMBER:
-            MP4GetMetadataTrack(mp4, &track, &total_tracks);
-            if (track > 0)
+            if (tags->track) 
             {
-                value = String::from(track);
-                item->setTrackNumber((int)track);
+                if (tags->track->index > 0)
+                {
+                    value = String::from(tags->track->index);
+                    item->setTrackNumber((int)tags->track->index);
+                }
             }
-            else
-                return;
             break;
         default:
-            return;
-    }
-
-    if ((field != M_DATE) && (field != M_TRACKNUMBER) && 
-        (mp4_retval))
-    {
-        value = mp4_retval;
-        free(mp4_retval);
+            break;
     }
+    // free memory
+    MP4TagsFree(tags);
     
     value = trim_string(value);
     
@@ -145,11 +133,10 @@
 
     try
     {
-        for (int i = 0; i < M_MAX; i++)
+        for (int i = 0; i < M_MAX; i++) 
             addMetaField((metadata_fields_t) i, mp4, item);
-
+        
         Ref<ConfigManager> cm = ConfigManager::getInstance();
-
         //  MP4GetTimeScale returns the time scale in units of ticks per 
         //  second for the mp4 file. Caveat: tracks may use the same time 
         //  scale as  the  movie or may use their own time scale.
@@ -159,7 +146,6 @@
         //
         //  Caveat: the duration is the movie (file) time scale units.
         MP4Duration duration = MP4GetDuration(mp4);
-
         duration = duration / timescale;
         if (duration > 0)
             item->getResource(0)->addAttribute(MetadataHandler::getResAttrName(R_DURATION),
@@ -190,41 +176,44 @@
         }
 
 #if defined(HAVE_MAGIC)
-        u_int8_t *art_data;
-        u_int32_t art_data_len;
-        String art_mimetype;
+        const MP4Tags* tags = MP4TagsAlloc();
+        MP4TagsFetch( tags, mp4 );
+        // if artworkCount > 0 then artwork != NULL
+        if (tags->artworkCount > 0) 
+        {
+            void *art_data = tags->artwork->data;
+            u_int32_t art_data_len = tags->artwork->size;
+            String art_mimetype;
 #ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT
-        if (MP4GetMetadataCoverArtCount(mp4) && 
-            MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len))
-#else
-            MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len);
+            if (art_data_len > 0)
 #endif
-        {
-            if (art_data)
             {
-                try
-                {
-                    art_mimetype = ContentManager::getInstance()->getMimeTypeFromBuffer((void *)art_data, art_data_len);
-                    if (!string_ok(art_mimetype))
-                        art_mimetype = _(MIMETYPE_DEFAULT);
-
-                }
-                catch (Exception ex)
+                if (art_data)
                 {
-                    free(art_data);
-                    throw ex;
-                }
-
-                free(art_data);
-                if (art_mimetype != _(MIMETYPE_DEFAULT))
-                {
-                    Ref<CdsResource> resource(new CdsResource(CH_MP4));
-                    resource->addAttribute(MetadataHandler::getResAttrName(R_PROTOCOLINFO), renderProtocolInfo(art_mimetype));
-                    resource->addParameter(_(RESOURCE_CONTENT_TYPE), _(ID3_ALBUM_ART));
-                    item->addResource(resource);
+                    try
+                    {
+                        art_mimetype = ContentManager::getInstance()->getMimeTypeFromBuffer(art_data, art_data_len);
+                        if (!string_ok(art_mimetype))
+                            art_mimetype = _(MIMETYPE_DEFAULT);
+
+                    }
+                    catch (Exception ex)
+                    {
+                        MP4TagsFree(tags);
+                        throw ex;
+                    }
+
+                    if (art_mimetype != _(MIMETYPE_DEFAULT))
+                    {
+                        Ref<CdsResource> resource(new CdsResource(CH_MP4));
+                        resource->addAttribute(MetadataHandler::getResAttrName(R_PROTOCOLINFO), renderProtocolInfo(art_mimetype));
+                        resource->addParameter(_(RESOURCE_CONTENT_TYPE), _(ID3_ALBUM_ART));
+                        item->addResource(resource);
+                    }
                 }
             }
         }
+        MP4TagsFree(tags);
 #endif
         MP4Close(mp4);
     }
@@ -249,23 +238,27 @@
 
     if (ctype != ID3_ALBUM_ART)
         throw _Exception(_("LibMP4V2Handler: got unknown content type: ") + ctype);
+        
+    const MP4Tags* tags = MP4TagsAlloc();
+    MP4TagsFetch( tags, mp4 );
 #ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT
-    if (!MP4GetMetadataCoverArtCount(mp4))
+    if (tags->artworkCount<1) {
+        MP4TagsFree(tags);
         throw _Exception(_("LibMP4V2Handler: resource has no album art information"));
+    }
 #endif
-    u_int8_t *art_data;
-    u_int32_t art_data_len;
-    if (MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len))
+    void *art_data = tags->artwork->data;
+    u_int32_t art_data_len = tags->artwork->size;
+    if (art_data_len > 0)
     {
         if (art_data)
         {
             *data_size = (off_t)art_data_len;
-            Ref<IOHandler> h(new MemIOHandler((void *)art_data, art_data_len));
-            free(art_data);
+            Ref<IOHandler> h(new MemIOHandler(art_data, art_data_len));
             return h;
         }
     }
-        
+    MP4TagsFree(tags);        
     throw _Exception(_("LibMP4V2Handler: could not serve album art "
                            "for file") + item->getLocation() + 
                            " - embedded image not found");


More information about the pkg-multimedia-maintainers mailing list