📄 movinopacket.java
字号:
/* * Movino J2ME Client * Copyright (C) 2007 Johannes Berg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */package org.movino.connection;import java.io.ByteArrayOutputStream;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;public class MovinoPacket { //these are used for outgoing traffic public static final int MOVINO_DATA_GARBAGE = 0; public static final int MOVINO_DATA_YUV_FRAME = 1; public static final int MOVINO_DATA_PCM_AUDIO = 2; public static final int MOVINO_DATA_JPEG_HEADER = 3; public static final int MOVINO_DATA_JPEG_DATA = 4; public static final int MOVINO_DATA_MULAW_AUDIO = 5; public static final int MOVINO_DATA_AMR_AUDIO = 6; public static final int MOVINO_DATA_START_MTU_MEASUREMENT = 7; public static final int MOVINO_DATA_STOP_MTU_MEASUREMENT = 8; public static final int MOVINO_DATA_VIDEO_FILE = 9; public static final int MOVINO_DATA_MPEG_FRAME = 10; public static final int MOVINO_DATA_VIDEO_CHUNK = 11; public static final int MOVINO_DATA_THEORA_HEADER = 12; public static final int MOVINO_DATA_THEORA_FRAME = 13; public static final int MOVINO_DATA_HANDSHAKE = 14; public static final int MOVINO_DATA_STREAM_INFO = 15; public static final int MOVINO_DATA_STREAM_CLOSED = 16; //these are used for incoming traffic public static final int MOVINO_REPLY_MTU_SIZE = 1; public static final int MOVINO_REPLY_HANDSHAKE = 2; public static final int MOVINO_REPLY_PING = 3; private int packetType; public MovinoPacket(int type){ packetType = type; } public int getType(){ return packetType; } public final void writePacket(DataOutputStream out) throws IOException{ ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream buffer_stream = new DataOutputStream(bout); buffer_stream.writeByte(packetType); buffer_stream.writeInt(0); writePacketData(buffer_stream); byte[] data = bout.toByteArray(); int len = data.length-5; data[1] = (byte)((len>>24)&0xff); data[2] = (byte)((len>>16)&0xff); data[3] = (byte)((len>>8)&0xff); data[4] = (byte)(len&0xff); out.write(data); //out.writeByte(packetType); //out.writeInt(getPacketLength()); //writePacketData(out); } public void writePacketData(DataOutputStream out) throws IOException{ } /*public int getPacketLength(){ return 0; }*/ public static MovinoPacket readPacket(DataInputStream in) throws IOException{ int type = in.readByte(); int len = in.readInt(); MovinoPacket packet = null; switch(type){ case MOVINO_REPLY_HANDSHAKE: packet = new HandShakePacket(in,len); break; case MOVINO_REPLY_PING: packet = new PingPacket(in,len); break; default: int skip_len = len; while(skip_len>0) skip_len -= in.skip(skip_len); packet = new MovinoPacket(type); break; } return packet; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -