Example #1
0
   main(int argc, char **argv)
      {
      int i;

      if (argc != 2)
         {
         fprintf(stderr, "usage: %s logfilename\n", argv[0]);
         exit(1);
         }

      if (strcmp(argv[1], "syslogd") == 0)
         {
         rtp_loginit(argv[1], LOG_LOCAL1, NULL, argv[0]);
         }
      else
         {
         rtp_loginit(argv[1], 0, NULL, argv[0]);
         }

      for (i = 0; i < 1024; i++)
         rtp_log(RTP_INFO, "duplicate message\n");

      while (1)
         {
         rtp_log(RTP_INFO, "log entry %d\n", i++);
         sleep(1);
         }
   } /* end main() */
Example #2
0
void WriteToOrb(SERVER *orb, UINT8 *das, int verbose, BOOL UseLoc)
{
static int count = 0;
double samprate, tstamp;
char buf[256];
struct reftek_dt dt;
int nbytes;
char *packet;
static int packetsz = 0;
static char srcname[ORBSRCNAME_SIZE];
static char *fid = "WriteToOrb";

/* Only deal with DT packets for which we can get sample rate */

    if (reftek_type(das) != REFTEK_DT) return;

    if (!reftek_dt(&dt, das, TRUE)) {
        rtp_log(RTP_ERR, "%s: DAS pkt dropped (can't decode)\n", fid);
        return;
    }

    if (!DeriveSampleRate(&dt, &samprate)) {
        rtp_log(RTP_ERR, "%s: DAS pkt dropped (unknown sample rate): %s\n",
            fid, reftek_str(das, buf)
        );
        return;
    }

/* Note decompression errors, if any */

    if (dt.dcerr) rtp_log(RTP_ERR, "%s: decompression error %d: %s\n",
        fid, dt.dcerr, reftek_str(das, buf)
    );

/* Convert to GENC format and send to ORB */

    ConvertPacket(&dt, samprate, UseLoc);

    if (stuffPkt(Pkt, srcname, &tstamp, &packet, &nbytes, &packetsz) < 0) {
        rtp_log(RTP_ERR, "stuffPkt routine failed for %s\n", Pkt->pkttype->name);
        return;
    }
    ++count;

    if (verbose) {
        showPkt(0, srcname, tstamp, packet, nbytes, stdout, PKT_TERSE);
    }

    if (orbput(orb->fd, srcname, dt.tstamp, packet, nbytes) != 0) {
        rtp_log(RTP_ERR, "orbput fails\n");
    }
}
VOID rtp_cmdpkt_decode(UINT8 *buf, RTP_CMDPKT *cmdpkt)
{
UINT16 stmp; size_t slen = 2;
UINT8 *ptr;
static CHAR *fid = "rtp_cmdpkt_decode";

    if (buf == (UINT8 *) NULL || cmdpkt == (RTP_CMDPKT *) NULL) {
        rtp_log(RTP_ERR, "%s: null input(s)", fid);
        errno = EINVAL;
    }

    ptr = buf;

    memcpy((void *) &stmp, (void *) ptr, slen);
    cmdpkt->unit = (UINT16) ntohs((u_short) stmp);
    ptr += slen;

    memcpy((void *) &stmp, (void *) ptr, slen);
    cmdpkt->len = (UINT16) ntohs((u_short) stmp);
    ptr += slen;

    if (cmdpkt->len > RTP_MAXMSGLEN) cmdpkt->len = RTP_MAXMSGLEN;

    memcpy((void *) cmdpkt->data, (void *) ptr, cmdpkt->len);

    return;
}
Example #4
0
/**
 * return used bandwidth

 */
