Ejemplo n.º 1
0
  void device::setup(const occa::properties &props) {
    occa::properties settings_ = settings();
    occa::properties defaults;

    std::string paths[2] = {"", ""};
    paths[1] = "mode/";
    paths[1] += (std::string) props["mode"];
    paths[1] += '/';

    for (int i = 0; i < 2; ++i) {
      const std::string &path = paths[i];

      if (settings_.has(path + "device")) {
        defaults += settings_[path + "device"];
      }
      if (settings_.has(path + "kernel")) {
        defaults["kernel"] += settings_[path + "kernel"];
      }
      if (settings_.has(path + "memory")) {
        defaults["memory"] += settings_[path + "memory"];
      }
    }

    setDHandle(occa::newModeDevice(defaults + props));

    stream newStream = createStream();
    dHandle->currentStream = newStream.handle;
  }
Ejemplo n.º 2
0
// Loads the old save by constructing a new save containing the old save's data
bool SaveConverter_Notes::load() {
    if (_size == 0)
        return false;

    Common::InSaveFile *save;

    // Test if it's an old savd
    if (!isOldSave(&save) || !save)
        return false;

    displayWarning();

    SaveWriter writer(1, 0);

    SavePartVars *vars = readVars(*save, _size, false);
    if (!vars)
        return loadFail(0, save);

    // We don't need the save anymore
    delete save;

    // Write all parts
    if (!writer.writePart(0, vars))
        return loadFail(0, 0);

    // We don't need this anymore
    delete vars;

    // Create the final read stream
    if (!createStream(writer))
        return loadFail(0, 0);

    return true;
}
Ejemplo n.º 3
0
void toggleStream(Generator& generator, XnProductionNodeType type, bool* bIsOn)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (!generator.IsValid())
	{
		createStream(generator, type);
	}

	if (!generator.IsValid())
	{
		// failed creating the stream
		return;
	}

	if (generator.IsGenerating())
	{
		generator.StopGenerating();
	}
	else
	{
		nRetVal = generator.StartGenerating();
		if (nRetVal != XN_STATUS_OK)
		{
			displayMessage("Failed to turn on %s: %s", generator.GetInfo().GetInstanceName(), xnGetStatusString(nRetVal));
			return;
		}
	}

	*bIsOn = (generator.IsGenerating() == TRUE);
}
Ejemplo n.º 4
0
	StreamHandle AudioDevice::playStream(const std::string &name)
	{
		StreamHandle handle = createStream(name);

		if(handle)
			handle->play();
		else
			JL_WARNING_LOG("Attempted to play non-existant stream!");

		return handle;
	}
Ejemplo n.º 5
0
FormatInfoPage *PalmDocPlugin::createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file) {
	shared_ptr<ZLInputStream> stream = createStream(file);
	stream->open();
	bool readAsPalmDoc = ((PalmDocStream&)*stream).hasExtraSections();
	stream->close();
	if (!readAsPalmDoc) {
		return new PlainTextInfoPage(dialog, file, ZLResourceKey("Text"), !TextFormatDetector().isHtml(*stream));
	} else {
		return 0;
	}
}
Ejemplo n.º 6
0
void DataHandler::createFileIfNotExisting(const char *dataFilePath) {
    if(!doesFileExist(dataFilePath)) {
        cerr << "File " << dataFilePath << " doesn't exist. Creating..." << endl;
        fstream createStream(dataFilePath, ios_base::out);
        if(createStream.fail()) {
            string error = string("File ") + dataFilePath + string(" doesn't exist and unable to create it!");
            throw error;
        }
        createStream.close();
    }
}
//********************************************************************
//
//********************************************************************
//--------------------------------------------------------------------
//
//--------------------------------------------------------------------
bool DSFilterSourceStreamAudio::init(INWStreamReader* _stream)
{
    bool bOK = true;

    if (!isOk())
    {
        bOK = createStream(_stream);

        mInit = true;
    }
    return bOK;

}
Ejemplo n.º 8
0
// Loads the old save by constructing a new save containing the old save's data
bool SaveConverter_v4::load() {
	clear();

	uint32 varSize = SaveHandler::getVarSize(_vm);
	if (varSize == 0)
		return false;

	Common::InSaveFile *save;

	// Test if it's an old savd
	if (!isOldSave(&save) || !save)
		return false;

	displayWarning();

	SaveWriter writer(3, 0);

	SavePartInfo *info = readInfo(*save, kSlotNameLength, false);
	if (!info)
		return loadFail(0, 0, 0, save);

	SavePartVars *vars = readVars(*save, varSize, true);
	if (!vars)
		return loadFail(info, 0, 0, save);

	SavePartMem *props = readMem(*save, 256000, true);
	if (!props)
		return loadFail(info, vars, 0, save);

	// We don't need the save anymore
	delete save;

	// Write all parts
	if (!writer.writePart(0, info))
		return loadFail(info, vars, props, 0);
	if (!writer.writePart(1, vars))
		return loadFail(info, vars, props, 0);
	if (!writer.writePart(2, props))
		return loadFail(info, vars, props, 0);

	// We don't need those anymore
	delete info;
	delete vars;
	delete props;

	// Create the final read stream
	if (!createStream(writer))
		return loadFail(0, 0, 0, 0);

	return true;
}
Ejemplo n.º 9
0
    void test_seek()
    {
        for (unsigned int i = 0; i < 50; i++)
        {
            uint8 buffer[MAX_BUFFER];
            uint32 size = (cOSRand::rand() % (MAX_BUFFER - 2)) + 2;
            for (uint32 i = 0; i < size; i++)
            {
                buffer[i] = (uint8)cOSRand::rand();
            }
            int type = cOSRand::rand();
            // Create the stream
            {
                cSmartPtr<basicIO> stream = createStream(type);
                stream->pipeWrite(buffer, size);
                closeStream(type, stream);
            }

            // Read from the stream with seeking...
            {
                cSmartPtr<basicIO> rstream = createReadStream(type);

                // From begin
                unsigned int idx;
                for (idx = 0; idx < 10; idx++)
                {
                    int positionFromBegin = cOSRand::rand() % size;
                    rstream->seek(positionFromBegin, basicInput::IO_SEEK_SET);
                    uint8 ch;
                    TESTS_ASSERT_EQUAL(rstream->pipeRead(&ch, 1), 1);
                    TESTS_ASSERT_EQUAL(buffer[positionFromBegin], ch);
                }

                // From end
                for (idx = 0; idx < 10; idx++)
                {
                    int positionFromEnd = (cOSRand::rand() % (size - 1)) + 1;
                    positionFromEnd = -positionFromEnd;
                    rstream->seek(positionFromEnd, basicInput::IO_SEEK_END);
                    uint8 ch;
                    TESTS_ASSERT_EQUAL(rstream->pipeRead(&ch, 1), 1);
                    TESTS_ASSERT_EQUAL(buffer[size + positionFromEnd], ch);
                }
            }

            cout << '-';
            cout.flush();
        }
    }
