Esempio n. 1
0
void GameInstanceEngine::listLanguages() {
	createEngine();

	std::vector<Aurora::Language> langs;
	if (_engine->detectLanguages(_probe->getGameID(), _target, _probe->getPlatform(), langs)) {
		if (!langs.empty()) {
			info("Available languages:");
			for (std::vector<Aurora::Language>::iterator l = langs.begin(); l != langs.end(); ++l)
				info("- %s", LangMan.getLanguageName(*l).c_str());
		}
	}

	std::vector<Aurora::Language> langsT, langsV;
	if (_engine->detectLanguages(_probe->getGameID(), _target, _probe->getPlatform(), langsT, langsV)) {
		if (!langsT.empty()) {
			info("Available text languages:");
			for (std::vector<Aurora::Language>::iterator l = langsT.begin(); l != langsT.end(); ++l)
				info("- %s", LangMan.getLanguageName(*l).c_str());
		}

		if (!langsV.empty()) {
			info("Available voice languages:");
			for (std::vector<Aurora::Language>::iterator l = langsV.begin(); l != langsV.end(); ++l)
				info("- %s", LangMan.getLanguageName(*l).c_str());
		}
	}

	destroyEngine();
}
Esempio n. 2
0
void GameInstanceEngine::run() {
	createEngine();

	_engine->start(_probe->getGameID(), _target, _probe->getPlatform());

	destroyEngine();
}
Esempio n. 3
0
int and_osles::open(int sample_rate, int channel, int bitsPerSample)
{
	LOGI("and_osles open()");

	close();

	LOGI("sample_rate %d, channel %d, bitsPerSample %d", 
		sample_rate, channel, bitsPerSample);

	m_osles_handle = (osles_handle *)malloc(sizeof(osles_handle));
	if(!m_osles_handle) {
		LOGE("failed to alloc osles handle");
		return -1;
	}
	
	if( createEngine() < 0){
		LOGE("failed to create engine");
		return -1;
	}

	if( createBufferQueueAudioPlayer(sample_rate, channel, bitsPerSample) < 0) {
		LOGE("failed to create player");
		return -1;
	}

	m_fifo = new and_fifobuffer;
	m_fifo->create(AUDIO_FIFO_SIZE);

	m_one_sec_size = sample_rate * channel * bitsPerSample / 8;

	LOGI("osles opened: rate %d, chn %d, bit %d, one_sec_size %d", 
		sample_rate, channel, bitsPerSample, m_one_sec_size);
	return 0;
}
OpenSLSoundPool::OpenSLSoundPool(int maxStreams, SLuint32 samplingRate, SLuint32 bitrate):
		engineObject(NULL),
		outputMixObject(NULL),
		maxStreams(maxStreams),
		samplingRate(samplingRate),
		bitrate(bitrate){

	LOGI("MySoundPool");

	if (OpenSLSoundPool::instance != NULL){
		LOGI("Can only be instantiated once");
		exit(EXIT_FAILURE);
	}
	OpenSLSoundPool::instance = this;

	// see if OpenSL library is available
	void* handle = dlopen("libOpenSLES.so", RTLD_LAZY);
	if (handle == NULL){
		LOGI("OpenSLES not available");
		exit(EXIT_FAILURE);
	}

	bufferQueues = new std::vector<BufferQueue*>();

	samples = new std::vector<ResourceBuffer*>();

	LOGI("OpenSLES available");
	LOGI("Initializing");
	createEngine();
	createBufferQueueAudioPlayer();

	minVolume = SL_MILLIBEL_MIN;
	maxVolume = 0;
}
Esempio n. 5
0
        Engine()
            : engineObject (nullptr), engineInterface (nullptr), outputMixObject (nullptr)
        {
            if (library.open ("libOpenSLES.so"))
            {
                typedef SLresult (*CreateEngineFunc) (SLObjectItf*, SLuint32, const SLEngineOption*,
                                                      SLuint32, const SLInterfaceID*, const SLboolean*);

                if (CreateEngineFunc createEngine = (CreateEngineFunc) library.getFunction ("slCreateEngine"))
                {
                    check (createEngine (&engineObject, 0, nullptr, 0, nullptr, nullptr));

                    SLInterfaceID* SL_IID_ENGINE    = (SLInterfaceID*) library.getFunction ("SL_IID_ENGINE");
                    SL_IID_ANDROIDSIMPLEBUFFERQUEUE = (SLInterfaceID*) library.getFunction ("SL_IID_ANDROIDSIMPLEBUFFERQUEUE");
                    SL_IID_PLAY                     = (SLInterfaceID*) library.getFunction ("SL_IID_PLAY");
                    SL_IID_RECORD                   = (SLInterfaceID*) library.getFunction ("SL_IID_RECORD");
                    SL_IID_ANDROIDCONFIGURATION     = (SLInterfaceID*) library.getFunction ("SL_IID_ANDROIDCONFIGURATION");

                    check ((*engineObject)->Realize (engineObject, SL_BOOLEAN_FALSE));
                    check ((*engineObject)->GetInterface (engineObject, *SL_IID_ENGINE, &engineInterface));

                    check ((*engineInterface)->CreateOutputMix (engineInterface, &outputMixObject, 0, nullptr, nullptr));
                    check ((*outputMixObject)->Realize (outputMixObject, SL_BOOLEAN_FALSE));
                }
            }
        }
