diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/sm-def.h | 4 | ||||
-rw-r--r-- | src/sm-helper.c | 8 | ||||
-rw-r--r-- | src/sm-helper.h | 1 | ||||
-rw-r--r-- | src/soundmanager.c | 47 |
4 files changed, 48 insertions, 12 deletions
diff --git a/src/sm-def.h b/src/sm-def.h index 58057e4..27f0b2f 100644 --- a/src/sm-def.h +++ b/src/sm-def.h @@ -25,7 +25,7 @@ #define COMMAND_EVENT_NUM 10 #define ROUTING_EVENT_NUM 10 -#define DEFAULT_SINK 4 +#define DEFAULT_SINK 1 #define DEFAULT_SOURCE_CLASS_ID 101 #define DYNAMIC_DOMAIN_ID 100 #define DEFAULT_DOMAIN_ID 0 @@ -111,4 +111,4 @@ typedef enum { #define MAX_LENGTH_STR 256 -#endif // SOUNDMANAGER_DEFINE_H
\ No newline at end of file +#endif // SOUNDMANAGER_DEFINE_H diff --git a/src/sm-helper.c b/src/sm-helper.c index e0dec49..b00ffa3 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; @@ -107,7 +109,7 @@ REQ_ERROR get_sink_id(const afb_req request, const char* key, uint16_t* out_sink else{ if((strlen("default") == strlen(default_sink)) && (0 == strncmp("default", default_sink, strlen("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; } @@ -124,6 +126,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 a8a2b9e..1bc2a9d 100644 --- a/src/soundmanager.c +++ b/src/soundmanager.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <json-c/json.h> #include <glib.h> +#include <pthread.h> #include "soundmanager.h" #include "audiomanager_proxy.h" #include "sm-def.h" @@ -355,7 +356,6 @@ void getListMainSinks(struct afb_req request) AFB_DEBUG("call %s", __FUNCTION__); GVariant* mainSinkList; - GError *err = NULL; ErrorCode ec = am_proxy_get_list_main_sinks(&mainSinkList); @@ -1040,6 +1040,33 @@ 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){ + return; + } + + guint16 sinkid, sinkclassid; + gchar* sinkname; + gint16 av, avr, volume, mutestate; + + GVariant* child = g_variant_get_child_value(mainSinkList, 1); + 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); + + set_default_sinkID(sinkid); +} + int preinit() { AFB_INFO("Initialize Dbus object"); @@ -1054,8 +1081,7 @@ int preinit() AFB_NOTICE( "Finish Initialize"); return 0; } -//test -#include <pthread.h> + static void *dbus_event_loop_run(void *args) { GMainLoop* loop = g_main_loop_new(NULL, FALSE); @@ -1164,13 +1190,16 @@ int sm_init() return -1; } AFB_DEBUG("domainID : %d", SOUNDMANAGER_DOMAIN_ID); - // tes + + set_default_sink(); + pthread_t thread_id; - int ret = pthread_create(&thread_id, NULL, dbus_event_loop_run, NULL); - if(ret != 0) - { - AFB_ERROR("Failed to create thread"); - } + int ret = pthread_create(&thread_id, NULL, dbus_event_loop_run, NULL); + if(ret != 0) + { + AFB_ERROR("Failed to create thread"); + return -1; + } return 0; } |