ref: d8275bd4dd0bcc2adc4e352ae43e0b6201c0b115
parent: d4a2911f07a2007df5f6448a52134579640b90cf
author: Jean-Marc Valin <[email protected]>
date: Wed May 3 18:05:52 EDT 2017
Implements changing the vendor string
--- a/src/opus_header.c
+++ b/src/opus_header.c
@@ -240,6 +240,25 @@
*length=newlen;
}
}
+
+int comment_replace_vendor_string(char **comments, int* length, const char *vendor_string)
+{
+ char* p=*comments;
+ int vendor_length;
+ int newlen;
+ int newvendor_length;
+ vendor_length=readint(p, 8);
+ newvendor_length=strlen(vendor_string);
+ newlen=*length+newvendor_length-vendor_length;
+ p=realloc(p, newlen);
+ if (p == NULL) return 1;
+ writeint(p, 8, newvendor_length);
+ memmove(p+12+newvendor_length, p+12+vendor_length, newlen-12-newvendor_length);
+ memcpy(p+12, vendor_string, newvendor_length);
+ *comments=p;
+ *length=newlen;
+ return 0;
+}
#undef readint
#undef writeint
--- a/src/opus_header.h
+++ b/src/opus_header.h
@@ -54,4 +54,6 @@
void comment_pad(char **comments, int* length, int amount);
+int comment_replace_vendor_string(char **comments, int* length, const char *vendor_string);
+
#endif
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -590,6 +590,7 @@
int ope_set_vendor_string(OggOpusEnc *enc, const char *vendor) {
if (enc->last_stream->header_is_frozen) return OPE_TOO_LATE;
if (enc->last_stream->stream_is_init) return OPE_TOO_LATE;
+ if (comment_replace_vendor_string(&enc->last_stream->comment, &enc->last_stream->comment_length, vendor)) return OPE_INTERNAL_ERROR;
(void)vendor;
return OPE_UNIMPLEMENTED;
}