Esempio n. 6
0
// init mididriver
jboolean
Java_org_billthefarmer_accordion_MidiDriver_init(JNIEnv *env,
						 jobject obj)
{
    EAS_RESULT result;

    if (result = initEAS() != EAS_SUCCESS)
    {
	shutdownEAS();

	LOG_E(LOG_TAG, "Init EAS failed: %ld", result);

	return JNI_FALSE;
    }

    // LOG_D(LOG_TAG, "Init EAS success, buffer: %ld", bufferSize);

    // allocate buffer in bytes
    buffer = (EAS_PCM *)malloc(bufferSize * sizeof(EAS_PCM));
    if (buffer == NULL)
    {
	shutdownEAS();

	LOG_E(LOG_TAG, "Allocate buffer failed");

	return JNI_FALSE;
    }

    // create the engine and output mix objects
    if (result = createEngine() != SL_RESULT_SUCCESS)
    {
	shutdownEAS();
	shutdownAudio();
	free(buffer);
	buffer = NULL;

	LOG_E(LOG_TAG, "Create engine failed: %ld", result);

	return JNI_FALSE;
    }

    // create buffer queue audio player
    if (result = createBufferQueueAudioPlayer() != SL_RESULT_SUCCESS)
    {
	shutdownEAS();
	shutdownAudio();
	free(buffer);
	buffer = NULL;

	LOG_E(LOG_TAG, "Create buffer queue audio player failed: %ld", result);

	return JNI_FALSE;
    }

    // call the callback to start playing
    bqPlayerCallback(bqPlayerBufferQueue, NULL);

    return JNI_TRUE;
}
Esempio n. 7
0
void AndroidAudio::initAudio()
{
	if (!audioEnabled && myConfig->readConfigInt("PlaySoundEffects")) {
		createEngine();
		startSoundPlayer();
		audioEnabled = true;
	}
}
Esempio n. 8
0
QT_BEGIN_NAMESPACE

QCompletionModel::QCompletionModel(QCompleterPrivate *c, QObject *parent)
    : QAbstractProxyModel(*new QCompletionModelPrivate, parent),
      c(c), showAll(false)
{
    createEngine();
}
Esempio n. 9
0
void init(JNIEnv *env,jobject clz){
	LOGI("%s","init");
	init1(env,clz);
	createEngine();
	av_register_all();
	set_play_callback(play);
	av_log_set_callback(logg);
}
Esempio n. 10
0
/*!
  Constructs a QContactManager whose backend has the name \a managerName and version \a implementationVersion, where the manager
  is constructed with the provided \a parameters.

  The \a parent QObject will be used as the parent of this QContactManager.

  If an empty \a managerName is specified, the default implementation for the platform will be instantiated.
  If the specified implementation version is not available, the manager with the name \a managerName with the default implementation version is instantiated.
  \since 1.0
 */
