annotate nuppelvideo.c @ 3804:53ed66a4f0bf

NuppelVideo decoder added, based on Panagiotis Issaris' patch
author alex
date Thu, 27 Dec 2001 21:32:17 +0000
parents
children 007b3992c6b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3804
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
1 /*
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
2 * NuppelVideo 0.05 file parser
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
3 * for MPlayer
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
4 * by Panagiotis Issaris <takis@lumumba.luc.ac.be>
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
5 *
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
6 * Reworked by alex
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
7 */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
8
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
9 #include <stdio.h>
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
10 #include <stdlib.h>
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
11 #include <unistd.h>
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
12
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
13 #include "config.h"
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
14 #include "mp_msg.h"
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
15
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
16 #include "libmpdemux/nuppelvideo.h"
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
17 #include "RTjpegN.h"
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
18 #include "minilzo.h"
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
19
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
20 #define KEEP_BUFFER
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
21
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
22 void decode_nuv( unsigned char *encoded, int encoded_size,
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
23 unsigned char *decoded, int width, int height)
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
24 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
25 int r;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
26 unsigned int out_len;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
27 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
28 static unsigned char *buffer = 0;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
29 static unsigned char *previous_buffer = 0;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
30 static is_lzo_inited = 0;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
31
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
32 // printf("NUV packet: frametype: %c comptype: %c\n",
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
33 // encodedh->frametype, encodedh->comptype);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
34
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
35 switch(encodedh->frametype)
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
36 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
37 case 'D': /* additional data for compressors */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
38 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
39 /* tables are in encoded */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
40 if (encodedh->comptype == 'R')
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
41 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
42 RTjpeg_init_decompress ( encoded, width, height );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
43 printf("Found RTjpeg tables\n");
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
44 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
45 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
46 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
47 case 'V':
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
48 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
49 /* do the buffer stuffs */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
50 if ( buffer == NULL )
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
51 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
52 buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
53 #if 0
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
54 printf ( "Allocated for %dx%d image %d bytes\n", width, height,
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
55 width * height + ( width * height ) / 2 );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
56 #endif
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
57 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
58
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
59 #ifdef KEEP_BUFFER
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
60 if ( previous_buffer == NULL )
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
61 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
62 previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
63 #if 0
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
64 printf ( "Allocated for %dx%d image %d bytes\n", width, height,
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
65 width * height + ( width * height ) / 2 );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
66 #endif
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
67 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
68 #endif
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
69
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
70 if (((encodedh->comptype == '2') ||
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
71 (encodedh->comptype == '3')) && !is_lzo_inited)
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
72 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
73 /* frame using lzo, init lzo first if not inited */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
74 if ( lzo_init() != LZO_E_OK )
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
75 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
76 fprintf ( stderr, "%s\n", "lzo_init() failed !!!" );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
77 return NULL;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
78 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
79 is_lzo_inited = 1;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
80 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
81
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
82 switch(encodedh->comptype)
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
83 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
84 case '0': /* raw YUV420 */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
85 memcpy(decoded, encoded + 12, width*height*3/2);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
86 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
87 case '1': /* RTJpeg */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
88 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
89 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
90 case '2': /* RTJpeg with LZO */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
91 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
92 if ( r != LZO_E_OK )
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
93 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
94 printf ( "Error decompressing\n" );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
95 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
96 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
97 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
98 case '3': /* raw YUV420 with LZO */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
99 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
100 if ( r != LZO_E_OK )
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
101 {
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
102 printf ( "Error decompressing\n" );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
103 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
104 memcpy(decoded, buffer, width*height*3/2);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
105 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
106 case 'N': /* black frame */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
107 memset ( decoded, 0, width * height );
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
108 memset ( decoded + width * height, 127, width * height / 2);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
109 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
110 case 'L': /* copy last frame */
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
111 #ifdef KEEP_BUFFER
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
112 memcpy ( decoded, previous_buffer, width*height*3/2);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
113 #endif
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
114 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
115 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
116
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
117 #ifdef KEEP_BUFFER
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
118 memcpy(previous_buffer, decoded, width*height*3/2);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
119 #endif
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
120 break;
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
121 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
122 default:
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
123 printf("Unknown chunk: %c\n", encodedh->frametype);
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
124 }
53ed66a4f0bf NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff changeset
125 }