aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-03-29 21:43:30 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2018-03-29 21:44:45 +0900
commit784e69dc7f8928f22ea1603aad8c81e4d76a24fe (patch)
treecac5fc0770b9aa4e9a13069a8504d260efa2ae05 /src
parentf12c118f08b77d3bcfd0330961d7b90d11d9dd1a (diff)
Add setSreamState and streamClose
Change-Id: Ifb25140466ac67e699008eefc6ff3edbcca01fae Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
Diffstat (limited to 'src')
-rw-r--r--src/sm-def.h1
-rw-r--r--src/soundmanager.c121
2 files changed, 113 insertions, 9 deletions
diff --git a/src/sm-def.h b/src/sm-def.h
index 17e31ff..0bab88d 100644
--- a/src/sm-def.h
+++ b/src/sm-def.h
@@ -76,6 +76,7 @@
#define KEY_AHL_AUDIO_ROLE "audio_role"
#define KEY_AHL_ENDPOINT_ID "endpoint_id"
#define KEY_AHL_ENDPOINT_TYPE "endpoint_type"
+#define KEY_AHL_REP_STREAM_ID "stream_id"
typedef enum {
ENDPOINT_SINK,
diff --git a/src/soundmanager.c b/src/soundmanager.c
index 7b929a2..96d95d1 100644
--- a/src/soundmanager.c
+++ b/src/soundmanager.c
@@ -32,6 +32,54 @@ struct event{
struct afb_event* event;
};
+struct pending{
+ int sourceID;
+ struct afb_req request;
+ bool use_ahl;
+ struct pending* next;
+};
+
+static struct pending* pending_list = NULL;
+
+static bool add_pending(int source_id, bool use_ahl, struct afb_req request){
+ struct pending* pd = malloc(sizeof(struct pending));
+ if(NULL == pd){
+ AFB_WARNING("memory allocation error");
+ return false;
+ }
+ pd->sourceID = source_id;
+ pd->request = request;
+ pd->use_ahl = use_ahl;
+ pd->next = NULL;
+ if(pending_list == NULL){
+ pending_list = pd;
+ }
+ struct pending* list = pending_list;
+ while(list->next != NULL){
+ list = list->next;
+ }
+ list->next = pd;
+ return true;
+}
+
+
+static struct pending* get_pending(int source_id){
+ struct pending* pd = pending_list;
+ while(pd && (pd->sourceID == source_id)){
+ pd = pd->next;
+ }
+ return pd;
+}
+
+static bool del_peding(int source_id){
+ struct pending* pd = get_pending(source_id);
+ if(pd != NULL){
+
+ return true;
+ }
+ return false;
+}
+
static int SOUNDMANAGER_DOMAIN_ID;
static struct event command_event_list[COMMAND_EVENT_NUM];
static struct event routing_event_list[ROUTING_EVENT_NUM];
@@ -761,25 +809,73 @@ void streamOpen(struct afb_req request){
json_object *res = json_object_new_object();
sm_add_object_to_json_object_func(res, __FUNCTION__, 4,
KEY_ERROR, ret,
- KEY_CONNECTION_ID, sid);
+ KEY_AHL_REP_STREAM_ID, sid);
const 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){
-// TODO : wtite function
-/* smClientCtxt* ctxt = afb_req_context_get(request);
+ ErrorCode ec;
+ smClientCtxt* ctxt = afb_req_context_get(request);
+ if(NULL == ctxt){
+ AFB_ERROR("stream is not created");
+ afb_req_fail(request,NULL, "stream is not created");
+ return;
+ }
if(ctxt->source.mainConnectionID > 0){
- json_object* jreq = json_object_new_object();
- json_object_object_add(jreq, KEY_MAIN_CONNECTION_ID, ctxt->source.mainConnectionID);
- afb_service_call_sync("soundmanager", "disconnect", jreq, &response);
- json_object_object_get_ex(response, KEY_RESPONSE, &j_resp);
- } */
+ ec = am_proxy_disconnect(ctxt->source.mainConnectionID);
+ SEND_RESULT_NO_RESP(ec);
+ ctxt->source.mainConnectionID = -1;
+ }
+ int source_id;
+ REQ_ERROR req_err = get_value_uint16(request, KEY_SOURCE_ID, &source_id);
+ if(ctxt->source.sourceID != source_id){
+ AFB_ERROR("requested sourceID is %d, but your sourceID is %d", source_id, ctxt->source.sourceID);
+ afb_req_fail(request,"wrong request", NULL);
+ return;
+ }
+ ec = am_proxy_deregister_source(ctxt->source.sourceID);
+ if(!SEND_RESULT(ec, request)) return;
+ /*create response json object*/
+ struct json_object *res = json_object_new_object();
+ sm_add_object_to_json_object_func(res, __FUNCTION__, 2,
+ KEY_ERROR, ec);
+ const char* info = get_response_audiomanager_massage_error(ec);
+ afb_req_success(request, res, info);
}
void setStreamState(struct afb_req request){
-// TODO : wtite function
+ int source_id = 0, main_connection_id = -1;
+ ErrorCode ec;
+ smClientCtxt* ctxt = afb_req_context_get(request);
+ if(NULL == ctxt){
+ AFB_ERROR("Context is not registered");
+ afb_req_fail(request, NULL, "call stream_open at first");
+ return;
+ }
+ ctxt->source.mainConnectionID = main_connection_id;
+ // get sourceID from request
+ if(REQ_OK != get_value_uint16(request, KEY_SOURCE_ID, &source_id)){
+ if(REQ_OK != get_value_uint16(request, KEY_AHL_REP_STREAM_ID, &source_id)){
+ AFB_ERROR("requested sourceID is %d, but your sourceID is %d", source_id, ctxt->source.sourceID);
+ afb_req_fail(request, "wrong-request", "Unable to find sourceID");
+ return;
+ }
+ }
+
+ if(source_id != ctxt->source.sourceID){
+ AFB_ERROR("requested sourceID is %d, but your sourceID is %d", source_id, ctxt->source.sourceID);
+ afb_req_fail(request, "wrong-request", "sourceID is not yours");
+ return;
+ }
+
+ ec = am_proxy_connect(source_id, ctxt->sink.sinkID, &main_connection_id);
+ if(!SEND_RESULT(ec, request)) return;
+
+ ctxt->source.mainConnectionID = main_connection_id;
+ afb_req_addref(request);
+ add_peding(source_id, request);
}
#endif
@@ -909,6 +1005,13 @@ static void on_async_set_sink_volume(void *closure, int handle, int sinkID,
static void on_async_set_source_state(void *closure, int handle, int sourceID, int sourceState)
{
AFB_DEBUG( "%s called", __FUNCTION__);
+ struct pending* pd = get_pending(sourceID);
+ if((pd != NULL) && (pd->use_ahl)){
+ AFB_DEBUG("Call ackSetSourceState in for the application");
+ am_proxy_ack_set_source_state(handle, 0);
+ del_peding(sourceID);
+ return;
+ }
struct json_object* ev_obj = json_object_new_object();
const char* ss_key = get_source_state_key(sourceState);
sm_add_object_to_json_object(ev_obj, 4,