我必须制作一个接收 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 始终为空。我检查了我的有效载荷,看起来不错;它是一个 byte[] 数组,通常在 2000-4000 之间,看起来像 [-1,-40,-32,-0,16.. etc]。我确定 RTP 数据包的标头大小应该是 12。
有人对我如何解决这个问题有见解吗?