int rtp_open_capables(media_format_t *mf, rtpcap_set_t *rtpcapset, media_control_t *ctrl, char *mode, int bandwidth)
{
   int sno=0;
   rtp_stream_t *strm;

   rtpcap_descript_t *rtpcap;
   xlist_user_t u;

   rtp_format_t *rtp = (rtp_format_t *)mf;

   rtp_log(("rtp_open_capables: open %d capables\n", xlist_size(rtpcapset->rtpcaps)));
   
   if(strlen(mode) >= MAX_MODEBYTES)
   {
	   rtp_log(("rtp_open_capables: mode unacceptable\n"));
	   return MP_INVALID;
   }

   strcpy(mf->default_mode, mode);
   mf->control = ctrl;

   rtp->rtp_in = (dev_rtp_t*)ctrl->find_device(ctrl, "rtp", "input");

	rtp_log(("rtp_open_capables: bandwidth[%d]\n", bandwidth));

   rtpcap = xlist_first(rtpcapset->rtpcaps, &u);
   while(rtpcap)
   {
	   if(rtpcapset->rtpcap_selection == RTPCAP_ALL_CAPABLES || (rtpcapset->rtpcap_selection == RTPCAP_SELECTED_CAPABLES && rtpcap->enable))
	   {
			strm = rtp_open_stream(rtp, sno++, rtpcap, ctrl, mode, bandwidth, rtpcapset);
			if(strm)
			{
				rtp_log(("rtp_open_capables: stream bandwidth[%d]\n", strm->bandwidth));
				bandwidth -= strm->bandwidth;
			}
	   }
	   else
			rtp_log(("rtp_open_capables: mime[%s] disabled\n", rtpcap->profile_mime));
	   
	   rtpcap = xlist_next(rtpcapset->rtpcaps, &u);
   }

   return rtp->bandwidth;
}
Example #5
0
int rtp_support_type (media_format_t *mf, char *type, char *subtype)
{
	if(!strcmp(type, "mime") && !strcmp(subtype, "application/sdp"))
	{
		rtp_log(("rtp_support_type: support mime:application/sdp\n"));
		return 1;
	}

	return 0;
}
Example #6
0
int rtp_new_all_player(media_format_t *mf, media_control_t* ctrl, char* mode, void* mode_param)
{
	int c=0;

	media_stream_t *cur = mf->first;

   if(!mode)
      mode = "rtp";

	while (cur != NULL)
	{
		cur->player = ctrl->find_player(ctrl, mode, cur->media_info->mime, cur->media_info->fourcc);

		if(!cur->player)
		{
			cur->playable = -1;

			rtp_log(("rtp_new_all_player: No %s player\n", cur->media_info->mime));
		}
		else if( cur->player->open_stream(cur->player, cur, cur->media_info) < MP_OK)
		{
			cur->playable = -1;

			rtp_log(("rtp_new_all_player: open %s stream fail!\n", cur->media_info->mime));

		}
		else
		{
			cur->playable = 1;
			c++;

			rtp_log(("ogm_new_mime_player: %s stream ok\n", cur->media_info->mime));
		}

		cur = cur->next;
	}

	return c;
}
Example #7
0
static BOOL peer_info(RTP *rtp)
{
int addrlen;
struct sockaddr_in cli_addr, *cli_addrp;
struct hostent *hp;
static CHAR *fid = "peer_info";

    addrlen = sizeof(cli_addr);
    cli_addrp = &cli_addr;
    if (getpeername(rtp->sd, (struct sockaddr *)cli_addrp, &addrlen) != 0) {
        rtp_log(RTP_ERR, "%s: getpeername: %s", fid, strerror(errno));
        return FALSE;
    }
    rtp->addr = (CHAR *) strdup(inet_ntoa(cli_addrp->sin_addr));
    MUTEX_LOCK(&mutex);
        hp = gethostbyaddr(
            (char *) &cli_addrp->sin_addr,
            sizeof(struct in_addr),
            cli_addrp->sin_family
        );
        if (hp != NULL) {
            rtp->peer = (CHAR *) strdup(hp->h_name);
        } else {
            rtp->peer = (CHAR *) strdup(rtp->addr);
        }
    MUTEX_UNLOCK(&mutex);

    if (rtp->peer == (CHAR *) NULL) {
        rtp_log(RTP_ERR, "%s: strdup: %s", fid, strerror(errno));
        return FALSE;
    }

    rtp->port = (UINT16) ntohs(cli_addr.sin_port);

    return TRUE;
}
Example #8
0
BOOL rtp_pid_decode(UINT8 *buf, INT32 *pid)
{
UINT32 ltmp; size_t llen = 4;
static CHAR *fid = "rtp_pid_decode";

    if (buf == (UINT8 *) NULL || pid == (INT32 *) NULL) {
        rtp_log(RTP_ERR, "%s: null input(s)", fid);
        return FALSE;
    }

    memcpy((void *) &ltmp, (void *) buf, llen);
    *pid = (INT32) ntohl((u_long) ltmp);

    return TRUE;
}
Example #9
0
int rtp_set_player (media_format_t * mf, media_player_t * player)
{
   int ret;
   char * type;

   type = player->media_type(player);
   if ( (ret = rtp_set_mime_player (mf, type, player)) >= MP_OK )
   {
      rtp_log (("rtp_set_player: '%s' stream playable\n", type));
      return ret;
   }
   
   type = player->codec_type(player);
   if ( (ret = rtp_set_mime_player (mf, type, player)) >= MP_OK )
   {
      rtp_log (("rtp_set_player: play '%s' stream\n", type));
      return ret;
   }

   rtp_debug(("rtp_set_player: can't play the media with player\n"));


   return ret;
}
Example #10
0
int rtp_stream_on_member_update(void *gen, uint32 ssrc, char *cn, int cnlen)
{
   media_stream_t *strm = (media_stream_t*)gen;
   rtp_stream_t *rtpstrm = (rtp_stream_t*)gen;

   if(strcmp(rtpstrm->source_cname, cn) != 0)
   {
      rtp_log(("rtp_stream_on_member_update: start stream[%s]\n", cn));
      rtpstrm->source_cname = xstr_clone(cn);
   }

   rtp_debug(("\rrtp_stream_on_member_update: stream[%s] ok\n\n\n", cn));   
   strm->start(strm);
   
   return MP_OK;
}
Example #11
0
BOOL rtp_cmdpkt_send(RTP *rtp, RTP_CMDPKT *cmdpkt)
{
INT32  datlen;
UINT8 msg[sizeof(RTP_CMDPKT)];
static CHAR *fid = "rtp_cmdpkt_send";

    if (rtp == (RTP *) NULL || cmdpkt == (RTP_CMDPKT *) NULL) {
        rtp_log(RTP_ERR, "%s: null input(s)", fid);
        errno = EINVAL;
        return FALSE;
    }

    datlen = rtp_cmdpkt_encode(msg, cmdpkt);

    return rtp_send(rtp, msg, RTP_MSG_CMDPKT, datlen);
}
Example #12
0
int rtp_set_mime_player (media_format_t * mf, char * mime, media_player_t * player)
{
   media_stream_t *cur = mf->first; 

   while (cur != NULL)
   {
      if (!strcmp(cur->mime, mime))
	  {
         cur->player = player;

         return MP_OK;
      }

      cur = cur->next;
   }

   rtp_log(("rtp_set_mime_player: stream '%s' not exist\n", mime));
   
   return MP_FAIL;
}
Example #13
0
/* New stream add to group */
int rtp_add_stream(media_format_t * rtp, media_stream_t *strm, int strmno, unsigned char type)
{
  media_stream_t *cur = rtp->first;

  if (rtp->first == NULL)
  {
    rtp->first = strm;
    rtp->first->next = NULL;
  }
  else
  {
    cur = rtp->first;
    while (cur->next != NULL)
      cur = cur->next;

    cur->next = strm;
    strm->next = NULL;
  }

  switch(type)
  {
      case(MP_AUDIO): rtp->nastreams++;
      
      /* default first audio stream as time reference */
      if (rtp->nastreams == 1)
		{
			rtp_log(("rtp_add_stream: stream #%d as default time stream\n", rtp->numstreams));
            rtp->time_ref = strmno;
      }
                  
      break;
               
      case(MP_VIDEO): rtp->nvstreams++; break;
    
      case(MP_TEXT): rtp->ntstreams++; break;
   }

   rtp->numstreams++;

   return MP_OK;
}
Example #14
0
media_player_t* rtp_new_stream_player(media_format_t *mf, int strmno, media_control_t* ctrl, char* mode, void* mode_param)
{
	media_stream_t *cur = mf->first;

   if(!mode)
      mode = "rtp";

	while (cur != NULL)
	{
		rtp_stream_t* rtp_strm = (rtp_stream_t*)cur;
		if (rtp_strm->sno == strmno)
		{
			cur->player = ctrl->find_player(ctrl, mode, cur->media_info->mime, cur->media_info->fourcc);

			if(!cur->player)
			{
				rtp_debug(("rtp_new_stream_player: stream can't be played\n"));
				cur->playable = -1;
				return NULL;

			}

			if( cur->player->open_stream(cur->player, cur, cur->media_info) < MP_OK)
			{
				cur->playable = -1;
				return NULL;
			}

			cur->playable = 1;

			rtp_log(("rtp_new_stream_player: player ok\n"));

			return cur->player;
		}

		cur = cur->next;
	}


	return NULL;
}
Example #15
0
int rtp_set_fourcc_player (media_format_t * mf, media_player_t * player, const char *fourcc)
{
   media_stream_t *cur = mf->first;

   while (cur != NULL)
   {
      if ( !strncmp(cur->fourcc, fourcc, 4) )
	   {
         cur->player = player;

         return MP_OK;
      }

      cur = cur->next;
   }

   rtp_log(("rtp_set_fourcc_player: stream [%c%c%c%c] not exist\n"
                  , fourcc[0], fourcc[1], fourcc[2], fourcc[3]));

   return MP_FAIL;
}
Example #16
0
media_player_t * rtp_new_mime_player(media_format_t * mf, char * mime, media_control_t* ctrl, char* mode, void* mode_param)
{
	media_stream_t *cur = mf->first;

    if(!mode)
        mode = "rtp";

	while (cur != NULL)
	{
		if (!strcmp(cur->mime, mime))
		{
			cur->player = ctrl->find_player(ctrl, mode, mime, NULL);

			if(!cur->player)
			{
				rtp_debug(("rtp_new_mime_player: stream can't be played\n"));
				cur->playable = -1;
				return NULL;
			}

			if( cur->player->open_stream(cur->player, cur, cur->media_info) < MP_OK)
			{
				cur->playable = -1;
				return NULL;
			}

			cur->playable = 1;

			rtp_log(("rtp_new_mime_player: player ok\n"));
		}

		cur = cur->next;
	}


	return NULL;
}
Example #17
0
module_interface_t * media_new_format()
{
   media_format_t * mf = NULL;

   rtp_format_t * rtp = xmalloc(sizeof(struct rtp_format_s));
   if(!rtp)
   {
      rtp_log(("rtp_new_rtp_group: No memery to allocate\n"));
      return NULL;
   }

   memset(rtp, 0, sizeof(struct rtp_format_s));

   rtp->open_capables = rtp_open_capables;

   mf = (media_format_t *)rtp;

   /* release a format */
   mf->done = rtp_done_format;

   mf->support_type = rtp_support_type;

   /* Open/Close a media source */
   mf->open = rtp_open;
   mf->close = rtp_close;

   /* Stream management */
   mf->add_stream = rtp_add_stream;
   
   mf->find_stream = rtp_find_stream;
   mf->find_mime = rtp_find_mime;
   mf->find_fourcc = rtp_find_fourcc;

   mf->set_control = rtp_set_control;

   mf->set_player = rtp_set_player;

   /* Stream info */
   mf->nstream = rtp_nstream;
   mf->stream_mime = rtp_stream_mime;
   mf->stream_fourcc = rtp_stream_fourcc;

   mf->stream_player = rtp_stream_player;
   mf->mime_player = rtp_mime_player;
   mf->fourcc_player = rtp_fourcc_player;

   mf->new_all_player = rtp_new_all_player;

   mf->new_stream_player = rtp_new_stream_player;
   mf->new_mime_player = rtp_new_mime_player;
   mf->set_mime_player = rtp_set_mime_player;


   mf->players = rtp_players;

   /* Seek the media by time */
   mf->seek_millisecond = rtp_seek_millisecond;

   /* demux next sync stream group */
   mf->demux_next = rtp_demux_next;

   return mf;

}
Example #18
0
static BOOL handshake(RTP *rtp)
{
UINT16 type;
INT16 client_version;
INT32 unused;
struct rtp_attr attr;
UINT8 msgbuf[RTP_MAXMSGLEN];
static CHAR *fid = "handshake";

/* Get the client protocol version number */
 
    rtp_log(RTP_DEBUG, "%s: read client protocol version", fid);
    if ((client_version = rtp_version_recv(rtp)) < 0) {
        rtp_log(RTP_ERR, "%s: rtp_version_recv: error %d",
            fid, client_version
        );
        return FALSE;
    }
    rtp_log(RTP_DEBUG, "%s: client version is %d", fid, client_version);

/* Send back our version number */
 
    rtp_log(RTP_DEBUG, "%s: send server protcol version %d",
        fid, RTP_VERSION
    );
    if (!rtp_version_send(rtp)) {
        rtp_log(RTP_ERR, "%s: rtp_version_send failed", fid);
        return FALSE;
    }

/* If the client is a higher version, protocol says quit now */
 
    if (client_version > RTP_VERSION) {
        rtp_log(RTP_ERR, "%s: unsupported protocol version (%d)",
            fid, client_version
        );
        return FALSE;
    }
 
/* Following is specific to protocol version */
 
    if (client_version == 1) {

    /* client should begin with its process id */

        if (!rtp_recv(rtp, msgbuf, &type, &unused)) {
            rtp_log(RTP_ERR, "%s: rtp_recv failed", fid);
            return FALSE;
        }

        if (type != RTP_MSG_PID) {
            rtp_log(RTP_ERR, "%s: unexpected message type %d != %d",
                fid, type, RTP_MSG_ATTR
            );
            errno = EPROTO;
            return FALSE;
        }

        rtp_pid_decode(msgbuf, &rtp->pid);
        rtp_log(RTP_DEBUG, "%s: client process id is %d", fid, rtp->pid);

    /* which we acknowledge with our process id */

        rtp_log(RTP_DEBUG, "%s: send pid ack", fid);
        if (!rtp_pid_send(rtp)) {
            rtp_log(RTP_ERR, "%s: rtp_pid_send failed", fid);
            return FALSE;
        }

    /* client should then send its attribute request */

        if (!rtp_recv(rtp, msgbuf, &type, &unused)) {
            rtp_log(RTP_ERR, "%s: rtp_recv failed", fid);
            return FALSE;
        }

        if (type != RTP_MSG_ATTR) {
            rtp_log(RTP_ERR, "%s: unexpected message type %d != %d",
                fid, type, RTP_MSG_ATTR
            );
            errno = EPROTO;
            return FALSE;
        }

        rtp_attr_decode(msgbuf, &attr);
        rtp_log(RTP_DEBUG, "%s: client attribute request received", fid);

    /* which will load in and echo back (maybe change it, too) */

        if (!set_attr(rtp, &attr)) {
            rtp_log(RTP_ERR, "%s: set_attr failed", fid);
            rtp_break(rtp);
            return FALSE;
        }

        rtp_log(RTP_DEBUG, "%s: send attribute ack", fid);
        if (!rtp_attr_send(rtp, &attr)) {
            return FALSE;
        }

    } else {
        rtp_log(RTP_ERR, "%s: unsupported protocol version (%d)",
            fid, client_version
        );
        errno = EPROTO;
        rtp_break(rtp);
        return FALSE;
    }

    rtp_log(RTP_DEBUG, "%s: handshake complete", fid);
    return TRUE;
}
Example #19
0
/* Can not seek, unless talk to server with rtsp */
int rtp_seek_millisecond (media_format_t *mf, int ms)
{
   rtp_log (("rtp_seek_millisecond: unseekable to %dms\n", ms));

   return 0;
}
Example #20
0
RTP *rtp_accept(RTP *server)
{
RTP *rtp;
struct sockaddr_in cli_addr;
int client, len = sizeof(cli_addr);
static CHAR *fid = "rtp_accept";
 
/* Create/fill the handle */
 
    if ((rtp = (RTP *) malloc(sizeof(RTP))) == (RTP *) NULL) {
        rtp_log(RTP_ERR, "%s: malloc: %s", fid, strerror(errno));
        return (RTP *) NULL;
    }

    rtp->sd   = server->sd;
    rtp->port = server->port;
    rtp->attr = server->attr;
    rtp->soh.sh_tstamp = -1;
    rtp->soh.sh_nslot  = RTP_DEFNSLOT;
    rtp->soh.sh_ndas   = 0;
    rtp->soh.sh_index  = -1;
    rtp->soh.sh_stat   = (struct rtp_stat *)
                         malloc(sizeof(struct rtp_stat)*rtp->soh.sh_nslot);
    if (rtp->soh.sh_stat == (struct rtp_stat *) NULL) {
        rtp_log(RTP_ERR, "%s: malloc: %s", fid, strerror(errno));
        free(rtp);
        return (RTP *) NULL;
    }

/* Accept a new connection */

    client = INVALID_SOCKET;
    while (client == INVALID_SOCKET) {
        client = accept(server->sd, (struct sockaddr *) &cli_addr, &len);
        if (client == INVALID_SOCKET && errno != EINTR) {
            rtp_log(RTP_ERR, "%s: accept: %s", fid, strerror(errno));
            free(rtp->soh.sh_stat);
            free(rtp);
            return (RTP *) NULL;
        }
    }

/* Complete the handle */

    rtp->sd = client;
    MUTEX_INIT(&rtp->rcv.mutex);
    MUTEX_INIT(&rtp->snd.mutex);
    if (!peer_info(rtp)) {
        rtp_log(RTP_DEBUG, "%s: peer_info failed", fid);
        free(rtp->soh.sh_stat);
        free(rtp);
        return (RTP *) NULL;
    }

/* Windows NT defaults non-blocking */

#ifndef WINNT
    if (fcntl(rtp->sd, F_SETFL, O_NONBLOCK) == -1) {
        rtp_log(RTP_ERR, "%s: fcntl: %s", fid, strerror(errno));
        free(rtp->soh.sh_stat);
        free(rtp);
        return (RTP *) NULL;
    }
#endif
    rtp_log(RTP_DEBUG, "%s: incoming connection from %s:%hu",
        fid, rtp->peer, rtp->port
    );

/* Do the handshake */

    if (!handshake(rtp)) {
        rtp_log(RTP_ERR, "%s: handshake failed", fid);
        free(rtp->soh.sh_stat);
        free(rtp);
        return (RTP *) NULL;
    }

/* Return handle for this connection */

    return rtp;
}
Example #21
0
rtp_stream_t* rtp_open_stream(rtp_format_t *rtp_format, int sno, rtpcap_descript_t *rtpcap, media_control_t *ctrl, char *mode, int bw_budget, void* extra)
{
	unsigned char stype;
	rtp_stream_t *strm;
   rtp_stream_t *peer;

   rtp_setting_t *rset = NULL;

   int rtp_portno, rtcp_portno;

	module_catalog_t *cata = ctrl->modules(ctrl);
   
	rtpcap_set_t* rtpcapset = (rtpcap_set_t*)extra;
	user_profile_t* user_prof = rtpcapset->user_profile;

	char* remote_nettype;
	char* remote_addrtype;
	char* remote_netaddr;

   if(strncmp(rtpcap->profile_mime, "audio", 5) == 0)
	{
		rtp_log(("rtp_open_stream: audio media\n"));

		stype = MP_AUDIO;
	}
	else if(strncmp(rtpcap->profile_mime, "video", 5) == 0)
	{
		rtp_log(("rtp_open_stream: video media type\n"));
		stype = MP_VIDEO;
	}
	else if(strncmp(rtpcap->profile_mime, "text", 4) == 0)
	{
		rtp_log(("rtp_open_stream: text media type\n"));
		stype = MP_TEXT;
	}
	else
	{
		rtp_debug(("rtp_open_stream: Unknown media type\n"));
		return NULL;
	}

	strm = xmalloc(sizeof(rtp_stream_t));
	if(!strm)
	{
		rtp_debug(("rtp_open_stream: No memory for rtp stream\n"));
		return NULL;
	}   

	peer = xmalloc(sizeof(rtp_stream_t));
	if(!peer)
	{
		rtp_debug(("rtp_open_stream: No memory for rtp stream\n"));
      xfree(strm);
		return NULL;
	}
   
	memset(strm, 0, sizeof(rtp_stream_t));
	memset(peer, 0, sizeof(rtp_stream_t));

   strm->stream.peer = (media_stream_t*)peer;
   peer->stream.peer = (media_stream_t*)strm;

	rset = (rtp_setting_t*)ctrl->fetch_setting(ctrl, "rtp", (media_device_t*)rtp_format->rtp_in);
	if(!rset)
	{
		rtp_debug(("rtp_open_stream: No rtp setting\n"));
		xfree(strm);
		return NULL;

	}

	strm->session = rtp_format->rtp_in->rtp_session(rtp_format->rtp_in, cata, ctrl,
									user_prof->cname, strlen(user_prof->cname)+1,
									user_prof->user->nettype, user_prof->user->addrtype, 
									user_prof->user->netaddr, 
									rset->default_rtp_portno, rset->default_rtcp_portno,
									rtpcap->profile_no, rtpcap->profile_mime, 
									rtpcap->clockrate, rtpcap->coding_param,
									bw_budget, rtpcap);

	if(!strm->session)
	{
		xfree(strm);
        
		rtp_debug(("rtp_open_stream: no session created\n"));

		return NULL;
	}

   strm->session->media_stream = strm;
	rtp_debug(("\rrtp_open_stream: strm@%x\n", (int)strm));

	/* get real portno and payload type */
	session_portno(strm->session, &rtp_portno, &rtcp_portno);
	rtpcap->profile_no = session_payload_type(strm->session);

	strm->rtp_format = rtp_format;
	peer->rtp_format = rtp_format;

   strm->rtp_cap = rtpcap;
   peer->rtp_cap = rtpcap;

   strm->stream.media_info = session_mediainfo(strm->session);
   peer->stream.media_info = strm->stream.media_info;
   
   peer->session = strm->session;
   
   strm->stream.start = rtp_start_stream;
   strm->stream.stop = rtp_stop_stream;
   
   peer->stream.start = rtp_start_stream;
   peer->stream.stop = rtp_stop_stream;

	rtp_log(("rtp_open_stream: FIXME - stream mime string overflow possible!!\n"));
	strcpy(strm->stream.mime, rtpcap->profile_mime);

	rtp_add_stream((media_format_t*)rtp_format, (media_stream_t*)strm, sno, stype);

	if(rtpcap->netaddr)
	{
		remote_nettype = rtpcap->nettype;
		remote_addrtype = rtpcap->addrtype;
		remote_netaddr = rtpcap->netaddr;
	}
	else
	{
		remote_nettype = rtpcapset->nettype;
		remote_addrtype = rtpcapset->addrtype;
		remote_netaddr = rtpcapset->netaddr;
	}
	
	rtp_log(("rtp_open_stream: for %s:%s(%u|%u)\n", rtpcapset->cname, remote_netaddr, rtpcap->rtp_portno, rtpcap->rtcp_portno));
	rtp_log(("rtp_open_stream: mime[%s] pt[%d]\n", rtpcap->profile_mime, rtpcap->profile_no));
   
	session_add_cname(strm->session, rtpcapset->cname, strlen(rtpcapset->cname), remote_netaddr, rtpcap->rtp_portno, rtpcap->rtcp_portno, rtpcap, ctrl);
	
	/* waiting to source to be available */
	strm->source_cname = xstr_clone(rtpcapset->cname);
	strm->bandwidth = session_bandwidth(strm->session);
   
	peer->source_cname = xstr_clone(user_prof->cname);
	peer->bandwidth = strm->bandwidth;

	rtp_format->bandwidth += strm->bandwidth + peer->bandwidth;

	session_set_callback(strm->session, CALLBACK_SESSION_MEMBER_UPDATE, rtp_stream_on_member_update, strm);

	rtp_log(("rtp_open_stream: stream opened, bandwidth[%d]\n", strm->bandwidth));

	return strm;
}
Example #22
0
BOOL decode_steim( VOID *ptr, INT16 *n, INT32 *samples, INT32 *prev ) {
   BOOL  skip_ird;
   INT8 f_ndx, c_ndx, n_difs;
   INT16 i, n_samp;
   INT32 sum, difs[4], fi_con, ri_con;
   UINT32 flags;
   STEIM *rec;

   n_samp = *n;

   /* Get the integration constants */
   rec = (STEIM *)((INT8 *)ptr+64);
   fi_con = swap_l( rec->frame[0].chunk[0].l );
   ri_con = swap_l( rec->frame[0].chunk[1].l );

   /* Init the running sum and save the first sample */
   sum = fi_con;
   n_samp--;
   *samples++ = sum;

   /* Skip the inter-record delta, i.e., the difference between records */
   skip_ird = TRUE;

   /* Process up to 15 frames */
   for( f_ndx=0; f_ndx<15; f_ndx++ ) {

      /* Get the frame flags */
      flags = swap_l( rec->frame[f_ndx].flags );

      /* Process 15 chunks per frame */
      for( c_ndx=0; c_ndx<15; c_ndx++ ) {

         /* Count down samples to 0 */
         if( n_samp <= 0 )
            break;

         /* Process a chunk based on type */
         switch( _chunk_type( flags, c_ndx ) ) {

            case CHUNK_NULL:
               continue;

            case CHUNK_BYTES:
               for( i=0; i<4; i++ )
                  difs[i] = (INT32)rec->frame[f_ndx].chunk[c_ndx].b[i];
               n_difs = 4;
               break;

            case CHUNK_WORDS:
               for( i=0; i<2; i++ )
                  difs[i] = (INT32)swap_w( rec->frame[f_ndx].chunk[c_ndx].w[i] );
               n_difs = 2;
               break;

            case CHUNK_LONG:
               difs[0] = swap_l( rec->frame[f_ndx].chunk[c_ndx].l );
               n_difs = 1;
               break;
         }

         /* Save the decoded samples */
         for( i=0; i<n_difs; i++ ) {
            if( skip_ird ) {
               skip_ird = FALSE;
               *prev = fi_con - difs[0];
//               *prev = 0;
            }
            else {
               sum += difs[i];
               *samples++ = sum;
               n_samp--;
               if( n_samp <= 0 )
                  break;
            }
         }
      }
   }

   if( n_samp > 0 ) {
#ifdef DEBUG
      printf( "WARNING: Partial decompression of sample data, n_samp = %d\n", n_samp );
#endif
      rtp_log(RTP_WARN, "WARNING: Partial decompression of sample data, n_samp = %d\n", n_samp );
      *n = n_samp;
      return( FALSE );
   }

   if( sum != ri_con ) {
#ifdef DEBUG
      printf( "WARNING: Unreconciled reverse integrating constant: %ld, sum: %ld\n",
         ri_con, sum );
#endif
      rtp_log(RTP_WARN, "WARNING: Unreconciled reverse integrating constant: %ld, sum: %ld\n",
         ri_con, sum );
      return( FALSE );
   }

   return( TRUE );
}