Ejemplo n.º 10
0
OSStatus AudioHardwareImpl::start(AudioDeviceIOProcID inProcID,
		AudioTimeStamp* ioRequestedStartTime, UInt32 inFlags)
{
	AudioHardwareStream* stream;
	
	if (m_streams.find(inProcID) != m_streams.end())
		return noErr;
	
	stream = createStream(inProcID);
	m_streams[inProcID] = stream;
	
	// TODO: time
	
	return stream;
}
Ejemplo n.º 11
0
status_t ProCamera::createStreamCpu(int width, int height, int format,
                                    int heapCount,
                                    bool synchronousMode,
                                    /*out*/
                                    sp<CpuConsumer>* cpuConsumer,
                                    int* streamId)
{
    ALOGV("%s: createStreamW %dx%d (fmt=0x%x)", __FUNCTION__, width, height,
                                                                        format);

    *cpuConsumer = NULL;

    sp <IProCameraUser> c = mCamera;
    if (c == 0) return NO_INIT;

    sp<BufferQueue> bq = new BufferQueue();
    sp<CpuConsumer> cc = new CpuConsumer(bq, heapCount/*, synchronousMode*/);
    cc->setName(String8("ProCamera::mCpuConsumer"));

    sp<Surface> stc = new Surface(bq);

    status_t s = createStream(width, height, format,
                              stc->getIGraphicBufferProducer(),
                              streamId);

    if (s != OK) {
        ALOGE("%s: Failure to create stream %dx%d (fmt=0x%x)", __FUNCTION__,
                    width, height, format);
        return s;
    }

    sp<ProFrameListener> frameAvailableListener =
        new ProFrameListener(this, *streamId);

    getStreamInfo(*streamId).cpuStream = true;
    getStreamInfo(*streamId).cpuConsumer = cc;
    getStreamInfo(*streamId).synchronousMode = synchronousMode;
    getStreamInfo(*streamId).stc = stc;
    // for lifetime management
    getStreamInfo(*streamId).frameAvailableListener = frameAvailableListener;

    cc->setFrameAvailableListener(frameAvailableListener);

    *cpuConsumer = cc;

    return s;
}
Ejemplo n.º 12
0
aalError Sample::load() {
	
	if(length != 0) {
		return AAL_ERROR_INIT;
	}
	
	Stream * stream = createStream(name);
	if(!stream) {
		return AAL_ERROR_FILEIO;
	}
	
	stream->getFormat(format);
	length = stream->getLength();
	deleteStream(stream);
	
	return AAL_OK;
}
Ejemplo n.º 13
0
status_t ProCamera::createStream(int width, int height, int format,
                                 const sp<Surface>& surface,
                                 /*out*/
                                 int* streamId)
{
    *streamId = -1;

    ALOGV("%s: createStreamW %dx%d (fmt=0x%x)", __FUNCTION__, width, height,
                                                                       format);

    if (surface == 0) {
        return BAD_VALUE;
    }

    return createStream(width, height, format,
                        surface->getIGraphicBufferProducer(),
                        streamId);
}
Ejemplo n.º 14
0
    void test_remote_address()
    {
        // Create memory-stream
        BasicIOPtr stream = createStream(0);
        // Start by normally encode a series of default memory stream
        #define NUMBER_OF_ADDRESSES (100)
        cSArray<remoteAddressNumericValue> m_address(NUMBER_OF_ADDRESSES);
        // Serialize
        for (uint i = 0; i < 100; i++)
        {
            // Randomize
            m_address[i] = remoteAddressNumericValue((addressNumericValue)(cOSRand::rand()));
            // And encode
            stream->streamWriteRemoteAddress(m_address[i]);
        }
        stream->seek(0, basicIO::IO_SEEK_SET);
        // Deserialize
        for (uint i = 0; i < 100; i++)
        {
            remoteAddressNumericValue temp = stream->streamReadRemoteAddress();
            TESTS_ASSERT_EQUAL(temp, m_address[i]);
        }

        // Now test for clipping!
        stream->seek(0, basicIO::IO_SEEK_SET);
        stream->changeEncodedAddressType(false, REMOTE_ADDRESS_64BIT);
        stream->changeDecodedAddressType(false, REMOTE_ADDRESS_64BIT);
        // Serialize
        for (uint i = 0; i < 100; i++)
            stream->streamWriteRemoteAddress(m_address[i]);

        stream->seek(0, basicIO::IO_SEEK_SET);
        // Deserialize
        for (uint i = 0; i < 100; i++)
        {
            remoteAddressNumericValue temp = stream->streamReadRemoteAddress();
            TESTS_ASSERT_EQUAL(temp, m_address[i]);
        }

    }
