linphone-developers
[Top][All Lists]
Advanced

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

[Linphone-developers] Buffring and Reciving RTP Packet and Playing Probl


From: Anurag Mishra
Subject: [Linphone-developers] Buffring and Reciving RTP Packet and Playing Problem in BlackBerry Application
Date: Wed, 4 Jan 2012 13:46:45 +0530

Hi All,


I have a some problem in my code RecvStream.java class in Receiving rtp packet .   i post you in attachments file .
i implemented g711 codec caller end (client end) not getting any voice . so pleace help me how to code for it ... 


public class RecvStream implements Runnable, PlayerListener {
private Player mPlayer;
private SendStream mSendStream;
private RtpSession mSession;
private long mStartTime=0;
private boolean mFirstRead=true;
private boolean mRunning;
private boolean mBuffering=true;
private static Logger sLogger=JOrtpFactory.instance().createLogger("RecvStream");
private long mPlayerTs=-1;
private long mReturnedMs=0;
private void reset() {
mPlayer=null;
mStartTime=0;
mFirstRead=true;
mBuffering=true;
mPlayerTs=-1;
mReturnedMs=0;
}
private SourceStream mInput= new SourceStream(){
ContentDescriptor mContentDescriptor=new ContentDescriptor("audio/pcm"); 
 (non-Javadoc)
* @see java.io.InputStream#read(byte[], int, int)
 
public int read(byte[] b, int offset, int length) throws IOException {
int len = 0;
return len;
}

public ContentDescriptor getContentDescriptor() {
return mContentDescriptor;
}

public long getContentLength() {
return -1;
}

public int getSeekType() {
return SourceStream.SEEKABLE_TO_START; 
}

public int getTransferSize() {
return 320;
}

public long seek(long where) throws IOException {
return where;
//throw new IOException("not seekable");
}

public long tell() {
return 0;
}

public Control getControl(String controlType) {
return null;
}

public Control[] getControls() {
return null;
}
};

public RecvStream(RtpSession session,SendStream sendStream) {
}


public void stop() {
if (mPlayer == null) return;//nothing to stop
mRunning=false;
try {
if (mPlayer.getState() == Player.STARTED) {
mPlayer.stop();
if (mPlayer.getState() != Player.CLOSED) {
mPlayer.close();
}
} catch (MediaException e) {
}
}
private int getCurTs(){
if (mStartTime==0) {
mStartTime=System.currentTimeMillis();
}
return (int)((System.currentTimeMillis() - mStartTime)*8);
}
public void start() {
mSession.setTimestampClock(new TimestampClock(){
public int getCurrentTimestamp() {
return getCurTs();
}
});
try{
mPlayer = Manager.createPlayer(new DataSource (null) {
SourceStream[] mStream = {mInput};
public void connect() throws IOException {
}

public void disconnect() {
}

public String getContentType() {
return mInput.getContentDescriptor().getContentType();
}

public SourceStream[] getStreams() {
return mStream;
}

public void start() throws IOException {
}

public void stop() throws IOException {
}

public Control getControl(String controlType) {
return null;
}

public Control[] getControls() {
return null;
}
});
mPlayer.addPlayerListener(this);
mPlayer.realize();
AudioPathControl  lPathCtr = (AudioPathControl) mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl");
lPathCtr.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSET);
mPlayer.prefetch();
//if ( DeviceInfo.isSimulator() == false) { //only start player on real device
mPlayer.start();
//}
}catch (Throwable e){
}

}

public void playerUpdate(Player arg0, String event, Object eventData) {
if (event.equals(PlayerListener.BUFFERING_STARTED)){
mBuffering=true;
} else if (event.equals(PlayerListener.DEVICE_UNAVAILABLE)) {
//pausing both player and recorder
try {
//already stooped mPlayer.stop(); 
mSendStream.getPlayer().stop();
} catch (Throwable e) {
}
} else if (event == PlayerListener.DEVICE_AVAILABLE) {
//starting both player and recorder
try {
mSendStream.getPlayer().start();
stop();
reset();
start();
} catch (Throwable e) {
}
}
}
public int getPlayLevel() {
if (mPlayer !=null) {
return ((VolumeControl)mPlayer.getControl("VolumeControl")).getLevel();
} else {
return 0;
}
}
public void setPlayLevel(int level) {
if (mPlayer !=null) {
((VolumeControl)mPlayer.getControl("VolumeControl")).setLevel(level);
}
}
public void enableSpeaker(boolean value) {
if (mPlayer == null) return;//just ignore
AudioPathControl  lPathCtr = (AudioPathControl) mPlayer.getControl ("net.rim.device.api.media.control.AudioPathControl");
try {
lPathCtr.setAudioPath(value?AudioPathControl.AUDIO_PATH_HANDSFREE:AudioPathControl.AUDIO_PATH_HANDSET);
} catch (Throwable e) {
}
}
public boolean isSpeakerEnabled() {
if (mPlayer == null) return false;//just ignore
AudioPathControl  lPathCtr = (AudioPathControl) mPlayer.getControl("net.rim.device.api.media.control.AudioPathControl");
return lPathCtr.getAudioPath()==AudioPathControl.AUDIO_PATH_HANDSFREE;
}
public long getPlayerTs() {
return mPlayerTs;
}

}



Thanks 
 Anurag

reply via email to

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