QContactManager::QContactManager(const QString& managerName, int implementationVersion, const QMap<QString, QString>& parameters, QObject* parent)
    : QObject(parent),
    d(new QContactManagerData)
{
    QMap<QString, QString> params = parameters;
    params[QString(QLatin1String(QTCONTACTS_IMPLEMENTATION_VERSION_NAME))] = QString::number(implementationVersion);
    createEngine(managerName, params);
}
Esempio n. 11
0
SLESAudioTrack::SLESAudioTrack(int samplerate, int bitsPerSample, int channel):engineObject(NULL),engineEngine(NULL),
                                 outputMixObject(NULL),
                                 bqPlayerObject(NULL),bqPlayerPlay(NULL),
                                 bqPlayerBufferQueue(NULL),bqPlayerEffectSend(NULL),
                                 bqPlayerMuteSolo(NULL),bqPlayerVolume(NULL){
    if(SL_RESULT_SUCCESS == createEngine()){
        if(SL_RESULT_SUCCESS != createBufferQueueAudioPlayer(samplerate, bitsPerSample, channel)){
            releaseEngine();
        }
    }
}
Esempio n. 12
0
//===============================
// Initialize, with a Jconf file
//===============================
bool cJulius::initialize( char *filename )
{
	bool ret;

	release();

	if (! loadJconf( filename )) return false;

	ret = createEngine();

	return ret;
}
Esempio n. 13
0
/**
 * 初始化
 */
