2002-02-09 01:25:21 +00:00
|
|
|
/*
|
|
|
|
* vo_yuv4mpeg.c, yuv4mpeg (mjpegtools) interface
|
|
|
|
*
|
|
|
|
* Thrown together by
|
|
|
|
* Robert Kesterson <robertk@robertk.com>
|
|
|
|
* Based on the pgm output plugin, the rgb2rgb postproc filter, divxdec,
|
|
|
|
* and probably others.
|
|
|
|
*
|
|
|
|
* This is undoubtedly incomplete, inaccurate, or just plain wrong. :-)
|
|
|
|
*
|
2002-07-06 15:20:34 +00:00
|
|
|
* 2002/06/19 Klaus Stengel <Klaus.Stengel@asamnet.de>
|
|
|
|
* - added support for interlaced output
|
|
|
|
* Activate by using '-vo yuv4mpeg:interlaced'
|
|
|
|
* or '-vo yuv4mpeg:interlaced_bf' if your source has
|
|
|
|
* bottom fields first
|
|
|
|
* - added some additional checks to catch problems
|
2002-04-25 13:33:43 +00:00
|
|
|
*
|
|
|
|
* 2002/04/17 Juergen Hammelmann <juergen.hammelmann@gmx.de>
|
|
|
|
* - added support for output of subtitles
|
|
|
|
* best, if you give option '-osdlevel 0' to mplayer for
|
|
|
|
* no watching the seek+timer
|
2002-02-09 01:25:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-02-10 16:56:30 +00:00
|
|
|
#include <unistd.h>
|
2002-02-17 08:24:43 +00:00
|
|
|
#include <errno.h>
|
2002-02-10 16:56:30 +00:00
|
|
|
#include <fcntl.h>
|
2007-01-04 19:41:41 +00:00
|
|
|
#include <limits.h>
|
2002-02-09 01:25:21 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2004-12-31 14:54:58 +00:00
|
|
|
#include "subopt-helper.h"
|
2002-02-09 01:25:21 +00:00
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
|
|
|
|
2004-09-25 16:10:55 +00:00
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "help_mp.h"
|
|
|
|
|
2002-04-25 13:33:43 +00:00
|
|
|
#include "sub.h"
|
|
|
|
|
2002-02-10 16:56:30 +00:00
|
|
|
#include "fastmemcpy.h"
|
2006-06-30 12:00:31 +00:00
|
|
|
#include "libswscale/swscale.h"
|
2006-10-25 14:41:55 +00:00
|
|
|
#include "libswscale/rgb2rgb.h"
|
2004-10-28 01:15:53 +00:00
|
|
|
#include "libmpcodecs/vf_scale.h"
|
2006-10-23 15:43:42 +00:00
|
|
|
#include "libavutil/rational.h"
|
2002-02-09 01:25:21 +00:00
|
|
|
|
2002-11-11 15:22:10 +00:00
|
|
|
static vo_info_t info =
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2004-12-03 21:02:14 +00:00
|
|
|
"yuv4mpeg output for mjpegtools",
|
2002-02-09 01:25:21 +00:00
|
|
|
"yuv4mpeg",
|
|
|
|
"Robert Kesterson <robertk@robertk.com>",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2002-11-11 15:22:10 +00:00
|
|
|
LIBVO_EXTERN (yuv4mpeg)
|
|
|
|
|
2004-12-12 15:17:53 +00:00
|
|
|
static int image_width = 0;
|
|
|
|
static int image_height = 0;
|
|
|
|
static float image_fps = 0;
|
2002-02-09 01:25:21 +00:00
|
|
|
|
|
|
|
static uint8_t *image = NULL;
|
|
|
|
static uint8_t *image_y = NULL;
|
|
|
|
static uint8_t *image_u = NULL;
|
|
|
|
static uint8_t *image_v = NULL;
|
|
|
|
|
2002-07-06 15:20:34 +00:00
|
|
|
static uint8_t *rgb_buffer = NULL;
|
|
|
|
static uint8_t *rgb_line_buffer = NULL;
|
|
|
|
|
2004-12-03 21:02:14 +00:00
|
|
|
static char *yuv_filename = NULL;
|
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
static int using_format = 0;
|
|
|
|
static FILE *yuv_out;
|
2002-07-06 15:20:34 +00:00
|
|
|
static int write_bytes;
|
|
|
|
|
|
|
|
#define Y4M_ILACE_NONE 'p' /* non-interlaced, progressive frame */
|
|
|
|
#define Y4M_ILACE_TOP_FIRST 't' /* interlaced, top-field first */
|
|
|
|
#define Y4M_ILACE_BOTTOM_FIRST 'b' /* interlaced, bottom-field first */
|
|
|
|
|
|
|
|
/* Set progressive mode as default */
|
|
|
|
static int config_interlace = Y4M_ILACE_NONE;
|
|
|
|
#define Y4M_IS_INTERLACED (config_interlace != Y4M_ILACE_NONE)
|
2002-02-09 01:25:21 +00:00
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int config(uint32_t width, uint32_t height, uint32_t d_width,
|
2005-04-18 15:52:38 +00:00
|
|
|
uint32_t d_height, uint32_t flags, char *title,
|
2002-08-28 21:32:32 +00:00
|
|
|
uint32_t format)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2006-10-23 15:43:42 +00:00
|
|
|
AVRational pixelaspect = av_div_q((AVRational){d_width, d_height},
|
|
|
|
(AVRational){width, height});
|
2007-01-04 19:41:41 +00:00
|
|
|
AVRational fps_frac = av_d2q(vo_fps, INT_MAX);
|
2004-12-12 15:17:53 +00:00
|
|
|
if (image_width == width && image_height == height &&
|
|
|
|
image_fps == vo_fps && vo_config_count)
|
|
|
|
return 0;
|
|
|
|
if (vo_config_count) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_WARN,
|
|
|
|
"Video formats differ (w:%i=>%i, h:%i=>%i, fps:%f=>%f), "
|
|
|
|
"restarting output.\n",
|
|
|
|
image_width, width, image_height, height, image_fps, vo_fps);
|
|
|
|
uninit();
|
|
|
|
}
|
2002-07-06 15:20:34 +00:00
|
|
|
image_height = height;
|
|
|
|
image_width = width;
|
2004-12-12 15:17:53 +00:00
|
|
|
image_fps = vo_fps;
|
2002-02-09 01:25:21 +00:00
|
|
|
using_format = format;
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
if (Y4M_IS_INTERLACED)
|
|
|
|
{
|
|
|
|
if (height % 4)
|
|
|
|
{
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_FATAL,
|
|
|
|
MSGTR_VO_YUV4MPEG_InterlacedHeightDivisibleBy4);
|
2002-07-06 15:20:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rgb_line_buffer = malloc(image_width * 3);
|
|
|
|
if (!rgb_line_buffer)
|
|
|
|
{
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_FATAL,
|
|
|
|
MSGTR_VO_YUV4MPEG_InterlacedLineBufAllocFail);
|
2002-07-06 15:20:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (using_format == IMGFMT_YV12)
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_WARN,
|
|
|
|
MSGTR_VO_YUV4MPEG_InterlacedInputNotRGB);
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width % 2)
|
|
|
|
{
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_FATAL,
|
|
|
|
MSGTR_VO_YUV4MPEG_WidthDivisibleBy2);
|
2002-07-06 15:20:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(using_format != IMGFMT_YV12)
|
|
|
|
{
|
2003-09-02 17:44:38 +00:00
|
|
|
sws_rgb2rgb_init(get_sws_cpuflags());
|
2002-07-06 15:20:34 +00:00
|
|
|
rgb_buffer = malloc(image_width * image_height * 3);
|
|
|
|
if (!rgb_buffer)
|
|
|
|
{
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_FATAL,
|
|
|
|
MSGTR_VO_YUV4MPEG_NoMemRGBFrameBuf);
|
2002-07-06 15:20:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
write_bytes = image_width * image_height * 3 / 2;
|
|
|
|
image = malloc(write_bytes);
|
2002-02-09 01:25:21 +00:00
|
|
|
|
2005-01-19 17:10:20 +00:00
|
|
|
yuv_out = fopen(yuv_filename, "wb");
|
2002-07-06 15:20:34 +00:00
|
|
|
if (!yuv_out || image == 0)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_FATAL,
|
2004-12-03 21:02:14 +00:00
|
|
|
MSGTR_VO_YUV4MPEG_OutFileOpenError,
|
2005-01-19 17:10:20 +00:00
|
|
|
yuv_filename);
|
2002-02-09 01:25:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
image_y = image;
|
|
|
|
image_u = image_y + image_width * image_height;
|
2002-07-06 15:20:34 +00:00
|
|
|
image_v = image_u + image_width * image_height / 4;
|
2002-02-09 01:25:21 +00:00
|
|
|
|
2007-01-04 19:41:41 +00:00
|
|
|
fprintf(yuv_out, "YUV4MPEG2 W%d H%d F%d:%d I%c A%d:%d\n",
|
|
|
|
image_width, image_height, fps_frac.num, fps_frac.den,
|
|
|
|
config_interlace,
|
2006-10-23 15:43:42 +00:00
|
|
|
pixelaspect.num, pixelaspect.den);
|
2002-02-09 01:25:21 +00:00
|
|
|
|
|
|
|
fflush(yuv_out);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-07-06 15:20:34 +00:00
|
|
|
/* Only use when h divisable by 2! */
|
|
|
|
static void swap_fields(uint8_t *ptr, const int h, const int stride)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<h; i +=2)
|
|
|
|
{
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(rgb_line_buffer , ptr + stride * i , stride);
|
|
|
|
fast_memcpy(ptr + stride * i , ptr + stride * (i+1), stride);
|
|
|
|
fast_memcpy(ptr + stride * (i+1), rgb_line_buffer , stride);
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-25 13:33:43 +00:00
|
|
|
static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|
|
|
unsigned char *srca, int stride) {
|
2002-07-06 15:20:34 +00:00
|
|
|
switch (using_format)
|
2002-04-25 13:33:43 +00:00
|
|
|
{
|
2002-07-06 15:20:34 +00:00
|
|
|
case IMGFMT_YV12:
|
|
|
|
vo_draw_alpha_yv12(w, h, src, srca, stride,
|
|
|
|
image + y0 * image_width + x0, image_width);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_BGR|24:
|
|
|
|
case IMGFMT_RGB|24:
|
|
|
|
if (config_interlace != Y4M_ILACE_BOTTOM_FIRST)
|
|
|
|
vo_draw_alpha_rgb24(w, h, src, srca, stride,
|
|
|
|
rgb_buffer + (y0 * image_width + x0) * 3, image_width * 3);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
swap_fields (rgb_buffer, image_height, image_width * 3);
|
|
|
|
|
|
|
|
vo_draw_alpha_rgb24(w, h, src, srca, stride,
|
|
|
|
rgb_buffer + (y0 * image_width + x0) * 3, image_width * 3);
|
|
|
|
|
|
|
|
swap_fields (rgb_buffer, image_height, image_width * 3);
|
|
|
|
}
|
|
|
|
break;
|
2002-04-25 13:33:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
static void draw_osd(void)
|
|
|
|
{
|
2002-04-25 13:33:43 +00:00
|
|
|
vo_draw_text(image_width, image_height, draw_alpha);
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
|
2002-07-06 15:20:34 +00:00
|
|
|
static void deinterleave_fields(uint8_t *ptr, const int stride,
|
|
|
|
const int img_height)
|
|
|
|
{
|
|
|
|
unsigned int i, j, k_start = 1, modv = img_height - 1;
|
|
|
|
unsigned char *line_state = malloc(modv);
|
|
|
|
|
|
|
|
for (i=0; i<modv; i++)
|
|
|
|
line_state[i] = 0;
|
|
|
|
|
|
|
|
line_state[0] = 1;
|
|
|
|
|
|
|
|
while(k_start < modv)
|
|
|
|
{
|
|
|
|
i = j = k_start;
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(rgb_line_buffer, ptr + stride * i, stride);
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
while (!line_state[j])
|
|
|
|
{
|
|
|
|
line_state[j] = 1;
|
|
|
|
i = j;
|
|
|
|
j = j * 2 % modv;
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(ptr + stride * i, ptr + stride * j, stride);
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(ptr + stride * i, rgb_line_buffer, stride);
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
while(k_start < modv && line_state[k_start])
|
|
|
|
k_start++;
|
|
|
|
}
|
|
|
|
free(line_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vo_y4m_write(const void *ptr, const size_t num_bytes)
|
|
|
|
{
|
|
|
|
if (fwrite(ptr, 1, num_bytes, yuv_out) != num_bytes)
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_ERR,
|
|
|
|
MSGTR_VO_YUV4MPEG_OutFileWriteError);
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
|
|
|
|
2002-12-14 17:12:40 +00:00
|
|
|
static int write_last_frame(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t *upper_y, *upper_u, *upper_v, *rgb_buffer_lower;
|
|
|
|
int rgb_stride, uv_stride, field_height;
|
|
|
|
unsigned int i, low_ofs;
|
|
|
|
|
|
|
|
fprintf(yuv_out, "FRAME\n");
|
|
|
|
|
|
|
|
if (using_format != IMGFMT_YV12)
|
|
|
|
{
|
|
|
|
rgb_stride = image_width * 3;
|
|
|
|
uv_stride = image_width / 2;
|
|
|
|
|
|
|
|
if (Y4M_IS_INTERLACED)
|
|
|
|
{
|
|
|
|
field_height = image_height / 2;
|
|
|
|
|
|
|
|
upper_y = image;
|
|
|
|
upper_u = upper_y + image_width * field_height;
|
|
|
|
upper_v = upper_u + image_width * field_height / 4;
|
|
|
|
low_ofs = image_width * field_height * 3 / 2;
|
|
|
|
rgb_buffer_lower = rgb_buffer + rgb_stride * field_height;
|
|
|
|
|
|
|
|
/* Write Y plane */
|
|
|
|
for(i = 0; i < field_height; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_y + image_width * i, image_width);
|
|
|
|
vo_y4m_write(upper_y + image_width * i + low_ofs, image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write U and V plane */
|
|
|
|
for(i = 0; i < field_height / 2; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_u + uv_stride * i, uv_stride);
|
|
|
|
vo_y4m_write(upper_u + uv_stride * i + low_ofs, uv_stride);
|
|
|
|
}
|
|
|
|
for(i = 0; i < field_height / 2; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_v + uv_stride * i, uv_stride);
|
|
|
|
vo_y4m_write(upper_v + uv_stride * i + low_ofs, uv_stride);
|
|
|
|
}
|
|
|
|
return VO_TRUE; /* Image written; We have to stop here */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Write progressive frame */
|
|
|
|
vo_y4m_write(image, write_bytes);
|
|
|
|
return VO_TRUE;
|
|
|
|
}
|
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
static void flip_page (void)
|
|
|
|
{
|
2002-07-06 15:20:34 +00:00
|
|
|
uint8_t *upper_y, *upper_u, *upper_v, *rgb_buffer_lower;
|
|
|
|
int rgb_stride, uv_stride, field_height;
|
|
|
|
unsigned int i, low_ofs;
|
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
fprintf(yuv_out, "FRAME\n");
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
if (using_format != IMGFMT_YV12)
|
|
|
|
{
|
|
|
|
rgb_stride = image_width * 3;
|
|
|
|
uv_stride = image_width / 2;
|
|
|
|
|
|
|
|
if (Y4M_IS_INTERLACED)
|
|
|
|
{
|
|
|
|
field_height = image_height / 2;
|
|
|
|
|
|
|
|
upper_y = image;
|
|
|
|
upper_u = upper_y + image_width * field_height;
|
|
|
|
upper_v = upper_u + image_width * field_height / 4;
|
|
|
|
low_ofs = image_width * field_height * 3 / 2;
|
|
|
|
rgb_buffer_lower = rgb_buffer + rgb_stride * field_height;
|
|
|
|
|
|
|
|
deinterleave_fields(rgb_buffer, rgb_stride, image_height);
|
|
|
|
|
|
|
|
rgb24toyv12(rgb_buffer, upper_y, upper_u, upper_v,
|
|
|
|
image_width, field_height,
|
|
|
|
image_width, uv_stride, rgb_stride);
|
|
|
|
rgb24toyv12(rgb_buffer_lower, upper_y + low_ofs,
|
|
|
|
upper_u + low_ofs, upper_v + low_ofs,
|
|
|
|
image_width, field_height,
|
|
|
|
image_width, uv_stride, rgb_stride);
|
|
|
|
|
|
|
|
/* Write Y plane */
|
|
|
|
for(i = 0; i < field_height; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_y + image_width * i, image_width);
|
|
|
|
vo_y4m_write(upper_y + image_width * i + low_ofs, image_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write U and V plane */
|
|
|
|
for(i = 0; i < field_height / 2; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_u + uv_stride * i, uv_stride);
|
|
|
|
vo_y4m_write(upper_u + uv_stride * i + low_ofs, uv_stride);
|
|
|
|
}
|
|
|
|
for(i = 0; i < field_height / 2; i++)
|
|
|
|
{
|
|
|
|
vo_y4m_write(upper_v + uv_stride * i, uv_stride);
|
|
|
|
vo_y4m_write(upper_v + uv_stride * i + low_ofs, uv_stride);
|
|
|
|
}
|
|
|
|
return; /* Image written; We have to stop here */
|
|
|
|
}
|
|
|
|
|
|
|
|
rgb24toyv12(rgb_buffer, image_y, image_u, image_v,
|
|
|
|
image_width, image_height,
|
|
|
|
image_width, uv_stride, rgb_stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write progressive frame */
|
|
|
|
vo_y4m_write(image, write_bytes);
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2002-07-06 15:20:34 +00:00
|
|
|
int i;
|
|
|
|
uint8_t *dst, *src = srcimg[0];
|
|
|
|
|
|
|
|
switch (using_format)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2002-07-06 15:20:34 +00:00
|
|
|
case IMGFMT_YV12:
|
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
// copy Y:
|
2002-07-06 15:20:34 +00:00
|
|
|
dst = image_y + image_width * y + x;
|
2002-02-09 01:25:21 +00:00
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(dst, src, w);
|
2002-02-09 01:25:21 +00:00
|
|
|
src += stride[0];
|
|
|
|
dst += image_width;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// copy U + V:
|
2002-02-14 22:31:21 +00:00
|
|
|
int imgstride = image_width >> 1;
|
2002-02-09 01:25:21 +00:00
|
|
|
uint8_t *src1 = srcimg[1];
|
|
|
|
uint8_t *src2 = srcimg[2];
|
2002-02-14 22:31:21 +00:00
|
|
|
uint8_t *dstu = image_u + imgstride * (y >> 1) + (x >> 1);
|
|
|
|
uint8_t *dstv = image_v + imgstride * (y >> 1) + (x >> 1);
|
2002-02-09 01:25:21 +00:00
|
|
|
for (i = 0; i < h / 2; i++)
|
|
|
|
{
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(dstu, src1 , w >> 1);
|
|
|
|
fast_memcpy(dstv, src2, w >> 1);
|
2002-02-09 01:25:21 +00:00
|
|
|
src1 += stride[1];
|
|
|
|
src2 += stride[2];
|
2002-02-14 22:31:21 +00:00
|
|
|
dstu += imgstride;
|
|
|
|
dstv += imgstride;
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-06 15:20:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IMGFMT_BGR24:
|
|
|
|
case IMGFMT_RGB24:
|
|
|
|
dst = rgb_buffer + (image_width * y + x) * 3;
|
|
|
|
for (i = 0; i < h; i++)
|
|
|
|
{
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(dst, src, w * 3);
|
2002-07-06 15:20:34 +00:00
|
|
|
src += stride[0];
|
|
|
|
dst += image_width * 3;
|
|
|
|
}
|
|
|
|
break;
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_frame(uint8_t * src[])
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
|
|
|
switch(using_format)
|
|
|
|
{
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
// gets done in draw_slice
|
|
|
|
break;
|
2002-07-06 15:20:34 +00:00
|
|
|
|
2002-10-09 22:37:27 +00:00
|
|
|
case IMGFMT_BGR24:
|
|
|
|
case IMGFMT_RGB24:
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(rgb_buffer, src[0], image_width * image_height * 3);
|
2002-02-09 01:25:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int query_format(uint32_t format)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
if (Y4M_IS_INTERLACED)
|
|
|
|
{
|
|
|
|
/* When processing interlaced material we want to get the raw RGB
|
|
|
|
* data and do the YV12 conversion ourselves to have the chrominance
|
|
|
|
* information sampled correct. */
|
|
|
|
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case IMGFMT_YV12:
|
2002-10-09 22:37:27 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
|
2002-07-06 15:20:34 +00:00
|
|
|
case IMGFMT_BGR|24:
|
|
|
|
case IMGFMT_RGB|24:
|
2002-10-09 22:37:27 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
switch(format)
|
|
|
|
{
|
|
|
|
case IMGFMT_YV12:
|
2002-10-09 22:37:27 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
|
2002-07-06 15:20:34 +00:00
|
|
|
case IMGFMT_BGR|24:
|
|
|
|
case IMGFMT_RGB|24:
|
2002-10-09 22:37:27 +00:00
|
|
|
return VFCAP_CSP_SUPPORTED|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
|
2002-07-06 15:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
|
2004-12-12 15:17:53 +00:00
|
|
|
// WARNING: config(...) also uses this
|
2002-02-09 01:25:21 +00:00
|
|
|
static void uninit(void)
|
|
|
|
{
|
|
|
|
if(image)
|
|
|
|
free(image);
|
|
|
|
image = NULL;
|
2002-07-06 15:20:34 +00:00
|
|
|
|
2002-02-09 01:25:21 +00:00
|
|
|
if(yuv_out)
|
|
|
|
fclose(yuv_out);
|
|
|
|
yuv_out = NULL;
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
if(rgb_buffer)
|
|
|
|
free(rgb_buffer);
|
|
|
|
rgb_buffer = NULL;
|
|
|
|
|
|
|
|
if(rgb_line_buffer)
|
|
|
|
free(rgb_line_buffer);
|
|
|
|
rgb_line_buffer = NULL;
|
2004-12-03 21:02:14 +00:00
|
|
|
|
|
|
|
if (yuv_filename)
|
|
|
|
free(yuv_filename);
|
|
|
|
yuv_filename = NULL;
|
2004-12-12 15:17:53 +00:00
|
|
|
image_width = 0;
|
|
|
|
image_height = 0;
|
|
|
|
image_fps = 0;
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void check_events(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int preinit(const char *arg)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
2004-12-31 14:54:58 +00:00
|
|
|
int il, il_bf;
|
|
|
|
opt_t subopts[] = {
|
|
|
|
{"interlaced", OPT_ARG_BOOL, &il, NULL},
|
|
|
|
{"interlaced_bf", OPT_ARG_BOOL, &il_bf, NULL},
|
2005-01-19 17:10:20 +00:00
|
|
|
{"file", OPT_ARG_MSTRZ, &yuv_filename, NULL},
|
2004-12-31 14:54:58 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
il = 0;
|
|
|
|
il_bf = 0;
|
2005-01-19 17:10:20 +00:00
|
|
|
yuv_filename = strdup("stream.yuv");
|
2004-12-31 14:54:58 +00:00
|
|
|
if (subopt_parse(arg, subopts) != 0) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_FATAL, MSGTR_VO_YUV4MPEG_UnknownSubDev, arg);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-12-03 21:02:14 +00:00
|
|
|
|
2004-12-31 14:54:58 +00:00
|
|
|
config_interlace = Y4M_ILACE_NONE;
|
|
|
|
if (il)
|
|
|
|
config_interlace = Y4M_ILACE_TOP_FIRST;
|
|
|
|
if (il_bf)
|
|
|
|
config_interlace = Y4M_ILACE_BOTTOM_FIRST;
|
2002-07-06 15:20:34 +00:00
|
|
|
|
|
|
|
/* Inform user which output mode is used */
|
|
|
|
switch (config_interlace)
|
|
|
|
{
|
|
|
|
case Y4M_ILACE_TOP_FIRST:
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_STATUS,
|
|
|
|
MSGTR_VO_YUV4MPEG_InterlacedTFFMode);
|
2002-07-06 15:20:34 +00:00
|
|
|
break;
|
|
|
|
case Y4M_ILACE_BOTTOM_FIRST:
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_STATUS,
|
|
|
|
MSGTR_VO_YUV4MPEG_InterlacedBFFMode);
|
2002-07-06 15:20:34 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-09-25 16:10:55 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_STATUS,
|
|
|
|
MSGTR_VO_YUV4MPEG_ProgressiveMode);
|
2002-07-06 15:20:34 +00:00
|
|
|
break;
|
2002-02-17 08:24:43 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int control(uint32_t request, void *data, ...)
|
2002-02-09 01:25:21 +00:00
|
|
|
{
|
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*((uint32_t*)data));
|
2002-12-14 17:12:40 +00:00
|
|
|
case VOCTRL_DUPLICATE_FRAME:
|
|
|
|
return write_last_frame();
|
2002-02-09 01:25:21 +00:00
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|