shithub: libopusenc

Download patch

ref: 79c0e61a606f5ae594c29c5a3e20ff69d88ace90
parent: 469caffa2d29496deaa481f182d42f1fd0826ca9
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Tue May 16 14:36:27 EDT 2017

Add support for header gain

--- a/include/opusenc.h
+++ b/include/opusenc.h
@@ -111,6 +111,8 @@
 #define OPE_GET_SERIALNO_REQUEST            14007
 #define OPE_SET_PACKET_CALLBACK_REQUEST     14008
 #define OPE_GET_PACKET_CALLBACK_REQUEST     14009
+#define OPE_SET_HEADER_GAIN_REQUEST         14010
+#define OPE_GET_HEADER_GAIN_REQUEST         14011
 
 /**\defgroup encoder_ctl Encoding Options*/
 /*@{*/
@@ -131,6 +133,8 @@
 /* FIXME: Add type-checking macros to these. */
 #define OPE_SET_PACKET_CALLBACK(x,u) OPE_SET_PACKET_CALLBACK_REQUEST, (x), (u)
 #define OPE_GET_PACKET_CALLBACK(x,u) OPE_GET_PACKET_CALLBACK_REQUEST, (x), (u)
+#define OPE_SET_HEADER_GAIN(x,u) OPE_SET_HEADER_GAIN_REQUEST, (x), (u)
+#define OPE_GET_HEADER_GAIN(x,u) OPE_GET_HEADER_GAIN_REQUEST, (x), (u)
 /*@}*/
 /*@}*/
 
--- a/src/opus_header.h
+++ b/src/opus_header.h
@@ -36,7 +36,7 @@
    int channels; /* Number of channels: 1..255 */
    int preskip;
    opus_uint32 input_sample_rate;
-   int gain; /* in dB S7.8 should be zero whenever possible */
+   opus_int32 gain; /* in dB S7.8 should be zero whenever possible */
    int channel_mapping;
    /* The rest is only used if channel_mapping != 0 */
    int nb_streams;
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -762,7 +762,10 @@
     case OPE_SET_SERIALNO_REQUEST:
     {
       opus_int32 value = va_arg(ap, opus_int32);
-      if (enc->last_stream->header_is_frozen) return OPE_TOO_LATE;
+      if (!enc->last_stream || enc->last_stream->header_is_frozen) {
+        ret = OPE_TOO_LATE;
+        break;
+      }
       enc->last_stream->serialno = value;
       enc->last_stream->serialno_is_set = 1;
       ret = OPE_OK;
@@ -777,8 +780,19 @@
       ret = OPE_OK;
     }
     break;
+    case OPE_SET_HEADER_GAIN_REQUEST:
+    {
+      opus_int32 value = va_arg(ap, opus_int32);
+      if (!enc->last_stream || enc->last_stream->header_is_frozen) {
+        ret = OPE_TOO_LATE;
+        break;
+      }
+      enc->header.gain = value;
+      ret = OPE_OK;
+    }
+    break;
     default:
-      return OPE_UNIMPLEMENTED;
+      ret = OPE_UNIMPLEMENTED;
   }
   va_end(ap);
   translate = ret != 0 && (request < 14000 || (ret < 0 && ret >= -10));