コード例 #1
0
ファイル: hci.c プロジェクト: jtheffernan/stm32-nucleof4
void HCI_Input(tHciDataPacket * hciReadPacket)
{
    uint8_t byte;
    hci_acl_hdr *acl_hdr;

	static hci_state state = WAITING_TYPE;

        uint16_t collected_payload_len = 0;
	uint16_t payload_len;
    
    hci_buffer = hciReadPacket->dataBuff;
    
    if(state == WAITING_TYPE)
        hci_pckt_len = 0;
    
    while(hci_pckt_len < HCI_PACKET_SIZE){

        byte = hci_buffer[hci_pckt_len++];

        if(state == WAITING_TYPE){
            /* Only ACL Data and Events packets are accepted. */
            if(byte == HCI_EVENT_PKT){
                 state = WAITING_EVENT_CODE;
            }
//            else if(byte == HCI_ACLDATA_PKT){
//                state = WAITING_HANDLE;
//            }
            else{
                /* Incorrect type. Reset state machine. */
                state = WAITING_TYPE;
                break;
            }
        }
        else if(state == WAITING_EVENT_CODE)
            state = WAITING_PARAM_LEN;
        else if(state == WAITING_HANDLE)
            state = WAITING_HANDLE_FLAG;
        else if(state == WAITING_HANDLE_FLAG)
            state = WAITING_DATA_LEN1;
        else if(state == WAITING_DATA_LEN1)
            state = WAITING_DATA_LEN2;

        else if(state == WAITING_DATA_LEN2){
            acl_hdr = (void *)&hci_buffer[HCI_HDR_SIZE];
            payload_len = acl_hdr->dlen;
            collected_payload_len = 0;
            state = WAITING_PAYLOAD;
        }
        else if(state == WAITING_PARAM_LEN){
             payload_len = byte;
             collected_payload_len = 0;
             state = WAITING_PAYLOAD;
        }
        else if(state == WAITING_PAYLOAD){
            collected_payload_len += 1;
            if(collected_payload_len >= payload_len){
                /* Reset state machine. */
                state = WAITING_TYPE;
                enqueue_packet(hciReadPacket);
                
                if(packet_complete_callback){
                  uint16_t len = hci_pckt_len;
                  packet_complete_callback(hci_buffer, len);
                }
                break;
            }
        }
    }        
}
コード例 #2
0
static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
                                uint8_t **bufptr, int len)
{
    uint8_t *buf = bufptr ? *bufptr : NULL;
    int ret, flags = 0;
    uint32_t timestamp;
    int rv = 0;

    if (!buf) {
        /* If parsing of the previous packet actually returned 0 or an error,
         * there's nothing more to be parsed from that packet, but we may have
         * indicated that we can return the next enqueued packet. */
        if (s->prev_ret <= 0)
            return rtp_parse_queued_packet(s, pkt);
        /* return the next packets, if any */
        if (s->st && s->parse_packet) {
            /* timestamp should be overwritten by parse_packet, if not,
             * the packet is left with pts == AV_NOPTS_VALUE */
            timestamp = RTP_NOTS_VALUE;
            rv        = s->parse_packet(s->ic, s->dynamic_protocol_context,
                                        s->st, pkt, &timestamp, NULL, 0, flags);
            finalize_packet(s, pkt, timestamp);
            return rv;
        } else {
            // TODO: Move to a dynamic packet handler (like above)
            if (s->read_buf_index >= s->read_buf_size)
                return AVERROR(EAGAIN);
            ret = ff_mpegts_parse_packet(s->ts, pkt, s->buf + s->read_buf_index,
                                         s->read_buf_size - s->read_buf_index);
            if (ret < 0)
                return AVERROR(EAGAIN);
            s->read_buf_index += ret;
            if (s->read_buf_index < s->read_buf_size)
                return 1;
            else
                return 0;
        }
    }

    if (len < 12)
        return -1;

    if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
        return -1;
    if (RTP_PT_IS_RTCP(buf[1])) {
        return rtcp_parse_packet(s, buf, len);
    }

    if ((s->seq == 0 && !s->queue) || s->queue_size <= 1) {
        /* First packet, or no reordering */
        return rtp_parse_packet_internal(s, pkt, buf, len);
    } else {
        uint16_t seq = AV_RB16(buf + 2);
        int16_t diff = seq - s->seq;
        if (diff < 0) {
            /* Packet older than the previously emitted one, drop */
            av_log(s->st ? s->st->codec : NULL, AV_LOG_WARNING,
                   "RTP: dropping old packet received too late\n");
            return -1;
        } else if (diff <= 1) {
            /* Correct packet */
            rv = rtp_parse_packet_internal(s, pkt, buf, len);
            return rv;
        } else {
            /* Still missing some packet, enqueue this one. */
            enqueue_packet(s, buf, len);
            *bufptr = NULL;
            /* Return the first enqueued packet if the queue is full,
             * even if we're missing something */
            if (s->queue_len >= s->queue_size)
                return rtp_parse_queued_packet(s, pkt);
            return -1;
        }
    }
}
コード例 #3
0
AdpErrs DevSW_Read(const DeviceDescr *device, const DevChanID type,
                   Packet **packet, bool block)
{
  int read_err;
  DevSWState *ds = device->SwitcherState;

    /*
     * To try to get information out of the device driver as
     * quickly as possible, we try and read more packets, even
     * if a completed packet is already available.
     */

    /*
     * have we got a packet currently pending?
     */
  if (ds->ds_nextreadpacket == NULL)
    /*
       * no - set things up
       */
    if (initialise_read(ds) < 0) {
      /*
       * we failed to initialise the next packet, but can
       * still return a packet that has already arrived.
       */
      *packet = Adp_removeFromQueue(&ds->ds_readqueue[type]); 
      return adp_ok;
    }
  read_err = device->DeviceRead(&ds->ds_activeread, block);
  switch (read_err) {
  case 1:
    /*
     * driver has pulled in a complete packet, queue it up
     */
#ifdef RET_DEBUG
    printf("got a complete packet\n");
#endif
    
    if (angelDebugLogEnable)
      dumpPacket(angelDebugLogFile,"rx:",&ds->ds_activeread.dc_packet);

    enqueue_packet(ds);
    *packet = Adp_removeFromQueue(&ds->ds_readqueue[type]);
    return adp_ok;
  case 0:
    /*
     * OK, return the head of the read queue for the given type
     */
    /*    enqueue_packet(ds); */
    *packet = Adp_removeFromQueue(&ds->ds_readqueue[type]);
    return adp_ok;
  case -1:
#ifdef RET_DEBUG
    printf("got a bad packet\n");
#endif
    /* bad packet */
    *packet = NULL;
    return adp_bad_packet;
  default:
    panic("DevSW_Read: bad read status %d", read_err);
  }
  return 0; /* get rid of a potential compiler warning */
}