2
The mediastreamer library aims at providing modular media processing and I/O
3
for linphone, but also for any telephony application.
4
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
#include "msrtprecv.h"
25
/* some utilities to convert mblk_t to MSMessage and vice-versa */
26
MSMessage *msgb_2_ms_message(mblk_t* mp){
29
if (mp->b_datap->ref_count!=1) return NULL; /* cannot handle properly non-unique buffers*/
30
/* create a MSBuffer using the mblk_t buffer */
31
msg=ms_message_alloc();
32
msbuf=ms_buffer_alloc(0);
33
msbuf->buffer=mp->b_datap->db_base;
34
msbuf->size=(char*)mp->b_datap->db_lim-(char*)mp->b_datap->db_base;
35
ms_message_set_buf(msg,msbuf);
36
msg->size=mp->b_wptr-mp->b_rptr;
45
static MSRtpRecvClass *ms_rtp_recv_class=NULL;
47
MSFilter * ms_rtp_recv_new(void)
53
if (ms_rtp_recv_class==NULL)
55
ms_rtp_recv_class=g_new(MSRtpRecvClass,1);
56
ms_rtp_recv_class_init(ms_rtp_recv_class);
58
MS_FILTER(r)->klass=MS_FILTER_CLASS(ms_rtp_recv_class);
64
void ms_rtp_recv_init(MSRtpRecv *r)
66
ms_filter_init(MS_FILTER(r));
67
MS_FILTER(r)->outfifos=r->f_outputs;
68
MS_FILTER(r)->outqueues=r->q_outputs;
69
memset(r->f_outputs,0,sizeof(MSFifo*)*MSRTPRECV_MAX_OUTPUTS);
70
memset(r->q_outputs,0,sizeof(MSFifo*)*MSRTPRECV_MAX_OUTPUTS);
75
void ms_rtp_recv_class_init(MSRtpRecvClass *klass)
77
ms_filter_class_init(MS_FILTER_CLASS(klass));
78
ms_filter_class_set_name(MS_FILTER_CLASS(klass),"RTPRecv");
79
MS_FILTER_CLASS(klass)->max_qoutputs=MSRTPRECV_MAX_OUTPUTS;
80
MS_FILTER_CLASS(klass)->max_foutputs=MSRTPRECV_MAX_OUTPUTS;
81
MS_FILTER_CLASS(klass)->w_maxgran=MSRTPRECV_DEF_GRAN;
82
ms_filter_class_set_attr(MS_FILTER_CLASS(klass),FILTER_IS_SOURCE);
83
MS_FILTER_CLASS(klass)->destroy=(MSFilterDestroyFunc)ms_rtp_recv_destroy;
84
MS_FILTER_CLASS(klass)->process=(MSFilterProcessFunc)ms_rtp_recv_process;
85
MS_FILTER_CLASS(klass)->setup=(MSFilterSetupFunc)ms_rtp_recv_setup;
88
void ms_rtp_recv_process(MSRtpRecv *r)
92
MSSync *sync= r->sync;
96
gint gran=ms_sync_get_samples_per_tick(MS_SYNC(sync));
98
if (r->rtpsession==NULL) return;
99
/* process output fifo and output queue*/
103
while( (mp=rtp_session_recvm_with_ts(r->rtpsession,r->prev_ts))!=NULL) {
104
/* try to get rtp packets and paste them to the output fifo */
106
len=mp->b_cont->b_wptr-mp->b_cont->b_rptr;
107
ms_fifo_get_write_ptr(fo,len,&d);
109
memcpy(d,mp->b_cont->b_rptr,len);
110
}else ms_warning("ms_rtp_recv_process: no space on output fifo !");
121
/* we are connected with queues (surely for video)*/
122
/* use the sync system time to compute a timestamp */
123
PayloadType *pt=rtp_profile_get_payload(r->rtpsession->profile,r->rtpsession->payload_type);
125
ms_warning("ms_rtp_recv_process(): NULL RtpPayload- skipping.");
128
clock=(sync->time*pt->clock_rate)/1000;
129
//g_message("sync->time=%i clock=%i",sync->time,clock);
130
/* get rtp packet, and send them through the output queue */
131
while ( (mp=rtp_session_recvm_with_ts(r->rtpsession,clock))!=NULL ){
138
msg=msgb_2_ms_message(mdata);
139
ms_queue_put(qo,msg);
141
if ((r->stream_started) && (got==0) && (gran!=0)){
142
/* we could not find a packet for current time but the stream has started */
143
/* notify this missing packet to next filter by sending an empty message */
145
//printf("sending missing packet information\n");
146
msg=ms_message_alloc();
147
ms_queue_put(qo,msg);
152
void ms_rtp_recv_destroy( MSRtpRecv *obj)
157
RtpSession * ms_rtp_recv_set_session(MSRtpRecv *obj,RtpSession *session)
159
RtpSession *old=obj->rtpsession;
160
obj->rtpsession=session;
166
void ms_rtp_recv_setup(MSRtpRecv *r,MSSync *sync)