我必须制作一个接收RTP数据包的Android MJPEG播放器,获取有效负载,并在屏幕上显示图像。
这就是我收到数据包的方式:
RTP.java
socket.receive(receive_packet);
rtp_packet = new RtpPacket(receive_packet.getData(), receive_packet.getLength());
RtpPacket.java
//Load header
header = new byte[12];
for(int i = 0; i < 12; i++)
header[i] = packet[i];
//Load payload
int payload_length = size - 12;
payload = new byte[payload_length];
for (int i = 12; i < payload_length; i ++)
payload[i-12] = packet[i];
//This is actually handled in the activity view, but it's here for testing purposes
Bitmap bmp = BitmapFactory.decodeByteArray(payload, 0, payload_length);
出于某种原因,bmp始终为null。我检查了我的有效载荷,看起来很好;它是一个byte []数组,通常在2000-4000之间,看起来像[-1,-40,-32,-0,16 ......等]。我确定RTP数据包的头大小应该是12。
有没有人了解我如何解决这个问题?