public void run() {
		long time, duration = 0;
		int i = 0, j = 0, tr;
		boolean firstFragment = true;
		byte[] nextBuffer;
		stats.reset();

		try { 
			while (!Thread.interrupted()) {
				
				if (j==0) buffer = socket.requestBuffer();
				socket.updateTimestamp(ts);
				
				// Each packet we send has a two byte long header (See section 5.1 of RFC 4629)
				buffer[rtphl] = 0;
				buffer[rtphl+1] = 0;
				
				time = System.nanoTime();
				if (fill(rtphl+j+2,MAXPACKETSIZE-rtphl-j-2)<0) return;
				duration += System.nanoTime() - time;
				j = 0;
				// Each h263 frame starts with: 0000 0000 0000 0000 1000 00??
				// Here we search where the next frame begins in the bit stream
				for (i=rtphl+2;i<MAXPACKETSIZE-1;i++) {
					if (buffer[i]==0 && buffer[i+1]==0 && (buffer[i+2]&0xFC)==0x80) {
						j=i;
						break;
					}
				}
				// Parse temporal reference
				tr = (buffer[i+2]&0x03)<<6 | (buffer[i+3]&0xFF)>>2;
				//Log.d(TAG,"j: "+j+" buffer: "+printBuffer(rtphl, rtphl+5)+" tr: "+tr);
				if (firstFragment) {
					// This is the first fragment of the frame -> header is set to 0x0400
					buffer[rtphl] = 4;
					firstFragment = false;
				} else {
					buffer[rtphl] = 0;
				}
				if (j>0) {
					// We have found the end of the frame
					stats.push(duration);
					ts+= stats.average(); duration = 0;
					//Log.d(TAG,"End of frame ! duration: "+stats.average());
					// The last fragment of a frame has to be marked
					socket.markNextPacket();
					send(j);
					nextBuffer = socket.requestBuffer();
					System.arraycopy(buffer,j+2,nextBuffer,rtphl+2,MAXPACKETSIZE-j-2);
					buffer = nextBuffer;
					j = MAXPACKETSIZE-j-2;
					firstFragment = true;
				} else {
					// We have not found the beginning of another frame
					// The whole packet is a fragment of a frame
					send(MAXPACKETSIZE);
				}
			}
		} catch (IOException e) { 
		} catch (InterruptedException e) {}

		Log.d(TAG,"H263 Packetizer stopped !");

	}
RFC 4629.

  H.263 Streaming over RTP.
  
  Must be fed with an InputStream containing H.263 frames.
  The stream must start with mpeg4 or 3gpp header, it will be skipped.
src/net/majorkernelpanic/streaming/rtp/H263Packetizer.java