Ejemplo n.º 1
0
asciistream & asciistream::operator = (const asciistream & rhs)
{
    if (this != &rhs) {
        asciistream newStream(rhs);
        swap(newStream);
    }
    return *this;
}
Ejemplo n.º 2
0
LispRef content(LispRef stream, LispRef eos_error_p, LispRef eos_value)
{
    WITH_DEBUG(fprintf(stderr, "content\n"));

    char tag;
    read_byte(tag);

    WITH_DEBUG(fprintf(stderr, "  tag: %x\n", tag));

    switch (tag)
    {
        case TC_NULL:
            return nullReference(stream, eos_error_p, eos_value);
        case TC_REFERENCE:
            return prevObject(stream, eos_error_p, eos_value);
        case TC_CLASS:
            return newClass(stream, eos_error_p, eos_value);
        case TC_OBJECT:
            return newObject(stream, eos_error_p, eos_value);
        case TC_STRING:
            return newString(stream, eos_error_p, eos_value);
        case TC_STATE:
            return newState(stream, eos_error_p, eos_value);
        case TC_VECTOR:
            return newVector(stream, eos_error_p, eos_value);
        case TC_STREAM:
            return newStream(stream, eos_error_p, eos_value);
        case TC_RESET:
            return reset(stream, eos_error_p, eos_value);
        case TC_SELF:
            return stream;
        case TC_FUNCTION:
            return newFunction(stream, eos_error_p, eos_value);
        case TC_BYTEVECTOR:
            return newBytevector(stream, eos_error_p, eos_value);
        case TC_INT:
            return newInt(stream, eos_error_p, eos_value);
        case TC_DOUBLE:
            return newDouble(stream, eos_error_p, eos_value);
        case TC_SYMBOL:
            return newSymbol(stream, eos_error_p, eos_value);
        case TC_KEYWORD:
            return newKeyword(stream, eos_error_p, eos_value);
        case TC_CHAR:
            return newChar(stream, eos_error_p, eos_value);
        case TC_CONS:
            return newCons(stream, eos_error_p, eos_value);
        default:
            {
                LispRef str, args;

                eul_allocate_string(str, "unknown tag in ~a");
                eul_allocate_cons(args, stream, eul_nil);
                eul_serial_error(stream, str, args);
                return eul_nil;
            }
    }
}
Ejemplo n.º 3
0
 void AudioData::reduceToMono(){
   if(channels == 1) return;
   std::vector<float> newStream(sampleCount / channels);
   for (unsigned int i = 0; i < sampleCount; i += channels){
     for (unsigned int j = 0; j < channels; j++){
       newStream[i/channels] += samples[i + j] / channels;
     }
   }
   samples = newStream;
   sampleCount /= channels;
   channels = 1;
   return;
 }
Ejemplo n.º 4
0
void cNtDirReloc::readDirectory(const cNtHeader& header,
                                uint directoryTypeIndex)
{
    if (directoryTypeIndex == UNKNOWNDIR)
        directoryTypeIndex = IMAGE_DIRECTORY_ENTRY_BASERELOC;

    const IMAGE_DATA_DIRECTORY& relocDirectory =
        header.OptionalHeader.DataDirectory[directoryTypeIndex];
    uint size    = relocDirectory.Size;
    uint address = relocDirectory.VirtualAddress;
    CHECK_MSG(size != 0, ".reloc cannot be found!!!");

    cVirtualMemoryAccesserPtr mem = header.getPeMemory();
    cMemoryAccesserStream newStream(mem, address, address + size);
    read(newStream);
}
// ------------------------------------------------------------------------------------------------
// CNSmlDataModBase::MergeL
// Merges data from old item to new item.
// ------------------------------------------------------------------------------------------------
void CNSmlDataModBase::MergeL( TDes8& aNewItem, const TDesC8& aOldItem,TBool aFieldLevel )
	{
	TBool modified( EFalse );
	CVersitParser* newItemParser = ChildCreateParserLC();
	RDesReadStream newStream( aNewItem );
	CleanupClosePushL( newStream );
	newItemParser->InternalizeL( newStream );
	CVersitParser* oldItemParser = ChildCreateParserLC();
	RDesReadStream oldStream( aOldItem );
	CleanupClosePushL( oldStream );
	oldItemParser->InternalizeL( oldStream );

	// Now we're ready to start analysis
	CArrayPtr<CVersitParser>* newEntities = newItemParser->ArrayOfEntities( EFalse );
	CArrayPtr<CVersitParser>* oldEntities = oldItemParser->ArrayOfEntities( ETrue );

	if( newEntities && oldEntities )
		{
		CleanupPtrArrayPushL( oldEntities );
		for( TInt i = 0; ( i < newEntities->Count() ) && ( i < oldEntities->Count() ); i++ )
			{
			MergeEntityL( newEntities->At( i ), oldEntities->At( i ), modified, aFieldLevel );
			}
		CleanupStack::PopAndDestroy(); // oldEntities
		}
	else
		{
		MergeEntityL( newItemParser, oldItemParser, modified, aFieldLevel );
		}

	// Only update if anything was modified in process
	if ( modified )
		{
		aNewItem.Zero();
		RDesWriteStream dws( aNewItem );
		CleanupClosePushL( dws );
		newItemParser->ExternalizeL( dws );
		dws.CommitL();
		CleanupStack::PopAndDestroy(); // dws
		}

	CleanupStack::PopAndDestroy( 4 ); // oldStream, oldItemParser, newStream, newItemParser
	}
