예제 #1
0
static DWORD rng_decompress(BYTE *out, BYTE *in, DWORD in_len)
{
	qsmodel qsm;
	rangecoder rc;
	int ch, syfreq, ltfreq;
	DWORD act_uncomprlen = 0;

	/* make an alphabet with 257 symbols, use 256 as end-of-file */
	initqsmodel(&qsm, 257, 12, 2000, NULL, 0);
	/* unknown crypt_index[0], seems to be always 0x00 */
	start_decoding(&rc, in + 1);

    while (1) {
        ltfreq = decode_culshift(&rc, 12);
        ch = qsgetsym(&qsm, ltfreq);
        if (ch == 256)  /* check for end-of-file */
            break;
        out[act_uncomprlen++] = ch;
        qsgetfreq(&qsm, ch, &syfreq, &ltfreq);
        decode_update(&rc, syfreq, ltfreq, 1 << 12);
        qsupdate(&qsm, ch);
	}
    qsgetfreq(&qsm, 256, &syfreq, &ltfreq);
    decode_update(&rc, syfreq, ltfreq, 1 << 12);
    done_decoding(&rc);
    deleteqsmodel(&qsm);

	return act_uncomprlen;
}
예제 #2
0
void Compression::decomp()
{
	//int             symbol = 1;
	int             ch;
	
	
	for ( cc = 255; cc-->0; ) {
		ff[cc].Fone = 1;
		ff[cc].Ftot = 2;
	}
	
	
	cc = 0;
	start_decoding();
	if (ZATE == 1 && ZEND == 1 && VALUE == Half) {
		outd.w(-1);		/* only a eof marker in file */
		return;
	}
	if (VALUE < Half) {
		VALUE += Half;
		ch = 1;
		sw = 1;
	} else {
		sw = 0;
		ch = 1;
	}
	high = Top_value;
	low = Half - 1;
	ff[cc].Fone = 2;
	ff[cc].Ftot = 3;
	Zero_av = 1;
	cc = 2;
	for (;;) {			/* Loop through characters. */
		
		if (ZEND == 1 && ZATE == 1) {
			if ((VALUE == 0 && Zero_av == 1) || VALUE == Half)
				break;
		}
		
		if(outd.w(sw^ch) == -3)
			break;
		
		ch = decode_symbol(ff[cc]);
		if (ch == 1)
			ff[cc].Fone++;
		ff[cc].Ftot++;
		if ((sw^ch) == 0 ) {
			cc = 2 * cc + 1;
		} else {
			cc = 2 * cc + 2;
		}
		if (cc >= 255 ) cc = 0;
		/* cc = 0; */
	}
	outd.w(-1);
}
예제 #3
0
/*
 * rtp_check_payload - this is called after receiving packets, but before a
 * m_rtp_byte_stream is selected.
 */
