introducing maximum volume limit for streams 05/14605/1
authorJanos Kovacs <jankovac502@gmail.com>
Tue, 17 Dec 2013 13:57:49 +0000 (15:57 +0200)
committerJaska Uimonen <jaska.uimonen@helsinki.fi>
Wed, 8 Jan 2014 11:33:18 +0000 (13:33 +0200)
Change-Id: I7291c1de7119c8ed38936adcb2138137c3b0c668

murphy/murphy-ivi.lua
murphy/scripting.c
murphy/userdata.h
murphy/volume.c
murphy/volume.h

index 79415db..fc3dd50 100644 (file)
@@ -178,13 +178,36 @@ volume_limit {
 }
 
 volume_limit {
-    name = "suppress",
+    name = "phone_suppress",
     type = volume_limit.class,
-    limit = -20;
+    limit = -20,
     node_type = { node.phone },
     calculate = builtin.method.volume_supress
 }
 
+
+volume_limit {
+    name = "navi_suppress",
+    type = volume_limit.class,
+    limit = -20,
+    node_type = { node.navigator, node.phone },
+    calculate = builtin.method.volume_supress
+}
+
+volume_limit {
+    name = "navi_maxlim",
+    type = volume_limit.maximum,
+    limit = -10,
+    node_type = { node.navigator }
+}
+
+volume_limit {
+    name = "player_maxlim",
+    type = volume_limit.maximum,
+    limit = -20,
+    node_type = { node.player }
+}
+
 volume_limit {
     name = "video",
     type = volume_limit.class,
index 9bbf714..c370366 100644 (file)
@@ -152,7 +152,8 @@ struct scripting_apclass {
 
 typedef enum {
     vollim_class = 1,
-    vollim_generic
+    vollim_generic,
+    vollim_maximum
 } vollim_type;
 
 typedef struct {
@@ -2099,17 +2100,17 @@ static int vollim_create(lua_State *L)
 
     if (!name)
         luaL_error(L, "missing name field");
-    if (type != vollim_class && type != vollim_generic)
+    if (type != vollim_class && type != vollim_generic && type != vollim_maximum)
         luaL_error(L, "missing or invalid type");
-    if (type == vollim_class && !classes)
-        luaL_error(L, "missing or invalid node_type for class volume limit");
+    if ((type == vollim_class || type == vollim_maximum) && !classes)
+        luaL_error(L, "missing or invalid node_type for class/maximum limit");
     if (type == vollim_generic && classes)
         luaL_error(L, "can't specify node_type for generic volume limit");
     if (!limit)
         luaL_error(L, "missing or invalid limit");
-    if (!calculate)
+    if (type != vollim_maximum && !calculate)
         luaL_error(L, "missing calculate field");
-    if (calculate->type == MRP_C_FUNCTION) {
+    if (type != vollim_maximum && calculate->type == MRP_C_FUNCTION) {
         if (strcmp(calculate->c.signature, "odo"))
             luaL_error(L, "invalid calculate field (mismatching signature)");
         if (calculate->c.data == mir_volume_suppress) {
@@ -2192,13 +2193,22 @@ static int vollim_create(lua_State *L)
         memcpy(vlim->args, &limit->value, sizeof(limit->value));
     }
 
-    if (type == vollim_generic)
+    switch (type) {
+    case vollim_generic:
         mir_volume_add_generic_limit(u, vollim_calculate, vlim->args);
-    else {
+        break;
+    case vollim_class:
         for (i = 0;  i < classes->nint;  i++) {
             mir_volume_add_class_limit(u, classes->ints[i], vollim_calculate,
                                        vlim->args);
         }
+        break;
+    case vollim_maximum:
+        mir_volume_add_maximum_limit(u, *(vlim->limit->value),
+                                     classes->nint, classes->ints);
+        break;
+    default:
+        break;
     }
 
     MRP_LUA_LEAVE(1);
@@ -3083,6 +3093,7 @@ static bool define_constants(lua_State *L)
     static const_def_t vollim_const[] = {
         { "class"            , vollim_class         },
         { "generic"          , vollim_generic       },
+        { "maximum"          , vollim_maximum       },
         {       NULL         ,         0            }
     };
 
index af71604..06c3cda 100644 (file)
@@ -54,6 +54,8 @@
 
 #define PA_RESOURCE_SET_ID_PID         "pid"
 
+#define MIR_VOLUME_MAX_ATTENUATION      -120 /* dB */
+
 typedef enum   pa_value_type            pa_value_type;
 typedef struct pa_value                 pa_value;
 typedef struct pa_null_sink             pa_null_sink;
index 6009b28..6751162 100644 (file)
@@ -50,9 +50,10 @@ struct vlim_table {
 };
 
 struct pa_mir_volume {
-    int          classlen;   /**< class table length  */
-    vlim_table  *classlim;   /**< class indexed table */
-    vlim_table   genlim;     /**< generic limit */
+    int          classlen;       /**< class table length  */
+    vlim_table  *classlim;       /**< class indexed table */
+    vlim_table   genlim;         /**< generic limit */
+    double       maxlim[mir_application_class_end];  /**< per class max. limit */
 };
 
 
@@ -68,9 +69,13 @@ static void add_volume_limit(struct userdata *, mir_node *, int);
 pa_mir_volume *pa_mir_volume_init(struct userdata *u)
 {
     pa_mir_volume *volume = pa_xnew0(pa_mir_volume, 1);
+    int i;
 
     (void)u;
 
+    for (i = 0;  i < mir_application_class_end;  i++)
+        volume->maxlim[i] = MIR_VOLUME_MAX_ATTENUATION;
+
     return volume;
 }
 
@@ -145,6 +150,25 @@ void mir_volume_add_generic_limit(struct userdata  *u,
 }
 
 
+void mir_volume_add_maximum_limit(struct userdata *u,
+                                  double maxlim,
+                                  size_t nclass,
+                                  int *classes)
+{
+    pa_mir_volume *volume;
+    int class;
+    size_t i;
+
+    pa_assert(u);
+    pa_assert_se((volume = u->volume));
+
+    for (i = 0;  i < nclass;  i++) {
+        if ((class = classes[i]) < mir_application_class_end)
+            volume->maxlim[class] = maxlim;
+    }
+}
+
+
 void mir_volume_make_limiting(struct userdata *u)
 {
     uint32_t stamp;
@@ -184,13 +208,18 @@ double mir_volume_apply_limits(struct userdata *u,
     double devlim, classlim;
     vlim_table *tbl;
     uint32_t clmask;
+    double maxlim;
 
     pa_assert(u);
     pa_assert_se((volume = u->volume));
 
     if (class < 0 || class >= volume->classlen) {
         if (class < 0 || class >= mir_application_class_end)
-            attenuation = -90.0;
+            attenuation = maxlim = MIR_VOLUME_MAX_ATTENUATION;
+        else {
+            attenuation = apply_table(0.0, &volume->genlim,
+                                      u,class,node, "device");
+        }
     }
     else {
         devlim = apply_table(0.0, &volume->genlim, u,class,node, "device");
@@ -200,10 +229,16 @@ double mir_volume_apply_limits(struct userdata *u,
             pa_assert(class >= mir_application_class_begin);
             pa_assert(class <  mir_application_class_end);
 
+            maxlim = volume->maxlim[class];
             clmask = (uint32_t)1 << (class - mir_application_class_begin);
-            
+
             if (class < volume->classlen && (tbl = volume->classlim + class))
                 classlim = apply_table(classlim, tbl, u, class, node, "class");
+
+            if (classlim <= MIR_VOLUME_MAX_ATTENUATION)
+                classlim = MIR_VOLUME_MAX_ATTENUATION;
+            else if (classlim < maxlim)
+                classlim = maxlim;
         }
 
         attenuation = devlim + classlim;
index 6ae21fa..2ee95ad 100644 (file)
@@ -25,6 +25,7 @@
 #include "userdata.h"
 #include "list.h"
 
+
 typedef double (*mir_volume_func_t)(struct userdata *, int, mir_node *, void*);
 
 
@@ -51,6 +52,7 @@ void pa_mir_volume_done(struct userdata *);
 
 void mir_volume_add_class_limit(struct userdata *,int,mir_volume_func_t,void*);
 void mir_volume_add_generic_limit(struct userdata *, mir_volume_func_t,void *);
+void mir_volume_add_maximum_limit(struct userdata *, double, size_t, int *);
 
 void mir_volume_make_limiting(struct userdata *);