Ejemplo n.º 15
0
    void test_read_write()
    {
        for (unsigned int i = 0; i < 50; i++)
        {
            uint8 buffer[MAX_BUFFER];
            uint8 read[MAX_BUFFER];
            uint32 size = (cOSRand::rand() % (MAX_BUFFER - 1)) + 1;
            for (uint32 i = 0; i < size; i++)
            {
                buffer[i] = (uint8)cOSRand::rand();
                read[i] = 0;
            }

            int type = cOSRand::rand();

            // Write out to the stream
            {
                cSmartPtr<basicIO> stream = createStream(type);
                stream->pipeWrite(buffer, size);
                closeStream(type, stream);
            }

            // Read from the stream
            {
                cSmartPtr<basicIO> rstream = createReadStream(type);
                rstream->pipeRead(read, size);

                // Test the reading
                for (uint32 j = 0; j < size; j++)
                {
                    TESTS_ASSERT_EQUAL(read[j], buffer[j]);
                }

                TESTS_ASSERT(rstream->isEOS());
            }

            cout << ',';
            cout.flush();
        }
    }
Ejemplo n.º 16
0
// Creates the stream, registers the data and end events and starts the stream
void readFile( void * loop ){

    gEventLoop = loop;

    void * stream = createStream( "prod", "stahp", chunk, initRead, loop );

    if (stream == NULL){
        fprintf(stderr, "cannot create stream\n");
        exit(-1);
    }
    
    // remember the stream for use in terminate function
    gStream = stream;

    registerEvent( loop, "prod", addToSum );

    registerEvent( loop, "stahp", terminate );

    // start the stream
    startStream( stream, fileName );
    
}
Ejemplo n.º 17
0
void LasReader::initialize()
{
    if (m_initialized)
        return;
    m_istream = createStream();

    m_istream->seekg(0);
    ILeStream in(m_istream);
    in >> m_lasHeader;

    if (!m_lasHeader.pointFormatSupported())
    {
        std::ostringstream oss;
        oss << "Unsupported LAS input point format: " <<
            (int)m_lasHeader.pointFormat() << ".";
       throw pdal_error(oss.str());
    }

    // We need to read the VLRs in initialize() because they may contain an
    // extra-bytes VLR that is needed to determine dimensions.
    m_istream->seekg(m_lasHeader.vlrOffset());
    for (size_t i = 0; i < m_lasHeader.vlrCount(); ++i)
    {
        VariableLengthRecord r;
        in >> r;
        m_vlrs.push_back(std::move(r));
    }

    if (m_lasHeader.versionAtLeast(1, 4))
    {
        m_istream->seekg(m_lasHeader.eVlrOffset());
        for (size_t i = 0; i < m_lasHeader.eVlrCount(); ++i)
        {
            ExtVariableLengthRecord r;
            in >> r;
            m_vlrs.push_back(std::move(r));
        }
        readExtraBytesVlr();
    }
Ejemplo n.º 18
0
/*============================================================================
  Description:  (API Call) Writes an entire stream in one pass.
  Arguments: 
   io_pStorage - pointer to parent storage in which to create the new stream
   in_wszStreamName - name of new stream
   in_pvBuf - data to write into stream
   in_pcbBufSize - number of bytes in in_pvBuf
  Return:
   Status code
  ==========================================================================*/
int
flushStream(Storage* io_pStorage,
            const wchar_t* in_wszStreamName,
            const void* in_pvBuf,
            unsigned long* in_pcbBufSize)
{
    int     iRet =          SSTG_OK;
    Stream* pNewStream =    NULL;

    ASSERT ((io_pStorage != NULL) &&
            (in_wszStreamName != NULL) &&
            (*in_wszStreamName != 0) &&
            (in_pvBuf != NULL));
    if ((io_pStorage == NULL) ||
        (in_wszStreamName == NULL) ||
        (*in_wszStreamName == 0) ||
        (in_pvBuf == NULL))
    {
        return SSTG_ERROR_ILLEGAL_CALL;
    }

    _KABOOM1;

    iRet = createStream(io_pStorage, in_wszStreamName, &pNewStream);
    if (iRet != SSTG_OK)
    {
        return iRet;
    }

    iRet = streamWrite(pNewStream, in_pvBuf, in_pcbBufSize);
    if (iRet != SSTG_OK)
    {
        return iRet;
    }

    iRet = closeStream(&pNewStream);

    return iRet;
}
Ejemplo n.º 19
0
bool SimplePdbPlugin::readMetainfo(Book &book) const {
	const ZLFile &file = book.file();
	shared_ptr<ZLInputStream> stream = createStream(file);
	detectEncodingAndLanguage(book, *stream);
	if (book.encoding().empty()) {
		return false;
	}
	int readType = HtmlMetainfoReader::NONE;
	if (book.title().empty()) {
		readType |= HtmlMetainfoReader::TITLE;
	}
	if (book.authors().empty()) {
		readType |= HtmlMetainfoReader::AUTHOR;
	}
	if (readType != HtmlMetainfoReader::NONE) {
	//if ((readType != HtmlMetainfoReader::NONE) && TextFormatDetector().isHtml(*stream)) {
		readType |= HtmlMetainfoReader::TAGS;
		HtmlMetainfoReader metainfoReader(book, (HtmlMetainfoReader::ReadType)readType);
		metainfoReader.readDocument(*stream);
	}

	return true;
}
Ejemplo n.º 20
0
FormatInfoPage *ZTXTPlugin::createInfoPage(ZLOptionsDialog &dialog, const std::string &fileName) {
	ZLFile file(fileName);
	fb::shared_ptr<ZLInputStream> stream = createStream(file);
	return new PlainTextInfoPage(dialog, fileName, ZLResourceKey("Text"), !TextFormatDetector().isHtml(*stream));
}
Ejemplo n.º 21
0
Common::SeekableReadStream *BlbArchive::createStream(uint index) {
	return createStream(&_entries[index]);
}
Ejemplo n.º 22
0
/*
 * Class:     EnumAccel_Unit
 * Method:    creatStream
 * Signature: (I)V
 */
JNIEXPORT void JNICALL Java_EnumAccel_00024Unit_createStream (JNIEnv *env, jobject jobj, jint rank){

  int h = createStream(rank);
}
Ejemplo n.º 23
0
// Loads the old save by constructing a new save containing the old save's data
bool SaveConverter_v3::load() {
	clear();

	uint32 varSize = SaveHandler::getVarSize(_vm);
	if (varSize == 0)
		return false;

	Common::InSaveFile *save;

	int type = isOldSave(&save);

	// Test if it's an old savd
	if ((type == 0) || !save)
		return false;

	displayWarning();

	bool screenShot;
	uint32 screenShotWidth;
	uint32 screenShotHeight;

	getScreenShotProps(type, screenShot, screenShotWidth, screenShotHeight);

	SaveWriter writer(screenShot ? 3 : 2, 0);

	SavePartInfo *info = readInfo(*save, kSlotNameLength, false);
	if (!info)
		return loadFail(0, 0, 0, save);

	SavePartVars *vars = readVars(*save, varSize, true);
	if (!vars)
		return loadFail(info, 0, 0, save);

	if (screenShot) {
		SavePartSprite *sprite = readSprite(*save, screenShotWidth, screenShotHeight, true);

		if (!sprite)
			return loadFail(info, vars, 0, save);

		if (!writer.writePart(2, sprite))
			return loadFail(info, vars, sprite, save);

		delete sprite;
	}

	// We don't need the save anymore
	delete save;

	// Write all parts
	if (!writer.writePart(0, info))
		return loadFail(info, vars, 0, 0);
	if (!writer.writePart(1, vars))
		return loadFail(info, vars, 0, 0);

	// We don't need those anymore
	delete info;
	delete vars;

	// Create the final read stream
	if (!createStream(writer))
		return loadFail(0, 0, 0, 0);

	return true;
}
Ejemplo n.º 24
0
 void useStream( std::string const& streamName ) {
     Stream stream = createStream( streamName );
     setStreamBuf( stream.streamBuf );
     m_stream.release();
     m_stream = stream;
 }
Ejemplo n.º 25
0
int createParticle(pScene sc,pMesh mesh) {
  pParticle   pp;
  pStream     st;
  pMaterial   pm;
  pTetra      pt1;
  pTriangle   pt;
  pPoint      ppt;
  double      v[4],cx,cy,cz;
  int         i,j,k,l,nmat,nbp,base;

  if ( ddebug )  printf("create particles\n");
  if ( egal(sc->iso.val[0],sc->iso.val[MAXISO-1]) )  return(0);

  if ( sc->stream ) { 
    st = sc->stream;
    if ( st->listp )  free(st->listp);
    free(sc->stream);
  }
  sc->stream     = createStream(sc,mesh);
  sc->par.cumtim = 0.0;
  sc->par.advtim = 0;
  assert(sc->stream);
  st = sc->stream;

  fprintf(stdout," Creating particles :");  fflush(stdout);
  st->nbstl = 0;

  base = ++mesh->mark;
  pt   = &mesh->tria[refitem];
  nmat = matRef(sc,pt->ref);
  pm   = &sc->material[nmat];
  k    = pm->depmat[LTria];
  if ( !k || pm->flag )  return(0);

  /* point positions */
  for (i=1; i<=mesh->np; i++) {
    ppt = &mesh->point[i];
    ppt->mark = base;
  }
  if ( sc->par.nbpart >= MAX_PRT )
    sc->par.nbpart = MAX_PRT;

  ++base;
  l   = 1;
  nbp = 0;
  while ( k != 0 && st->nbstl < MAX_LST-1 ) {
    pt = &mesh->tria[k];
    if ( pt->v[0] ) {
      cx = cy = cz = 0.0;
      for (i=0; i<3; i++) {
        ppt = &mesh->point[pt->v[i]];
        cx += 0.33 * ppt->c[0];
        cy += 0.33 * ppt->c[1];
        cz += 0.33 * ppt->c[2];
        ppt->flag = 1;
      }  
      st->listp[l++] = cx;
      st->listp[l++] = cy;
      st->listp[l++] = cz;
      ++st->nbstl;
      if ( st->nbstl > MAX_LST-1 ) break;
      k = pt->nxt;
    }
  }
  fprintf(stdout,"%d\n",st->nbstl);
  if ( !st->nbstl )  return(0);

  /* init positions */
  tp = calloc((st->nbstl+1),sizeof(Particle));
  assert(tp);
  for (k=1; k<=st->nbstl; k++)
    tp[k].nsdep = mesh->ntet / 2;

  for (k=1; k<=mesh->ntet; k++)
    mesh->tetra[k].cpt = 0;

  l = 1;
  for (k=1; k<=st->nbstl; k++) {
    pp = &tp[k];
    pp->pos[1][0] = st->listp[l++];
    pp->pos[1][1] = st->listp[l++];
    pp->pos[1][2] = st->listp[l++];

    tp[k].nsdep = locateTetra(mesh,pp->nsdep,++mesh->mark,pp->pos[1],pp->cb);

    if ( !pp->nsdep ) {
      for (j=1; j<=mesh->ntet; j++) {
        pt1 = &mesh->tetra[j];
        if ( pt1->mark != mesh->mark && inTetra(mesh,j,pp->pos[1],pp->cb) )
          break;
      }
      if ( j > mesh->ntet )  return(0);
      else
        pp->nsdep = j;
    }
    pp->norm  = field3DInterp(mesh,tp[k].nsdep,tp[k].cb,v);
    pp->size  = sizeTetra(mesh,tp[k].nsdep);
    if ( pp->size == 0.0 )
      pp->step = EPS*sc->dmax;
    else
      pp->step = HSIZ * min(pp->size,pp->norm);
    pp->step = min(0.05*sc->par.dt,pp->step);
    pp->flag =  1;
    pp->cur  =  1;
    colorParticle(sc,pp);

    for (i=2; i<=sc->par.nbpart; i++) {
      pp->pos[i][0] = pp->pos[1][0];
      pp->pos[i][1] = pp->pos[1][1];
      pp->pos[i][2] = pp->pos[1][2];
    }
  }

  return(1);
}
Ejemplo n.º 26
0
/*
 * For server: create the shared memory.  Create incoming and
 * outgoing streams.
 */
static jint
createConnection(SharedMemoryTransport *transport, jlong otherPID, 
                 SharedMemoryConnection **connectionPtr)
{
    jint error;
    char streamPrefix[MAX_IPC_NAME];

    SharedMemoryConnection *connection = allocConnection();
    if (connection == NULL) {
        return SYS_NOMEM;
    }

    sprintf(connection->name, "%s.%ld", transport->name, otherPID);
    error = sysSharedMemCreate(connection->name, sizeof(SharedMemory),
                               &connection->sharedMemory, &connection->shared);
    if (error != SYS_OK) {
        closeConnection(connection);
        return error;
    }

    memset(connection->shared, 0, sizeof(SharedMemory));

    /* This process is the server */
    connection->incoming.shared = &connection->shared->toServer;
    connection->outgoing.shared = &connection->shared->toClient;

    strcpy(streamPrefix, connection->name);
    strcat(streamPrefix, ".ctos");
    error = createStream(streamPrefix, &connection->incoming);
    if (error != SYS_OK) {
        closeConnection(connection);
        return error;
    }

    strcpy(streamPrefix, connection->name);
    strcat(streamPrefix, ".stoc");
    error = createStream(streamPrefix, &connection->outgoing);
    if (error != SYS_OK) {
        closeConnection(connection);
        return error;
    }

    error = sysProcessOpen(otherPID, &connection->otherProcess);
    if (error != SYS_OK) {
        fprintf(stderr,"Error accessing process, rc = %d\n", error);
        closeConnection(connection);
        return error;
    }

    /*
     * Create an event that signals that the connection is shutting 
     * down. The event is unnamed as it's process local, and is 
     * manually reset (so that a signalling the event will signal
     * all threads waiting on it).
     */
    error = sysEventCreate(NULL, &connection->shutdown, JNI_TRUE);
    if (error != SYS_OK) {
        fprintf(stderr,"Error creating unnamed event, rc = %d\n", error);
	closeConnection(connection);
	return error;
    }

    *connectionPtr = connection;
    return SYS_OK;
}
status_t BnCameraDeviceUser::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case DISCONNECT: {
            ALOGV("DISCONNECT");
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            disconnect();
            reply->writeNoException();
            return NO_ERROR;
        } break;
        case SUBMIT_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            // arg0 = request
            sp<CaptureRequest> request;
            if (data.readInt32() != 0) {
                request = new CaptureRequest();
                request->readFromParcel(const_cast<Parcel*>(&data));
            }

            // arg1 = streaming (bool)
            bool repeating = data.readInt32();

            // return code: requestId (int32)
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);

            return NO_ERROR;
        } break;
        case SUBMIT_REQUEST_LIST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            List<sp<CaptureRequest> > requestList;
            int requestListSize = data.readInt32();
            for (int i = 0; i < requestListSize; i++) {
                if (data.readInt32() != 0) {
                    sp<CaptureRequest> request = new CaptureRequest();
                    if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) {
                        return BAD_VALUE;
                    }
                    requestList.push_back(request);
                } else {
                    sp<CaptureRequest> request = 0;
                    requestList.push_back(request);
                    ALOGE("A request is missing. Sending in null request.");
                }
            }

            bool repeating = data.readInt32();

            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);

            return NO_ERROR;
        } break;
        case CANCEL_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int requestId = data.readInt32();
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(cancelRequest(requestId, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);
            return NO_ERROR;
        } break;
        case DELETE_STREAM: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int streamId = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(deleteStream(streamId));
            return NO_ERROR;
        } break;
        case CREATE_STREAM: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            status_t ret = BAD_VALUE;
            if (data.readInt32() != 0) {
                OutputConfiguration outputConfiguration(data);
                ret = createStream(outputConfiguration);
            } else {
                ALOGE("%s: cannot take an empty OutputConfiguration", __FUNCTION__);
            }

            reply->writeNoException();
            ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__);
            reply->writeInt32(ret);
            ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret);

            return NO_ERROR;
        } break;
        case CREATE_INPUT_STREAM: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int width, height, format;

            width = data.readInt32();
            height = data.readInt32();
            format = data.readInt32();
            status_t ret = createInputStream(width, height, format);

            reply->writeNoException();
            reply->writeInt32(ret);
            return NO_ERROR;

        } break;
        case GET_INPUT_SURFACE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            sp<IGraphicBufferProducer> bp;
            status_t ret = getInputBufferProducer(&bp);
            sp<IBinder> b(IInterface::asBinder(ret == OK ? bp : NULL));

            reply->writeNoException();
            reply->writeInt32(ret);
            reply->writeInt32(1);
            reply->writeString16(String16("camera input")); // name of surface
            reply->writeStrongBinder(b);

            return NO_ERROR;
        } break;
        case CREATE_DEFAULT_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            int templateId = data.readInt32();

            CameraMetadata request;
            status_t ret;
            ret = createDefaultRequest(templateId, &request);

            reply->writeNoException();
            reply->writeInt32(ret);

            // out-variables are after exception and return value
            reply->writeInt32(1); // to mark presence of metadata object
            request.writeToParcel(const_cast<Parcel*>(reply));

            return NO_ERROR;
        } break;
        case GET_CAMERA_INFO: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            CameraMetadata info;
            status_t ret;
            ret = getCameraInfo(&info);

            reply->writeNoException();
            reply->writeInt32(ret);

            // out-variables are after exception and return value
            reply->writeInt32(1); // to mark presence of metadata object
            info.writeToParcel(reply);

            return NO_ERROR;
        } break;
        case WAIT_UNTIL_IDLE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            reply->writeInt32(waitUntilIdle());
            return NO_ERROR;
        } break;
        case FLUSH: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(flush(&lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);
            return NO_ERROR;
        }
        case BEGIN_CONFIGURE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            reply->writeInt32(beginConfigure());
            return NO_ERROR;
        } break;
        case END_CONFIGURE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            bool isConstrainedHighSpeed = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(endConfigure(isConstrainedHighSpeed));
            return NO_ERROR;
        } break;
        case PREPARE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int streamId = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(prepare(streamId));
            return NO_ERROR;
        } break;
        case TEAR_DOWN: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int streamId = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(tearDown(streamId));
            return NO_ERROR;
        } break;

        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}
