Example #1
0
int load_GSM(media_entry *p) {

	unsigned char byte1;
	int ret;
	
	if (!(p->description.flags & MED_PKT_LEN)) {
                                p->description.pkt_len=20; /* By default for GSM */
                                p->description.delta_mtime=p->description.pkt_len;
                                p->description.flags|=MED_PKT_LEN;
	}
	if ( (ret=mediaopen(p)) < 0)
		return ret;
        if (read(p->fd,&byte1,1) != 1) return ERR_PARSE;
        mediaclose(p);

        switch (byte1 & 0x07) {
                case 0: p->description.bitrate = 4750; break;
                case 1: p->description.bitrate = 5150; break;
                case 2: p->description.bitrate = 5900; break;
                case 3: p->description.bitrate = 6700; break;
                case 4: p->description.bitrate = 7400; break;
                case 5: p->description.bitrate = 7950; break;
                case 6: p->description.bitrate = 10200; break;
                case 7: p->description.bitrate = 12200; break;
        }       
        p->description.flags|=MED_BITRATE;      

        return ERR_NOERROR;
}
RTP_session *RTP_session_destroy(RTP_session * session)
{
	RTP_session *next = session->next;
	OMSBuffer *buff = session->current_media->pkt_buffer;
	//struct stat fdstat;

	RTP_transport_close(session);
	//Release SD_flag using in multicast and unjoing the multicast group
	// if(session->sd_descr->flags & SD_FL_MULTICAST){

	// destroy consumer
	OMSbuff_unref(session->cons);
	if (session->current_media->pkt_buffer->control->refs == 0) {
		session->current_media->pkt_buffer = NULL;
		OMSbuff_free(buff);
		// close file if it's not a pipe
		//fstat(session->current_media->fd, &fdstat);
		//if ( !S_ISFIFO(fdstat.st_mode) )
		mediaclose(session->current_media);
	}
	// Deallocate memory
	free(session);

	return next;
}
Example #3
0
RTP_session *RTP_session_destroy(RTP_session *session)
{
	RTP_session *next = session->next;
	OMSBuffer *buff = session->current_media->pkt_buffer;
	//struct stat fdstat;

	// shawill: close socket. To be moved in a specific function (RTP_transport_close)
	//Release SD_flag using in multicast and unjoing the multicast group
	// if(session->sd_descr->flags & SD_FL_MULTICAST){
	if( (session->transport.type==RTP_rtp_avp) && session->transport.u.udp.is_multicast) {
		struct ip_mreq mreq;
		mreq.imr_multiaddr.s_addr = inet_addr(session->sd_descr->multicast);
		mreq.imr_interface.s_addr = INADDR_ANY;
		setsockopt(session->transport.rtp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
		session->sd_descr->flags &= ~SD_FL_MULTICAST_PORT; /*Release SD_FL_MULTICAST_PORT*/
	}
	
	switch (session->transport.type) {
		case RTP_rtp_avp:
			// we must close socket only if we use udp, because for interleaved tcp
			// we use rtsp that must not be closed here.
			close(session->transport.rtp_fd);
			close(session->transport.rtcp_fd_in);
			close(session->transport.rtcp_fd_out);
			// release ports
			RTP_release_port_pair(&(session->transport.u.udp.ser_ports));
			break;
		case RTP_rtp_avp_tcp:
			session->transport.rtp_fd = session->transport.rtcp_fd_out = -1;
			break;
		default:
			break;
	}
	
	// destroy consumer
	OMSbuff_unref(session->cons);
	if (session->current_media->pkt_buffer->control->refs==0) {
			session->current_media->pkt_buffer=NULL;
			OMSbuff_free(buff);
			// close file if it's not a pipe
			//fstat(session->current_media->fd, &fdstat);
			//if ( !S_ISFIFO(fdstat.st_mode) )
				mediaclose(session->current_media);
	}
	// Deallocate memory
	free(session);

	return next;
}
Example #4
0
int load_MPA(media_entry *p)
{
	int ret;
	long int tag_dim;
        int n,RowIndex, ColIndex;
        int BitrateMatrix[16][5] = {
                {0,     0,     0,     0,     0     },
                {32000, 32000, 32000, 32000, 8000  },
                {64000, 48000, 40000, 48000, 16000 },
                {96000, 56000, 48000, 56000, 24000 },
                {128000,64000, 56000, 64000, 32000 },
                {160000,80000, 64000, 80000, 40000 },
                {192000,96000, 80000, 96000, 48000 },
                {224000,112000,96000, 112000,56000 },
                {256000,128000,112000,128000,64000 },
                {288000,160000,128000,144000,80000 },
                {320000,192000,160000,160000,96000 },
                {352000,224000,192000,176000,112000},
                {384000,256000,224000,192000,128000},
                {416000,320000,256000,224000,144000},
                {448000,384000,320000,256000,160000},
                {0,     0,     0,     0,     0     }
        };

	fnc_log(FNC_LOG_DEBUG, "loading MPA...\n");

	if ( (ret=mediaopen(p)) < 0)
		return ret;
        
	
	p->buff_size=0;
	if ( (p->buff_size = read(p->fd, p->buff_data, 4)) != 4) return ERR_PARSE;

	// shawill: look if ID3 tag is present
	if (!memcmp(p->buff_data, "ID3", 3)) { // ID3 tag present
		n = read_dim(p->fd, &tag_dim); // shawill: one day we will look also at this function
		printf("%ld\n",tag_dim);
		p->description.flags|=MED_ID3;
		p->description.tag_dim=tag_dim;
		lseek(p->fd,tag_dim,SEEK_CUR);
		if ( (p->buff_size = read(p->fd, p->buff_data, 4)) != 4) return ERR_PARSE;
	}
        
	//fstat(p->fd, &fdstat);
	//if ( !S_ISFIFO(fdstat.st_mode) ) {
		mediaclose(p);
		// close(p->fd);
		p->buff_size = 4;
	//}
        
	if (! ((p->buff_data[0]==0xff) && ((p->buff_data[1] & 0xe0)==0xe0))) return ERR_PARSE;

        switch (p->buff_data[1] & 0x1e) {                /* Mpeg version and Level */
                case 18: ColIndex = 4; break;  /* Mpeg-2 L3 */
                case 20: ColIndex = 4; break;  /* Mpeg-2 L2 */
                case 22: ColIndex = 3; break;  /* Mpeg-2 L1 */
                case 26: ColIndex = 2; break;  /* Mpeg-1 L3 */
                case 28: ColIndex = 1; break;  /* Mpeg-1 L2 */
                case 30: ColIndex = 0; break;  /* Mpeg-1 L1 */
                default: {
				 return ERR_PARSE;
			 }
        }

        RowIndex = (p->buff_data[2] & 0xf0) / 16;
        p->description.bitrate = BitrateMatrix[RowIndex][ColIndex];
        p->description.flags|=MED_BITRATE;      

        if (p->buff_data[1] & 0x08) {     /* Mpeg-1 */
                switch (p->buff_data[2] & 0x0c) {
                        case 0x00: p->description.sample_rate=44100; break;
                        case 0x04: p->description.sample_rate=48000; break;
                        case 0x08: p->description.sample_rate=32000; break;
                	default: {
				 return ERR_PARSE;
			 }
                }
        } else {                /* Mpeg-2 */
                // switch (sync3 & 0x0c) {
                switch (p->buff_data[2] & 0x0c) {
                        case 0x00: p->description.sample_rate=22050; break;
                        case 0x04: p->description.sample_rate=24000; break;
                        case 0x08: p->description.sample_rate=16000; break;
                	default: {
				 return ERR_PARSE;
			 }
                }
        }
        p->description.flags|=MED_SAMPLE_RATE;          

        if ((p->buff_data[1] & 0x06) == 6)
		p->description.frame_len = 384;
        else
		p->description.frame_len = 1152;

        p->description.flags|=MED_FRAME_LEN;
        p->description.pkt_len=(double)p->description.frame_len/(double)p->description.sample_rate*1000;
        p->description.delta_mtime=p->description.pkt_len;
        p->description.flags|=MED_PKT_LEN;

        return ERR_NOERROR;
}