shithub: opus

Download patch

ref: f3b44ef42c4a46b294c639b4caa65d3f38c5f772
parent: 9a44cde20587d5ba9195a7542725090bae1ba162
author: Gregory Maxwell <[email protected]>
date: Wed Jun 3 09:37:45 EDT 2009

Add get_mode CTL for the encoder and decoder.

--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -918,6 +918,14 @@
    va_start(ap, request);
    switch (request)
    {
+      case CELT_GET_MODE_REQUEST:
+      {
+         const CELTMode ** value = va_arg(ap, const CELTMode**);
+         if (value==0)
+            goto bad_arg;
+         *value=st->mode;
+      }
+      break;
       case CELT_SET_COMPLEXITY_REQUEST:
       {
          int value = va_arg(ap, celt_int32_t);
@@ -1351,6 +1359,14 @@
    va_start(ap, request);
    switch (request)
    {
+      case CELT_GET_MODE_REQUEST:
+      {
+         const CELTMode ** value = va_arg(ap, const CELTMode**);
+         if (value==0)
+            goto bad_arg;
+         *value=st->mode;
+      }
+      break;
       case CELT_RESET_STATE:
       {
          const CELTMode *mode = st->mode;
@@ -1369,11 +1385,9 @@
    }
    va_end(ap);
    return CELT_OK;
-#if 0    /* Put this back in if you ever need "bad_arg" */
 bad_arg:
    va_end(ap);
    return CELT_BAD_ARG;
-#endif
 bad_request:
       va_end(ap);
   return CELT_UNIMPLEMENTED;
--- a/libcelt/celt.h
+++ b/libcelt/celt.h
@@ -52,6 +52,7 @@
 #endif
 
 #define _celt_check_int(x) (((void)((x) == (celt_int32_t)0)), (celt_int32_t)(x))
+#define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr)))
 
 /* Error codes */
 /** No error */
@@ -68,6 +69,9 @@
 #define CELT_UNIMPLEMENTED    -5
 
 /* Requests */
+#define CELT_GET_MODE_REQUEST    1
+/** Get the CELTMode used by an encoder or decoder */
+#define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x)
 #define CELT_SET_COMPLEXITY_REQUEST    2
 /** Controls the complexity from 0-10 (int) */
 #define CELT_SET_COMPLEXITY(x) CELT_SET_COMPLEXITY_REQUEST, _celt_check_int(x)