Ejemplo n.º 28
0
aalError DSoundSource::init(SourceId _id, const Channel & _channel) {
	
	id = _id;
	
	DSBUFFERDESC _desc;
	WAVEFORMATEX _format;
	bool streaming(false);
	
	clean();
	
	channel = _channel;
	
	memset(&_desc, 0, sizeof(DSBUFFERDESC));
	_desc.dwSize = sizeof(DSBUFFERDESC);
	_desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2;
	
	if(channel.flags & FLAG_VOLUME) {
		_desc.dwFlags |= DSBCAPS_CTRLVOLUME;
	}
	if(channel.flags & FLAG_PITCH) {
		_desc.dwFlags |= DSBCAPS_CTRLFREQUENCY;
	}
	if(channel.flags & FLAG_PAN) {
		_desc.dwFlags |= DSBCAPS_CTRLPAN;
	}
	
	if(channel.flags & FLAG_ANY_3D_FX) {
		_desc.dwFlags |= DSBCAPS_CTRL3D;
		_desc.dwFlags &= ~DSBCAPS_CTRLPAN;
		channel.flags &= ~FLAG_PAN;
	}
	
	_desc.lpwfxFormat = &_format;
	
	_format.nSamplesPerSec = sample->getFormat().frequency;
	_format.wBitsPerSample = (WORD)sample->getFormat().quality;
	_format.nChannels = (WORD)sample->getFormat().channels;
	_format.wFormatTag = WAVE_FORMAT_PCM;
	_format.nBlockAlign = (WORD)(sample->getFormat().channels * (sample->getFormat().quality >> 3));
	_format.nAvgBytesPerSec = _format.nBlockAlign * sample->getFormat().frequency;
	_format.cbSize = 0;
	
	// Get buffer size and determine if streaming must be enable
	if(sample->getLength() > stream_limit_bytes) {
		size = stream_limit_bytes, streaming = true;
	} else {
		size = sample->getLength();
	}
	_desc.dwBufferBytes = size;
	
	if(backend->device->CreateSoundBuffer(&_desc, &lpdsb, NULL)) {
		return AAL_ERROR_SYSTEM;
	}
	
	if(aalError error = init()) {
		return error;
	}
	
	stream = createStream(sample->getName());
	
	if(!stream) {
		return AAL_ERROR_FILEIO;
	}
	
	// Load sample data if not streamed
	if(!streaming) {
		
		if(stream->setPosition(0)) {
			return AAL_ERROR_SYSTEM;
		}
		
		DWORD cur0, cur1;
		void * ptr0, *ptr1;
		if(lpdsb->Lock(0, 0, &ptr0, &cur0, &ptr1, &cur1, DSBLOCK_ENTIREBUFFER)) {
			return AAL_ERROR_SYSTEM;
		}
		
		stream->read(ptr0, size, write);
		
		if(lpdsb->Unlock(ptr0, cur0, ptr1, cur1)) {
			return AAL_ERROR_SYSTEM;
		}
		
		if(write != size) {
			return AAL_ERROR_SYSTEM;
		}
		
		deleteStream(stream);
	}
	
	return AAL_OK;
}
Ejemplo n.º 29
0
SINT4
storageSelfTest1(StgMode in_stgModeOpen, StgMode in_stgModeCreate)
{
    SINT4           iRet =          SSTG_OK;
    RootStorage*    pRoot =         NULL;
    Storage*        pStorage1 =     NULL;
    Storage*        pStorage2 =     NULL;
    Storage*        pStorage3 =     NULL;
    Stream*         pStream1 =      NULL;
    Stream*         pStream2 =      NULL;
    Stream*         pStream3 =      NULL;
    Stream*         pStream4 =      NULL;
    int             cch =           0;
    unsigned long   cchL =          0;
    wchar_t         pwchBuf[] =     L"Stuff to write into streams";
    wchar_t         pwchBuf2[60];

    /* The main thing being tested here is the open list.  If the calling
     * application fails to close some streams and storages before closing
     * the structured storage file, the structured storage library is supposed 
     * to clean everything up automatically.
     */

    /* Create a bunch of streams and storages */
    iRet = createStructuredStorageEx (WSZ_TEST_FILENAME, in_stgModeCreate, &pRoot, 0);
    ASSERT (iRet == SSTG_OK && pRoot != NULL);

    iRet = getStorageFromRoot (pRoot, &pStorage1);
    ASSERT (iRet == SSTG_OK && pStorage1 != NULL);

    iRet = createStream (pStorage1, WSZ_TEST_STREAM_1, &pStream1);
    ASSERT (iRet == SSTG_OK && pStream1 != NULL);

    cch = 0;
    ASSERT (writeLEwstring(pStream1, pwchBuf, &cch) == SSTG_OK && cch == 28);

    iRet = createStorage (pStorage1, WSZ_TEST_STORAGE_2, &pStorage2);
    ASSERT (iRet == SSTG_OK && pStorage2 != NULL);

    iRet = createStorage (pStorage2, WSZ_TEST_STORAGE_3, &pStorage3);
    ASSERT (iRet == SSTG_OK && pStorage3 != NULL);

    iRet = createStream (pStorage2, WSZ_TEST_STREAM_2, &pStream2);
    ASSERT (iRet == SSTG_OK && pStream2 != NULL);

    cch = 0;
    ASSERT (writeLEwstring(pStream2, pwchBuf, &cch) == SSTG_OK && cch == 28);

    cchL = 28 * sizeof(wchar_t);
    iRet = flushStream(pStorage2, WSZ_TEST_STREAM_3, pwchBuf, &cchL);
    ASSERT(iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t)));

    /* Test to ensure that destroying a mini stream works */
    cchL = 28 * sizeof(wchar_t);
    iRet = flushStream(pStorage2, WSZ_TEST_STREAM_4, pwchBuf, &cchL);
    ASSERT(iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t)));
    iRet = destroy(pStorage2, WSZ_TEST_STREAM_4);
    ASSERT(iRet == SSTG_OK);

    /* Test to make sure duplicates are not allowed */
    iRet = createStream(pStorage2, WSZ_TEST_STREAM_3, &pStream4);
    ASSERT (iRet != SSTG_OK && pStream4 == NULL);

    /* Now close the entire compound file without closing any of the open
     * children */
    iRet = closeStructuredStorage(&pRoot);
    ASSERT (iRet == SSTG_OK && pRoot == NULL);

    pStorage1 = NULL;
    pStorage2 = NULL;
    pStorage3 = NULL;
    pStream1 = NULL;
    pStream2 = NULL;
    pStream3 = NULL;

    /* Now do the same thing for reading. */
    /* Open a bunch of streams and storages for reading. */
    iRet = openStructuredStorageEx (WSZ_TEST_FILENAME, in_stgModeOpen, &pRoot);
    ASSERT (iRet == SSTG_OK);

    iRet = getStorageFromRoot (pRoot, &pStorage1);
    ASSERT (iRet == SSTG_OK && pStorage1 != NULL);

    iRet = openStream (pStorage1, WSZ_TEST_STREAM_1, &pStream1);
    ASSERT (iRet == SSTG_OK && pStream1 != NULL);

    cch = 28;
    iRet = readLEwstring(pStream1, &cch, pwchBuf2);
    ASSERT (iRet == SSTG_OK && cch == 28);
    ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0);
    memset(pwchBuf2, 0, sizeof(pwchBuf2));

    iRet = openStorage (pStorage1, WSZ_TEST_STORAGE_2, &pStorage2);
    ASSERT (iRet == SSTG_OK && pStorage2 != NULL);

    iRet = openStorage (pStorage2, WSZ_TEST_STORAGE_3, &pStorage3);
    ASSERT (iRet == SSTG_OK && pStorage3 != NULL);

    iRet = openStream (pStorage2, WSZ_TEST_STREAM_2, &pStream2);
    ASSERT (iRet == SSTG_OK && pStream2 != NULL);

    cch = 28;
    ASSERT (readLEwstring(pStream2, &cch, pwchBuf2) == SSTG_OK && cch == 28);
    ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0);
    memset(pwchBuf2, 0, sizeof(pwchBuf2));

    iRet = openStream (pStorage2, WSZ_TEST_STREAM_3, &pStream3);
    ASSERT (iRet == SSTG_OK && pStream3 != NULL);

    cch = 28 * sizeof(wchar_t);
    iRet = streamRead(pStream3, pwchBuf2, &cchL);
    ASSERT (iRet == SSTG_OK && cchL == (28 * sizeof(wchar_t)));
    ASSERT (memcmp(pwchBuf, pwchBuf2, wcslen(pwchBuf) + 1) == 0);
    memset(pwchBuf2, 0, sizeof(pwchBuf2));

    /* Close the entire compound file without closing any of the open
     * children */
    iRet = closeStructuredStorage(&pRoot);
    ASSERT (iRet == SSTG_OK && pRoot == NULL);

    /* Remove test file */
    SSRW_WREMOVE (WSZ_TEST_FILENAME);

    return iRet;
}
status_t BnCameraDeviceUser::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case DISCONNECT: {
            ALOGV("DISCONNECT");
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            disconnect();
            reply->writeNoException();
            return NO_ERROR;
        } break;
        case SUBMIT_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            // arg0 = request
            sp<CaptureRequest> request;
            if (data.readInt32() != 0) {
                request = new CaptureRequest();
                request->readFromParcel(const_cast<Parcel*>(&data));
            }

            // arg1 = streaming (bool)
            bool repeating = data.readInt32();

            // return code: requestId (int32)
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(submitRequest(request, repeating, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);

            return NO_ERROR;
        } break;
        case SUBMIT_REQUEST_LIST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            List<sp<CaptureRequest> > requestList;
            int requestListSize = data.readInt32();
            for (int i = 0; i < requestListSize; i++) {
                if (data.readInt32() != 0) {
                    sp<CaptureRequest> request = new CaptureRequest();
                    if (request->readFromParcel(const_cast<Parcel*>(&data)) != OK) {
                        return BAD_VALUE;
                    }
                    requestList.push_back(request);
                } else {
                    sp<CaptureRequest> request = 0;
                    requestList.push_back(request);
                    ALOGE("A request is missing. Sending in null request.");
                }
            }

            bool repeating = data.readInt32();

            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(submitRequestList(requestList, repeating, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);

            return NO_ERROR;
        } break;
        case CANCEL_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int requestId = data.readInt32();
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(cancelRequest(requestId, &lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);
            return NO_ERROR;
        } break;
        case DELETE_STREAM: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int streamId = data.readInt32();
            reply->writeNoException();
            reply->writeInt32(deleteStream(streamId));
            return NO_ERROR;
        } break;
        case CREATE_STREAM: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            int width, height, format;

            width = data.readInt32();
            ALOGV("%s: CREATE_STREAM: width = %d", __FUNCTION__, width);
            height = data.readInt32();
            ALOGV("%s: CREATE_STREAM: height = %d", __FUNCTION__, height);
            format = data.readInt32();
            ALOGV("%s: CREATE_STREAM: format = %d", __FUNCTION__, format);

            sp<IGraphicBufferProducer> bp;
            if (data.readInt32() != 0) {
                String16 name = readMaybeEmptyString16(data);
                bp = interface_cast<IGraphicBufferProducer>(
                        data.readStrongBinder());

                ALOGV("%s: CREATE_STREAM: bp = %p, name = %s", __FUNCTION__,
                      bp.get(), String8(name).string());
            } else {
                ALOGV("%s: CREATE_STREAM: bp = unset, name = unset",
                      __FUNCTION__);
            }

            status_t ret;
            ret = createStream(width, height, format, bp);

            reply->writeNoException();
            ALOGV("%s: CREATE_STREAM: write noException", __FUNCTION__);
            reply->writeInt32(ret);
            ALOGV("%s: CREATE_STREAM: write ret = %d", __FUNCTION__, ret);

            return NO_ERROR;
        } break;

        case CREATE_DEFAULT_REQUEST: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            int templateId = data.readInt32();

            CameraMetadata request;
            status_t ret;
            ret = createDefaultRequest(templateId, &request);

            reply->writeNoException();
            reply->writeInt32(ret);

            // out-variables are after exception and return value
            reply->writeInt32(1); // to mark presence of metadata object
            request.writeToParcel(const_cast<Parcel*>(reply));

            return NO_ERROR;
        } break;
        case GET_CAMERA_INFO: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);

            CameraMetadata info;
            status_t ret;
            ret = getCameraInfo(&info);

            reply->writeNoException();
            reply->writeInt32(ret);

            // out-variables are after exception and return value
            reply->writeInt32(1); // to mark presence of metadata object
            info.writeToParcel(reply);

            return NO_ERROR;
        } break;
        case WAIT_UNTIL_IDLE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            reply->writeInt32(waitUntilIdle());
            return NO_ERROR;
        } break;
        case FLUSH: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            int64_t lastFrameNumber = -1;
            reply->writeInt32(flush(&lastFrameNumber));
            reply->writeInt32(1);
            reply->writeInt64(lastFrameNumber);
            return NO_ERROR;
        }
        case BEGIN_CONFIGURE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            reply->writeInt32(beginConfigure());
            return NO_ERROR;
        } break;
        case END_CONFIGURE: {
            CHECK_INTERFACE(ICameraDeviceUser, data, reply);
            reply->writeNoException();
            reply->writeInt32(endConfigure());
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}