[MPlayer-cvslog] r18795 - in trunk/libmpdemux/realrtsp: real.c real.h rtsp_session.c

ben subversion at mplayerhq.hu
Fri Jun 23 21:30:16 CEST 2006


Author: ben
Date: Fri Jun 23 21:30:15 2006
New Revision: 18795

Modified:
   trunk/libmpdemux/realrtsp/real.c
   trunk/libmpdemux/realrtsp/real.h
   trunk/libmpdemux/realrtsp/rtsp_session.c

Log:
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer

Modified: trunk/libmpdemux/realrtsp/real.c
==============================================================================
--- trunk/libmpdemux/realrtsp/real.c	(original)
+++ trunk/libmpdemux/realrtsp/real.c	Fri Jun 23 21:30:15 2006
@@ -59,6 +59,8 @@
 #define MAX(x,y) ((x>y) ? x : y)
 #endif
 
+#define BUF_SIZE 4096
+
 #ifdef LOG
 static void hexdump (const char *buf, int length) {
 
@@ -846,3 +848,24 @@
   buf = xbuffer_free(buf);
   return h;
 }
+
+struct real_rtsp_session_t *
+init_real_rtsp_session (void)
+{
+  struct real_rtsp_session_t *real_rtsp_session = NULL;
+
+  real_rtsp_session = malloc (sizeof (struct real_rtsp_session_t));
+  real_rtsp_session->recv = xbuffer_init (BUF_SIZE);
+
+  return real_rtsp_session;
+}
+
+void
+free_real_rtsp_session (struct real_rtsp_session_t* real_session)
+{
+  if (!real_session)
+    return;
+  
+  xbuffer_free (real_session->recv);
+  free (real_session);
+}

Modified: trunk/libmpdemux/realrtsp/real.h
==============================================================================
--- trunk/libmpdemux/realrtsp/real.h	(original)
+++ trunk/libmpdemux/realrtsp/real.h	Fri Jun 23 21:30:15 2006
@@ -33,6 +33,20 @@
 #include "rmff.h"
 #include "rtsp.h"
 
+#define HEADER_SIZE 4096
+
+struct real_rtsp_session_t {
+  /* receive buffer */
+  uint8_t *recv;
+  int recv_size;
+  int recv_read;
+
+  /* header buffer */
+  uint8_t header[HEADER_SIZE];
+  int header_len;
+  int header_read;
+};
+
 /*
  * calculates response and checksum of a given challenge
  * (RealChallenge1 in rtsp). See implementation for details.
@@ -41,6 +55,8 @@
 int real_get_rdt_chunk(rtsp_t *rtsp_session, char **buffer);
 rmff_header_t *real_parse_sdp(char *data, char **stream_rules, uint32_t bandwidth);
 rmff_header_t *real_setup_and_get_header(rtsp_t *rtsp_session, uint32_t bandwidth);
+struct real_rtsp_session_t *init_real_rtsp_session (void);
+void free_real_rtsp_session (struct real_rtsp_session_t* real_session);
 
 #endif
 

Modified: trunk/libmpdemux/realrtsp/rtsp_session.c
==============================================================================
--- trunk/libmpdemux/realrtsp/rtsp_session.c	(original)
+++ trunk/libmpdemux/realrtsp/rtsp_session.c	Fri Jun 23 21:30:15 2006
@@ -52,35 +52,23 @@
 #define LOG
 */
 
-#define BUF_SIZE 4096
-#define HEADER_SIZE 4096
-
 struct rtsp_session_s {
-
   rtsp_t       *s;
-
-  /* receive buffer */
-  uint8_t       *recv;
-  int           recv_size;
-  int           recv_read;
-
-  /* header buffer */
-  uint8_t       header[HEADER_SIZE];
-  int           header_len;
-  int           header_read;
-
+  struct real_rtsp_session_t* real_session;
 };
 
 //rtsp_session_t *rtsp_session_start(char *mrl) {
 rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth) {
 
-  rtsp_session_t *rtsp_session=malloc(sizeof(rtsp_session_t));
+  rtsp_session_t *rtsp_session = NULL;
   char *server;
   char *mrl_line = NULL;
   rmff_header_t *h;
 
-  rtsp_session->recv = xbuffer_init(BUF_SIZE);
-
+  rtsp_session = malloc (sizeof (rtsp_session_t));
+  rtsp_session->s = NULL;
+  rtsp_session->real_session = NULL;
+ 
 //connect:
   *redir = 0;
 
@@ -89,7 +77,6 @@
   if (!rtsp_session->s)
   {
     printf("rtsp_session: failed to connect to server %s\n", path);
-    rtsp_session->recv = xbuffer_free(rtsp_session->recv);
     free(rtsp_session);
     return NULL;
   }
@@ -128,24 +115,29 @@
       {
         printf("rtsp_session: session can not be established.\n");
         rtsp_close(rtsp_session->s);
-        rtsp_session->recv = xbuffer_free(rtsp_session->recv);
+        free (server);
         free(rtsp_session);
         return NULL;
       }
     }
 	
