Android UDP需要从后端数据包中恢复

时间:2014-04-15 22:59:28

标签: java sockets udp

所以我有一个UDP的监听器线程,以便为h264和KLV引入数据包。我遇到的问题是它运行得很好,但是如果它碰巧错过了一些数据包(我通过在线播放视频重新编写),它永远不会恢复,而是只是一帧又一帧地混乱。以下是处理输入数据的代码:

private void listenAndWaitAndThrowIntent(InetAddress broadcastIP, Integer port) throws Exception 
{
    if (m_socket == null || m_socket.isClosed()) 
    {
        m_socket = new DatagramSocket(port);
        m_socket.setBroadcast(true);
    }

    m_socket.setSoTimeout(1000);
    DatagramPacket packet = new DatagramPacket(m_recvPacket, ARSTools.m_packetSize);
    //Log.e("UDP", "Waiting for UDP broadcast");
    try
    {
        m_socket.receive(packet);
    }
    catch (Exception e)
    {
        Log.i("UDP", "Socket Read Error: " + e);
        return;
    }
    //Log.e("UDP", "UDP packet obtained: " + packet.getLength());

    int count = packet.getLength();

    byte [] newPacket = new byte[count];
    for(int i = 0; i < count; ++i)
        newPacket[i] = packet.getData()[i];

    ARSDemuxer.GetInstance().m_inPackets.addLast(newPacket);

}

显然,我对此的无知是原因,但我不确定解决方案是什么。一旦3或4个数据包丢失,计数开始几乎每一帧,你看到的只是垃圾。

0 个答案:

没有答案