Beispiel #1
0
Datei: opengl.c Projekt: 7max/glc
int opengl_close()
{
	int ret;
	if (!opengl.started)
		return 0;

	glc_log(opengl.glc, GLC_DEBUG, "opengl", "closing");

	if (opengl.capturing)
		gl_capture_stop(opengl.gl_capture);
	gl_capture_destroy(opengl.gl_capture);

	if (opengl.unscaled) {
		if (lib.running) {
			if ((ret = glc_util_write_end_of_stream(opengl.glc, opengl.unscaled))) {
				glc_log(opengl.glc, GLC_ERROR, "opengl",
					 "can't write end of stream: %s (%d)", strerror(ret), ret);
				return ret;
			}
		} else
			ps_buffer_cancel(opengl.unscaled);

		if (opengl.convert_ycbcr_420jpeg) {
			ycbcr_process_wait(opengl.ycbcr);
			ycbcr_destroy(opengl.ycbcr);
		} else {
			scale_process_wait(opengl.scale);
			scale_destroy(opengl.scale);
		}
	} else if (lib.running) {
		if ((ret = glc_util_write_end_of_stream(opengl.glc, opengl.buffer))) {
			glc_log(opengl.glc, GLC_ERROR, "opengl",
				 "can't write end of stream: %s (%d)", strerror(ret), ret);
			return ret;
		}
	} else
		ps_buffer_cancel(opengl.buffer);

	if (opengl.unscaled) {
		ps_buffer_destroy(opengl.unscaled);
		free(opengl.unscaled);
	}

	return 0;
}
Beispiel #2
0
int export_yuv4mpeg(struct play_s *play)
{
	/*
	 Export yuv4mpeg uses following pipeline:

	 file -(uncompressed_buffer)->     reads data from stream file
	 unpack -(uncompressed_buffer)->   decompresses lzo/quicklz packets
	 scale -(scale)->           does rescaling
	 color -(color)->           applies color correction
	 ycbcr -(ycbcr)->           does conversion to Y'CbCr (if necessary)
	 yuv4mpeg                   writes yuv4mpeg stream
	*/

	ps_bufferattr_t attr;
	ps_buffer_t uncompressed_buffer, compressed_buffer,
		    ycbcr_buffer, color_buffer, scale_buffer;
	yuv4mpeg_t yuv4mpeg;
	ycbcr_t ycbcr;
	scale_t scale;
	unpack_t unpack;
	color_t color;
	int ret = 0;

	if ((ret = ps_bufferattr_init(&attr)))
		goto err;

	/* buffers */
	if ((ret = ps_bufferattr_setsize(&attr, play->compressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&compressed_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_setsize(&attr, play->uncompressed_size)))
		goto err;
	if ((ret = ps_buffer_init(&uncompressed_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&color_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&ycbcr_buffer, &attr)))
		goto err;
	if ((ret = ps_buffer_init(&scale_buffer, &attr)))
		goto err;

	if ((ret = ps_bufferattr_destroy(&attr)))
		goto err;

	/* initialize filters */
	if ((ret = unpack_init(&unpack, &play->glc)))
		goto err;
	if ((ret = ycbcr_init(&ycbcr, &play->glc)))
		goto err;
	ycbcr_set_levels(ycbcr, play->tv_levels);
	if ((ret = scale_init(&scale, &play->glc)))
		goto err;
	if (play->scale_width && play->scale_height)
		scale_set_size(scale, play->scale_width, play->scale_height);
	else
		scale_set_scale(scale, play->scale_factor);
	if ((ret = color_init(&color, &play->glc)))
		goto err;
	if (play->override_color_correction)
		color_override(color, play->brightness, play->contrast,
			       play->red_gamma, play->green_gamma, play->blue_gamma);
	if ((ret = yuv4mpeg_init(&yuv4mpeg, &play->glc)))
		goto err;
	yuv4mpeg_set_fps(yuv4mpeg, play->fps);
	yuv4mpeg_set_stream_id(yuv4mpeg, play->export_video_id);
	yuv4mpeg_set_interpolation(yuv4mpeg, play->interpolate);
	yuv4mpeg_set_filename(yuv4mpeg, play->export_filename_format);

	/* construct the pipeline */
	if ((ret = unpack_process_start(unpack, &compressed_buffer, &uncompressed_buffer)))
		goto err;
	if ((ret = scale_process_start(scale, &uncompressed_buffer, &scale_buffer)))
		goto err;
	if ((ret = color_process_start(color, &scale_buffer, &color_buffer)))
		goto err;
	if ((ret = ycbcr_process_start(ycbcr, &color_buffer, &ycbcr_buffer)))
		goto err;
	if ((ret = yuv4mpeg_process_start(yuv4mpeg, &ycbcr_buffer)))
		goto err;

	/* feed it with data */
	if ((ret = file_read(play->file, &compressed_buffer)))
		goto err;

	/* threads will do the dirty work... */
	if ((ret = yuv4mpeg_process_wait(yuv4mpeg)))
		goto err;
	if ((ret = color_process_wait(color)))
		goto err;
	if ((ret = scale_process_wait(scale)))
		goto err;
	if ((ret = ycbcr_process_wait(ycbcr)))
		goto err;
	if ((ret = unpack_process_wait(unpack)))
		goto err;

	unpack_destroy(unpack);
	ycbcr_destroy(ycbcr);
	scale_destroy(scale);
	color_destroy(color);
	yuv4mpeg_destroy(yuv4mpeg);

	ps_buffer_destroy(&compressed_buffer);
	ps_buffer_destroy(&uncompressed_buffer);
	ps_buffer_destroy(&color_buffer);
	ps_buffer_destroy(&scale_buffer);
	ps_buffer_destroy(&ycbcr_buffer);

	return 0;
err:
	fprintf(stderr, "exporting yuv4mpeg failed: %s (%d)\n", strerror(ret), ret);
	return ret;
}