Add handing audio codec from config file 88/43688/2
authorHyunjun Ko <zzoon.ko@samsung.com>
Mon, 13 Jul 2015 07:55:34 +0000 (16:55 +0900)
committerhj kim <backto.kim@samsung.com>
Tue, 14 Jul 2015 01:02:04 +0000 (18:02 -0700)
Change-Id: I7f171dadedabf6a369169a06773633ce949f0dad

gst/rtsp-server/rtsp-client-wfd.c
gst/rtsp-server/rtsp-client-wfd.h
gst/rtsp-server/rtsp-media-factory-wfd.c
gst/rtsp-server/rtsp-media-factory-wfd.h
gst/rtsp-server/rtsp-server-wfd.c
gst/rtsp-server/rtsp-server-wfd.h

index f5f7c0c..ba74919 100644 (file)
@@ -77,6 +77,7 @@ struct _GstRTSPWFDClientPrivate
 
   /* Parameters for WIFI-DISPLAY */
   guint caCodec;
+  guint8 audio_codec;
   guint cFreq;
   guint cChanels;
   guint cBitwidth;
@@ -237,6 +238,7 @@ gst_rtsp_wfd_client_init (GstRTSPWFDClient * client)
   priv->protection_enabled = FALSE;
   priv->video_native_resolution = GST_WFD_VIDEO_CEA_RESOLUTION;
   priv->video_resolution_supported = GST_WFD_CEA_640x480P60;
+  priv->audio_codec = GST_WFD_AUDIO_AAC;
   priv->keep_alive_flag = FALSE;
   g_mutex_init (&priv->keep_alive_lock);
 
@@ -348,6 +350,22 @@ wfd_get_param_request_done (GstRTSPWFDClient * client)
   return;
 }
 
+static guint
+wfd_get_prefered_audio_codec (guint8 srcAudioCodec,
+    guint sinkAudioCodec)
+{
+  int i = 0;
+  guint codec = 0;
+  for (i = 0; i < 8; i++) {
+    if (((sinkAudioCodec << i) & 0x80)
+        && ((srcAudioCodec << i) & 0x80)) {
+      codec = (0x01 << (7 - i));
+      break;
+    }
+  }
+  return codec;
+}
+
 static guint64
 wfd_get_prefered_resolution (guint64 srcResolution,
     guint64 sinkResolution,
@@ -1184,6 +1202,52 @@ typedef enum
 } GstWFDMessageType;
 
 static gboolean
