下面开始分析函数.
~~~~~~~~~~~~~~~~~~~~~~~~~~
public Session()
{
this(null, null);
try
{
mOrigin = InetAddress.getLocalHost();
}
catch (Exception ignore)
{
mOrigin = null;
}
}
/**
* Creates a streaming session that can be customized by adding tracks.
* @param destination The destination address of the streams
* @param origin The origin address of the streams (appears in the session description)
*/
public Session(InetAddress origin, InetAddress destination)
{
long uptime = System.currentTimeMillis();
mDestination = destination;
mOrigin = origin;
mTimestamp = (uptime/1000)<<32
&
(
(
(
uptime-(
(uptime/1000)*1000
)
)>>32
)/1000
); // NTP timestamp
}
//两个初始化函数,设计到的变量有mOrigin,mDestination,mTimestamp.
//System.currentTimeMillis()产生一个当前的毫秒,这个毫秒其实就是自1970年1月1日0时起的毫秒数
~~~~~~~~~~~~~~~~~~~~~~~~
public void addAudioTrack(AudioStream track)
{
mAudioStream = track;
}
public void removeAudioTrack()
{
mAudioStream = null;
}
public AudioStream getAudioTrack()
{
return mAudioStream;
}
//对mAudioStream的setter和getter方法
~~~~~~~~~~~
public void addVideoTrack(VideoStream track)
{
mVideoStream = track;
}
public void removeVideoTrack()
{
mVideoStream = null;
}
public VideoStream getVideoTrack()
{
return mVideoStream;
}
//对mVideoStream的setter和getter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public boolean trackExists(int id)
{
if (id==0)
return mAudioStream!=null;
else
return mVideoStream!=null;
}
//判断频道是否存在
//0表示音频 1表示视频
~~~~~~~~~~~~~~~~~~~~~~~~~~
public Stream getTrack(int id)
{
if (id==0)
return mAudioStream;
else
return mVideoStream;
}
//对视频流和音频流的返回
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void setContext(Context context)
{
mContext = context;
}
//设置mContext对象
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void setOrigin(InetAddress origin)
{
mOrigin = origin;
}
//设置mOrigin对象
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void setDestination(InetAddress destination) throws IllegalStateException
{
mDestination = destination;
}
public InetAddress getDestination()
{
return mDestination;
}
//设置mDestination
//对mDestination的getter和setter方法
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public void setTimeToLive(int ttl)
{
mTimeToLive = ttl;
}
//设置TTL
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public boolean isStreaming()
{
if ( (mAudioStream!=null && mAudioStream.isStreaming()) || (mVideoStream!=null && mVideoStream.isStreaming()) )
return true;
else
return false;
}
//判断是否正在传输阶段
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public long getBitrate()
{
long sum = 0;
if (mAudioStream != null) sum += mAudioStream.getBitrate();
if (mVideoStream != null) sum += mVideoStream.getBitrate();
return sum;
}
//获取传输速率
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
剩下的6个函数需要对后面的几个类了解之后才能顺利进行!