linphone-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Linphone-developers] ORTP : Not able to hear the voice


From: rajasekar bonthala
Subject: [Linphone-developers] ORTP : Not able to hear the voice
Date: Thu, 23 Nov 2006 12:21:56 +0530

Hi,

In ORTP in src/tests/  there are few files(rtpsend.c , rtprecv.c)  for testing RTP sending and receiving media.

I am working on Fedora LINUX i386 machine. I have done some modification in rtprecv.c for testing. I ran rtprecv on one machine and rtpsend on another machine. The code is pasted below. I am runing rtpsend on one machine with the comand " ./rtpsend /dev/audio 192.168.3.193 49000"  and rtprecv on another machine with command
" ./rtprecv local 49000 --format mulaw --soundcard ".   But I am not able to hear any sound on the receiving side. Can anybody please help me to get out of this problem.

Thanks,
RajaSekhar (code for two files is pasted below)

/*************  rtpsend.c ****************/
#include <ortp/ortp.h>
#include <signal.h>
#include <stdlib.h>

#ifndef _WIN32
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#endif

int runcond=1;

void stophandler(int signum)
{
    runcond=0;
}

static char *help="usage: rtpsend    filename dest_ip4addr dest_port [ --with-clockslide <value> ] [ --with-jitter <milliseconds>]\n";