void SLESContext::init() {
    ALOGI("createEngine");
    SLresult result = createEngine();
    ALOGI("createEngine result is s%", resultToString(result));
    if (SL_RESULT_SUCCESS == result) {
        ALOGI("Realize the engine object");
        result = realizeObject(engineObject);
        if (SL_RESULT_SUCCESS == result) {
            ALOGI("Get the engine interface");
            result = GetEngineInterface();
        }
    }
}
Esempio n. 14
0
EditorFrame::EditorFrame(const wxString& title)
	: wxFrame(nullptr, wxID_ANY, title)
	, paneCtrl(nullptr)
	, toolbarCtrl(nullptr)
	, statusCtrl(nullptr)
	, notebookCtrl(nullptr)
	, eventManager(nullptr)
	, pluginManager(nullptr)
	, documentManager(nullptr)
	, engine(nullptr)
	, archive(nullptr)
	, input(nullptr)
{
	gs_EditorInstance = this;

	CoreInitialize();

#ifdef EDITOR_OLD_UI
	documentManager = AllocateThis(DocumentManager);
	documentManager->onDocumentAdded.Connect(this, &EditorFrame::onDocumentAdded);
	documentManager->onDocumentRemoved.Connect(this, &EditorFrame::onDocumentRemoved);
	documentManager->onDocumentRenamed.Connect(this, &EditorFrame::onDocumentRenamed);
#endif

	createPlugins();

#ifdef EDITOR_OLD_UI
	createUI();
#endif

	createEngine();
	eventManager = AllocateThis(EventManager);

#ifdef ENABLE_PLUGIN_MONO
	Plugin* monoPlugin = pluginManager->getPluginFromClass( ReflectionGetType(MonoPlugin) );
	pluginManager->enablePlugin(monoPlugin);
#endif

#ifdef EDITOR_OLD_UI
	enablePlugins();
	createToolbar();
	createLastUI();
#endif

	Bind(wxEVT_IDLE, &EditorFrame::OnIdle, this);
	Bind(wxEVT_CLOSE_WINDOW, &EditorFrame::OnClose, this);

    auto projectPlugin = GetPlugin<ProjectPlugin>();
    projectPlugin->createDocument();
}
Esempio n. 15
0
//=================================
// Initialize, with argument array
//=================================
bool cJulius::initialize( int argnum, char *argarray[])
{
	bool ret;

	release();

	m_jconf = j_config_load_args_new( argnum, argarray );

	if (m_jconf == NULL) {		/* error */
	    return false;
	}

	ret = createEngine();

	return ret;
}
Esempio n. 16
0
QmlCppEngine::QmlCppEngine(const DebuggerRunParameters &rp, QStringList *errors)
    : DebuggerEngine(rp)
{
    setObjectName(QLatin1String("QmlCppEngine"));
    m_qmlEngine = new QmlEngine(rp, this);
    QStringList innerErrors;
    m_cppEngine = createEngine(rp.cppEngineType, rp, &innerErrors);
    if (!m_cppEngine) {
        errors->append(tr("The slave debugging engine required for combined "
                          "QML/C++-Debugging could not be created: %1")
                       .arg(innerErrors.join(QLatin1Char('\n'))));
        return;
    }
    m_cppEngine->setMasterEngine(this);
    setActiveEngine(m_cppEngine);
}
void URendererAudioOpenSLES::start(){

	//创建播放引擎和播放对象
	if(!mPlayer || createEngine() || createBufferQueueAudioPlayer(this->mChannels,this->mSampleRate)){
		//设置出错标记
		mPrepared = false;
		this->mPlayer->notifyMsg(MEDIA_INFO_PREPARE_ERROR,ERROR_SOFT_PLAYER_OPENSLES);
		ulog_err("URendererAudioOpenSLES::start failed");
	}else{
		//设置音频渲染器状态
		ulog_info("URendererAudioOpenSLES::start\n");
		mPrepared = true;
		this->UThread::start();
		//AudioPlayerCallback(this->mPlayerBufferQueue,this->mPlayer);
	}

}
Esempio n. 18
0
static EmuEngine *loadEmuEngine(const char *dir, const char *lib)
{
	char path[1024];
	snprintf(path, sizeof(path), "%s/lib%s.so", dir, lib);

	void *handle = dlopen(path, RTLD_NOW);
	if (handle == NULL) {
		LOGD("Cannot load %s: %s", path, dlerror());
		return NULL;
	}

	EmuEngine *(*createEngine)() = (EmuEngine *(*)())
			dlsym(handle, "createEngine");
	if (createEngine == NULL) {
		dlclose(handle);
		return NULL;
	}
	return createEngine();
}
Esempio n. 19
0
/* SoundPlayer constructor */
SoundPlayer::SoundPlayer(AAssetManager* mgr):
    mgr(mgr),
    fdPlayerObject(NULL),
    fdPlayerPlay(NULL),
    fdPlayerSeek(NULL),
    fdPlayerMuteSolo(NULL),
    fdPlayerVolume(NULL)
{
    if ((engineRefs == 0) && createEngine())
    {
        acquiredEngineRef = true;
        engineRefs++;
    }
    else
    {
        acquiredEngineRef = true;
        engineRefs++;
    }
}
Esempio n. 20
0
        OpenSLSession (DynamicLibrary& slLibraryToUse,
                       int numInputChannels, int numOutputChannels,
                       double samleRateToUse, int bufferSizeToUse,
                       int numBuffersToUse)
            : inputChannels (numInputChannels), outputChannels (numOutputChannels),
              sampleRate (samleRateToUse), bufferSize (bufferSizeToUse), numBuffers (numBuffersToUse),
              running (false), audioProcessingEnabled (true), callback (nullptr)
        {
            jassert (numInputChannels > 0 || numOutputChannels > 0);

            if (CreateEngineFunc createEngine = (CreateEngineFunc) slLibraryToUse.getFunction ("slCreateEngine"))
            {
                SLObjectItf obj = nullptr;

                SLresult err = createEngine (&obj, 0, nullptr, 0, nullptr, nullptr);
                if (err != SL_RESULT_SUCCESS || obj == nullptr || (*obj)->Realize (obj, 0) != SL_RESULT_SUCCESS)
                {
                    if (obj != nullptr)
                        (*obj)->Destroy (obj);

                    return;
                }

                engine = SlRef<SLEngineItf_>::cast (SlObjectRef (obj));
            }

            if (outputChannels > 0)
            {
                SLObjectItf obj = nullptr;

                SLresult err = (*engine)->CreateOutputMix (engine, &obj, 0, nullptr, nullptr);
                if (err != SL_RESULT_SUCCESS || obj == nullptr || (*obj)->Realize (obj, 0) != SL_RESULT_SUCCESS)
                {
                    if (obj != nullptr)
                        (*obj)->Destroy (obj);

                    return;
                }

                outputMix = SlRef<SLOutputMixItf_>::cast (SlObjectRef (obj));
            }
        }
