安卓與PC網絡對接實現視頻實時播放


研究安卓網絡通信一段時間了,  由於最近公司催的比較緊, 硬着頭皮弄出來了.

現在手機客戶端終於能夠連接流媒體服務器實時播放前端的視頻流了.

其實通信方面主要還是命令包的解析, 以及分包組包.

比如要把以下的結構賦值, 就要進行以下函數的轉化.

      /*
     *  

    TNetPackHead = record
      Flag: DWORD;  //0,1,2,3
      Level: TLevel;  //4,5,6,7
      cmd: Word;    //1633 8,9
      Size: Word;   // 10,11
      byChannel:   Byte;
      sServer: array[0..15] of char;
      sHost: array[0..15] of char;
      sMemo: array[0..15] of char;
      byStreamType: Byte;
    end;
     * */

    public byte[] OpenDvrInfo(String DvrIp,int iCmd, int ichan, int istream)
    {
    byte[] b = new byte[100];       
    byte[] temp;
    //分別將struct的成員格式為byte數組。       
    temp = toLH(1);
    System.arraycopy(temp, 0, b, 0, temp.length);
    temp = toLH(0);
    System.arraycopy(temp, 0, b, 4, temp.length);    
    temp = toLH2(iCmd);
    System.arraycopy(temp, 0, b, 6, temp.length); 
    temp = toLH2(10);
    System.arraycopy(temp, 0, b, 8, temp.length);
   
    b[12] = (byte)ichan;
    temp = DvrIp.getBytes();
    System.arraycopy(temp, 0, b, 13, DvrIp.length());
    System.arraycopy(temp, 0, b, 29, DvrIp.length());
    System.arraycopy(temp, 0, b, 45, DvrIp.length());
    b[61] = (byte)istream;
  
    return b;       
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM