Exemplo n.º 1
0
bool CAudioRtpByteStream::start_next_frame (uint8_t **buffer, 
					    uint32_t *buflen,
					    frame_timestamp_t *pts,
					    void **ud)
{
  uint32_t ts;
  int32_t diff;

  if (m_working_pak != NULL) {
    diff = m_working_pak->rtp_data_len - m_bytes_used;
  } else diff = 0;

  if (diff > 0) {
    // Still bytes in the buffer...
    *buffer = (uint8_t *)m_working_pak->rtp_data + m_bytes_used;
    *buflen = diff;
    pts->msec_timestamp = m_last_realtime;
    pts->audio_freq_timestamp = m_last_rtp_ts;
    pts->audio_freq = m_timescale;
    pts->timestamp_is_pts = false;
#ifdef DEBUG_RTP_FRAMES
    rtp_message(LOG_DEBUG, "%s Still left - %d bytes", m_name, *buflen);
#endif
    return true;
  } else {
    if (m_working_pak) xfree(m_working_pak);
    m_buffer_len = 0;
    m_bytes_used = m_skip_on_advance_bytes;
    m_working_pak = m_head;
    check_seq(m_working_pak->rtp_pak_seq);
    set_last_seq(m_working_pak->rtp_pak_seq);
    remove_packet_rtp_queue(m_working_pak, 0);

    *buffer = (uint8_t *)m_working_pak->rtp_data + m_bytes_used;
    *buflen = m_working_pak->rtp_data_len;
    ts = m_working_pak->rtp_pak_ts;
#ifdef DEBUG_RTP_FRAMES
    rtp_message(LOG_DEBUG, "%s buffer seq %d ts %x len %d", m_name, 
		m_working_pak->rtp_pak_seq, 
		m_working_pak->rtp_pak_ts, *buflen);
#endif
  }

  // We're going to have to handle wrap better...
  uint64_t retts = rtp_ts_to_msec(ts, 
				  m_working_pak->pd.rtp_pd_timestamp,
				  m_wrap_offset);
  
  m_last_rtp_ts = ts;
  pts->msec_timestamp = retts;
  pts->audio_freq_timestamp = m_last_rtp_ts;
  pts->audio_freq = m_timescale;
  pts->timestamp_is_pts = false;
  return true;
}
Exemplo n.º 2
0
/**
 * Parses a read in fastq format.
 * Returns FASTQ_END at end of file, FASTQ_OK on success, FASTQ_ERR on problem
 */
static int parse_fastq_read(ReadSeq *read, gzFile f) {
  size_t qual_len;

  read->status = FASTQ_OK;

  read_fastq_lines(read, f);
  if(read->status != FASTQ_OK) {
    return read->status;
  }

  
  /* check_header(read); */
  /* if(read->status != FASTQ_OK) { */
  /*   return read->status; */
  /* } */


  /* third line should start with '+' separator */
  if(read->line3[0] != '+') {
    my_warn("%s:%d: third line does not start with '+'", 
	  __FILE__, __LINE__);
    read->status = FASTQ_ERR;
    return read->status;
  }
   
  /* check length of read and quality */
  read->read_len = strlen(read->line2);
  qual_len = strlen(read->line4);
  
  if(read->read_len < 1) {
    my_warn("%s:%d: read has no bases\n", __FILE__, __LINE__);
    return read->status;
  }

  /* next line should be quality scores */
  if(read->read_len != qual_len) {
    my_warn("%s:%d: read len (%ld) does not match quality score len (%ld)",
	  __FILE__, __LINE__, read->read_len, qual_len);
    read->status = FASTQ_ERR;
    return read->status;
  }

  check_seq(read);
  check_qual(read);

  return read->status;
}
Exemplo n.º 3
0
bool CRtpByteStream::start_next_frame (uint8_t **buffer, 
				       uint32_t *buflen,
				       frame_timestamp_t *pts,
				       void **ud)
{
  uint16_t seq = 0;
  uint32_t rtp_ts = 0;
  uint64_t timetick;
  uint64_t ts = 0;
  int first = 0;
  int finished = 0;
  rtp_packet *rpak;
  int32_t diff;

  diff = m_buffer_len - m_bytes_used;

  if (diff >= 2) {
    // Still bytes in the buffer...
    *buffer = m_buffer + m_bytes_used;
    *buflen = diff;
#ifdef DEBUG_RTP_FRAMES
    rtp_message(LOG_DEBUG, "%s Still left - %d bytes", m_name, *buflen);
#endif
#if 0
    rtp_message(LOG_DEBUG, "%s start %02x %02x %02x %02x %02x", m_name,
		(*buffer)[0],
		(*buffer)[1],
		(*buffer)[2],
		(*buffer)[3],
		(*buffer)[4]);
#endif
    pts->msec_timestamp = m_last_realtime;
    pts->audio_freq_timestamp = m_last_rtp_ts;
    pts->audio_freq = m_timescale;
    pts->timestamp_is_pts = true;
    return true;
  } else {
    check_seq(m_head->rtp_pak_seq);

    m_buffer_len = 0;
    while (finished == 0) {
      rpak = m_head;
      if (rpak == NULL) { 
	// incomplete frame - bail on this
	player_error_message("%s - This should never happen - rtp bytestream"
			     "is incomplete and active", m_name);
	player_error_message("Please report to mpeg4ip");
	player_error_message("first %d seq %u ts %x blen %d",
			     first, seq, rtp_ts, m_buffer_len);
	m_buffer_len = 0;
	m_bytes_used = 0;
	return 0;
      }
	
      remove_packet_rtp_queue(rpak, 0);
      
      if (first == 0) {
	seq = rpak->rtp_pak_seq + 1;
	ts = rpak->pd.rtp_pd_timestamp;
	rtp_ts = rpak->rtp_pak_ts;
	first = 1;
      } else {
	if ((seq != rpak->rtp_pak_seq) ||
	    (rtp_ts != rpak->rtp_pak_ts)) {
	  if (seq != rpak->rtp_pak_seq) {
	    rtp_message(LOG_INFO, "%s missing rtp sequence - should be %u is %u", 
			m_name, seq, rpak->rtp_pak_seq);
	  } else {
	    rtp_message(LOG_INFO, "%s timestamp error - seq %u should be %x is %x", 
			m_name, seq, rtp_ts, rpak->rtp_pak_ts);
	  }
	  m_buffer_len = 0;
	  rtp_ts = rpak->rtp_pak_ts;
	}
	seq = rpak->rtp_pak_seq + 1;
      }
      uint8_t *from;
      uint32_t len;
      from = (uint8_t *)rpak->rtp_data + m_skip_on_advance_bytes;
      len = rpak->rtp_data_len - m_skip_on_advance_bytes;
      if ((m_buffer_len + len) >= m_buffer_len_max) {
	// realloc
	m_buffer_len_max = m_buffer_len + len + 1024;
	m_buffer = (uint8_t *)realloc(m_buffer, m_buffer_len_max);
      }
      memcpy(m_buffer + m_buffer_len, 
	     from,
	     len);
      m_buffer_len += len;
      if (rpak->rtp_pak_m == 1) {
	finished = 1;
      }
      set_last_seq(rpak->rtp_pak_seq);
      xfree(rpak);
    }
    m_bytes_used = 0;
    *buffer = m_buffer + m_bytes_used;
    *buflen = m_buffer_len - m_bytes_used;
#if 0
  rtp_message(LOG_DEBUG, "%s start %02x %02x %02x %02x %02x", m_name,
		  	(*buffer)[0],
		  	(*buffer)[1],
		  	(*buffer)[2],
		  	(*buffer)[3],
		  	(*buffer)[4]);
#endif
#ifdef DEBUG_RTP_FRAMES
    rtp_message(LOG_DEBUG, "%s buffer len %d", m_name, m_buffer_len);
#endif
  }
  timetick = rtp_ts_to_msec(rtp_ts, ts, m_wrap_offset);
  m_last_rtp_ts = rtp_ts;
  
  pts->msec_timestamp = timetick;
  pts->audio_freq_timestamp = m_last_rtp_ts;
  pts->audio_freq = m_timescale;
  pts->timestamp_is_pts = true;
  return (true);
}
Exemplo n.º 4
0
static void async_process_dbug_read(const AsyncMode mode, bool *const finished)
{
    Packet *packet;
    unsigned int msg_home, msg_oppo;
    AdpErrs adp_err;

    adp_err = DevSW_Read(deviceToUse, DC_DBUG, &packet,
                         mode == async_block_on_read);

#ifdef FAKE_BAD_LINE_RX
    adp_err = fake_bad_line_rx(packet, adp_err);
#endif /* FAKE_BAD_LINE_RX */

    if (adp_err == adp_bad_packet) {
        /* We got a bad packet, ask for a resend, send a resend message */
#ifdef DEBUG
        printf("received a bad packet\n");
#endif /* DEBUG */
        send_resend_msg(DC_DBUG);
    } else if (packet != NULL) {
        /* update the heartbeat clock */
        gettimeofday(&time_lastalive, NULL);

	/*
	 * we got a live one here - were we waiting for it?
	 */
	if (mode == async_block_on_read) {
           /* not any more */
           *finished = TRUE;
	}
#ifdef RETRANS

        if (packet->pk_length < CF_DATA_BYTE_POS) {
            /* we have got a packet with no header information! */
            printf("ERROR: packet with no transport header\n");
            send_resend_msg(DC_DBUG);
        } else {
# ifdef RET_DEBUG
            unsigned int c;
# endif /* RET_DEBUG */
            /*
             * TODO: Check to see if its acknowledgeing anything, remove
             * those packets it is from the queue.  If it is a retrans, add the
             * packets to the queue
             */
            msg_home = packet->pk_buffer[CF_HOME_SEQ_BYTE_POS];
            msg_oppo = packet->pk_buffer[CF_OPPO_SEQ_BYTE_POS];
# ifdef RET_DEBUG
            printf("msg seq numbers are hseq 0x%x oseq 0x%x\n",
                   msg_home, msg_oppo);
	    for ((c = 0); (c < packet->pk_length); c++) {
               printf("%02.2x", packet->pk_buffer[c]);
	    }
            printf("\n");
# endif /* RET_DEBUG */
            /* now was it a resend request? */
            if ((packet->pk_buffer[CF_FLAGS_BYTE_POS])
                & CF_RESEND) {
                /* we have been asked for a resend, so we had better resend */
                /*
                 * I do NOT think we can use a resend as acknowledgement for
                 * anything, so let us NOT do this for the moment:
                 * check_seq(msg_home, msg_oppo);
                 */
# ifdef RET_DEBUG
                printf("received a resend request\n");
# endif /* RET_DEBUG */
                if (HomeSeq != msg_oppo) {
                    int found = FALSE;
                    /* need to resend from msg_oppo +1 upwards */
                    DevSW_FreePacket(packet);
                    resending = TRUE;
                    /* find the correct packet to resend from */
                    packet = writeQueueRoot;
                    while (((packet->pk_next) != NULL) && !found) {
                        if ((packet->pk_buffer[CF_OPPO_SEQ_BYTE_POS])
                            != msg_oppo+1) {
                            resend_pkt = packet;
                            found = TRUE;
                        }
                        packet = packet->pk_next;
                    }
                    if (!found) {
                        panic("trying to resend non-existent packets\n");
                    }
                } else if (OppoSeq != msg_home) {
                    /*
                     * send a resend request telling the target where we think
                     * the world is at
                     */
                    DevSW_FreePacket(packet);
                    send_resend_msg(DC_DBUG);
                }
            } else {
                /* not a resend request, let us check the sequence numbers */

                if ((packet->pk_buffer[CF_CHANNEL_BYTE_POS] != CI_HBOOT) &&
                    (packet->pk_buffer[CF_CHANNEL_BYTE_POS] != CI_TBOOT)) {
                    adp_err = check_seq((unsigned char)msg_home,
					(unsigned char)msg_oppo);
                    if (adp_err == adp_seq_low) {
                        /* we have already received this packet so discard */
                        DevSW_FreePacket(packet);
                    } else if (adp_err == adp_seq_high) {
                        /*
                         * we must have missed a packet somewhere, discard this
                         * packet and tell the target where we are
                         */
                        DevSW_FreePacket(packet);
                        send_resend_msg(DC_DBUG);
                    } else {
                       /*
                        * now pass the packet to whoever is waiting for it
                        */
                       FireCallback(packet);
		    }
                } else {
                   FireCallback(packet);
		}
            }
        }
#else
	/*
	 * now pass the packet to whoever is waiting for it
	 */
        FireCallback(packet);
#endif /* RETRANS */
    }
}