Esempio n. 21
0
int main(void)
{
	int width = 4;
	int height = 16;

	// create two players...
	Player *player1 = createPlayer("Player1");
	Player *player2 = createPlayer("Player2");

	// game logic and the like
	Engine *engine = createEngine(consoleRenderer, eventHandler);

	// initialize renderer
	initConsoleRenderer(width + 2, height + 2);

	while (TRUE)
	{
		// create the game board
		SuPong *suPong = createGame(width, height, player1, player2);
		resetEngine(engine);
		
		// now run the game...
		while (engine->state == RUNNING)
		{
			engineTick(engine, suPong);
			usleep(100000);
		}

		// engine->state now contains the winner...
		// you could for example restart the game for a next match...
		// do this by calling run(engine, suPong) again
		//	engine->state

		renderGameEnd(engine);
		usleep(1000000);
	}

	// shutdown renderer
	shutdownConsoleRenderer();

	return 0;
}
Esempio n. 22
0
int main(int argc, char** argv)
{
	// Create the OpenSL engine
	createEngine();

	// Create the audio player with everything ready.
	createUriAudioPlayer( "F:\\3DTetris\\trunk\\bin\\Adreno\\Sound\\MainTheme.wav" );

	printf("Playing...");
	setPlayingUriAudioPlayer(true);      // play the music
	getch();

	printf("Pause...");  
	setPlayingUriAudioPlayer(false);    // pause the player
	getch();

	printf("Playing...");    
	setPlayingUriAudioPlayer(true);

	getch();  // Just wait for the playing threads
}
static void runClassifier(const std::string& outputFilename,
	const std::string& inputFileNames, const std::string& modelFileName,
	bool shouldClassify, bool shouldTrain, bool shouldLearnFeatures, bool shouldExtractFeatures)
{
	util::log("minerva-classifier") << "Loading classifier.\n";

	classifiers::ClassifierEngine* engine = nullptr;

	try
	{
		checkInputs(inputFileNames, modelFileName, shouldClassify,
			shouldTrain, shouldLearnFeatures, shouldExtractFeatures);
	
		engine = createEngine(outputFilename, shouldClassify, shouldTrain,
			shouldLearnFeatures, shouldExtractFeatures);
		
		if(engine == nullptr)
		{
			throw std::runtime_error("Failed to create classifier engine.");
		}

		engine->loadModel(modelFileName);

		engine->runOnPaths(getPaths(inputFileNames));
		
		engine->reportStatistics(std::cout);
	
		delete engine;
	}
	catch(const std::exception& e)
	{
		std::cout << "Minerva Classifier Failed:\n";
		std::cout << "Message: " << e.what() << "\n\n";
		
		delete engine;
	}
	
}
Esempio n. 24
0
void EngineManager::run(GameInstance &game) const {
	try {
		createEngine(game);

		game._engine->run(game._target);
		EventMan.requestQuit();

		// Clean up after the engine
		cleanup(game);

		EventMan.doQuit();

	} catch(...) {
		EventMan.requestQuit();

		// Clean up after the engine
		cleanup(game);

		EventMan.doQuit();

		throw;
	}

}
int QGeoSatelliteInfoSourceGypsy::init()
{
    GError *error = NULL;
    char *path;
    GConfClient* client;
    gchar* device_name;

    g_type_init ();
    createEngine();

    client = m_engine->eng_gconf_client_get_default();
    if (!client) {
        qWarning ("QGeoSatelliteInfoSourceGypsy client creation failed.");
        return -1;
    }
    device_name = m_engine->eng_gconf_client_get_string(client, "/apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice", NULL);
    g_object_unref(client);
    QString deviceName(QString::fromAscii(device_name));
    if (deviceName.isEmpty() ||
            (deviceName.trimmed().at(0) == '/' && !QFile::exists(deviceName.trimmed()))) {
        qWarning ("QGeoSatelliteInfoSourceGypsy Empty/nonexistent GPS device name detected.");
        qWarning ("Use gconftool-2 to set it, e.g. on terminal: ");
        qWarning ("gconftool-2 -t string -s /apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice /dev/ttyUSB0");
        m_engine->eng_g_free(device_name);
        return -1;
    }
    GypsyControl *control = NULL;
    control = m_engine->eng_gypsy_control_get_default();
    if (!control) {
        qWarning("QGeoSatelliteInfoSourceGypsy unable to create Gypsy control.");
        m_engine->eng_g_free(device_name);
        return -1;
    }
    // (path is the DBus path)
    path = m_engine->eng_gypsy_control_create (control, device_name, &error);
    m_engine->eng_g_free(device_name);
    g_object_unref(control);
    if (!path) {
        qWarning ("QGeoSatelliteInfoSourceGypsy error creating client.");
        if (error) {
            qWarning ("error message: %s", error->message);
            g_error_free (error);
        }
        return -1;
    }
    m_device = m_engine->eng_gypsy_device_new (path);
    m_satellite = m_engine->eng_gypsy_satellite_new (path);
    m_engine->eng_g_free(path);
    if (!m_device || !m_satellite) {
        qWarning ("QGeoSatelliteInfoSourceGypsy error creating satellite device.");
        qWarning ("Is GPS device set correctly? If not, use gconftool-2 to set it, e.g.: ");
        qWarning ("gconftool-2 -t string -s /apps/geoclue/master/org.freedesktop.Geoclue.GPSDevice /dev/ttyUSB0");
        if (m_device)
            g_object_unref(m_device);
        if (m_satellite)
            g_object_unref(m_satellite);
        return -1;
    }
    m_engine->eng_gypsy_device_start (m_device, &error);
    if (error) {
        qWarning ("QGeoSatelliteInfoSourceGypsy error starting device: %s ",
                   error->message);
        g_error_free(error);
        g_object_unref(m_device);
        g_object_unref(m_satellite);
        return -1;
    }
    return 0;
}
Esempio n. 26
0
/*!
  Constructs a QContactManager whose implementation is identified by \a managerName with the given \a parameters.

  The \a parent QObject will be used as the parent of this QContactManager.

  If an empty \a managerName is specified, the default implementation for the platform will
  be used.
  \since 1.0
 */