void CPlayerMedia::rtp_check_payload (void)
{
  // note wmay - 3/16/2005 - need to push in text here.
  // we'll only every allow 1 type to be read, so we'll be able to
  // set up the interface directly.
  bool try_bytestream_buffering = false;

  if (get_sync_type() == TIMED_TEXT_SYNC) {
    determine_payload_type_from_rtp();
    // set the buffer time to 0, so we can pass buffering immediately
    m_rtp_byte_stream->set_rtp_buffer_time(0);
    try_bytestream_buffering = true;
  } else {
    if (m_head != NULL) {
      /*
       * Make sure that the payload type is the same
       */
      if (m_head->rtp_pak_pt == m_tail->rtp_pak_pt) {
	// we either want only 1 possible protocol, or at least
	// 10 packets of the same consecutively.  10 is arbitrary.
	if (m_media_info->fmt_list->next == NULL || 
	    m_rtp_queue_len > 10) { 
	  if (determine_payload_type_from_rtp() == FALSE) {
	    clear_rtp_packets(); 
	  } else {
	    // call this function again so we begin the buffering check
	    // right away - better than a go-to.
	    try_bytestream_buffering = true;
	  }
	}
      } else {
	clear_rtp_packets();
      }
    }
  }
  // if we've set the rtp bytestream, immediately try and see if they are done
  // buffering;  if so, start the decode task moving.
  if (try_bytestream_buffering) {
    if (m_rtp_byte_stream->check_buffering() != 0) {
      m_rtp_buffering = 1;
      start_decoding();
    }
  }
}
예제 #4
0
unsigned int do_deari(unsigned int insize)
{
  in_size = (unsigned int)insize;    
  
  in_pos = 0;
  deari_pos = 0;

  start_model();                              /* Set up other modules.    */
  start_inputing_bits();
  start_decoding();
  for (;;) {                                  /* Loop through characters. */
    int ch; int symbol;
    symbol = decode_symbol(cum_freq);       /* Decode next symbol.      */
    if (symbol==EOF_symbol) break;          /* Exit loop if EOF symbol. */
    ch = index_to_char[symbol];             /* Translate to a character.*/
    deari[deari_pos++]=(unsigned char)ch;   /* Write that character.    */
    update_model(symbol);                   /* Update the model.        */
  }
  
  return deari_pos;
}
예제 #5
0
int unpack(FILE* out,FILE* in) 
{
	freq cf;
	rangecoder rc;
	struct buffer buffer;
	struct ari_model model;
	size_t processed=0;

	buffer.offset = 0;
	buffer.len_power = 1+BLOCKSIZE_POWER;
	buffer.len = 1<<buffer.len_power;
	buffer.len_mask = buffer.len - 1;
	buffer.data = malloc(buffer.len);
	rc.in = in;
	model_setup(&model);

	if(!buffer.data)
		return -2;

	if (start_decoding(&rc) != 0) {   
		return -1;
	}

	while ( (cf = decode_culfreq(&rc,2)) ) {   
		freq i, blocksize;

		decode_update(&rc,1,1,2);

		blocksize = decode_short(&rc) | ((size_t)decode_short(&rc)) <<16;

		for (i=0; i<blocksize; i++) {   
			freq symbol;

			cf = decode_culfreq(&rc,model.counts[SYMBOLS]);

			symbol =  model_get_symbol(&model, cf);
			decode_update(&rc, model.counts[symbol+1]-model.counts[symbol],model.counts[symbol],model.counts[SYMBOLS]);
			model_update_freq(&model,symbol);

			/*fprintf(stderr,"Decoding:%d(%c),%ld,%ld\n",symbol,symbol,counts[symbol+1]-counts[symbol],counts[symbol]);*/

			if(symbol > 0xff) {
				const uint8_t extra_bits = code_to_length[symbol-0x100].extra_bits;
				const size_t  extra_data = decode_culshift(&rc, extra_bits);

				const size_t  length = code_to_length[symbol-0x100].start + extra_data;
				size_t distance;
				size_t distance_hi;

				decode_update_shift(&rc, 1, extra_data, extra_bits);

				distance = decode_culshift(&rc,8);
				decode_update_shift(&rc, 1, distance, 8);

				distance_hi = decode_culshift(&rc,8);
				decode_update_shift(&rc, 1, distance_hi, 8);

				distance |= distance_hi<<8;

				/* fprintf(stderr,"Retrieved length,distance:%ld,%ld\n",length,distance);*/
				buffer.offset = copy_back_bytes(&buffer,buffer.offset,distance,length);
			}
			else {
				buffer.data[buffer.offset++] = symbol;
				if(buffer.offset >= buffer.len) {
					buffer.offset = 0;
					fwrite(buffer.data,1,buffer.len,out);
				}
			}
		}
		processed += blocksize;
		if(processed > 1<<19) {
			done_decoding(&rc);
			start_decoding(&rc);
			processed=0;
		}
		/*fprintf(stderr,"%ld;;%d\n",blocksize,model.counts[SYMBOLS]);*/
       	}
	fwrite(buffer.data,1,buffer.offset,out);
	done_decoding(&rc);
	model_done(&model);
	free(buffer.data);

	fclose(out);
	return 0;
}
예제 #6
0
/*
 * CPlayerMedia::recv_callback - callback from RTP with valid data
 */
void CPlayerMedia::recv_callback (struct rtp *session, rtp_event *e)
{
  if (e == NULL) return;
  /*
   * If we're paused, just dump the packet.  Multicast case
   */
  if (m_paused) {
    if (e->type == RX_RTP) {
      media_message(LOG_DEBUG, "%s dropping pak", get_name());
      xfree(e->data);
      return;
    }
  }
#if DROP_PAKS
    if (e->type == RX_RTP && dropcount >= 50) {
      xfree((rtp_packet *)e->data);
      dropcount = 0;
      return;
    } else { 
      dropcount++;
    }
#endif
  if (m_rtp_byte_stream != NULL) {
    if ((m_rtp_byte_stream->recv_callback(session, e) > 0) &&
	(e->type == RX_RTP)) {
      // indicates they are done buffering.
      if (m_rtp_buffering == 0) {
	m_rtp_buffering = 1;
	start_decoding();
      } else {
	// we're not buffering, but the decode thread might be waiting; if so, 
	// tweak it if we have a complete frame.
	if (m_decode_thread_waiting) {
	  if (m_rtp_byte_stream->check_rtp_frame_complete_for_payload_type()) {
	    bytestream_primed();
	  }
	}
      }
    }
    return;
  }
  // we only get here if there is not a valid rtp bytestream yet.
  switch (e->type) {
  case RX_RTP:
    /* regular rtp packet - add it to the queue */
    rtp_packet *rpak;
      
    rpak = (rtp_packet *)e->data;
    if (rpak->rtp_data_len == 0) {
      xfree(rpak);
    } else {
      rpak->pd.rtp_pd_timestamp = get_time_of_day();
      rpak->pd.rtp_pd_have_timestamp = true;
      add_rtp_packet_to_queue(rpak, &m_head, &m_tail, 
			      get_name());
      m_rtp_queue_len++;
      rtp_check_payload();
    }
    break;
  case RX_SR:
    rtcp_sr *srpak;
    srpak = (rtcp_sr *)e->data;

    m_rtcp_ntp_frac = srpak->ntp_frac;
    m_rtcp_ntp_sec = srpak->ntp_sec;
    m_rtcp_rtp_ts = srpak->rtp_ts;
    m_rtcp_received = 1;
    break;
  case RX_APP:
    free(e->data);
    break;
  default:
  case RX_RR:
  case RX_SDES:
  case RX_BYE:
  case SOURCE_CREATED:
  case SOURCE_DELETED:
  case RX_RR_EMPTY:
  case RX_RTCP_START:
  case RX_RTCP_FINISH:
  case RR_TIMEOUT:
#if 0
    media_message(LOG_DEBUG, "Thread %u - Callback from rtp with %d %p", 
		  SDL_ThreadID(),e->type, e->data);
#endif
    break;
  }
}