uint32_t AUDMEncoder::grab(uint8_t * obuffer)
{
  uint32_t len,sam;
  if(getPacket(obuffer,&len,&sam))
    return len;
  return MINUS_ONE;
}
Example #2
0
ssize_t AudioStream::getBuffer(Encoded data, size_t request)
{
    if(!request)
        return getPacket(data);

    return AudioFile::getBuffer(data, request);
}
bool Adafruit_BluefruitLE_SPI::getResponse(void)
{
    // Blocking wait until IRQ is asserted
    while ( !digitalRead(m_irq_pin) ) {}

    // There is data from Bluefruit & enough room in the fifo
    while ( digitalRead(m_irq_pin) &&
            m_rx_fifo.remaining() >= SDEP_MAX_PACKETSIZE )
    {
        // Get a SDEP packet
        sdepMsgResponse_t msg_response;
        memclr(&msg_response, sizeof(sdepMsgResponse_t));

        if ( !getPacket(&msg_response) ) return false;

        // Write to fifo
        if ( msg_response.header.length > 0)
        {
            m_rx_fifo.write_n(msg_response.payload, msg_response.header.length);
        }

        // No more packet data
        if ( !msg_response.header.more_data ) break;

        // It takes a bit since all Data received to IRQ to get LOW
        // May need to delay a bit for it to be stable before the next try
        // delayMicroseconds(SPI_DEFAULT_DELAY_US);
    }

    return true;
}
   void ClusterDelta::receiveExpectedTime()
   {

      getPacket(8);
      mLocalReceiveTime.setNow();
                     vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << "[SYNC]     Got Expected Time at: " << mLocalReceiveTime.getBaseVal() << "\n" << vprDEBUG_FLUSH;
      mExpectedRemoteTime.set(mReader->readUint64(), vpr::Interval::Base);
                     vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << "[SYNC]     Got Expected Time: " << mExpectedRemoteTime.getBaseVal() << "\n" << vprDEBUG_FLUSH;
      if (mExpectedRemoteTime > mLocalReceiveTime)
      {
         mErrorTime = mExpectedRemoteTime - mLocalReceiveTime;
      }
      else
      {
         mErrorTime = mLocalReceiveTime - mExpectedRemoteTime;
      }

                     vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << "[SYNC]     Error of: " << mErrorTime.getBaseVal() << "\n" << vprDEBUG_FLUSH;

      if ( mErrorTime.getBaseVal() < mTol )
      {
         mAccept = true;
      }
      else
      {
         mAccept = false;
         mTol = gmtl::Math::pow(mTol,(float)1.5);
      }
   }
Example #5
0
uint8_t OMMoCoNode::check() {



	uint8_t command = getPacket();

		// no packet available
	if( command == 0 )
		return(0);

		// command OM_SER_BASECOM is reserved for core protocol commands.
		// We handle these automatically for the node.

	if( ! isBroadcast() && command == OM_SER_BASECOM ) {
		_coreProtocol(this->buffer());
		return(0);
	}
	else {
		// we have a command code which is higher than 1,
		// send to the supplied handler.
		if( f_bcastHandler != 0 && isBroadcast() ) {
				// a callback is assigned, and this is a
				// broadcast command
			f_bcastHandler(command, this->buffer());
		}
		else if( f_cmdHandler != 0 && ! isBroadcast() ) {
				// a callback is assigned, call callback
				// with command code and payload
			f_cmdHandler(command, this->buffer());
		}
	}


	return(command);
}
Example #6
0
void Session::processBatch(BATCH_PACKET *batchpk)
{
    std::string str(zlib_decode(batchpk->payload));

    int offset=0;
    int len=str.size();
    while(offset<len)
    {
        int pkLen=readInt(substr(str,offset,4));
        if(pkLen==0)break;
        offset+=4;
        std::string buf;
        buf.resize(pkLen);
        buf.assign(str,offset,pkLen);
        offset+=pkLen;
        if(buf[0]==BATCH_PACKET::ID)continue;//INVAILD batchpacket inside batchpacket
        Packet* pk=getPacket(buf[0]);
        if(pk!=nullptr)
        {
            pk->buffer=buf;
            pk->decode();

            PlayerClass->handleDataPacket(pk);

            delete pk;
        }


    }

}
Example #7
0
/*
 *  Process a socket readable event
 */
