java版rtp视频流服务端

  • p0_307055
    了解作者
  • 8.8KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-08 01:50
    上传日期
输出rtp 视频流,播放文件为ts格式,可以用ffmpeg将mkv,avi等格式文件转换为ts格式,用vlc播放器可以播放视频流
vivideostream.zip
  • vivideostream
  • src
  • RtpHead.java
    7.2KB
  • RTPTest.java
    4.2KB
  • .settings
  • org.eclipse.jdt.core.prefs
    598B
  • bin
  • RtpHead.class
    4.5KB
  • RTPTest.class
    2.8KB
  • .project
    389B
  • .classpath
    301B
内容介绍
public class RtpHead { // public char cc; // public char x; // public char p; // public char v; // // public char pt; // public char m; public char h1; public char h2; public short sequence_number; //short用int表示,超过范围时置为0重新计数 public int timestamp; public int ssrc; public void init_rtp_header(){ // this.v = 2; // this.p = 0; // this.x = 0; // this.cc = 0; // this.m = 0; // this.pt = 33; h1 = 128; h2 = 33; this.sequence_number = 123; this.timestamp = 123; this.ssrc = 123; } public RtpHead(){ init_rtp_header(); } public void sequence_number_increase(){ this.sequence_number++; } //offset 4 8 public static int bytes2int(byte[]src, int offset){ int value; value = (int) ( ( src[offset] & 0xff) | ((src[offset+1] & 0xff)<<8) | ((src[offset+2] & 0xff)<<16) | ((src[offset+3] & 0xff)<<24 ) ) ; return value; } //offset 2 public static int bytes2short(byte[]src, int offset){ int value; value = (int) ( ( src[offset] & 0xff) | ((src[offset+1] & 0xff)<<8)) ; return value; } //offset 2 public static void short2byte(byte[]src, int offset, short i){ src[offset] = (byte) (0xff & i); src[offset+1] = (byte) ((0xff00 & i)>>8); } //offset 4 8 public static void int2byte(byte[]src, int offset, int i){ src[offset] = (byte) (0xff & i); src[offset+1] = (byte) ((0xff00 & i)>>8); src[offset+2] = (byte) ((0xff0000 & i)>>16); src[offset+3] = (byte) ((0xff000000 & i)>>24); } //offset 2 public static void short2char(char[]src, int offset, short i){ src[offset] = (char) (0xff & i); src[offset+1] = (char) ((0xff00 & i)>>8); } //offset 4 8 public static void int2char(char[]src, int offset, int i){ src[offset] = (char) (0xff & i); src[offset+1] = (char) ((0xff00 & i)>>8); src[offset+2] = (char) ((0xff0000 & i)>>16); src[offset+3] = (char) ((0xff000000 & i)>>24); } //低位在前,高位在后 //short用int表示,超过范围时置为0重新计数 public static void seq_num_inc(char[]src){ // char l = src[2]; // char h = src[3]; // short value = (short) ( ( src[2] & 0xff) | ((src[3] & 0xff)<<8)) ; // value++; // // src[2] = (char) (0xff & value); // src[3] = (char) ((0xff00 & value)>>8); int value = (int) ( ( src[2] & 0xff) | ((src[3] & 0xff)<<8)) ; value++; if(value == 65536){ value = 0; //unsigned short } src[2] = (char) (0xff & value); src[3] = (char) ((0xff00 & value)>>8); } public static void seq_num_inc4byte(byte[]src){ // int value = (int) ( ( src[2] & 0xff) | ((src[3] & 0xff)<<8)) ; // value++; // if(value == 65536){ // value = 0; //unsigned short // } // src[2] = (byte) (0xff & value); // src[3] = (byte) ((0xff00 & value)>>8); int x1 = src[2] & 0xff; //低位 int x2 = src[3] & 0xff; //高位 int value = (x1<<8) | x2; value++; if(value == 65536){ value = 0; //unsigned short } src[2] = (byte) ((0xff00 & value)>>8); src[3] = (byte) (0xff & value); } public static void initBytes(byte[]src, RtpHead rtpHead){ System.out.println("xxxxxxxx"); // char src[] = new char[RTPTest.MTU]; src[0] = (byte) rtpHead.h1; src[1] = (byte) rtpHead.h2; System.out.println("rtphead h1 " + Integer.toBinaryString(src[0])); // System.out.println("rtphead h2 " + Integer.toBinaryString(src[1])); // RtpHead.short2byte(src, 2, rtpHead.sequence_number); System.out.println("rtphead sequence_number 1 " + (int)src[2]); // System.out.println("rtphead sequence_number 2 " + src[3]); // RtpHead.int2byte(src, 4, rtpHead.timestamp); System.out.println("rtphead timestamp 1 " + src[4]); // System.out.println("rtphead timestamp 2 " + src[5]); // System.out.println("rtphead timestamp 3 " + src[6]); // System.out.println("rtphead timestamp 4 " + src[7]); // RtpHead.int2byte(src, 8, rtpHead.ssrc); System.out.println("rtphead ssrc 1 " + src[8]); // System.out.println("rtphead ssrc 2 " + src[9]); // System.out.println("rtphead ssrc 3 " + src[10]); // System.out.println("rtphead ssrc 4 " + src[11]); // } public static void initChars(char[]src, RtpHead rtpHead){ System.out.println("xxxxxxxx"); // char src[] = new char[RTPTest.MTU]; src[0] = rtpHead.h1; src[1] = rtpHead.h2; System.out.println("rtphead h1 " + Integer.toBinaryString(src[0])); // System.out.println("rtphead h2 " + Integer.toBinaryString(src[1])); // RtpHead.short2char(src, 2, rtpHead.sequence_number); System.out.println("rtphead sequence_number 1 " + (int)src[2]); // System.out.println("rtphead sequence_number 2 " + src[3]); // RtpHead.int2char(src, 4, rtpHead.timestamp); System.out.println("rtphead timestamp 1 " + src[4]); // System.out.println("rtphead timestamp 2 " + src[5]); // System.out.println("rtphead timestamp 3 " + src[6]); // System.out.println("rtphead timestamp 4 " + src[7]); // RtpHead.int2char(src, 8, rtpHead.ssrc); System.out.println("rtphead ssrc 1 " + src[8]); // System.out.println("rtphead ssrc 2 " + src[9]); // System.out.println("rtphead ssrc 3 " + src[10]); // System.out.println("rtphead ssrc 4 " + src[11]); // } public static void main(String[] args){ RtpHead rtpHead = new RtpHead(); // rtpHead.cc = 255; byte[] temp = new byte[4]; System.out.println("rtphead h1 " + Integer.toBinaryString(rtpHead.h1)); //rtpHead.cc System.out.println("rtphead h2 " + Integer.toBinaryString(rtpHead.h2)); // RtpHead.short2byte(temp, 0, rtpHead.sequence_number); System.out.println("rtphead sequence_number 1 " + temp[0]); // System.out.println("rtphead sequence_number 2 " + temp[1]); // RtpHead.int2byte(temp, 0, rtpHead.timestamp); System.out.println("rtphead timestamp 1 " + temp[0]); // System.out.println("rtphead timestamp 2 " + temp[1]); // System.out.println("rtphead timestamp 3 " + temp[2]); // System.out.println("rtphead timestamp 4 " + temp[3]); // RtpHead.int2byte(temp, 0, rtpHead.ssrc); System.out.println("rtphead ssrc 1 " + temp[0]); // System.out.println("rtphead ssrc 2 " + temp[1]); // System.out.println("rtphead ssrc 3 " + temp[2]); // System.out.println("rtphead ssrc 4 " + temp[3]); // //////////////////////////////////////////////////// //////////////////////////////////////////////////// char src[] = new char[RTPTest.MTU]; RtpHead.initChars(src, rtpHead); //////////////////////////////////////////////////// for(int i=0; i<10; i++){ RtpHead.seq_num_inc(src); System.out.println("rtphead sequence_number 1 " + (int)src[2]); // System.out.println("rtphead sequence_number 2 " + src[3]); // } } }
评论
    相关推荐
    • Java
      Java 对于Java练习
    • java
      Java Java基础
    • Java
      Java 我创建的Java项目
    • JAVA教程
      一本非常不错的清华大学java教程,讲解非常详细,看了就知道。
    • Java Cipher
      Java Cipher 加密和解密工具 附带源码 Java Cipher 加密和解密工具 附带源码 Java Cipher 加密和解密工具 附带源码 Java Cipher 加密和解密工具 附带源码
    • javabank
      Java银行 Java com的模拟操作将在bancárias上发布! 要求:Java 8。
    • java 李兴华
      java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java 李兴华 java ...
    • Java204
      支持中文,支持动态注释的超强Java语言反编译器。 注意:Java204的工作目录中不能包含中文字符!! 支持现有所有Java环境产生的Class代码,而最重要的是它生成的源代码可读性极好,又充分考虑了国人的Java编码习惯,...
    • java程序
      java程序-吃点点java程序-吃点点java程序-吃点点java程序-吃点点java程序-吃点点java程序-吃点点
    • Java
      Java 2021/02/19 .java Main.java 学生.java Bmi.java 。班级 Bmi类 主类 MyBmi.class 学生班 学生样本类 2021/02/20 .java DeleteFile.java WriteFile.java MyDataPrint.java 。班级 DeleteFile.class ...