Esempio n. 1
0
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Refresh the render-view with new image from render-buffer
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Session::update_img_sample() {
    //Only for NON-INTERACTIVE session
	if(b_session) {
    	thread_scoped_lock img_lock(img_mutex);
		//TODO: optimize this by making it thread safe and removing lock
		b_session->update_render_img();
	}
	update_status_time();
} //update_img_sample()
Esempio n. 2
0
	bool readNextFrame()
	{
		TRACE_FN;
		std::lock_guard<std::recursive_mutex> l(this->frame_queue_lock);
		if (this->stopped)
			return false;

		char ret;
		if (this->current_frame_read == 0)
			ret = smk_first(this->smk_ctx);
		else
			ret = smk_next(this->smk_ctx);

		if (ret == SMK_ERROR)
		{
			LogWarning("Error decoding frame %u", this->current_frame_read);
			return false;
		}

		if (ret == SMK_LAST)
		{
			LogInfo("Last frame %u", this->current_frame_read);
			this->stopped = true;
		}

		const unsigned char *palette_data = smk_get_palette(this->smk_ctx);
		if (!palette_data)
		{
			LogWarning("Failed to get palette data for frame %u", this->current_frame_read);
			return false;
		}
		const unsigned char *image_data = smk_get_video(this->smk_ctx);
		if (!image_data)
		{
			LogWarning("Failed to get image data for frame %u", this->current_frame_read);
			return false;
		}

		auto frame = mksp<FrameImage>();
		frame->frame = this->current_frame_read;

		auto img = mksp<PaletteImage>(this->frame_size);
		frame->image = img;
		frame->palette = mksp<Palette>(256);

		PaletteImageLock img_lock(img);
		memcpy(img_lock.getData(), image_data, this->frame_size.x * this->frame_size.y);

		for (unsigned int i = 0; i < 256; i++)
		{
			auto red = *palette_data++;
			auto green = *palette_data++;
			auto blue = *palette_data++;
			frame->palette->setColour(i, {red, green, blue});
		}

		auto audio_frame = mksp<FrameAudio>();
		audio_frame->frame = current_frame_read;
		audio_frame->format = this->audio_format;
		unsigned long audio_bytes = smk_get_audio_size(this->smk_ctx, 0);
		if (audio_bytes == 0)
		{
			LogWarning("Error reading audio size for frame %u", this->current_frame_read);
			return false;
		}

		auto sample_count =
		    audio_bytes / (this->audio_bytes_per_sample * this->audio_format.channels);
		audio_frame->samples.reset(new char[audio_bytes]);
		audio_frame->sample_count = sample_count;
		auto sample_pointer = smk_get_audio(this->smk_ctx, 0);
		if (!sample_pointer)
		{
			LogWarning("Error reading audio data for frame %u", this->current_frame_read);
			return false;
		}
		memcpy(audio_frame->samples.get(), sample_pointer, audio_bytes);

		LogInfo("Read %lu samples bytes, %u samples", audio_bytes, audio_frame->sample_count);

		this->image_queue.push(frame);
		this->audio_queue.push(audio_frame);

		LogInfo("read frame %u", this->current_frame_read);
		this->current_frame_read++;
		return true;
	}