-    rtsp_session->header_len=rmff_dump_header(h,rtsp_session->header,1024);
-
-    rtsp_session->recv = xbuffer_copyin(rtsp_session->recv, 0, rtsp_session->header, rtsp_session->header_len);
-    rtsp_session->recv_size = rtsp_session->header_len;
-    rtsp_session->recv_read = 0;
-    
+    rtsp_session->real_session = init_real_rtsp_session ();
+    rtsp_session->real_session->header_len =
+      rmff_dump_header (h, (char *) rtsp_session->real_session->header, 1024);
+
+    rtsp_session->real_session->recv =
+      xbuffer_copyin (rtsp_session->real_session->recv, 0,
+                      rtsp_session->real_session->header,
+                      rtsp_session->real_session->header_len);
+
+    rtsp_session->real_session->recv_size =
+      rtsp_session->real_session->header_len;
+    rtsp_session->real_session->recv_read = 0;
   } else
   {
     printf("rtsp_session: Not a Real server. Server type is '%s'.\n",server);
     rtsp_close(rtsp_session->s);
     free(server);
-    rtsp_session->recv = xbuffer_free(rtsp_session->recv);
     free(rtsp_session);
     return NULL;
   }
@@ -156,10 +148,12 @@
 
 int rtsp_session_read (rtsp_session_t *this, char *data, int len) {
   
+  if (this->real_session) {
   int to_copy=len;
   char *dest=data;
-  char *source=this->recv + this->recv_read;
-  int fill=this->recv_size - this->recv_read;
+  char *source =
+    (char *) (this->real_session->recv + this->real_session->recv_read);
+  int fill = this->real_session->recv_size - this->real_session->recv_read;
 
   if (len < 0) return 0;
   while (to_copy > fill) {
@@ -167,14 +161,15 @@
     memcpy(dest, source, fill);
     to_copy -= fill;
     dest += fill;
-    this->recv_read = 0;
-    this->recv_size = real_get_rdt_chunk (this->s, (char **)&(this->recv));
-    if (this->recv_size < 0)
+    this->real_session->recv_read = 0;
+    this->real_session->recv_size =
+      real_get_rdt_chunk (this->s, (char **)&(this->real_session->recv));
+    if (this->real_session->recv_size < 0)
       return -1;
-    source = this->recv;
-    fill = this->recv_size;
+    source = (char *) this->real_session->recv;
+    fill = this->real_session->recv_size;
 
-    if (this->recv_size == 0) {
+    if (this->real_session->recv_size == 0) {
 #ifdef LOG
       printf ("librtsp: %d of %d bytes provided\n", len-to_copy, len);
 #endif
@@ -183,28 +178,38 @@
   }
   
   memcpy(dest, source, to_copy);
-  this->recv_read += to_copy;
+  this->real_session->recv_read += to_copy;
 
 #ifdef LOG
   printf ("librtsp: %d bytes provided\n", len);
 #endif
 
   return len;
+  }
+
+  return 0;
 }
 
 int rtsp_session_peek_header(rtsp_session_t *this, char *buf, int maxsize) {
 
   int len;
 
-  len = (this->header_len < maxsize) ? this->header_len : maxsize;
+  if (this->real_session)
+  {
+  len = (this->real_session->header_len < maxsize)
+    ? this->real_session->header_len : maxsize;
 
-  memcpy(buf, this->header, len);
+  memcpy(buf, this->real_session->header, len);
   return len;
+  }
+
+  return 0;
 }
 
 void rtsp_session_end(rtsp_session_t *session) {
 
   rtsp_close(session->s);
-  session->recv = xbuffer_free(session->recv);
+  if (session->real_session)
+    free_real_rtsp_session (session->real_session);
   free(session);
 }



More information about the MPlayer-cvslog mailing list