[SCM] Mumudvb packaging branch, upstream, updated. 24c2efb080b56abb8e7be67bae30ba7fe457759e

Brice Dubost dubost at poulet.adm.crans.org
Sat Nov 1 13:31:03 UTC 2008


The following commit has been merged in the upstream branch:
commit 24a7e6797c524ef44fc027172dc5c1b34fc81c7a
Author: Brice Dubost <dubost at poulet.adm.crans.org>
Date:   Sun Sep 21 01:09:10 2008 +0200

    First test version of sap announces
    
     * added sap_organisation option
     * Errors corrected in sap generation
     * Sending of sap announces
    
    Todo :
    get the right ip address of the server

diff --git a/src/mumudvb.c b/src/mumudvb.c
index 73b0734..5dffe0f 100644
--- a/src/mumudvb.c
+++ b/src/mumudvb.c
@@ -237,6 +237,8 @@ main (int argc, char **argv)
   };
   int c, option_index = 0;
 
+  //paranoia
+  sap_organisation[0]=0;
 
   // Initialise PID map
   for (k = 0; k < 8192; k++)
@@ -389,6 +391,27 @@ main (int argc, char **argv)
 			"!!! You have enabled the support for autoconfiguration, this is a beta feature.Please report any bug/comment\n");
 	    }
 	}
+      else if (!strcmp (substring, "sap"))
+	{
+	  substring = strtok (NULL, delimiteurs);
+	  sap = atoi (substring);
+	  if(autoconfiguration)
+	    {
+	      log_message( MSG_WARN,
+			"!!! You have enabled the support for autoconfiguration, this is a beta feature.Please report any bug/comment\n");
+	    }
+	}
+      else if (!strcmp (substring, "sap_organisation"))
+	{
+	  // other substring extraction method in order to keep spaces
+	  substring = strtok (NULL, delimiteurs);
+	  if (!(strlen (substring) >= 255 - 1))
+	    strcpy(sap_organisation,strtok(substring,"\n"));	
+	  else
+	    {
+		log_message( MSG_INFO,"Sap Organisation name too long\n");
+	    }
+	}
       else if (!strcmp (substring, "freq"))
 	{
 	  substring = strtok (NULL, delimiteurs);
@@ -644,6 +667,7 @@ main (int argc, char **argv)
   //end of config file reading
   /******************************************************/
 
+
   number_of_channels = curr_channel;
   if (curr_channel > MAX_CHANNELS)
     {
@@ -930,6 +954,23 @@ main (int argc, char **argv)
       channels[curr_channel].socketOut = makeclientsocket (channels[curr_channel].ipOut, channels[curr_channel].portOut, DEFAULT_TTL, &channels[curr_channel].sOut);
     }
 
+
+  /*****************************************************/
+  // init sap
+  /*****************************************************/
+
+  if(sap)
+    {
+      //For sap announces, we open the socket
+      sap_socketOut =  makeclientsocket (SAP_IP, SAP_PORT, SAP_TTL, &sap_sOut);
+      if(!strlen(sap_organisation))
+	sprintf(sap_organisation,"mumudvb");
+      sap_serial= 1 + (int) (424242.0 * (rand() / (RAND_MAX + 1.0)));
+      sap_last_time_sent = 0;
+      //todo : loop to create the version
+    }
+
+
   /*****************************************************/
   // Information about streamed channels
   /*****************************************************/
@@ -1330,9 +1371,20 @@ SignalHandler (int signum)
       else //we are not doing autoconfiguration we can do something else
 	{
 	  //sap announces
-	  //TODO : update only when it's needed
-	  if(sap)
-	    sap_update(channels[0], &sap_messages[0]);
+	  if(!sap_last_time_sent)
+	    {
+	      // it's the first time we are here, we initialize all the channels
+	      for (curr_channel = 0; curr_channel < number_of_channels; curr_channel++)
+		{
+		  sap_update(channels[curr_channel], &sap_messages[curr_channel]);
+		}
+	      sap_last_time_sent=now-SAP_INTERVAL-1;
+	    }
+	  if((now-sap_last_time_sent)>=SAP_INTERVAL)
+	    {
+	      sap_send(sap_messages, number_of_channels);
+	      sap_last_time_sent=now;
+	    }
 	  //end of sap announces
 
 	  for (curr_channel = 0; curr_channel < number_of_channels; curr_channel++)
@@ -1342,6 +1394,7 @@ SignalHandler (int signum)
 			     "Channel \"%s\" back.Card %d\n",
 			     channels[curr_channel].name, card);
 		channels[curr_channel].streamed_channel_old = 1;	// update
+		sap_update(channels[curr_channel], &sap_messages[curr_channel]);
 	      }
 	    else if ((channels[curr_channel].streamed_channel_old) && (channels[curr_channel].streamed_channel < 30))
 	      {
@@ -1349,6 +1402,7 @@ SignalHandler (int signum)
 			     "Channel \"%s\" down.Card %d\n",
 			     channels[curr_channel].name, card);
 		channels[curr_channel].streamed_channel_old = 0;	// update
+		sap_update(channels[curr_channel], &sap_messages[curr_channel]);
 	      }
 
 	  /*******************************************/