static void readEvent(MaConn *conn)
{
    MaPacket    *packet;
    MprBuf      *content;
    int         nbytes, len;

    do {
        if ((packet = getPacket(conn, &len)) == 0) {
            break;
        }
        mprAssert(len > 0);
        content = packet->content;
        nbytes = mprReadSocket(conn->sock, mprGetBufEnd(content), len);
        showRequest(content, nbytes, len);
       
        if (nbytes > 0) {
            mprAdjustBufEnd(content, nbytes);
            maProcessReadEvent(conn, packet);
        } else {
            if (mprIsSocketEof(conn->sock)) {
                conn->dedicated = 0;
                if (conn->request) {
                    maProcessReadEvent(conn, packet);
                }
            } else if (nbytes < 0) {
                maFailConnection(conn, MPR_HTTP_CODE_COMMS_ERROR, "Communications read error");
            }
        }
    } while (!conn->disconnected && conn->dedicated);
}
/**
    \fn refillPacketBuffer
    \brief Fetch a new packet
*/
bool ADM_edAudioTrackFromVideo::refillPacketBuffer(void)
{
   packetBufferSize=0; 
   uint64_t dts;
   _SEGMENT *seg=parent->_segments.getSegment(_audioSeg);
   static bool endOfAudio=false;
   if(!seg) return false;

   if(lastDts>=seg->_startTimeUs+seg->_durationUs)
     {
       ADM_info("Consumed all data from this audio segment\n");
       switchToNextAudioSegment();
       seg=parent->_segments.getSegment(_audioSeg);
       if(!seg) return false;
     }



   ADM_audioStreamTrack *trk=getTrackAtVideoNumber(seg->_reference);
    if(!trk) return false;    

    if(!getPacket(packetBuffer,&packetBufferSize,ADM_EDITOR_PACKET_BUFFER_SIZE,
                        &packetBufferSamples,&dts))
    {
             if(endOfAudio==false)
                ADM_warning("End of audio\n");
             endOfAudio=true;
             return false;
    }
    // fixup dts
    packetBufferDts=dts;
    endOfAudio=false;
    return true;
}
Example #9
0
int
runDaemon(int debug)
{
  char			packetPtr[PACKETLEN];
  size_t	       	packetSize;
  struct sockaddr_in	sa;

  if (checkOtherProcess())
    return (EXIT_FAILURE);
  signal(SIGTERM, sigHandler);
  signal(SIGINT, sigHandler);
  signal(SIGUSR1, sigHandler);

  if (!debug) {
    daemon(1, 1);
    if (savePid())
      return EXIT_FAILURE;
  }

  fprintf(stderr, "Daemon started\n");

  initConnection(&sa);
  while (1) {
    setClient(acceptClient(&sa));
    bzero(packetPtr, PACKETLEN);
    getPacket(packetPtr, &packetSize);
    handlePacket(packetPtr, packetSize);
    setClient(-1);
  }
  setSock(-1);
  return EXIT_SUCCESS;
}
// for servers communication with clients
bool forkClient(int port, int maxClients, int *ppsend, int *pprecv) {
	if (fork > 0) {
		int  server = 0;
		string *packet;
		Sockaddr_in serverAddr;
		server = socket(AF_INET, SOCK_STREAM, 0);
		if (server < 0) return false;

		serverAddr.sin_family = AF_INET;
		serverAddr.sin_addr.s_addr = INADDR_ANY;
		serverAddr.sin_port = htons(port);

		if ( bind(server, (sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) return false;
		else listen(server, 0);

		int  psend = ppsend[0];
		int  precv = pprecv[1];
		int  sock[maxClients];
		int  socks = 0;

		close(ppsend[1]);
		close(pprecv[0]);

		for (;;) {
			// route data from sockets to pipe
			packet->clear();
			for (int i = 0; i < socks; i++)
				if ((packet = getPacket(sock[i])))
					if (*packet == SHUTDOWN)
						write(precv, packet->c_str(), packet->length());

			// route data from pipe to the right socket
			packet->clear();
			while ((packet = getPacket(psend, true)))
				send(sock[(int)packet->at(9)], (string(START) + *packet).c_str(), packet->length() + 8, 0);

			// TODO accept-zeug

			usleep(SLEEPTIME);
		}
		for (int i = 0; i < socks; i++)
			close(sock[i]);
		close(ppsend[0]);
		close(pprecv[1]);
	}
	return true;
}
//_____________________________________________
uint32_t AVDMProcessAudio_Faac::grab(uint8_t * obuffer)
{
uint32_t len,sam;
	printf("Faac: Read\n");
	if(getPacket(obuffer,&len,&sam))
		return len;
	return MINUS_ONE;
}
Example #12
0
bool login(string name, string password, CPlayer* player, CCamera* camera){
    char wiad[49]="";

    if(name.length()>20){ cout << "Name too long!\n"; return false; }
    if(password.length()>20){ cout << "Password too long!\n"; return false; }

    string whole="login"+name+":"+password;
    strcat(wiad, whole.c_str());
    player->nick = name;
    sendToServer(wiad);

    cout << "Sent!\n";

    while(1) {
        if(event.type == ENET_EVENT_TYPE_RECEIVE) {

            if(receive(event.packet->data, "GOOD")) {
                cout << "\nLogged!\n" << endl;

                string wiad = getPacket(event.packet->data);

                string var = "";
                int index = 0, what = 0;
                for(int i = 5; i < wiad.size()+2; ++i) {
                    if(wiad[i] != ' ') {
                        var.resize(var.size()+1);
                        var[index] = wiad[i];
                        ++index;
                    }
                    else {
                        index = 0;
                        ++what;
                        if(what == 1) player->hair = atoi(var.c_str());
                        if(what == 2) player->head = atoi(var.c_str());
                        if(what == 3) player->body = atoi(var.c_str());
                        if(what == 4) player->leg = atoi(var.c_str());
                        if(what == 5) player->boots = atoi(var.c_str());
                        if(what == 6) player->pos.x = atoi(var.c_str());
                        if(what == 7) player->pos.y = atoi(var.c_str());
                        var = "";
                    }
                }

                camera->setPos(player->pos.x, player->pos.y);

                return true;
            }
            else if(receive(event.packet->data, "FAIL")) {
                cout << "\nError when logging!\n" << endl;
                return false;
            }
            else {
                cout << "\nUuu smieci dostaje!\n" << endl;
                return false;
            }
        }
    }
}
 void ClusterDelta::receiveHandshake()
 {
    getPacket(8);
    mLocalReceiveTime.setNow();
    vpr::Uint64 temp =  mReader->readUint64();
                   vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << "[SYNC] Received Time: " << temp << "\n" << vprDEBUG_FLUSH;
    mRemoteSendTime.set(temp, vpr::Interval::Base);
                   vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << "[SYNC] Received Time: " << mRemoteSendTime.getBaseVal() << "\n" << vprDEBUG_FLUSH;
 }
 void ClusterDelta::receiveResponce()
 {
    getPacket(1);
    mAccept = mReader->readBool();
    if ( mAccept == false )
    {
       vprDEBUG(gadgetDBG_RIM,vprDBG_VERB_LVL) << clrOutNORM(clrRED,"[SYNC]FAILED SYNC") << "\n" << vprDEBUG_FLUSH;
    }
 }
Example #15
0
static int
brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) {
  ResponsePacket packet;
  int size;

  while ((size = getPacket(&packet))) {
    switch (packet.data.code) {
      case BN_RSP_ROUTE:
        enqueueKey(BN_SET_RoutingKeys, packet.data.values.routingKey);
        break;

      case BN_RSP_DISPLAY:
        doVisualDisplay();
        break;

      default: {
        unsigned char set = BN_SET_NavigationKeys;
        unsigned char keys = packet.data.values.dotKeys & 0X3F;
        unsigned char base = BN_KEY_Dot1;
        unsigned char modifier = 0;

        switch (packet.data.code) {
          case BN_RSP_CHARACTER:
            if (keys) break;

          case BN_RSP_SPACE:
            modifier = BN_KEY_Space;
            break;

          case BN_RSP_BACKSPACE:
            modifier = BN_KEY_Backspace;
            break;

          case BN_RSP_ENTER:
            modifier = BN_KEY_Enter;
            break;

          case BN_RSP_THUMB:
            keys = packet.data.values.thumbKeys & 0X0F;
            base = BN_KEY_Previous;
            break;

          default:
            logUnexpectedPacket(packet.bytes, size);
            continue;
        }

        if (modifier) enqueueKeyEvent(set, modifier, 1);
        enqueueKeys(keys, set, base);
        if (modifier) enqueueKeyEvent(set, modifier, 0);
        break;
      }
    }
  }

  return (errno == EAGAIN)? EOF: BRL_CMD_RESTARTBRL;
}
Example #16
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if (!isSerialDevice(&device)) {
     unsupportedDevice(device);
     return 0;
  }

  if ((serialDevice = serialOpenDevice(device))) {
    if (serialRestartDevice(serialDevice, serialBaud)) {
      static const unsigned char request[] = {BNO_DESCRIBE};
      charactersPerSecond = serialBaud / 10;
      if (writePacket(brl, request, sizeof(request)) != -1) {
        while (serialAwaitInput(serialDevice, 100)) {
          ResponsePacket response;
          int size = getPacket(&response);
          if (size) {
            if (response.data.code == BNI_DESCRIBE) {
              statusCells = response.data.values.description.statusCells;
              brl->textColumns = response.data.values.description.textCells;
              brl->textRows = 1;
              brl->keyBindings = "keys";

              if ((statusCells == 5) && (brl->textColumns == 30)) {
                statusCells -= 2;
                brl->textColumns += 2;
              }
              dataCells = brl->textColumns * brl->textRows;
              cellCount = statusCells + dataCells;

              makeOutputTable(dotsTable_ISO11548_1);
              makeInputTable();

              if ((cellBuffer = malloc(cellCount))) {
                memset(cellBuffer, 0, cellCount);
                statusArea = cellBuffer;
                dataArea = statusArea + statusCells;
                refreshCells(brl);
                persistentKeyboardMode = KBM_NAVIGATE;
                temporaryKeyboardMode = persistentKeyboardMode;
                persistentRoutingOperation = BRL_BLK_ROUTE;
                temporaryRoutingOperation = persistentRoutingOperation;
                return 1;
              } else {
                logSystemError("cell buffer allocation");
              }
            } else {
              logUnexpectedPacket(response.bytes, size);
            }
          }
        }
      }
    }
    serialCloseDevice(serialDevice);
    serialDevice = NULL;
  }
  return 0;
}
Example #17
0
/**
 * Gets the next packet waiting to be sent from an APP to MIP
 * @param ret Where returned packet is stored
 * @param src Port to get packet from
 */
