shithub: aacenc

Download patch

ref: ee71b5ca01f038ebad2a35acb5ecf27705b60e7f
parent: 63c7c06747fbfa3dae13610e5a449f2f17bea7f1
author: knik <knik@users.sourceforge.net>
date: Fri Jul 21 11:38:29 EDT 2017

enabled --cover-art option

--- a/frontend/main.c
+++ b/frontend/main.c
@@ -428,7 +428,7 @@
     uint8_t compilation = 0;
     const char *artist = NULL, *title = NULL, *album = NULL, *year = NULL,
         *genre = NULL, *comment = NULL, *composer = NULL;
-    uint8_t *art = NULL;
+    uint8_t *artData = NULL;
     uint64_t artSize = 0;
     uint64_t encoded_samples = 0;
     unsigned int delay_samples;
@@ -627,26 +627,26 @@
                     fseek(artFile, 0, SEEK_END);
                     artSize = ftell(artFile);
 
-                    art = malloc(artSize);
+                    artData = malloc(artSize);
 
                     fseek(artFile, 0, SEEK_SET);
                     clearerr(artFile);
 
-                    r = fread(art, artSize, 1, artFile);
+                    r = fread(artData, artSize, 1, artFile);
 
                     if (r != 1)
                     {
                         dieMessage = "Error reading cover art file!\n";
-                        free(art);
-                        art = NULL;
+                        free(artData);
+                        artData = NULL;
                     }
                     else if (artSize < 12
-                             || !check_image_header((const char *) art))
+                             || !check_image_header((const char *) artData))
                     {
                         /* the above expression checks the image signature */
                         dieMessage = "Unsupported cover image file format!\n";
-                        free(art);
-                        art = NULL;
+                        free(artData);
+                        artData = NULL;
                     }
 
                     fclose(artFile);
@@ -811,7 +811,7 @@
     }
 
     if (container != MP4_CONTAINER && (trackno || artist ||
-                                       title || album || year || art ||
+                                       title || album || year || artData ||
                                        genre || comment || discno ||
                                        composer || compilation))
     {
@@ -1135,7 +1135,11 @@
         SETTAG(year);
         SETTAG(genre);
         SETTAG(comment);
-        // fixme: add cover-art option
+        if (artData && artSize)
+        {
+            mp4config.tag.cover.data = artData;
+            mp4config.tag.cover.size = artSize;
+        }
 
         mp4atom_tail();
         mp4atom_close();
@@ -1160,6 +1164,8 @@
 
     wav_close(infile);
 
+    if (artData)
+        free(artData);
     if (pcmbuf)
         free(pcmbuf);
     if (bitbuf)
--- a/frontend/mp4write.c
+++ b/frontend/mp4write.c
@@ -543,6 +543,22 @@
     return size;
 }
 
+static int tagimage(char *tagname, int n /*image size*/)
+{
+    int numsize = n;
+    int size = 0;
+    int datasize = numsize + 16;
+
+    size += u32out(datasize + 8);
+    size += dataout(tagname, 4);
+    size += u32out(datasize);
+    size += dataout("data", 4);
+    size += u32out(0x0d); // data type: image
+    size += u32out(0);
+
+    return size;
+}
+
 static int metaout(void)
 {
     int size = 0;
@@ -607,10 +623,11 @@
     }
     if (mp4config.tag.year)
         size += tagtxt("\xa9" "day", mp4config.tag.year);
-#if 0
-    if (mp4config.tag.cover)
-        size += tagtxt("\xa9" "covr", mp4config.tag.cover);
-#endif
+    if (mp4config.tag.cover.data)
+    {
+        size += tagimage("covr", mp4config.tag.cover.size);
+        size += dataout(mp4config.tag.cover.data, mp4config.tag.cover.size);
+    }
     if (mp4config.tag.comment)
         size += tagtxt("\xa9" "cmt", mp4config.tag.comment);
 
--- a/frontend/mp4write.h
+++ b/frontend/mp4write.h
@@ -60,7 +60,10 @@
         uint32_t trackno;
         uint32_t discno;
         const char *year;
-        const char *cover;      // cover filename
+        struct {
+            uint8_t *data;
+            int size;
+        } cover;
         const char *comment;
     } tag;
 } mp4config_t;