2001-12-27 21:32:17 +00:00
|
|
|
/*
|
|
|
|
* NuppelVideo 0.05 file parser
|
|
|
|
* for MPlayer
|
|
|
|
* by Panagiotis Issaris <takis@lumumba.luc.ac.be>
|
|
|
|
*
|
|
|
|
* Reworked by alex
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2002-05-30 11:56:59 +00:00
|
|
|
#include <string.h>
|
2001-12-27 21:32:17 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "mp_msg.h"
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2001-12-27 21:32:17 +00:00
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "../libvo/fastmemcpy.h"
|
2001-12-27 23:05:01 +00:00
|
|
|
|
2001-12-27 21:32:17 +00:00
|
|
|
#include "libmpdemux/nuppelvideo.h"
|
2008-04-06 18:17:59 +00:00
|
|
|
#include "rtjpegn.h"
|
2007-01-31 23:20:03 +00:00
|
|
|
#include "libavutil/lzo.h"
|
2001-12-27 21:32:17 +00:00
|
|
|
|
|
|
|
#define KEEP_BUFFER
|
|
|
|
|
|
|
|
void decode_nuv( unsigned char *encoded, int encoded_size,
|
|
|
|
unsigned char *decoded, int width, int height)
|
|
|
|
{
|
|
|
|
int r;
|
2006-04-09 18:25:35 +00:00
|
|
|
unsigned int out_len = width * height + ( width * height ) / 2;
|
2001-12-27 21:32:17 +00:00
|
|
|
struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded;
|
2002-02-10 18:17:17 +00:00
|
|
|
static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */
|
|
|
|
#ifdef KEEP_BUFFER
|
|
|
|
static unsigned char *previous_buffer = 0; /* to support Last-frame-copy */
|
|
|
|
#endif
|
2001-12-27 21:32:17 +00:00
|
|
|
|
2001-12-27 23:05:01 +00:00
|
|
|
// printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n",
|
|
|
|
// encodedh->frametype, encodedh->comptype, encoded_size, width, height);
|
2001-12-27 21:32:17 +00:00
|
|
|
|
2005-03-03 10:19:56 +00:00
|
|
|
le2me_rtframeheader(encodedh);
|
2001-12-27 21:32:17 +00:00
|
|
|
switch(encodedh->frametype)
|
|
|
|
{
|
|
|
|
case 'D': /* additional data for compressors */
|
|
|
|
{
|
|
|
|
/* tables are in encoded */
|
|
|
|
if (encodedh->comptype == 'R')
|
|
|
|
{
|
2002-08-28 22:45:48 +00:00
|
|
|
RTjpeg_init_decompress ( (unsigned long *)(encoded+12), width, height );
|
2002-03-15 21:23:49 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n",
|
2001-12-27 23:05:01 +00:00
|
|
|
encoded_size-12, width, height);
|
2001-12-27 21:32:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'V':
|
|
|
|
{
|
2007-01-31 23:20:03 +00:00
|
|
|
int in_len = encodedh->packetlength;
|
2001-12-27 21:32:17 +00:00
|
|
|
#ifdef KEEP_BUFFER
|
2002-02-10 18:17:17 +00:00
|
|
|
if (!previous_buffer)
|
2007-01-31 23:20:03 +00:00
|
|
|
previous_buffer = ( unsigned char * ) malloc ( out_len + LZO_OUTPUT_PADDING );
|
2001-12-27 21:32:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch(encodedh->comptype)
|
|
|
|
{
|
|
|
|
case '0': /* raw YUV420 */
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(decoded, encoded + 12, out_len);
|
2001-12-27 21:32:17 +00:00
|
|
|
break;
|
|
|
|
case '1': /* RTJpeg */
|
|
|
|
RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded );
|
|
|
|
break;
|
|
|
|
case '2': /* RTJpeg with LZO */
|
2002-02-10 18:17:17 +00:00
|
|
|
if (!buffer)
|
2007-01-31 23:20:03 +00:00
|
|
|
buffer = ( unsigned char * ) malloc ( out_len + LZO_OUTPUT_PADDING );
|
2002-02-10 18:17:17 +00:00
|
|
|
if (!buffer)
|
|
|
|
{
|
2002-03-15 21:23:49 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
|
2002-02-10 18:17:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-01-31 23:20:03 +00:00
|
|
|
r = lzo1x_decode ( buffer, &out_len, encoded + 12, &in_len );
|
|
|
|
if ( r )
|
2001-12-27 21:32:17 +00:00
|
|
|
{
|
2002-03-15 21:23:49 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
|
|
|
|
break;
|
2001-12-27 21:32:17 +00:00
|
|
|
}
|
|
|
|
RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded );
|
|
|
|
break;
|
|
|
|
case '3': /* raw YUV420 with LZO */
|
2007-01-31 23:20:03 +00:00
|
|
|
r = lzo1x_decode ( decoded, &out_len, encoded + 12, &in_len );
|
|
|
|
if ( r )
|
2001-12-27 21:32:17 +00:00
|
|
|
{
|
2002-03-15 21:23:49 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n");
|
|
|
|
break;
|
2001-12-27 21:32:17 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'N': /* black frame */
|
|
|
|
memset ( decoded, 0, width * height );
|
|
|
|
memset ( decoded + width * height, 127, width * height / 2);
|
|
|
|
break;
|
|
|
|
case 'L': /* copy last frame */
|
|
|
|
#ifdef KEEP_BUFFER
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy ( decoded, previous_buffer, width*height*3/2);
|
2001-12-27 21:32:17 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KEEP_BUFFER
|
2007-06-05 14:27:54 +00:00
|
|
|
fast_memcpy(previous_buffer, decoded, width*height*3/2);
|
2001-12-27 21:32:17 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2002-03-15 21:23:49 +00:00
|
|
|
mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n",
|
|
|
|
encodedh->frametype);
|
2001-12-27 21:32:17 +00:00
|
|
|
}
|
|
|
|
}
|