zoukankan      html  css  js  c++  java
  • RTPConnector实现类RTPJxtaMulticastSocketAdapter的问题

    我底层传输使用JxtaMulticastSocket,以便能在JXTA平台使用JMF的RTP支持。

     在RTPConnector的实现类中有

        /**
         * An inner class to implement an PushSourceStream based on UDP sockets.
         
    */
        class SockInputStream extends Thread implements PushSourceStream {

            JxtaMulticastSocket sock;
            // ... other declariation

            public SockInputStream(JxtaMulticastSocket sock) {
                this.sock = sock;
            }

            @Override
            public int read(byte buffer[], int offset, int length) {
                byte[] buf = new byte[length];
                DatagramPacket p = new DatagramPacket(buf, offset, length);
                try {
                    sock.receive(p);
                    byte[] data = p.getData();
                    System.arraycopy(data, 0, buffer, offset, p.getLength());
                } catch (IOException e) {
                    return -1;
                }
                synchronized (this) {
                    dataRead = true;
                    notify();
                }
                return p.getLength();
            }

            // ... other function ...
        }

     上面是正常的代码,下面贴的是不正常的代码,是我参考其他资料写出的

        /**
         * An inner class to implement an PushSourceStream based on UDP sockets.
         
    */
        class SockInputStream extends Thread implements PushSourceStream {

            DatagramSocket sock;
            // ... other declaration ...

            public SockInputStream(DatagramSocket sock, InetAddress addr, int port) {
                this.sock = sock;
                // ...
            }

            public int read(byte buffer[], int offset, int length) {
                DatagramPacket p = new DatagramPacket(buffer, offset, length, addr, port);
                try {
                    sock.receive(p);
                } catch (IOException e) {
                    return -1;
                }
                synchronized (this) {
                    dataRead = true;
                    notify();
                }
                return p.getLength();
            }

            // ... other function ...
        }

    比较一下可以发现不同之处。

     这个问题让我头疼了2天

  • 相关阅读:
    前端代码规范
    node服务通过Jenkins上线流程
    移动端常用布局方法
    前端工程化
    前端开发辅助
    前端Node项目发布流程
    观list.clear()方法 有感
    数据导出 写入到excle文件
    tomcat内存使用情况
    三种分布式锁 简易说说(包含前一篇提到的redis分布式锁)
  • 原文地址:https://www.cnblogs.com/cuizhf/p/2220531.html
Copyright © 2011-2022 走看看