diff options
author | Mike Melanson <mike@multimedia.cx> | 2002-07-15 00:56:12 +0000 |
---|---|---|
committer | Mike Melanson <mike@multimedia.cx> | 2002-07-15 00:56:12 +0000 |
commit | 4b09fc3038ce33b9db1874b22f1d2666a7c6cd6c (patch) | |
tree | 576406973eeb37d5da35773f78398ae255aa4a74 | |
parent | 9390fc8d754001d0ac9f804c12039b281635e8ee (diff) | |
download | xine-lib-4b09fc3038ce33b9db1874b22f1d2666a7c6cd6c.tar.gz xine-lib-4b09fc3038ce33b9db1874b22f1d2666a7c6cd6c.tar.bz2 |
initial commit for 3 new decoders: Raw RGB, Raw YUV, and MS RLE
CVS patchset: 2270
CVS date: 2002/07/15 00:56:12
-rw-r--r-- | src/libxinevdec/Makefile.am | 13 | ||||
-rw-r--r-- | src/libxinevdec/msrle.c | 384 | ||||
-rw-r--r-- | src/libxinevdec/rgb.c | 329 | ||||
-rw-r--r-- | src/libxinevdec/yuv.c | 312 |
4 files changed, 1037 insertions, 1 deletions
diff --git a/src/libxinevdec/Makefile.am b/src/libxinevdec/Makefile.am index ea84b66cd..0af976c4c 100644 --- a/src/libxinevdec/Makefile.am +++ b/src/libxinevdec/Makefile.am @@ -9,7 +9,9 @@ libdir = $(XINE_PLUGINDIR) lib_LTLIBRARIES = xineplug_decode_cinepak.la xineplug_decode_cyuv.la \ xineplug_decode_msvc.la xineplug_decode_roqvideo.la \ - xineplug_decode_svq1.la xineplug_decode_fli.la + xineplug_decode_svq1.la xineplug_decode_fli.la \ + xineplug_decode_rgb.la xineplug_decode_yuv.la \ + xineplug_decode_msrle.la xineplug_decode_cinepak_la_SOURCES = cinepak.c xineplug_decode_cinepak_la_LDFLAGS = -avoid-version -module @@ -29,6 +31,15 @@ xineplug_decode_svq1_la_LDFLAGS = -avoid-version -module xineplug_decode_fli_la_SOURCES = fli.c xineplug_decode_fli_la_LDFLAGS = -avoid-version -module +xineplug_decode_rgb_la_SOURCES = rgb.c +xineplug_decode_rgb_la_LDFLAGS = -avoid-version -module + +xineplug_decode_yuv_la_SOURCES = yuv.c +xineplug_decode_yuv_la_LDFLAGS = -avoid-version -module + +xineplug_decode_msrle_la_SOURCES = msrle.c +xineplug_decode_msrle_la_LDFLAGS = -avoid-version -module + noinst_HEADERS = svq1_codebooks.h debug: diff --git a/src/libxinevdec/msrle.c b/src/libxinevdec/msrle.c new file mode 100644 index 000000000..1c9f7ae76 --- /dev/null +++ b/src/libxinevdec/msrle.c @@ -0,0 +1,384 @@ +/* + * Copyright (C) 2000-2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * MS RLE Decoder by Mike Melanson (melanson@pcisys.net) + * For more information on the MS RLE format, visit: + * http://www.pcisys.net/~melanson/codecs/ + * + * $Id: msrle.c,v 1.1 2002/07/15 00:56:12 tmmm Exp $ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "video_out.h" +#include "buffer.h" +#include "xine_internal.h" +#include "xineutils.h" +#include "bswap.h" + +#define VIDEOBUFSIZE 128*1024 + +typedef struct msrle_decoder_s { + video_decoder_t video_decoder; /* parent video decoder structure */ + + /* these are traditional variables in a video decoder object */ + vo_instance_t *video_out; /* object that will receive frames */ + uint64_t video_step; /* frame duration in pts units */ + int decoder_ok; /* current decoder status */ + int skipframes; + + unsigned char *buf; /* the accumulated buffer data */ + int bufsize; /* the maximum size of buf */ + int size; /* the current size of buf */ + + int width; /* the width of a video frame */ + int height; /* the height of a video frame */ + + unsigned char yuv_palette[256 * 4]; + yuv_planes_t yuv_planes; + +} msrle_decoder_t; + +/************************************************************************** + * MS RLE specific decode functions + *************************************************************************/ + +#define FETCH_NEXT_STREAM_BYTE() \ + if (stream_ptr >= this->size) \ + { \ + printf(_("MS RLE: stream ptr just went out of bounds (1)\n")); \ + return; \ + } \ + stream_byte = this->buf[stream_ptr++]; + +void decode_msrle8(msrle_decoder_t *this) { + + int stream_ptr = 0; + unsigned char rle_code; + unsigned char extra_byte; + unsigned char stream_byte; + int pixel_ptr = 0; + int row_dec = this->yuv_planes.row_stride; + int row_ptr = (this->height - 1) * row_dec; + int frame_size = this->yuv_planes.row_stride * this->height; + unsigned char y, u, v; + + while (row_ptr >= 0) { + FETCH_NEXT_STREAM_BYTE(); + rle_code = stream_byte; + if (rle_code == 0) { + /* fetch the next byte to see how to handle escape code */ + FETCH_NEXT_STREAM_BYTE(); + if (stream_byte == 0) { + /* line is done, goto the next one */ + row_ptr -= row_dec; + pixel_ptr = 0; + } else if (stream_byte == 1) + /* decode is done */ + return; + else if (stream_byte == 2) { + /* reposition frame decode coordinates */ + FETCH_NEXT_STREAM_BYTE(); + pixel_ptr += stream_byte; + FETCH_NEXT_STREAM_BYTE(); + row_ptr -= stream_byte * row_dec; + } else { + /* copy pixels from encoded stream */ + if ((row_ptr + pixel_ptr + stream_byte > frame_size) || + (row_ptr < 0)) { + printf(_("MS RLE: frame ptr just went out of bounds (1)\n")); + return; + } + + rle_code = stream_byte; + extra_byte = stream_byte & 0x01; + if (stream_ptr + rle_code + extra_byte > this->size) { + printf(_("MS RLE: stream ptr just went out of bounds (2)\n")); + return; + } + + while (rle_code--) { + FETCH_NEXT_STREAM_BYTE(); + y = this->yuv_palette[stream_byte * 4 + 0]; + u = this->yuv_palette[stream_byte * 4 + 1]; + v = this->yuv_palette[stream_byte * 4 + 2]; + this->yuv_planes.y[row_ptr + pixel_ptr] = y; + this->yuv_planes.u[row_ptr + pixel_ptr] = u; + this->yuv_planes.v[row_ptr + pixel_ptr] = v; + pixel_ptr++; + } + + /* if the RLE code is odd, skip a byte in the stream */ + if (extra_byte) + stream_ptr++; + } + } else { + /* decode a run of data */ + if ((row_ptr + pixel_ptr + stream_byte > frame_size) || + (row_ptr < 0)) { + printf(_("MS RLE: frame ptr just went out of bounds (2)\n")); + return; + } + + FETCH_NEXT_STREAM_BYTE(); + + y = this->yuv_palette[stream_byte * 4 + 0]; + u = this->yuv_palette[stream_byte * 4 + 1]; + v = this->yuv_palette[stream_byte * 4 + 2]; + + while(rle_code--) { + this->yuv_planes.y[row_ptr + pixel_ptr] = y; + this->yuv_planes.u[row_ptr + pixel_ptr] = u; + this->yuv_planes.v[row_ptr + pixel_ptr] = v; + pixel_ptr++; + } + } + } + + /* one last sanity check on the way out */ + if (stream_ptr < this->size) + printf(_("MS RLE: ended frame decode with bytes left over (%d < %d)\n"), + stream_ptr, this->size); +} + +/************************************************************************** + * xine video plugin functions + *************************************************************************/ + +static int msrle_can_handle (video_decoder_t *this_gen, int buf_type) { + + return (buf_type == BUF_VIDEO_MSRLE); + +} + +/* + * This function is responsible is called to initialize the video decoder + * for use. Initialization usually involves setting up the fields in your + * private video decoder object. + */ +static void msrle_init (video_decoder_t *this_gen, + vo_instance_t *video_out) { + msrle_decoder_t *this = (msrle_decoder_t *) this_gen; + + /* set our own video_out object to the one that xine gives us */ + this->video_out = video_out; + + /* indicate that the decoder is not quite ready yet */ + this->decoder_ok = 0; +} + +/* + * This function receives a buffer of data from the demuxer layer and + * figures out how to handle it based on its header flags. + */ +static void msrle_decode_data (video_decoder_t *this_gen, + buf_element_t *buf) { + + msrle_decoder_t *this = (msrle_decoder_t *) this_gen; + xine_bmiheader *bih; + palette_entry_t *palette; + int i; + vo_frame_t *img; /* video out frame */ + + /* a video decoder does not care about this flag (?) */ + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + /* load the palette */ + if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && + (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { + palette = (palette_entry_t *)buf->decoder_info[3]; + for (i = 0; i < buf->decoder_info[2]; i++) { + this->yuv_palette[i * 4 + 0] = + COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); + this->yuv_palette[i * 4 + 1] = + COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); + this->yuv_palette[i * 4 + 2] = + COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); + } + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { /* need to initialize */ + this->video_out->open (this->video_out); + + if(this->buf) + free(this->buf); + + bih = (xine_bmiheader *) buf->content; + this->width = (bih->biWidth + 3) & ~0x03; + this->height = (bih->biHeight + 3) & ~0x03; + this->video_step = buf->decoder_info[1]; + + if (this->buf) + free (this->buf); + this->bufsize = VIDEOBUFSIZE; + this->buf = malloc(this->bufsize); + this->size = 0; + + this->video_out->open (this->video_out); + this->decoder_ok = 1; + + init_yuv_planes(&this->yuv_planes, this->width, this->height); + + return; + } else if (this->decoder_ok) { + + if (this->size + buf->size > this->bufsize) { + this->bufsize = this->size + 2 * buf->size; + this->buf = realloc (this->buf, this->bufsize); + } + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) + this->video_step = buf->decoder_info[0]; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + + img = this->video_out->get_frame (this->video_out, + this->width, this->height, + 42, IMGFMT_YUY2, VO_BOTH_FIELDS); + + img->duration = this->video_step; + img->pts = buf->pts; + img->bad_frame = 0; + + decode_msrle8(this); + yuv444_to_yuy2(&this->yuv_planes, img->base[0]); + +/* + if (img->copy) { + + int height = abs(this->biHeight); + int stride = this->biWidth; + uint8_t* src[3]; + + src[0] = img->base[0]; + src[1] = img->base[1]; + src[2] = img->base[2]; + while ((height -= 16) >= 0) { + img->copy(img, src); + src[0] += 16 * stride; + src[1] += 4 * stride; + src[2] += 4 * stride; + } + } +*/ + + img->draw(img); + img->free(img); + + this->size = 0; + } + } +} + +/* + * This function is called when xine needs to flush the system. Not + * sure when or if this is used or even if it needs to do anything. + */ +static void msrle_flush (video_decoder_t *this_gen) { +} + +/* + * This function resets the video decoder. + */ +static void msrle_reset (video_decoder_t *this_gen) { + msrle_decoder_t *this = (msrle_decoder_t *) this_gen; + + this->size = 0; +} + +/* + * This function is called when xine shuts down the decoder. It should + * free any memory and release any other resources allocated during the + * execution of the decoder. + */ +static void msrle_close (video_decoder_t *this_gen) { + msrle_decoder_t *this = (msrle_decoder_t *) this_gen; + + if (this->buf) { + free (this->buf); + this->buf = NULL; + } + + if (this->decoder_ok) { + this->decoder_ok = 0; + this->video_out->close(this->video_out); + } +} + +/* + * This function returns the human-readable ID string to identify + * this decoder. + */ +static char *msrle_get_id(void) { + return "Microsoft RLE"; +} + +/* + * This function frees the video decoder instance allocated to the decoder. + */ +static void msrle_dispose (video_decoder_t *this_gen) { + free (this_gen); +} + +/* + * This function should be the plugin's only advertised function to the + * outside world. It allows xine to query the plugin module for the addresses + * to the necessary functions in the video decoder object. The video + * decoder object also has a priority field which allows different decoder + * plugins for the same buffer types to coexist peacefully. The higher the + * priority number, the more precedence a decoder has. E.g., 9 beats 1. + */ +video_decoder_t *init_video_decoder_plugin (int iface_version, xine_t *xine) { + + msrle_decoder_t *this ; + + if (iface_version != 10) { + printf( "msrle: plugin doesn't support plugin API version %d.\n" + "msrle: this means there's a version mismatch between xine and this " + "msrle: decoder plugin.\nInstalling current plugins should help.\n", + iface_version); + return NULL; + } + + this = (msrle_decoder_t *) malloc (sizeof (msrle_decoder_t)); + memset(this, 0, sizeof (msrle_decoder_t)); + + this->video_decoder.interface_version = iface_version; + this->video_decoder.can_handle = msrle_can_handle; + this->video_decoder.init = msrle_init; + this->video_decoder.decode_data = msrle_decode_data; + this->video_decoder.flush = msrle_flush; + this->video_decoder.reset = msrle_reset; + this->video_decoder.close = msrle_close; + this->video_decoder.get_identifier = msrle_get_id; + this->video_decoder.dispose = msrle_dispose; + this->video_decoder.priority = 1; + + return (video_decoder_t *) this; +} + diff --git a/src/libxinevdec/rgb.c b/src/libxinevdec/rgb.c new file mode 100644 index 000000000..ebe1c7d35 --- /dev/null +++ b/src/libxinevdec/rgb.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2000-2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * Raw RGB "Decoder" by Mike Melanson (melanson@pcisys.net) + * Actually, this decoder just converts a raw RGB image to a YUY2 map + * suitable for display under xine. + * + * $Id: rgb.c,v 1.1 2002/07/15 00:56:12 tmmm Exp $ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "video_out.h" +#include "buffer.h" +#include "xine_internal.h" +#include "xineutils.h" +#include "bswap.h" + +#define VIDEOBUFSIZE 128*1024 + +#define LE_16(x) (le2me_16(*(uint16_t *)(x))) +#define LE_32(x) (le2me_32(*(uint32_t *)(x))) + +typedef struct rgb_decoder_s { + video_decoder_t video_decoder; /* parent video decoder structure */ + + /* these are traditional variables in a video decoder object */ + vo_instance_t *video_out; /* object that will receive frames */ + uint64_t video_step; /* frame duration in pts units */ + int decoder_ok; /* current decoder status */ + int skipframes; + + unsigned char *buf; /* the accumulated buffer data */ + int bufsize; /* the maximum size of buf */ + int size; /* the current size of buf */ + + int width; /* the width of a video frame */ + int height; /* the height of a video frame */ + int bytes_per_pixel; + + unsigned char yuv_palette[256 * 4]; + yuv_planes_t yuv_planes; + +} rgb_decoder_t; + +static int rgb_can_handle (video_decoder_t *this_gen, int buf_type) { + + return (buf_type == BUF_VIDEO_RGB); +} + +static void rgb_init (video_decoder_t *this_gen, + vo_instance_t *video_out) { + rgb_decoder_t *this = (rgb_decoder_t *) this_gen; + + /* set our own video_out object to the one that xine gives us */ + this->video_out = video_out; + + /* indicate that the decoder is not quite ready yet */ + this->decoder_ok = 0; +} + +static void rgb_decode_data (video_decoder_t *this_gen, + buf_element_t *buf) { + + rgb_decoder_t *this = (rgb_decoder_t *) this_gen; + xine_bmiheader *bih; + palette_entry_t *palette; + int i; + int pixel_ptr, row_ptr; + int palette_index; + int buf_ptr; + unsigned int packed_pixel; + unsigned char r, g, b; + + vo_frame_t *img; /* video out frame */ + + /* a video decoder does not care about this flag (?) */ + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + if ((buf->decoder_flags & BUF_FLAG_SPECIAL) && + (buf->decoder_info[1] == BUF_SPECIAL_PALETTE)) { + palette = (palette_entry_t *)buf->decoder_info[3]; + for (i = 0; i < buf->decoder_info[2]; i++) { + this->yuv_palette[i * 4 + 0] = + COMPUTE_Y(palette[i].r, palette[i].g, palette[i].b); + this->yuv_palette[i * 4 + 1] = + COMPUTE_U(palette[i].r, palette[i].g, palette[i].b); + this->yuv_palette[i * 4 + 2] = + COMPUTE_V(palette[i].r, palette[i].g, palette[i].b); + } + } + + if (buf->decoder_flags & BUF_FLAG_HEADER) { /* need to initialize */ + this->video_out->open (this->video_out); + + if(this->buf) + free(this->buf); + + bih = (xine_bmiheader *) buf->content; + this->width = (bih->biWidth + 3) & ~0x03; + this->height = (bih->biHeight + 3) & ~0x03; + this->video_step = buf->decoder_info[1]; + /* round this number up in case of 15 */ + this->bytes_per_pixel = (bih->biBitCount + 1) / 8; + + if (this->buf) + free (this->buf); + this->bufsize = VIDEOBUFSIZE; + this->buf = malloc(this->bufsize); + this->size = 0; + + this->video_out->open (this->video_out); + this->decoder_ok = 1; + + init_yuv_planes(&this->yuv_planes, this->width, this->height); + + return; + } else if (this->decoder_ok) { + + if (this->size + buf->size > this->bufsize) { + this->bufsize = this->size + 2 * buf->size; + this->buf = realloc (this->buf, this->bufsize); + } + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) + this->video_step = buf->decoder_info[0]; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + + img = this->video_out->get_frame (this->video_out, + this->width, this->height, + 42, IMGFMT_YUY2, VO_BOTH_FIELDS); + + img->duration = this->video_step; + img->pts = buf->pts; + img->bad_frame = 0; + + /* iterate through each row */ + buf_ptr = 0; + row_ptr = this->yuv_planes.row_stride * + (this->yuv_planes.row_count - 1); + for (; row_ptr >= 0; row_ptr -= this->yuv_planes.row_stride) { + for (pixel_ptr = 0; pixel_ptr < this->width; pixel_ptr++) { + + if (this->bytes_per_pixel == 1) { + + palette_index = this->buf[buf_ptr++]; + + this->yuv_planes.y[row_ptr + pixel_ptr] = + this->yuv_palette[palette_index * 4 + 0]; + this->yuv_planes.u[row_ptr + pixel_ptr] = + this->yuv_palette[palette_index * 4 + 1]; + this->yuv_planes.v[row_ptr + pixel_ptr] = + this->yuv_palette[palette_index * 4 + 2]; + + } else if (this->bytes_per_pixel == 2) { + + packed_pixel = LE_16(&this->buf[buf_ptr]); + buf_ptr += 2; + UNPACK_BGR15(packed_pixel, r, g, b); + + this->yuv_planes.y[row_ptr + pixel_ptr] = + COMPUTE_Y(r, g, b); + this->yuv_planes.u[row_ptr + pixel_ptr] = + COMPUTE_U(r, g, b); + this->yuv_planes.v[row_ptr + pixel_ptr] = + COMPUTE_V(r, g, b); + + } else { + + b = this->buf[buf_ptr++]; + g = this->buf[buf_ptr++]; + r = this->buf[buf_ptr++]; + + this->yuv_planes.y[row_ptr + pixel_ptr] = + COMPUTE_Y(r, g, b); + this->yuv_planes.u[row_ptr + pixel_ptr] = + COMPUTE_U(r, g, b); + this->yuv_planes.v[row_ptr + pixel_ptr] = + COMPUTE_V(r, g, b); + + } + } + + // take care of the extra 2 pixels on the C lines + this->yuv_planes.u[row_ptr + pixel_ptr] = + this->yuv_planes.u[row_ptr + pixel_ptr - 1]; + this->yuv_planes.u[row_ptr + pixel_ptr + 1] = + this->yuv_planes.u[row_ptr + pixel_ptr - 2]; + + this->yuv_planes.v[row_ptr + pixel_ptr] = + this->yuv_planes.v[row_ptr + pixel_ptr - 1]; + this->yuv_planes.v[row_ptr + pixel_ptr + 1] = + this->yuv_planes.v[row_ptr + pixel_ptr - 2]; + } + + yuv444_to_yuy2(&this->yuv_planes, img->base[0]); + +/* + if (img->copy) { + + int height = abs(this->biHeight); + int stride = this->biWidth; + uint8_t* src[3]; + + src[0] = img->base[0]; + src[1] = img->base[1]; + src[2] = img->base[2]; + while ((height -= 16) >= 0) { + img->copy(img, src); + src[0] += 16 * stride; + src[1] += 4 * stride; + src[2] += 4 * stride; + } + } +*/ + + img->draw(img); + img->free(img); + + this->size = 0; + } + } +} + +/* + * This function is called when xine needs to flush the system. Not + * sure when or if this is used or even if it needs to do anything. + */ +static void rgb_flush (video_decoder_t *this_gen) { +} + +/* + * This function resets the video decoder. + */ +static void rgb_reset (video_decoder_t *this_gen) { + rgb_decoder_t *this = (rgb_decoder_t *) this_gen; + + this->size = 0; +} + +/* + * This function is called when xine shuts down the decoder. It should + * free any memory and release any other resources allocated during the + * execution of the decoder. + */ +static void rgb_close (video_decoder_t *this_gen) { + rgb_decoder_t *this = (rgb_decoder_t *) this_gen; + + if (this->buf) { + free (this->buf); + this->buf = NULL; + } + + if (this->decoder_ok) { + this->decoder_ok = 0; + this->video_out->close(this->video_out); + } +} + +/* + * This function returns the human-readable ID string to identify + * this decoder. + */ +static char *rgb_get_id(void) { + return "Raw RGB"; +} + +/* + * This function frees the video decoder instance allocated to the decoder. + */ +static void rgb_dispose (video_decoder_t *this_gen) { + free (this_gen); +} + +video_decoder_t *init_video_decoder_plugin (int iface_version, xine_t *xine) { + + rgb_decoder_t *this ; + + if (iface_version != 10) { + printf( "rgb: plugin doesn't support plugin API version %d.\n" + "rgb: this means there's a version mismatch between xine and this " + "rgb: decoder plugin.\nInstalling current plugins should help.\n", + iface_version); + return NULL; + } + + this = (rgb_decoder_t *) malloc (sizeof (rgb_decoder_t)); + memset(this, 0, sizeof (rgb_decoder_t)); + + this->video_decoder.interface_version = iface_version; + this->video_decoder.can_handle = rgb_can_handle; + this->video_decoder.init = rgb_init; + this->video_decoder.decode_data = rgb_decode_data; + this->video_decoder.flush = rgb_flush; + this->video_decoder.reset = rgb_reset; + this->video_decoder.close = rgb_close; + this->video_decoder.get_identifier = rgb_get_id; + this->video_decoder.dispose = rgb_dispose; + this->video_decoder.priority = 1; + + return (video_decoder_t *) this; +} + diff --git a/src/libxinevdec/yuv.c b/src/libxinevdec/yuv.c new file mode 100644 index 000000000..70a383adf --- /dev/null +++ b/src/libxinevdec/yuv.c @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2000-2002 the xine project + * + * This file is part of xine, a free video player. + * + * xine is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * xine is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * + * YUV "Decoder" by Mike Melanson (melanson@pcisys.net) + * Actually, this decoder just reorganizes chunks of raw YUV data in such + * a way that xine can display them. + * + * $Id: yuv.c,v 1.1 2002/07/15 00:56:12 tmmm Exp $ + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> + +#include "video_out.h" +#include "buffer.h" +#include "xine_internal.h" +#include "xineutils.h" +#include "bswap.h" + +#define VIDEOBUFSIZE 128*1024 + +typedef struct yuv_decoder_s { + video_decoder_t video_decoder; /* parent video decoder structure */ + + /* these are traditional variables in a video decoder object */ + vo_instance_t *video_out; /* object that will receive frames */ + uint64_t video_step; /* frame duration in pts units */ + int decoder_ok; /* current decoder status */ + int skipframes; + + unsigned char *buf; /* the accumulated buffer data */ + int bufsize; /* the maximum size of buf */ + int size; /* the current size of buf */ + + int width; /* the width of a video frame */ + int height; /* the height of a video frame */ + +} yuv_decoder_t; + +/************************************************************************** + * xine video plugin functions + *************************************************************************/ + +static int yuv_can_handle (video_decoder_t *this_gen, int buf_type) { + + return (buf_type == BUF_VIDEO_YVU9); +} + +/* + * This function is responsible is called to initialize the video decoder + * for use. Initialization usually involves setting up the fields in your + * private video decoder object. + */ +static void yuv_init (video_decoder_t *this_gen, + vo_instance_t *video_out) { + yuv_decoder_t *this = (yuv_decoder_t *) this_gen; + + /* set our own video_out object to the one that xine gives us */ + this->video_out = video_out; + + /* indicate that the decoder is not quite ready yet */ + this->decoder_ok = 0; +} + +/* + * This function receives a buffer of data from the demuxer layer and + * figures out how to handle it based on its header flags. + */ +static void yuv_decode_data (video_decoder_t *this_gen, + buf_element_t *buf) { + + yuv_decoder_t *this = (yuv_decoder_t *) this_gen; + xine_bmiheader *bih; + + vo_frame_t *img; /* video out frame */ + + int c_plane_stride; + int c_plane_x_ptr, c_plane_y_ptr; + int raw_plane_ptr; + unsigned char *raw_u_plane; + unsigned char *raw_v_plane; + + /* a video decoder does not care about this flag (?) */ + if (buf->decoder_flags & BUF_FLAG_PREVIEW) + return; + + if (buf->decoder_flags & BUF_FLAG_HEADER) { /* need to initialize */ + this->video_out->open (this->video_out); + + if(this->buf) + free(this->buf); + + bih = (xine_bmiheader *) buf->content; + this->width = (bih->biWidth + 3) & ~0x03; + this->height = (bih->biHeight + 3) & ~0x03; + this->video_step = buf->decoder_info[1]; + + if (this->buf) + free (this->buf); + this->bufsize = VIDEOBUFSIZE; + this->buf = malloc(this->bufsize); + this->size = 0; + + this->video_out->open (this->video_out); + this->decoder_ok = 1; + + return; + } else if (this->decoder_ok) { + + if (this->size + buf->size > this->bufsize) { + this->bufsize = this->size + 2 * buf->size; + this->buf = realloc (this->buf, this->bufsize); + } + + xine_fast_memcpy (&this->buf[this->size], buf->content, buf->size); + + this->size += buf->size; + + if (buf->decoder_flags & BUF_FLAG_FRAMERATE) + this->video_step = buf->decoder_info[0]; + + if (buf->decoder_flags & BUF_FLAG_FRAME_END) { + + if (buf->type == BUF_VIDEO_YVU9) { + + img = this->video_out->get_frame (this->video_out, + this->width, this->height, + 42, IMGFMT_YV12, VO_BOTH_FIELDS); + + xine_fast_memcpy(img->base[0], this->buf, this->width * this->height); + + raw_u_plane = &this->buf[this->width * this->height]; + raw_v_plane = &this->buf[(this->width * this->height) + + (this->width * this->height) / 16]; + c_plane_stride = this->width / 2; + c_plane_y_ptr = c_plane_x_ptr = 0; + raw_plane_ptr = 0; + + while (raw_plane_ptr++ < (this->width * this->height / 16)) { + + img->base[2][c_plane_y_ptr + c_plane_x_ptr + 0] = + raw_u_plane[raw_plane_ptr]; + img->base[2][c_plane_y_ptr + c_plane_x_ptr + 1] = + raw_u_plane[raw_plane_ptr]; + + img->base[2][c_plane_y_ptr + c_plane_stride + c_plane_x_ptr + 0] = + raw_u_plane[raw_plane_ptr]; + img->base[2][c_plane_y_ptr + c_plane_stride + c_plane_x_ptr + 1] = + raw_u_plane[raw_plane_ptr]; + + img->base[1][c_plane_y_ptr + c_plane_x_ptr + 0] = + raw_v_plane[raw_plane_ptr]; + img->base[1][c_plane_y_ptr + c_plane_x_ptr + 1] = + raw_v_plane[raw_plane_ptr]; + + img->base[1][c_plane_y_ptr + c_plane_stride + c_plane_x_ptr + 0] = + raw_v_plane[raw_plane_ptr]; + img->base[1][c_plane_y_ptr + c_plane_stride + c_plane_x_ptr + 1] = + raw_v_plane[raw_plane_ptr]; + + c_plane_x_ptr += 2; + if (c_plane_x_ptr >= this->width / 2) { + c_plane_x_ptr = 0; + c_plane_y_ptr += c_plane_stride * 2; + } + } + } else { + + /* just allocate something to avoid compiler warnings */ + img = this->video_out->get_frame (this->video_out, + this->width, this->height, + 42, IMGFMT_YV12, VO_BOTH_FIELDS); + + } + + img->duration = this->video_step; + img->pts = buf->pts; + img->bad_frame = 0; + +/* + if (img->copy) { + + int height = abs(this->biHeight); + int stride = this->biWidth; + uint8_t* src[3]; + + src[0] = img->base[0]; + src[1] = img->base[1]; + src[2] = img->base[2]; + while ((height -= 16) >= 0) { + img->copy(img, src); + src[0] += 16 * stride; + src[1] += 4 * stride; + src[2] += 4 * stride; + } + } +*/ + + img->draw(img); + img->free(img); + + this->size = 0; + } + } +} + +/* + * This function is called when xine needs to flush the system. Not + * sure when or if this is used or even if it needs to do anything. + */ +static void yuv_flush (video_decoder_t *this_gen) { +} + +/* + * This function resets the video decoder. + */ +static void yuv_reset (video_decoder_t *this_gen) { + yuv_decoder_t *this = (yuv_decoder_t *) this_gen; + + this->size = 0; +} + +/* + * This function is called when xine shuts down the decoder. It should + * free any memory and release any other resources allocated during the + * execution of the decoder. + */ +static void yuv_close (video_decoder_t *this_gen) { + yuv_decoder_t *this = (yuv_decoder_t *) this_gen; + + if (this->buf) { + free (this->buf); + this->buf = NULL; + } + + if (this->decoder_ok) { + this->decoder_ok = 0; + this->video_out->close(this->video_out); + } +} + +/* + * This function returns the human-readable ID string to identify + * this decoder. + */ +static char *yuv_get_id(void) { + return "Raw YUV"; +} + +/* + * This function frees the video decoder instance allocated to the decoder. + */ +static void yuv_dispose (video_decoder_t *this_gen) { + free (this_gen); +} + +/* + * This function should be the plugin's only advertised function to the + * outside world. It allows xine to query the plugin module for the addresses + * to the necessary functions in the video decoder object. The video + * decoder object also has a priority field which allows different decoder + * plugins for the same buffer types to coexist peacefully. The higher the + * priority number, the more precedence a decoder has. E.g., 9 beats 1. + */ +video_decoder_t *init_video_decoder_plugin (int iface_version, xine_t *xine) { + + yuv_decoder_t *this ; + + if (iface_version != 10) { + printf( "yuv: plugin doesn't support plugin API version %d.\n" + "yuv: this means there's a version mismatch between xine and this " + "yuv: decoder plugin.\nInstalling current plugins should help.\n", + iface_version); + return NULL; + } + + this = (yuv_decoder_t *) malloc (sizeof (yuv_decoder_t)); + memset(this, 0, sizeof (yuv_decoder_t)); + + this->video_decoder.interface_version = iface_version; + this->video_decoder.can_handle = yuv_can_handle; + this->video_decoder.init = yuv_init; + this->video_decoder.decode_data = yuv_decode_data; + this->video_decoder.flush = yuv_flush; + this->video_decoder.reset = yuv_reset; + this->video_decoder.close = yuv_close; + this->video_decoder.get_identifier = yuv_get_id; + this->video_decoder.dispose = yuv_dispose; + this->video_decoder.priority = 1; + + return (video_decoder_t *) this; +} + |