shithub: libopusenc

Download patch

ref: a8cc9885ea0165d3cc925542aafb89cb613a46f2
parent: 5f0cfe9679c3dc104603d4ce24d99576d7db38a8
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Mon May 1 15:49:56 EDT 2017

Making it possible to set the serialno

--- a/include/opusenc.h
+++ b/include/opusenc.h
@@ -61,6 +61,8 @@
 #define OPE_GET_MUXING_DELAY_REQUEST 14003
 #define OPE_SET_COMMENT_PADDING_REQUEST 14004
 #define OPE_GET_COMMENT_PADDING_REQUEST 14005
+#define OPE_SET_SERIALNO_REQUEST 14006
+#define OPE_GET_SERIALNO_REQUEST 14007
 
 #define OPE_SET_DECISION_DELAY(x) OPE_SET_DECISION_DELAY_REQUEST, __opus_check_int(x)
 #define OPE_GET_DECISION_DELAY(x) OPE_GET_DECISION_DELAY_REQUEST, __opus_check_int_ptr(x)
@@ -68,6 +70,8 @@
 #define OPE_GET_MUXING_DELAY(x) OPE_GET_MUXING_DELAY_REQUEST, __opus_check_int_ptr(x)
 #define OPE_SET_COMMENT_PADDING(x) OPE_SET_COMMENT_PADDING_REQUEST, __opus_check_int(x)
 #define OPE_GET_COMMENT_PADDING(x) OPE_GET_COMMENT_PADDING_REQUEST, __opus_check_int_ptr(x)
+#define OPE_SET_SERIALNO(x) OPE_SET_SERIALNO_REQUEST, __opus_check_int(x)
+#define OPE_GET_SERIALNO(x) OPE_GET_SERIALNO_REQUEST, __opus_check_int_ptr(x)
 
 
 typedef int (*ope_write_func)(void *user_data, const unsigned char *ptr, int len);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -93,6 +93,8 @@
   OpusHeader header;
   int comment_padding;
   char *comment;
+  int serialno_is_set;
+  int serialno;
   int comment_length;
   int seen_file_icons;
   ogg_stream_state os;
@@ -178,6 +180,7 @@
   enc->decision_delay = 96000;
   enc->max_ogg_delay = 48000;
   enc->comment_padding = 512;
+  enc->serialno_is_set = 0;
   enc->seen_file_icons = 0;
   enc->header.channels=channels;
   enc->header.channel_mapping=family;
@@ -236,13 +239,15 @@
 
 static void init_stream(OggOpusEnc *enc) {
   time_t start_time;
-  int serialno;
   assert(!enc->stream_is_init);
-  start_time = time(NULL);
-  srand(((getpid()&65535)<<15)^start_time);
+  if (!enc->serialno_is_set) {
+    start_time = time(NULL);
+    srand(((getpid()&65535)<<15)^start_time);
 
-  serialno = rand();
-  if (ogg_stream_init(&enc->os, serialno) == -1) {
+    enc->serialno = rand();
+  }
+  
+  if (ogg_stream_init(&enc->os, enc->serialno) == -1) {
     assert(0);
     /* FIXME: How the hell do we handle that? */
   }
@@ -492,7 +497,9 @@
     case OPUS_SET_SIGNAL_REQUEST:
     case OPUS_SET_LSB_DEPTH_REQUEST:
     case OPUS_SET_PREDICTION_DISABLED_REQUEST:
+#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST
     case OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST:
+#endif
     {
       opus_int32 value = va_arg(ap, opus_int32);
       ret = opus_multistream_encoder_ctl(enc->st, request, value);
@@ -561,6 +568,14 @@
         break;
       }
       enc->comment_padding = value;
+      ret = OPE_OK;
+    }
+    break;
+    case OPE_SET_SERIALNO_REQUEST:
+    {
+      opus_int32 value = va_arg(ap, opus_int32);
+      enc->serialno = value;
+      enc->serialno_is_set = 1;
       ret = OPE_OK;
     }
     break;