1 #include "amhelper.h"
2 #include <mixlog.h>
3 
4 static DBusGConnection *connection;
5 
6 static DBusGProxy *proxy_lpe = NULL;
7 
8 static gboolean am_enable=FALSE;
9 
10 /* Connect to am dbus server
11  * return -1 means failed
12  * return 0 means succeeded
13  * */
dbus_init()14 gint dbus_init() {
15     GError *error;
16     const char *name = "org.moblin.audiomanager";
17 
18     const char *path_lpe = "/org/moblin/audiomanager/lpe";
19     const char *interface_lpe = "org.moblin.audiomanager.lpe";
20 
21     const gchar* env  = g_getenv("MIX_AM");
22     if (env && env[0] == '1') {
23 	am_enable = TRUE;
24     }
25     else
26 	am_enable = FALSE;
27 
28     if (am_enable) {
29 	    error = NULL;
30 	    connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
31 
32 	    if (connection == NULL) {
33 		mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_WARNING, "Failed to open connection to bus: %s\n",
34 		            error->message);
35 		g_error_free(error);
36 		return -1;
37 	    }
38 	    mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_VERBOSE, "Successfully get a dbus connection\n");
39 
40 	    proxy_lpe = dbus_g_proxy_new_for_name(connection, name,
41 		                            path_lpe, interface_lpe);
42 	    if (proxy_lpe == NULL) {
43 		mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_WARNING, "Failed to connect to AM dbus server\n");
44 		return -1;
45 	    }
46 	    else {
47 	    	mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_VERBOSE, "Successfully connected to AM dbus\npath: %s\ninterface: %s\n",
48 			path_lpe, interface_lpe);
49 	    }
50     }
51     return 0;
52 }
53 
lpe_stream_register(guint32 lpe_stream_id,char * media_role,char * lpe_stream_name,guint32 stream_type)54 gint32 lpe_stream_register(guint32 lpe_stream_id, char* media_role, char* lpe_stream_name, guint32 stream_type)
55 {
56   GError *error;
57   gint32 s_output = 0;
58   error = NULL;
59 
60   if (am_enable) {
61 	  mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "lpe_stream_id: %d\n", lpe_stream_id);
62 
63 	  if (lpe_stream_id == 0) {
64 		return 0;
65 	  }
66 	  if(!dbus_g_proxy_call (proxy_lpe, "LPEStreamRegister", &error, G_TYPE_UINT,
67 		lpe_stream_id, G_TYPE_STRING, media_role, G_TYPE_STRING, lpe_stream_name, G_TYPE_UINT, stream_type,
68 		G_TYPE_INVALID, G_TYPE_INT, &s_output, G_TYPE_INVALID)) {
69 		mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_WARNING, "LPEStreamRegister failed: %s\n", error->message);
70                 g_error_free(error);
71 		return s_output;
72 	  }
73 
74 	  mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_INFO, "LPEStreamRegister returned am stream id %d\n", s_output);
75   }
76 
77   return s_output;
78 }
79 
lpe_stream_unregister(guint32 am_stream_id)80 gint32 lpe_stream_unregister(guint32 am_stream_id)
81 {
82   GError *error;
83   gint32 s_output = 0;
84 
85   if (am_enable) {
86 	  error = NULL;
87 	  if(!dbus_g_proxy_call (proxy_lpe, "LPEStreamUnregister", &error, G_TYPE_UINT, am_stream_id,
88 		G_TYPE_INVALID, G_TYPE_INT, &s_output, G_TYPE_INVALID)){
89 		mix_log(MIX_AUDIO_COMP, MIX_LOG_LEVEL_WARNING, "LPEStreamUnregister failed: %s\n", error->message);
90 		g_error_free(error);
91 		return s_output;
92 	  }
93   }
94   return s_output;
95 }
96 
lpe_stream_notify_pause(guint32 stream_id)97 gint32 lpe_stream_notify_pause(guint32 stream_id)
98 {
99   GError *error;
100   gint32 s_output=0;
101 
102   if (am_enable) {
103     dbus_g_proxy_call (proxy_lpe, "LPEStreamNotifyPause", &error, G_TYPE_UINT, stream_id, G_TYPE_INVALID, G_TYPE_INT, &s_output, G_TYPE_INVALID);
104   }
105 
106   return s_output;
107 }
108 
lpe_stream_notify_resume(guint32 stream_id)109 gint32 lpe_stream_notify_resume(guint32 stream_id)
110 {
111   GError *error;
112   gint32 s_output=0;
113 
114   if (am_enable) {
115     dbus_g_proxy_call (proxy_lpe, "LPEStreamNotifyResume", &error, G_TYPE_UINT, stream_id, G_TYPE_INVALID, G_TYPE_INT, &s_output, G_TYPE_INVALID);
116   }
117 
118   return s_output;
119 }
120 
121