summaryrefslogtreecommitdiffstats
path: root/src/soundmanager.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/soundmanager.c')
-rw-r--r--src/soundmanager.c119
1 files changed, 118 insertions, 1 deletions
diff --git a/src/soundmanager.c b/src/soundmanager.c
index d8df22e..cf165e3 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -55,6 +55,33 @@ static struct afb_event ev_async_connect;
static struct afb_event ev_async_disconnect;
static struct afb_event ev_async_set_source_state;
+
+/* Client context */
+typedef struct source {
+ int sourceID;
+ int mainConnectionID;
+} source;
+
+typedef struct sink {
+ int endpointID;
+ int endpointType;
+ int sinkID;
+} sink;
+
+typedef struct events {
+ afb_event asyncSetSourceState;
+} events;
+
+typedef struct smClientCtxt{
+ char* appname;
+ source source;
+ sink sink;
+ events events;
+} smClientCtxt;
+
+static void on_client_context_terminated(void *data);
+static void create_client_context(afb_req request, guint16 source_id, guint16 sink_id, int endpoint_type);
+
/*
********** Method of Sound Manager (API) **********
*/
@@ -763,8 +790,63 @@ void unsubscribe(struct afb_req request)
#ifdef ENABLE_AGL_AHL
+
void streamOpen(struct afb_req request){
-// TODO : wtite function
+ AFB_DEBUG("call %s", __FUNCTION__);
+ // register audio role and endpoint
+ // get audio_role
+ const gchar* audio_role = afb_req_value(request, KEY_AHL_AUDIO_ROLE);
+ if(!audio_role)
+ {
+ afb_req_fail(request, "wrong request", "Please input 'audio_role' as key");
+ return;
+ }
+ // get endpoint
+ guint16 endpoint_type = ENDPOINT_SOURCE, endpoint_id = 0;
+ if(REQ_OK != get_sink_id(request, KEY_AHL_ENDPOINT_ID, &endpoint_id)){return;}
+ get_value_uint16(request, KEY_AHL_ENDPOINT_TYPE, &endpoint_type);
+
+ if(endpoint_type != ENDPOINT_SOURCE){
+ AFB_WARNING("register sink from application is not supported");
+ afb_req_fail(request,"wrong-request", "register source from application is only supported");
+ return;
+ }
+ // call registerSource
+ json_object *jreq = afb_req_json(request);
+ json_object *response = json_object_new_object();
+ json_object_object_add(jreq, KEY_APPNAME, json_object_new_string(audio_role));
+
+ afb_service_call_sync("soundmanager", "registerSource", jreq, &response);
+ // jreq is released by afb_service_call_sync then don't release jreq here.
+
+ AFB_DEBUG("request result :%s", json_object_to_json_string_ext(response, JSON_C_TO_STRING_PRETTY));
+
+ json_object *j_resp, *j_sid, *j_err;
+ int sid = -1, ret = -1;
+ if(json_object_object_get_ex(response, KEY_RESPONSE, &j_resp)){
+ AFB_DEBUG("Get response success: %s", json_object_to_json_string_ext(j_resp, JSON_C_TO_STRING_PRETTY));
+ json_object_object_get_ex(j_resp, KEY_SOURCE_ID, &j_sid);
+ json_object_object_get_ex(j_resp, KEY_ERROR, &j_err);
+ // requestSurface must return sourceID and error then I don't check whether sid and ret is in json_object.
+ sid = json_object_get_int(j_sid);
+ ret = json_object_get_int(j_err);
+ json_object_put(j_resp);
+ json_object_put(j_sid);
+ json_object_put(j_err);
+ json_object_put(response);
+ }else {
+ afb_req_fail(request, NULL, "Failed streamOpen");
+ json_object_put(response);
+ return;
+ }
+
+ json_object *res = json_object_new_object();
+ sm_add_object_to_json_object_func(res, __FUNCTION__, 4,
+ KEY_ERROR, ret,
+ KEY_CONNECTION_ID, sid);
+ char *info = get_response_audiomanager_massage_error(ret);
+ create_client_context(request, sid, endpoint_id, endpoint_type);
+ afb_req_success(request, res, info);
}
void streamClose(struct afb_req request){
@@ -1000,6 +1082,41 @@ static gboolean on_async_set_source_state(
*
*/
+static void on_client_context_terminated(void *data){
+ smClientCtxt* ctxt = (smClientCtxt*)data;
+ if(NULL == ctxt){
+ return;
+ }
+ AFB_DEBUG("Client %s session is closed", ctxt->appname);
+ free(ctxt->appname);
+ free(ctxt);
+ // TODO : After application is terminated, what should we do?
+}
+
+static void create_client_context(afb_req request, guint16 source_id, guint16 sink_id, int endpoint_type){
+ AFB_DEBUG("");
+ static int applicationID_debug = 0;
+ smClientCtxt* ctxt = malloc(sizeof(smClientCtxt));
+ ctxt->appname = malloc(MAX_LENGTH_STR * sizeof(char));
+ char *appid = afb_req_get_application_id(request);
+ if(NULL == appid){
+ char debug[MAX_LENGTH_STR];
+ //char* debug;
+ snprintf(debug, MAX_LENGTH_STR, "%s%d", "applicationID_debug", ++applicationID_debug);
+ AFB_INFO("application id is not set. Define as %s", debug);
+ strncpy(ctxt->appname, debug, MAX_LENGTH_STR);
+ }
+ else{
+ strncpy(ctxt->appname, appid, MAX_LENGTH_STR);
+ }
+ ctxt->source.sourceID = source_id;
+ ctxt->sink.endpointID = sink_id;
+ ctxt->sink.sinkID = sink_id;
+ ctxt->sink.endpointType = endpoint_type;
+ ctxt->events.asyncSetSourceState = afb_daemon_make_event("asyncSetSourceState");
+ afb_req_context_set(request, ctxt, on_client_context_terminated);
+}
+
static int registerDomain()
{
/* Default Setting of Sound Manager Domain */