void getMipPacket(struct mipd_packet **ret, struct applist *src) {
	//if(debug) fprintf(stderr, "MIPTP: getMipPacket()\n");

	struct packetlist *pct = NULL;
	*ret = NULL;

	getPacket(src->sendinfo->nextSendSeqno++, &pct, src->sendinfo->sendQueue);
	if(debug) fprintf(stderr, "MIPTP: Sending data packet of size %d to MIP %d, port %d, SN %d\n", pct->datalen, pct->dst_mip, ((struct tp_packet *)pct->data)->port, ((struct tp_packet *)pct->data)->seqno);
	if(pct != NULL) mipdCreatepacket(pct->dst_mip, pct->datalen, (char *)pct->data, ret);

}
// get response with timeout -ignoring 
int OMMoCoMaster::_getResponse() {

		// if we sent a broadcast packet, do not look for a response
	if( isBroadcast() == true )
		return(1);
	
	unsigned long cur_tm = millis();

	// timeout if we don't get a response packet in
	// time

	uint8_t code = getPacket();
	while (code == 0) {
		if (millis() - cur_tm > OM_SER_MASTER_TIMEOUT)
			return -1;
		code = getPacket();
	}

	return code;
}
Example #19
0
bool        ADMMpegPacket::getPacketOfType(uint8_t pid,uint32_t maxSize, uint32_t *packetSize,uint64_t *pts,uint64_t *dts,uint8_t *buffer,uint64_t *startAt)
{
    uint8_t tmppid;
    while(1)
    {
        if(true!=getPacket(maxSize,&tmppid,packetSize,pts,dts,buffer,startAt))
            return false;
        else if(tmppid==pid) return true;
    }
    return false;
}
bool CTcpStreamExtractorNode::data(QString gate_name,
                                   const CConstDataPointer &data)
{
    // No need to track gates.
    Q_UNUSED(gate_name);
    QString info;

    if(data->getType() == "tcpdump") {
        auto tcp_dump = data.staticCast<const CTcpDumpData>();

        // User parameters.
        QHostAddress addr_from;
        QHostAddress addr_to;
        quint32 ip_from = 0;
        quint32 ip_to = 0;
        quint16 port_from = 0;
        quint16 port_to = 0;

        bool dest_filter = getConfig().getParameter("dest_filter")->value.toBool();
        if(dest_filter) {
            // Get the destination IP to ranges to filter.
            QString dest_filter_from = getConfig().
                    getParameter("dest_ip_filter_from")->value.toString();
            QString dest_filter_to = getConfig().
                    getParameter("dest_ip_filter_to")->value.toString();
            addr_from = dest_filter_from;
            addr_to = dest_filter_to;
            ip_from = addr_from.toIPv4Address();
            ip_to = addr_to.toIPv4Address();

            // Get the destination port range to filter.
            port_from = getConfig().
                    getParameter("dest_port_filter_from")->value.toUInt();
            port_to = getConfig().
                    getParameter("dest_port_filter_to")->value.toUInt();
        }

        qint32 packet_count = tcp_dump->availablePackets();
        for(qint32 i = 0; i < packet_count; ++i) {
            QSharedPointer<const CTcpDumpPacket> packet = tcp_dump->getPacket(i);
            if(dest_filter) {
                if(packet->dest() < ip_from || packet->dest() >= ip_to ||
                   packet->dest_port() < port_from ||
                   packet->dest_port() > port_to) {
                    // Skip this package as it's outside the filter range.
                    continue;
                }
            }
            m_tcp_streams->addTcpPacket(packet);
        }

<<<<<<< HEAD
Example #21
0
void Session::streamEncapsulated(EncapsulatedPacket const & packet)
{
    if(!IsKeptConnection())return;
    Packet* pk=getPacket(packet.buffer[0]);
    if(pk!=nullptr)
    {
        pk->buffer=packet.buffer;
        pk->decode();


       PlayerClass->handleDataPacket(pk);
        delete pk;
    }
}
void bucketToRenderView::checkStream() {   
   DisplayPacket p = getPacket();
   switch (p.type.sbits32) {
       case 6: {
		   std::cout << "  * starting to recieve frame "<< p.data[0].sbits32<< std::endl;
           break;
       }
       case 5: {
           renderWidth = p.data[0].sbits32;
           renderHeight = p.data[1].sbits32;
           float g = p.data[2].f;
           std::cout << "  * starting image("<<renderWidth<<" x "<<renderHeight<<"), gamma="<<g<< std::endl;
		   MRenderView::setCurrentCamera(renderCamera);
		   MRenderView::startRender(renderWidth, renderHeight);
           break;
       }
       case 2: {
           int xl = p.data[0].sbits32;
           int xh = p.data[1].sbits32;
           int yl = p.data[2].sbits32;
           int yh = p.data[3].sbits32;
           int size = (xh - xl + 1) * (yh - yl + 1);
           std::vector<RV_PIXEL> data(size);
		   for (int i = 0; i < size; i++){
				data[i].r = fgetc( renderPipe );
				data[i].g =	fgetc( renderPipe );
				data[i].b = fgetc( renderPipe );
				data[i].a = fgetc( renderPipe );
		   }
           //std::cout << "  * getting image tile ("<<xl<<", "<<yl<<") to ("<<xh<<", "<<yh<<")" << std::endl;
		   MRenderView::updatePixels ( xl, xh, yl,yh, &data[0] );
		   MRenderView::refresh( xl, xh, yl, yh );
           break;
       }
       case 4: {
           std::cout << "  * done receiving frame" << std::endl;
		   MRenderView::endRender();
           break;
       }
       case 3: {
           std::cout << "  * connection denied!" << std::endl;
           break;
       }
       default: {
           std::cout << "  * unknown packet type" << std::endl;
           break;
       }
   }
} 
Example #23
0
mpegStream::mpegStream(QTcpSocket *parent)
:socket(parent)
{
	//file=new QFile;
	//file->open(QIODevice::ReadOnly);
	blockcount=0;
	read_buffer_size=61440/2;
	th=new jvcMpegThread(&dataArray,read_buffer_size);
	connect(th,SIGNAL(newImageSignal(QByteArray*)),this,SIGNAL(newDataSignal(QByteArray*)));
	connect(th,SIGNAL(giveMoreData()),this,SLOT(readDataStream()));
	connect(this,SIGNAL(newDataForDecode(uint)),th,SLOT(getPacket(uint)));
	block.clear();
	
	
}
void
VerifyingConsumer::OnData(shared_ptr<const Data> data)
{
  if (!m_active)
    return;

  App::OnData(data); // tracing inside

  NS_LOG_FUNCTION(this << data);

  m_validator->validate(*data, bind(&VerifyingConsumer::ValidationPassed, this, _1),
  bind(&VerifyingConsumer::OnDataValidationFailed, this, _1, _2));

  // NS_LOG_INFO ("Received content object: " << boost::cref(*data));

  // This could be a problem......
  uint32_t seq = data->getName().at(-1).toSequenceNumber();
  NS_LOG_INFO("< DATA for " << seq);

  int hopCount = 0;
  auto ns3PacketTag = data->getTag<Ns3PacketTag>();
  if (ns3PacketTag != nullptr) { // e.g., packet came from local node's cache
    FwHopCountTag hopCountTag;
    if (ns3PacketTag->getPacket()->PeekPacketTag(hopCountTag)) {
      hopCount = hopCountTag.Get();
      NS_LOG_DEBUG("Hop count: " << hopCount);
    }
  }

  SeqTimeoutsContainer::iterator entry = m_seqLastDelay.find(seq);
  if (entry != m_seqLastDelay.end()) {
    m_lastRetransmittedInterestDataDelay(this, seq, Simulator::Now() - entry->time, hopCount);
  }

  entry = m_seqFullDelay.find(seq);
  if (entry != m_seqFullDelay.end()) {
    m_firstInterestDataDelay(this, seq, Simulator::Now() - entry->time, m_seqRetxCounts[seq], hopCount);
  }

  m_seqRetxCounts.erase(seq);
  m_seqFullDelay.erase(seq);
  m_seqLastDelay.erase(seq);

  m_seqTimeouts.erase(seq);
  m_retxSeqs.erase(seq);

  m_rtt->AckSeq(SequenceNumber32(seq));
}
/**
      \fn goToTime
      \brief seek in the current track until we meet the time give (in ms)
*/
 uint8_t	mkvAudio::goToTime(uint32_t mstime)
{
uint64_t target=mstime;

      // First identify the cluster...
      int clus=-1;
            for(int i=0;i<_nbClusters-1;i++)
            {
              if(target>=_clusters[i].timeCode && target<_clusters[i+1].timeCode)
              {
                clus=i;
                i=_nbClusters; 
              }
            }
            if(clus==-1) clus=_nbClusters-1; // Hopefully in the last one
            
            target-=_clusters[clus].timeCode; // now the time is relative
            goToCluster(clus);
            _currentCluster=clus;
            _curTimeCode=_clusters[clus].timeCode;
            
            printf("[MKVAUDIO] Asked for %u ms, go to cluster %u which starts at %u\n",mstime,clus,_curTimeCode);
            if(clus<_nbClusters-1)
              printf("[MKVAUDIO] next cluster starts at %u\n",_clusters[clus+1].timeCode);
#if 1
            // Now seek more finely
            // will be off by one frame
#define MAX_SEEK_BUFFER 20000
            uint8_t buffer[MAX_SEEK_BUFFER];
            uint32_t len,samples,timecode;
            while(getPacket(buffer, &len, &samples,&timecode))
            {
              uint32_t curTime=_clusters[_currentCluster].timeCode;
              vprintf("Wanted: %u clus : %u Timecode:%u=> %u\n",mstime,curTime,timecode,timecode+curTime);
              ADM_assert(len<MAX_SEEK_BUFFER); 
              
              if(timecode+curTime>=mstime) 
              {
                printf("[MKV audio] fine seek to %u (clu)+%u=%u\n",curTime,timecode,timecode+curTime);
                return 1;
              }
            }
            printf("Failed to seek to %u mstime\n");
            return 0;
#else
            return 1;
#endif
}
Example #26
0
/*
 * First thread "pck_collec"  implementation for Packet collection
 */
void *pck_collec(void *tr){
    while(endOfPackets()==0){
       		if(isPacketAvailable()){
       			pthread_mutex_lock( &mutexip );
       			packets[pck_counter] = getPacket();
       			pck_counter++;
       			recv_pck++;
       			pthread_mutex_unlock( &mutexip );
       		}
       		pthread_mutex_lock( &mutexip );
       		if(pck_counter>=max_pck)
       			pck_counter=0;
       		pthread_mutex_unlock( &mutexip );
    }
     pthread_exit(NULL);
}
/**
      \fn mkvAudio 
*/
 mkvAudio::mkvAudio(const char *name,mkvTrak *track,mkvIndex *clust,uint32_t nbClusters) 
  : AVDMGenericAudioStream()
{
  _nbClusters=nbClusters;
  _clusters=clust;
  ADM_assert(_clusters);
  _destroyable = 1;
  
   _parser=new ADM_ebml_file();
   ADM_assert(_parser->open(name));
  _track=track; 
  ADM_assert(_track);
  
  
  // Compute total length in byte
  _length=_track->_sizeInBytes; // FIXME
  
  float f=_track->wavHeader.frequency;
  f*=_track->_defaultFrameDuration;
  f=f/1000000.;
  
  _frameDurationInSample=(uint32_t)floor(f+0.5);
  
  _wavheader=new WAVHeader;
  memcpy(_wavheader,&(_track->wavHeader),sizeof(WAVHeader));
  printf("[MKVAUDIO] found %lu bytes, %u samples per frame\n",_length,_frameDurationInSample);
  _currentLace=_maxLace=0;
  _clusterParser=NULL;
  goToCluster(0);
  /* In case of AC3, do not trust the header...*/
  if(_wavheader->encoding==WAV_AC3)
  {
    uint8_t ac3Buffer[20000];
    uint32_t len,sample,timecode;
     if( getPacket(ac3Buffer, &len, &sample,&timecode))
     {
       uint32_t fq,br,chan,syncoff;
        if( ADM_AC3GetInfo(ac3Buffer, len, &fq, &br, &chan,&syncoff) )
        {
            _wavheader->channels=chan;
            _wavheader->frequency=fq;
            _wavheader->byterate=br;
        }
     }
     goToCluster(0);
  }
}
Example #28
0
void removeWorker(ParallelPacketWorker_t *data) {
  volatile HashPacket_t * pkt;
  //HashList_t **queues = data->queues;
  hashtable_t *table = data->table;
  //print_locked(table->locked);

  bool (*removef)(hashtable_t *, int) = data->removef;


  while (data->myCount > 0) {
    pkt = getPacket(data->queues, data->tid);
    if (!(*removef)(table, pkt->key)) {
      data->myCount = -1;
      return;
    } 
    (data->myCount)--;
  }
}
Example #29
0
void cb()
{
    //printf("Interrupt Received\n\r");
    //ZigBee_TX_Request(0x00, 0, 0x00FFFF, 0, 0x01, 0x01, test, 4);

    RxPacket rx_data = getPacket();
    // Echo packet back
    int i;
    char buff[rx_data.data_len];
    char temp;
    for(i=0; i<rx_data.data_len; i++)
    {
        temp = (rx_data.data[i]);
        //buff[i] = temp;
        buff[i] = temp;	// Cipher Code
    }
    TX_Request_16bit(0x01, rx_data.source_addr_16bit, 0, buff, rx_data.data_len);
    //ZigBee_TX_Request(0,0,0xFFFF,rx_data.source_addr_16bit, 1, 0, buff, rx_data.data_len);

}
Example #30
0
/*
    Read data from the peer. This will use the existing conn->input packet or allocate a new packet if required to 
    hold the data. The number of bytes read is stored in conn->lastRead. SSL connections are traced.
    Socket error messages are stored in conn->errorMsg.
 */
static void readPeerData(HttpConn *conn)
{
    HttpPacket  *packet;
    ssize       size;

    if ((packet = getPacket(conn, &size)) != 0) {
        conn->lastRead = mprReadSocket(conn->sock, mprGetBufEnd(packet->content), size);
        if (conn->lastRead > 0) {
            mprAdjustBufEnd(packet->content, conn->lastRead);
        } else if (conn->lastRead < 0 && mprIsSocketEof(conn->sock)) {
            if (conn->state < HTTP_STATE_PARSED) {
                conn->error = 1;
                conn->rx->eof = 1;
            }
            conn->errorMsg = conn->sock->errorMsg ? conn->sock->errorMsg : sclone("Connection reset");
            conn->keepAliveCount = 0;
            conn->lastRead = 0;
            httpTrace(conn, "connection.close", "context", "msg:'%s'", conn->errorMsg);
        }
    }
}