Ejemplo n.º 6
0
void TomlParser::setFile(string name)
{
    fstream newStream(name);
    stream = newStream;
}
Ejemplo n.º 7
0
void CamClient::appClientInit()
{
    newStream();
}
Ejemplo n.º 8
0
int acceptBrowserServerConnectionToStream(int browserListener, fd_set * master, int * fdmax, stream_s **stream, command_line_s *commandLine){
  socklen_t addr_size;

  struct sockaddr_in browser_addr;
  connection_list_s *connection = NULL;

  int browser_sock;
  int server_sock;
  struct sockaddr_in client_addr;
  struct sockaddr_in server_addr;

  char str[50];
  addr_size = sizeof(browser_addr);

  log_msg(log, "Attempting to accept connection\n");

  if(*stream == NULL){//new stream!
    memcpy(&client_addr.sin_addr, &commandLine->fake_ip, sizeof(struct in_addr));
    memcpy(&server_addr.sin_addr, &commandLine->www_ip, sizeof(struct in_addr));
    client_addr.sin_family = AF_INET;
    server_addr.sin_family = AF_INET;
    client_addr.sin_port = htons(RAND_PORT);
    server_addr.sin_port = htons(SERV_PORT);

    memset(client_addr.sin_zero, '\0', sizeof(client_addr.sin_zero));
    memset(server_addr.sin_zero, '\0', sizeof(server_addr.sin_zero));

    *stream = newStream(&client_addr, &server_addr, commandLine->alpha);
  }
  else{
    memcpy(&client_addr, &(*stream)->client_addr, addr_size);
    memcpy(&server_addr, &(*stream)->server_addr, addr_size);
  }

  //create new socket to server//CHECK FOR ERRORS
  if ((server_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) printf("socket failed\n");

  //change port number to unoccupied one, client_addr should be copied from stream
  client_addr.sin_port = htons(ntohs(client_addr.sin_port) + port_offset);
  INC_POFFSET();

  if (bind(server_sock, (struct sockaddr*)&client_addr, addr_size) < 0) {
    char tmp[80];
    inet_ntop(AF_INET, &client_addr.sin_addr, tmp, 80);
    log_msg(log, "Socket: %d\nBind addr: %s\nport: %d\n", server_sock, tmp, ntohs(client_addr.sin_port)); 
    log_msg(log, "Bind failed\n");
    perror("bind"); 
    exit(EXIT_FAILURE);
  }

  if (connect(server_sock, (struct sockaddr*)&(*stream)->server_addr, addr_size))
		log_msg(log, "Connect failed\n");

  //accept new socket to browser
  if ((browser_sock = accept(browserListener, (struct sockaddr *) &browser_addr,
                            &addr_size)) == -1)
    {
      close(browserListener);
      log_msg(log, "Error accepting connection.");
      return EXIT_FAILURE;
    }
  
  //create new connection adn add it to stream
  connection = newConnection(browser_sock, server_sock);
  addConnectionToStream(connection, *stream);
  log_msg(log, "Added connections on sockets b:%d,s:%d\n",connection->browser_sock, connection->server_sock); 


  //Add socket to browser to fdset
  FD_SET(browser_sock, master); // add new socket to master set
  if (browser_sock > *fdmax) {    // keep track of the max
    *fdmax = browser_sock;
  }

  //Add socket to server to master
  FD_SET(server_sock, master); // add new socket to master set
  if (server_sock > *fdmax) {    // keep track of the max
    *fdmax = server_sock;
  }

  inet_ntop(AF_INET, (void *)(&(browser_addr.sin_addr)), str, 50);
  log_msg(log, "Accepted connection from %s", str);
  return 0;
}
Ejemplo n.º 9
0
  //  |---[ Stream ]--------------------
  stream device::createStream() {
    stream newStream(dHandle, dHandle->createStream());
    dHandle->streams.push_back(newStream.handle);

    return newStream;
  }
Ejemplo n.º 10
0
/**
* @brief 
*
* @param requestType
* @param requestUrl
* @param requestHeaders
* @param responseHeaders
*
* @return 
*/
bool RtspSession::recvRequest( const std::string &requestType, const std::string &requestUrl, const Connection::Headers &requestHeaders, Connection::Headers &responseHeaders )
{
    Debug( 2, "Session %d - Processing RTSP request: %s", mSession, requestType.c_str() );

    if ( requestType == "SETUP" )
    {
        std::string requestHost, requestStreamName, requestStreamSource;
        int trackId = -1;
        FeedProvider *provider = mConnection->validateRequestUrl( requestUrl, &requestHost, &requestStreamName, &requestStreamSource, &trackId );
        if ( !provider )
        {
            mConnection->sendResponse( responseHeaders, "", 404, "Not Found" );
            return( false );
        }
        if ( !provider->ready() )
        {
            mConnection->sendResponse( responseHeaders, "", 503, "Stream not ready" );
            return( false );
        }
 
        if ( trackId < 0 || trackId > 1 )
        {
            Error( "Got invalid trackID %d from request URL '%s'", trackId, requestUrl.c_str() );
            return( false );
        }

        if ( mRtspStreams.find( trackId ) != mRtspStreams.end() )
        {
            Error( "Got RTSP SETUP for existing trackID %d", trackId );
            return( false );
        }

        Connection::Headers::const_iterator iter = requestHeaders.find("Transport");
        if ( iter == requestHeaders.end() )
        {
            Error( "No Transport header found in SETUP" );
            return( false );
        }
        std::string transportSpec = iter->second;

        RtspStream *stream = newStream( trackId, mEncoder, transportSpec );

        transportSpec.clear();
        transportSpec += "RTP/AVP";
        if ( stream->lowerTransport() == RtspStream::LOWTRANS_TCP )
        {
            transportSpec += "/TCP";
        }
        else
        {
            transportSpec += "/UDP";
            if ( stream->delivery() == RtspStream::DEL_UNICAST )
                transportSpec += ";unicast";
            else
                transportSpec += ";multicast";
        }
        if ( stream->interleaved() )
        {
            transportSpec += stringtf( ";interleaved=%d-%d", stream->channel(0), stream->channel(1) );
        }
        else
        {
            transportSpec += stringtf( ";client_port=%d-%d", stream->destPort(0), stream->destPort(1) );
            transportSpec += stringtf( ";server_port=%d-%d", stream->sourcePort(0), stream->sourcePort(1) );
        }
        transportSpec += stringtf( ";ssrc=%08X", stream->ssrc() );
        transportSpec += ";mode=\"PLAY\"";
        responseHeaders.insert( Connection::Headers::value_type( "Session", stringtf( "%08X", mSession ) ) );
        responseHeaders.insert( Connection::Headers::value_type( "Transport", transportSpec ) );

        state( READY );
        return( true );
    }
    else if ( requestType == "PLAY" )
    {
        std::string rtpInfo;
        for ( RtspStreams::iterator iter = mRtspStreams.begin(); iter != mRtspStreams.end(); iter++ )
        {
            const RtspStream *stream = iter->second;
            if ( rtpInfo.size() )
                rtpInfo += ",";
            rtpInfo += stringtf( "url=%s/trackID=%d;seq=0;rtptime=0", requestUrl.c_str(), stream->trackId() );
        }
        responseHeaders.insert( Connection::Headers::value_type( "Session", stringtf( "%08X", mSession ) ) );
        responseHeaders.insert( Connection::Headers::value_type( "Range", "npt=0-" ) );
        responseHeaders.insert( Connection::Headers::value_type( "RTP-Info", rtpInfo ) );
        for ( RtspStreams::iterator iter = mRtspStreams.begin(); iter != mRtspStreams.end(); iter++ )
            iter->second->start();
        state( PLAYING );
        return( true );
    }
    else if ( requestType == "GET_PARAMETER" )
    {
        FeedProvider *provider = mConnection->validateRequestUrl( requestUrl );
        if ( provider )
        {
            responseHeaders.insert( Connection::Headers::value_type( "Session", stringtf( "%08X", mSession ) ) );
            return( true );
        }
        mConnection->sendResponse( responseHeaders, "", 451, "Parameter Not Understood" );
        return( false );
    }
    else if ( requestType == "TEARDOWN" )
    {
        Debug( 1, "Stopping streams" );
        for ( RtspStreams::iterator iter = mRtspStreams.begin(); iter != mRtspStreams.end(); iter++ )
            iter->second->stop();
        Debug( 1, "Waiting for streams" );
        for ( RtspStreams::iterator iter = mRtspStreams.begin(); iter != mRtspStreams.end(); iter++ )
            iter->second->join();
        for ( RtspStreams::iterator iter = mRtspStreams.begin(); iter != mRtspStreams.end(); iter++ )
            delete iter->second;
        mRtspStreams.clear();
        state( INIT );
        return( true );
    }
    Error( "Unrecognised RTSP command '%s'", requestType.c_str() );
    return( false );
}
Ejemplo n.º 11
0
		shared_ptr<IStream> SourceFile::saveStream( const string _url)
		{
			setOverWrite(true);
			return newStream(_url);
		}
Ejemplo n.º 12
0
		shared_ptr<IStream> SourceFile::loadStream( const string _url)
		{
			setOverWrite(false);
			return newStream(_url);
		}