1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| private byte[] muxSEI(String msg) { byte[] seiContent = msg.getBytes(); byte[] seiType = new byte[]{0x06, 0x05}; byte[] seiUuid = new byte[]{ 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04}; byte[] seiEnd = new byte[]{(byte) 0x80}; int contentSize = 16 + seiContent.length;
//数据长度(数据长度减去255,有多少个就写多少个FF,剩下的不为0,再写一个字节) int ffCount = 0; while (true) { if (contentSize >= 255) { ffCount++; } if (contentSize < 255) { break; } contentSize -= 255; }
String size = Integer.toHexString(contentSize); byte[] contentLastSize = Hex.decodeHex(size); byte[] contentFirstSize = new byte[ffCount]; for (int i = 0; i < ffCount; i++) { contentFirstSize[i] = (byte) 0xff; } byte[] sei_content_size = combineArrays(contentFirstSize, contentLastSize);
return combineArrays(seiType, sei_content_size, seiUuid, seiContent, seiEnd); }
private byte[] combineArrays(byte[]... a) { int massLength = 0; for (byte[] b : a) { massLength += b.length; } byte[] c = new byte[massLength]; byte[] d; int index = 0; for (byte[] anA : a) { d = anA; System.arraycopy(d, 0, c, 0 + index, d.length); index += d.length; } return c; }
|