int main(int argc, char *argv[])
{
    RtpSession *session;
    unsigned char buffer[160];
    int i;
    FILE *infile;
    char *ssrc;
    uint32_t user_ts=0;
    int clockslide=0;
    int jitter=0;
    if (argc<4){
        printf(help);
        return -1;
    }
    for(i=4;i<argc;i++){
        if (strcmp(argv[i],"--with-clockslide")==0){
            i++;
            if (i>=argc) {
                printf(help);
                return -1;
            }
            clockslide=atoi(argv[i]);
            ortp_message("Using clockslide of %i milisecond every 50 packets.",clockslide);
        }else if (strcmp(argv[i],"--with-jitter")==0){
            ortp_message("Jitter will be added to outgoing stream.");
            i++;
            if (i>=argc) {
                printf(help);
                return -1;
            }
            jitter=atoi(argv[i]);
        }
    }
   
    ortp_init();
    ortp_scheduler_init();
    ortp_set_log_level_mask(ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
    session=rtp_session_new(RTP_SESSION_SENDONLY);   
   
    rtp_session_set_scheduling_mode(session,1);
    rtp_session_set_blocking_mode(session,1);
    rtp_session_set_connected_mode(session,TRUE);
    rtp_session_set_remote_addr(session,argv[2],atoi(argv[3]));
    rtp_session_set_payload_type(session,0);
   
    ssrc=getenv("SSRC");
    if (ssrc!=NULL) {
        printf("using SSRC=%i.\n",atoi(ssrc));
        rtp_session_set_ssrc(session,atoi(ssrc));
    }
       
    #ifndef _WIN32
    infile=fopen(argv[1],"r");
    #else
    infile=fopen(argv[1],"rb");
    #endif

    if (infile==NULL) {
        perror("Cannot open file");
        return -1;
    }

    signal(SIGINT,stophandler);
    while( ((i=fread(buffer,1,160,infile))>0) && (runcond) )
    {
        rtp_session_send_with_ts(session,buffer,i,user_ts);
        user_ts+=160;
        if (clockslide!=0 && user_ts%(160*50)==0){
            ortp_message("Clock sliding of %i miliseconds now",clockslide);
            rtp_session_make_time_distorsion(session,clockslide);
        }
        /*this will simulate a burst of late packets */
        if (jitter && (user_ts%(8000)==0)) {
            struct timespec pausetime, remtime;
            ortp_message("Simulating late packets now (%i milliseconds)",jitter);
            pausetime.tv_sec=jitter/1000;
            pausetime.tv_nsec=(jitter%1000)*1000000;
            while(nanosleep(&pausetime,&remtime)==-1 && errno==EINTR){
                pausetime=remtime;
            }
        }
    }

    fclose(infile);
    rtp_session_destroy(session);
    ortp_exit();
    ortp_global_stats_display();

    return 0;
}


/************** End of rtpsend.c ***********/


/**************rtprecv.c ************************/

#include <ortp/ortp.h>
#include <signal.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#include < stdio.h>
#include <sys/types.h>
#include <sys/soundcard.h>
#include <sys/ioctl.h>
#endif

int cond=1;

void stop_handler(int signum)
{
    cond=0;
}

void ssrc_cb(RtpSession *session)
{
    printf("hey, the ssrc has changed !\n");
}

static char *help="usage: rtprecv  filename loc_port [--format format] [--soundcard] [--noadapt] [--with-jitter <milliseconds>]\n";

#define MULAW 0
#define ALAW 1

//#if defined(__hpux) && HAVE_SYS_AUDIO_H

//#include <sys/audio.h>

int sound_init(int format)
{
    int fd;
        int speed = 8000;
        int stereo = 1;
        printf("\n Initializing the sound card \n");
    fd=open("/dev/audio",O_WRONLY);
    if (fd<0){
        perror("Can't open /dev/audio");
        return -1;
    }
        printf("\n Configurng in Process \n");
    ioctl(fd, SNDCTL_DSP_RESET,0);      //ioctl(fd,AUDIO_RESET,0);
    ioctl(fd, SNDCTL_DSP_SPEED,&speed);   //ioctl(fd,AUDIO_SET_SAMPLE_RATE,8000);
    ioctl(fd, SNDCTL_DSP_STEREO,&stereo);     //ioctl(fd,AUDIO_SET_CHANNELS,1);
    if (format==MULAW)
        ioctl(fd, SNDCTL_DSP_SETFMT, AFMT_MU_LAW); //ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_ULAW);
    else ioctl(fd,SNDCTL_DSP_SETFMT,AFMT_A_LAW );      //ioctl(fd,AUDIO_SET_DATA_FORMAT,AUDIO_FORMAT_ALAW);
    return fd;   
}

//#else
//int sound_init(int format)
//{
//    return -1;
//}
//#endif

int main(int argc, char*argv[])
{
    RtpSession *session;
    unsigned char buffer[160];
    int err;
    uint32_t ts=0;
    int stream_received=0;
    FILE *outfile;
    int local_port;
    int have_more;
    int i;
    int format=0;
    int soundcard=0;
    int sound_fd=0;
    int jittcomp=40;
    bool_t adapt=TRUE;
   
    /* init the lib */
    if (argc<3){
        printf(help);
        return -1;
    }
    local_port=atoi(argv[2]);
    if (local_port<=0) {
        printf(help);
        return -1;
    }
    for (i=3;i<argc;i++)
    {
        if (strcmp(argv[i],"--noadapt")==0) adapt=FALSE;
        if (strcmp(argv[i],"--format")==0){
            i++;
            if (i<argc){
                if (strcmp(argv[i],"mulaw")==0){
                    format=MULAW;
                }else
                if (strcmp(argv[i],"alaw")==0){
                    format=ALAW;
                }else{
                    printf("Unsupported format %s\n",argv[i]);
                    return -1;
                }
            }
        }
        else if (strcmp(argv[i],"--soundcard")==0){
            soundcard=1;
        }
        else if (strcmp(argv[i],"--with-jitter")==0){
            i++;
            if (i<argc){
                jittcomp=atoi(argv[i]);
                printf("Using a jitter buffer of %i milliseconds.\n",jittcomp);
            }
        }
    }
   
    outfile=fopen(argv[1],"wb");
    if (outfile==NULL) {
        perror("Cannot open file for writing");
        return -1;
    }
   
   
    if (soundcard){
        sound_fd=sound_init(format);
    }
   
    ortp_init();
    ortp_scheduler_init();
    ortp_set_log_level_mask(ORTP_DEBUG|ORTP_MESSAGE|ORTP_WARNING|ORTP_ERROR);
    signal(SIGINT,stop_handler);
    session=rtp_session_new(RTP_SESSION_RECVONLY);   
    rtp_session_set_scheduling_mode(session,1);
    rtp_session_set_blocking_mode(session,1);
    rtp_session_set_local_addr(session," 0.0.0.0",atoi(argv[2]));
    rtp_session_set_connected_mode(session,TRUE);
    rtp_session_set_symmetric_rtp(session,TRUE);
    rtp_session_enable_adaptive_jitter_compensation(session,adapt);
    rtp_session_set_jitter_compensation(session,jittcomp);
    rtp_session_set_payload_type(session,0);
    rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)ssrc_cb,0);
    rtp_session_signal_connect(session,"ssrc_changed",(RtpCallback)rtp_session_reset,0);
   
    while(cond)
    {
        have_more=1;
        while (have_more){
            err=rtp_session_recv_with_ts(session,buffer,160,ts,&have_more);
            if (err>0) stream_received=1;
            /* this is to avoid to write to disk some silence before the first RTP packet is returned*/   
            if ((stream_received) && (err>0)) {
                size_t ret = fwrite(buffer,1,err,outfile);
                if (sound_fd>0)
                                {
                                        printf("\n Writing to Sound device \n");
                    ret = write(sound_fd,buffer,err);
                                }
            }
        }
        ts+=160;
        //ortp_message("Receiving packet.");
    }
   
    rtp_session_destroy(session);
    ortp_exit();
   
    ortp_global_stats_display();
   
    return 0;
}
/******************* End of rtprecv.c ****************/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]