QContactManager::QContactManager(const QString& managerName, const QMap<QString, QString>& parameters, QObject* parent)
    : QObject(parent),
    d(new QContactManagerData)
{
    createEngine(managerName, parameters);
}
Esempio n. 27
0
/*!
  Constructs a QContactManager whose parent QObject is \a parent.
  The default implementation for the platform will be created.
  \since 1.0
 */
QContactManager::QContactManager(QObject* parent)
    : QObject(parent),
    d(new QContactManagerData)
{
    createEngine(QString(), QMap<QString, QString>());
}
Esempio n. 28
0
/*!
  Constructs a QOrganizerManager whose parent QObject is \a parent.
  The default implementation for the platform will be created.
 */
QOrganizerManager::QOrganizerManager(QObject* parent)
    : QObject(parent),
    d(new QOrganizerManagerData)
{
    createEngine(QString(), QMap<QString, QString>());
}
Esempio n. 29
0
MojErr MojDb::open(const MojChar* path, MojDbStorageEngine* engine)
{
	MojAssert(path);
	MojLogTrace(s_log);

	MojErr err = requireNotOpen();
	MojErrCheck(err);

	MojLogInfo(s_log, _T("opening: '%s'..."), path);

	MojAutoCloser<MojDb> closer(this);
	m_isOpen = true;

	// check the database version number and bail if there's a mismatch
	err = checkDbVersion(path);
	MojErrCheck(err);
	// engine
	if (engine == NULL) {
		err = createEngine();
		MojErrCheck(err);
		MojAssert(m_storageEngine.get());
		err = m_storageEngine->configure(m_conf);
		MojErrCheck(err);
		err = m_storageEngine->open(path);
		MojErrCheck(err);
	} else {
		m_storageEngine.reset(engine);
	}

	MojDbReq req;
	err = req.begin(this, true);
	MojErrCheck(err);

	// db
    MojLogInfo(s_log, _T("Open Database: '%s'"), ObjDbName);
	err = m_storageEngine->openDatabase(ObjDbName, req.txn(), m_objDb);
	MojErrCheck(err);
	MojAssert(m_objDb.get());

	// seq
    MojLogInfo(s_log, _T("Open Database: '%s'"), IdSeqName);
	err = m_storageEngine->openSequence(IdSeqName, req.txn(), m_idSeq);
	MojErrCheck(err);
	MojAssert(m_idSeq.get());

	// kinds
    MojLogInfo(s_log, _T("Open Kind Engine"));
	err = m_kindEngine.open(this, req);
    MojLogInfo(s_log, _T("Kind Opened..."));
	MojErrCheck(err);

	// perms
    MojLogInfo(s_log, _T("Open Permissions"));
	err = m_permissionEngine.open(m_conf, this, req);
	MojErrCheck(err);

	// quota
	err = m_quotaEngine.open(m_conf, this, req);
	MojErrCheck(err);
	err = req.end();
	MojErrCheck(err);

	// idgen
	err = m_idGenerator.init();
	MojErrCheck(err);

	closer.release();
	MojLogInfo(s_log, _T("open completed"));

	return MojErrNone;
}
Esempio n. 30
0
int stream_component_open(VideoState *is, int stream_index) {

  AVFormatContext *pFormatCtx = is->pFormatCtx;
  AVCodecContext *codecCtx = NULL;
  AVCodec *codec = NULL;
  AVDictionary *optionsDict = NULL;

  if(stream_index < 0 || stream_index >= pFormatCtx->nb_streams) {
    return -1;
  }

  // Get a pointer to the codec context for the video stream
  codecCtx = pFormatCtx->streams[stream_index]->codec;

  if(codecCtx->codec_type == AVMEDIA_TYPE_AUDIO) {
	is->audio_callback = audio_callback;

    // Set audio settings from codec info
	AudioPlayer *player = malloc(sizeof(AudioPlayer));
    is->audio_player = player;
    createEngine(&is->audio_player);
    createBufferQueueAudioPlayer(&is->audio_player, is, codecCtx->channels, codecCtx->sample_rate);
    //is->audio_hw_buf_size = 4096;
  } else if (codecCtx->codec_type == AVMEDIA_TYPE_VIDEO) {
	// Set video settings from codec info
	VideoPlayer *player = malloc(sizeof(VideoPlayer));
	is->video_player = player;
	createVideoEngine(&is->video_player);
	createScreen(&is->video_player, is->native_window, 0, 0);
  }
  codec = avcodec_find_decoder(codecCtx->codec_id);
  if(!codec || (avcodec_open2(codecCtx, codec, &optionsDict) < 0)) {
    fprintf(stderr, "Unsupported codec!\n");
    return -1;
  }

  switch(codecCtx->codec_type) {
  case AVMEDIA_TYPE_AUDIO:
    is->audioStream = stream_index;
    is->audio_st = pFormatCtx->streams[stream_index];
    is->audio_buf_size = 0;
    is->audio_buf_index = 0;

    /* averaging filter for audio sync */
    is->audio_diff_avg_coef = exp(log(0.01 / AUDIO_DIFF_AVG_NB));
    is->audio_diff_avg_count = 0;
    /* Correct audio only if larger error than this */
    is->audio_diff_threshold = 2.0 * SDL_AUDIO_BUFFER_SIZE / codecCtx->sample_rate;

	is->sws_ctx_audio = swr_alloc();
	if (!is->sws_ctx_audio) {
		fprintf(stderr, "Could not allocate resampler context\n");
		return -1;
	}

    memset(&is->audio_pkt, 0, sizeof(is->audio_pkt));
    packet_queue_init(&is->audioq);
    break;
  case AVMEDIA_TYPE_VIDEO:
    is->videoStream = stream_index;
    is->video_st = pFormatCtx->streams[stream_index];

    is->frame_timer = (double)av_gettime() / 1000000.0;
    is->frame_last_delay = 40e-3;
    is->video_current_pts_time = av_gettime();

    packet_queue_init(&is->videoq);

    createScreen(&is->video_player, NULL, is->video_st->codec->width, is->video_st->codec->height);

    is->video_tid = malloc(sizeof(*(is->video_tid)));
	// uncomment for video
    pthread_create(is->video_tid, NULL, (void *) &video_thread, is);
    is->sws_ctx = createScaler(&is->video_player, is->video_st->codec);

    codecCtx->get_buffer2 = our_get_buffer;

    break;
  default:
    break;
  }

  return 0;
}