80,360
社区成员
发帖
与我相关
我的任务
分享
while(!stop)
byte headerBuf[] = readSockData(20);
if (headerBuf == null) {
continue;
}
int pt = (byte) ((headerBuf[9] & 0xff) & 0x7f); //这里得到视频编码类型(H264)
int payloadLen = (((headerBuf[4] & 0xff) << 24) |
((headerBuf[5] & 0xff) << 16) |
((headerBuf[6] & 0xff) << 8) |
(headerBuf[7] & 0xff)); //这里得到H264数据的长度
int pack_len = payloadLen - 12; //减去rtp header的长度(12)
if (pt == RtspPacket.PT_H264) { //当编码类型为H264时
byte packBuf[] = null;
//h264码流
try {
packBuf = readSockData(pack_len); //通过解码得到的帧数据长度,通过
} catch (OutOfMemoryError e) {
Log.d(TAG, "out of memory");
continue;
}
}
}
private byte[] readSockData(int dataBufLen) {
try {
int len = 0;
byte dataBuf[] = new byte[dataBufLen];
if (in != null) {
while (dataBufLen - len > 0) {
int ret = in.read(dataBuf); //DataInputStream in = mSocket.getInputStream();
if (ret < 0) {
return null;
}
len = len + ret;
}
return dataBuf;
}
} catch (Exception e) {
return null;
}
return null;
}