diff --git a/src/sap.c b/src/sap.c
index 843db1d..2dd83ea 100644
--- a/src/sap.c
+++ b/src/sap.c
@@ -41,6 +41,14 @@ int sap_init(mumudvb_sap_message_t *sap_messages, int num_messages)
 //SAP_send : send the sap message
 void sap_send(mumudvb_sap_message_t *sap_messages, int num_messages)
 {
+  int curr_message;
+  log_message(MSG_DEBUG,"DEBUG : SAP sending\n");
+
+  for( curr_message=0; curr_message<num_messages;curr_message++)
+    {
+      if(sap_messages[curr_message].to_be_sent)
+	sendudp (sap_socketOut, &sap_sOut, sap_messages[curr_message].buf, sap_messages[curr_message].len);
+    }
 
   return;
 }
@@ -50,11 +58,13 @@ void sap_send(mumudvb_sap_message_t *sap_messages, int num_messages)
 int sap_update(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_message)
 {
   //TAILLE DU PAQUET < MTU
-  //TODO : add debug messages 
   
   //This function is called when the channel changes so it increases the version and update the packet
   char temp_string[256];
 
+  //paranoia
+  memset(sap_message->buf,0, MAX_UDP_SIZE * sizeof (unsigned char));
+
   sap_message->version++;
   sap_message->buf[0]=SAP_HEADER;
   sap_message->buf[1]=SAP_HEADER2;
@@ -70,10 +80,10 @@ int sap_update(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_message)
 
   //the mime type
   sprintf(temp_string,"application/sdp");
-  memcpy(sap_message->buf + 8, temp_string, sizeof(temp_string));
-  sap_message->len=8+sizeof(temp_string);
-
-  //boucle sur les chaines
+  memcpy(sap_message->buf + 8, temp_string, strlen(temp_string));
+  sap_message->len=8+strlen(temp_string);
+  sap_message->buf[sap_message->len]=0;
+  sap_message->len++;
 
   // one program per message
   if(!sap_add_program(channel, sap_message))
@@ -94,7 +104,8 @@ int sap_add_program(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_messag
   char temp_string[256];
 
 
-  if(!channel.streamed_channel)
+  //we check if it's an alive channel
+  if(!channel.streamed_channel_old)
     return 1;
 
   //Now we write the sdp part
@@ -103,25 +114,25 @@ int sap_add_program(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_messag
   //v=0
 
   sprintf(temp_string,"v=0\r\n");
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
   
   //owner/creator and session identifier
   //o=username session_id version network_type address_type address
   //ex : o=mumudvb 123134 1 IN IP4 235.255.215.1
-  //find a way ta create session id
+  //TODO find a way to create session id
   //for version we'll use sap version
   //o=....
 
-  sprintf(temp_string,"o=mumudvb %d %d IN IP4 %s\r\n", sap_message->version, sap_message->version, channel.ipOut);
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  sprintf(temp_string,"o=%s %d %d IN IP4 %s\r\n", sap_organisation, sap_serial, sap_message->version, channel.ipOut);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
   //session name (basically channel name)
   //s=...
-  sprintf(temp_string,"s=%s\r\n", channel.name);
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  sprintf(temp_string,"s=TEST%s\r\n", channel.name); //TODO : remove TEST
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
 
   //connection information
@@ -130,16 +141,16 @@ int sap_add_program(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_messag
   //c=...
 
   sprintf(temp_string,"o=%s/%d\r\n", channel.ipOut, DEFAULT_TTL);
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
   //time session is active
   //t=...
   //permanent : t=0 0
 
   sprintf(temp_string,"t=0 0\r\n");
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
   //attributes : group and co, we'll take the minisapserver ones
   //a=...
@@ -147,27 +158,25 @@ int sap_add_program(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_messag
   //a=type:broadcast
   //a=x-plgroup: //channel's group
 
-  sprintf(temp_string,"a=tool:mumudvb-VERSION\r\n");
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  sprintf(temp_string,"a=tool:mumudvb-%s\r\n", VERSION);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
   sprintf(temp_string,"a=type:broadcast\r\n");
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
 
   //media name and transport address
   //m=...
   //m=video channel_port udp mpeg
 
   sprintf(temp_string,"m=video %d udp mpeg\r\n", channel.portOut);
-  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, sizeof(temp_string));
-  payload_len+=sizeof(temp_string);
+  memcpy(sap_message->buf + sap_message->len + payload_len, temp_string, strlen(temp_string));
+  payload_len+=strlen(temp_string);
   
-  //TODO : display the message for debug
-
   log_message(MSG_DEBUG,"DEBUG : SAP payload\n");
-  log_message(MSG_DEBUG,sap_message->buf + sap_message->len);
-  log_message(MSG_DEBUG,"DEBUG : end of SAP payload\n");
+  log_message(MSG_DEBUG, &sap_message->buf[sap_message->len]);
+  log_message(MSG_DEBUG,"DEBUG : end of SAP payload\n\n");
 
   sap_message->len+=payload_len;
 
diff --git a/src/sap.h b/src/sap.h
index 8011141..3ad88c7 100644
--- a/src/sap.h
+++ b/src/sap.h
@@ -51,7 +51,15 @@ typedef struct{
   int to_be_sent;
 }mumudvb_sap_message_t;
 
+char sap_organisation[256];
 
+struct sockaddr_in sap_sOut;
+int sap_socketOut;
+
+int sap_serial;
+long sap_last_time_sent;
+
+void sap_send(mumudvb_sap_message_t *sap_messages, int num_messages);
 int sap_update(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_message);
 int sap_add_program(mumudvb_channel_t channel, mumudvb_sap_message_t *sap_message);
 

-- 
Mumudvb packaging



More information about the pkg-vdr-dvb-changes mailing list