bool Init(int freq, int channels, int blockSize, std::function<int(int16_t* data, int nSamples)> update)
	{
		this->update = update;

		SDL_AudioSpec fmt;

		memset(&fmt, 0, sizeof(SDL_AudioSpec));
		memset(&spec, 0, sizeof(SDL_AudioSpec));

		fmt.freq = freq;
		fmt.format = AUDIO_S16LSB;
		fmt.channels = channels;
		fmt.samples = blockSize;
		fmt.callback = SdlCallback;
		fmt.userdata = this;

		if(SDL_OpenAudio(&fmt, &spec) != 0)
			return false;

		FlogExpD(spec.freq);
		FlogExpD((int)spec.channels);
		FlogExpD(spec.samples);

		return true;
	}
Пример #2
0
	void SendArguments(Plugin& plugin){
		FlogExpD(Str(plugin.args.size()));
		plugin.messageQueue->WriteMessage("arguments", Str(plugin.args.size()));
		for(auto& arg : plugin.args){
			FlogExpD(std::get<0>(arg));
			FlogExpD(std::get<1>(arg));
			plugin.messageQueue->WriteMessage(std::get<0>(arg), std::get<1>(arg));
		}
	}
Пример #3
0
	void Open(const std::string& filename, bool rw)
	{
		std::string mode = rw ? "rb" : "rwb";
		f = fopen(filename.c_str(), mode.c_str());

		FlogExpD(filename);

		if(!f)
			throw StreamEx(Str("could not open file: " << filename));
		
		fseek(f, 0, SEEK_END);
		fileSize = ftell(f);
		fseek(f, 0, SEEK_SET);

		this->filename = filename;
		int size = FF_INPUT_BUFFER_PADDING_SIZE + 1024 * 32;

		buffer = (unsigned char*)av_mallocz(size);

		if(buffer == NULL)
			throw StreamEx("failed to allocate RAM");

		ctx = GenAVIOContext(buffer, size, rw);

		if(ctx == NULL)
			throw StreamEx("failed to allocate RAM");
	}
Пример #4
0
	void StartSession(const std::string& shmName, PlatformPtr platform, IpcMessageQueuePtr hostQueue){
		for(auto& plugin : plugins){
			try { 
				std::string messageQueueName = UuidGenerator::Create()->GenerateUuid(RandChar::Create());
				FlogExpD(messageQueueName);
				plugin.messageQueue = IpcMessageQueue::Create(messageQueueName, 2, 1024 * 1024 * 32, 4, 1024 * 16);

				plugin.process = platform->StartProcess(plugin.executable, {messageQueueName, shmName}, plugin.directory);
				plugin.started = true;

				SendArguments(plugin);
			} catch (PlatformEx e) {
				FlogE("could not start plugin: " << plugin.executable << " because: " << e.GetMsg());
				plugin.started = false;
				hostQueue->WriteMessage(Str("error -1 " << plugin.name), "could not start process");
			}
		}
	}