+_set_negotiated_audio_codec (GstRTSPWFDClient *client,
+    guint audio_codec)
+{
+  GstRTSPClient *parent_client = GST_RTSP_CLIENT_CAST (client);
+
+  GstRTSPMediaFactory *factory = NULL;
+  GstRTSPMountPoints *mount_points = NULL;
+  gchar *path = NULL;
+  gint matched = 0;
+  gboolean ret = TRUE;
+
+  if (!(mount_points = gst_rtsp_client_get_mount_points (parent_client))) {
+    ret = FALSE;
+    GST_ERROR_OBJECT (client, "Failed to set negotiated audio codec: no mount points...");
+    goto no_mount_points;
+  }
+
+  path = g_strdup(WFD_MOUNT_POINT);
+  if (!path) {
+    ret = FALSE;
+    GST_ERROR_OBJECT (client, "Failed to set negotiated audio codec: no path...");
+    goto no_path;
+  }
+
+  if (!(factory = gst_rtsp_mount_points_match (mount_points,
+          path, &matched))) {
+    GST_ERROR_OBJECT (client, "Failed to set negotiated audio codec: no factory...");
+    ret = FALSE;
+    goto no_factory;
+  }
+
+  gst_rtsp_media_factory_wfd_set_audio_codec (factory,
+      audio_codec);
+  ret = TRUE;
+
+  g_object_unref(factory);
+
+no_factory:
+  g_free(path);
+no_path:
+  g_object_unref(mount_points);
+no_mount_points:
+  return ret;
+}
+
+static gboolean
 _set_negotiated_resolution(GstRTSPWFDClient *client,
     guint32 width, guint32 height)
 {
@@ -1375,16 +1439,12 @@ _set_wfd_message_body (GstRTSPWFDClient * client, GstWFDMessageType msg_type,
       goto error;
     }
 
-    /* set the preffered audio formats */
-    if (priv->caCodec & GST_WFD_AUDIO_AC3) {
-      GST_ERROR_OBJECT (client, "AC3 is not supported");
-      goto error;
-    } else if (priv->caCodec & GST_WFD_AUDIO_AAC) {
-      taudiocodec = GST_WFD_AUDIO_AAC;
-    } else if (priv->caCodec & GST_WFD_AUDIO_LPCM) {
-      taudiocodec = GST_WFD_AUDIO_LPCM;
-    }
+    taudiocodec = wfd_get_prefered_audio_codec (priv->audio_codec, priv->caCodec);
     priv->caCodec = taudiocodec;
+    if (!_set_negotiated_audio_codec(client, priv->caCodec)) {
+      GST_ERROR_OBJECT (client, "Failed to set negotiated "
+          "audio codec to media factory...");
+    }
 
     if (priv->cFreq & GST_WFD_FREQ_48000)
       taudiofreq = GST_WFD_FREQ_48000;
@@ -2141,6 +2201,21 @@ gst_rtsp_wfd_client_set_video_native_resolution (GstRTSPWFDClient * client,
   return res;
 }
 
+GstRTSPResult
+gst_rtsp_wfd_client_set_audio_codec (GstRTSPWFDClient * client,
+    guint8 audio_codec)
+{
+  GstRTSPResult res = GST_RTSP_OK;
+  GstRTSPWFDClientPrivate *priv = GST_RTSP_WFD_CLIENT_GET_PRIVATE (client);
+
+  g_return_val_if_fail (priv != NULL, GST_RTSP_EINVAL);
+
+  priv->audio_codec = audio_codec;
+  GST_DEBUG ("Audio codec : %d", audio_codec);
+
+  return res;
+}
+
 static gboolean
 wfd_ckeck_keep_alive_response (gpointer userdata)
 {
index 02aff65..0ff110b 100644 (file)
@@ -128,6 +128,8 @@ GstRTSPResult         gst_rtsp_wfd_client_set_video_supported_resolution (
                           GstRTSPWFDClient * client, guint64 supported_reso);
 GstRTSPResult         gst_rtsp_wfd_client_set_video_native_resolution (
                                      GstRTSPWFDClient * client, guint64 native_reso);
+GstRTSPResult         gst_rtsp_wfd_client_set_audio_codec (
+                                     GstRTSPWFDClient * client, guint8 audio_codec);
 /**
  * GstRTSPWFDClientSessionFilterFunc:
  * @client: a #GstRTSPWFDClient object
index 54a1b25..c4d26c5 100644 (file)
@@ -196,6 +196,14 @@ void gst_rtsp_media_factory_wfd_set_negotiated_resolution (GstRTSPMediaFactory *
   priv->video_width = width;
   priv->video_height = height;
 }
+void gst_rtsp_media_factory_wfd_set_audio_codec (GstRTSPMediaFactory *factory,
+   guint audio_codec)
+{
+  GstRTSPMediaFactoryWFD *factory_wfd = GST_RTSP_MEDIA_FACTORY_WFD (factory);
+  GstRTSPMediaFactoryWFDPrivate *priv = factory_wfd->priv;
+
+  priv->audio_codec = audio_codec;
+}
 
 static void
 gst_rtsp_media_factory_wfd_init (GstRTSPMediaFactoryWFD * factory)
index 9a32ddd..5320d63 100644 (file)
@@ -123,6 +123,8 @@ void  gst_rtsp_media_factory_wfd_set_dump_ts (GstRTSPMediaFactoryWFD * factory,
     gboolean dump_ts);
 void gst_rtsp_media_factory_wfd_set_negotiated_resolution (GstRTSPMediaFactory *factory,
    guint32 width, guint32 height);
+void gst_rtsp_media_factory_wfd_set_audio_codec (GstRTSPMediaFactory *factory,
+    guint audio_codec);
 
 G_END_DECLS
 #endif /* __GST_RTSP_MEDIA_FACTORY_WFD_H__ */
index 7ce9c14..15dac76 100644 (file)
@@ -73,6 +73,7 @@ struct _GstRTSPWFDServerPrivate
   GList *clients;
   guint64 native_resolution;
   guint64 supported_resolution;
+  guint8 audio_codec;
 };
 
 G_DEFINE_TYPE (GstRTSPWFDServer, gst_rtsp_wfd_server, GST_TYPE_RTSP_SERVER);
@@ -123,6 +124,7 @@ gst_rtsp_wfd_server_init (GstRTSPWFDServer * server)
   server->priv = priv;
   server->priv->native_resolution = 0;
   server->priv->supported_resolution = 1;
+  server->priv->audio_codec = 2;
   GST_INFO_OBJECT (server, "New server is initialized");
 }
 
@@ -238,6 +240,9 @@ create_client_wfd (GstRTSPServer * server)
   gst_rtsp_wfd_client_set_video_native_resolution (client,
         priv->native_resolution);
 
+  gst_rtsp_wfd_client_set_audio_codec (client,
+        priv->audio_codec);
+
   GST_RTSP_WFD_SERVER_UNLOCK (server);
 
   return GST_RTSP_CLIENT (client);
index c1da877..13a5f3a 100644 (file)
@@ -80,6 +80,7 @@ GstRTSPResult         gst_rtsp_wfd_server_trigger_request      (GstRTSPServer *s
 
 GstRTSPResult         gst_rtsp_wfd_server_set_supported_reso (GstRTSPWFDServer *server, guint64 supported_reso);
 GstRTSPResult         gst_rtsp_wfd_server_set_video_native_reso    (GstRTSPWFDServer *server, guint64 native_reso);
+GstRTSPResult         gst_rtsp_wfd_server_set_audio_codec    (GstRTSPWFDServer *server, guint8 audio_codec);
 
 #if 0
 void                  gst_rtsp_server_set_address          (GstRTSPServer *server, const gchar *address);