summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sm-helper.c8
-rw-r--r--src/sm-helper.h1
-rw-r--r--src/soundmanager.c32
3 files changed, 40 insertions, 1 deletions
diff --git a/src/sm-helper.c b/src/sm-helper.c
index f2620ce..9f78414 100644
--- a/src/sm-helper.c
+++ b/src/sm-helper.c
@@ -22,6 +22,8 @@
#include "sm-helper.h"
#include "sm-error.h"
+static int default_sinkID = DEFAULT_SINK;
+
REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uint16_t *out_id)
{
char* endptr;
@@ -102,7 +104,7 @@ REQ_ERROR get_sink_id(const afb_req request, const char* key, uint16_t* out_sink
AFB_DEBUG("%s", json_object_to_json_string_ext(test, JSON_C_TO_STRING_PRETTY));
if(0 == strcmp(requested_sink_str, "default")){
- *out_sink_id = DEFAULT_SINK;
+ *out_sink_id = default_sinkID;
AFB_INFO("sinkID(endpointID) is attached as default sinkID as %d", DEFAULT_SINK);
result = REQ_OK;
}
@@ -119,6 +121,10 @@ REQ_ERROR get_sink_id(const afb_req request, const char* key, uint16_t* out_sink
return REQ_OK;
}
+void set_default_sinkID(int sinkID){
+ default_sinkID = sinkID;
+}
+
void sm_add_object_to_json_object(struct json_object* j_obj, int count,...)
{
va_list args;
diff --git a/src/sm-helper.h b/src/sm-helper.h
index 0eb57a7..a6d09f1 100644
--- a/src/sm-helper.h
+++ b/src/sm-helper.h
@@ -47,6 +47,7 @@ REQ_ERROR get_value_uint16(const struct afb_req request, const char *source, uin
REQ_ERROR get_value_int16(const struct afb_req request, const char *source, int16_t *out_id);
REQ_ERROR get_value_int32(const struct afb_req request, const char *source, int32_t *out_id);
REQ_ERROR get_sink_id(const struct afb_req request, const char* key, uint16_t *out_sink_id);
+void set_default_sinkID(int sinkID);
void sm_add_object_to_json_object(struct json_object* j_obj, int count, ...);
void sm_add_object_to_json_object_func(struct json_object* j_obj, const char* verb_name, int count, ...);
int sm_search_event_name_index(const char* value);
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 6acf2a0..1d10a1e 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -966,6 +966,37 @@ static void create_client_context(afb_req request, guint16 source_id, guint16 si
afb_req_context_set(request, ctxt, on_client_context_terminated);
}
+void set_default_sink(){
+ GVariant *mainSinkList;
+ ErrorCode ec = am_proxy_get_list_main_sinks(&mainSinkList);
+ if(ec != OK){
+ return;
+ }
+
+ gsize size = g_variant_n_children(mainSinkList);
+
+ if(0 == size){
+ AFB_NOTICE("Sink is not registered in Audio Manaager then can't set default sinkID, then set as %d", DEFAULT_SINK);
+ return;
+ }
+
+ guint16 sinkid, sinkclassid;
+ gchar* sinkname;
+ gint16 av, avr, volume, mutestate;
+
+ // Take the first one as default sinkID
+ GVariant* child = g_variant_get_child_value(mainSinkList, 0);
+ g_variant_get(
+ child,"(qs(nn)nnq)",
+ &sinkid, &sinkname, &av, &avr, &volume, &mutestate, &sinkclassid);
+ AFB_DEBUG( "sinkID: %d, sinkName: %s, availability: %d, availableReason: %d, volume: %d, muteState: %d, sinkClassID: %d",
+ sinkid, sinkname, av, avr, volume, mutestate, sinkclassid);
+ g_variant_unref(child);
+ g_variant_unref(mainSinkList);
+
+ set_default_sinkID(sinkid);
+}
+
int preinit()
{
AFB_INFO("Initialize Dbus object");
@@ -1071,6 +1102,7 @@ int sm_init()
}
AFB_DEBUG("domainID : %d", SOUNDMANAGER_DOMAIN_ID);
+ set_default_sink();
return 0;
}