shithub: opus-tools

Download patch

ref: e8baf59939f8d33d0bcd1232753a651d3dde052e
parent: c2ee5af26a6487ab3b3dfa95a4df28df82982236
author: Jean-Marc Valin <[email protected]>
date: Thu Aug 4 14:15:33 EDT 2011

Adding OpusTags at the front of comments packets

Comments can now be placed anywhere in a file

--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -95,6 +95,12 @@
    int len, i, nb_fields;
    char *end;
    
+   if (strncmp(c, "OpusTags", 8) != 0)
+   {
+      fprintf (stderr, "Invalid/corrupted comments\n");
+      return;
+   }
+   c += 8;
    fprintf(stderr, "Encoded with ");
    if (length<8)
    {
@@ -556,7 +562,7 @@
                }
                fout = out_file_open(outFile, rate, &channels);
 
-            } else if (packet_count==1)
+            } else if (strncmp((char*)op.packet, "OpusTags", 8)==0)
             {
                if (!quiet)
                   print_comments((char*)op.packet, op.bytes);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -771,15 +771,16 @@
 {
   int vendor_length=strlen(vendor_string);
   int user_comment_list_length=0;
-  int len=4+vendor_length+4;
+  int len=8+4+vendor_length+4;
   char *p=(char*)malloc(len);
   if(p==NULL){
      fprintf (stderr, "malloc failed in comment_init()\n");
      exit(1);
   }
-  writeint(p, 0, vendor_length);
-  memcpy(p+4, vendor_string, vendor_length);
-  writeint(p, 4+vendor_length, user_comment_list_length);
+  memcpy(p, "OpusTags", 8);
+  writeint(p, 8, vendor_length);
+  memcpy(p+12, vendor_string, vendor_length);
+  writeint(p, 12+vendor_length, user_comment_list_length);
   *length=len;
   *comments=p;
 }