Mercurial > mplayer.hg
annotate nuppelvideo.c @ 3966:6185a66a63cf
*** empty log message ***
author | gabucino |
---|---|
date | Thu, 03 Jan 2002 21:12:35 +0000 |
parents | 007b3992c6b5 |
children | a1d27234018f |
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 |
3810 | 16 #include "fastmemcpy.h" |
17 | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
18 #include "libmpdemux/nuppelvideo.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
19 #include "RTjpegN.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
20 #include "minilzo.h" |
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 #define KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
23 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
24 void decode_nuv( unsigned char *encoded, int encoded_size, |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
25 unsigned char *decoded, int width, int height) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
26 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
27 int r; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
28 unsigned int out_len; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
29 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
30 static unsigned char *buffer = 0; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
31 static unsigned char *previous_buffer = 0; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
32 static is_lzo_inited = 0; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
33 |
3810 | 34 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n", |
35 // encodedh->frametype, encodedh->comptype, encoded_size, width, height); | |
3804
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 switch(encodedh->frametype) |
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 case 'D': /* additional data for compressors */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
40 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
41 /* tables are in encoded */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
42 if (encodedh->comptype == 'R') |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
43 { |
3810 | 44 RTjpeg_init_decompress ( encoded+12, width, height ); |
45 printf("Found RTjpeg tables (size: %d, width: %d, height: %d)\n", | |
46 encoded_size-12, width, height); | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
47 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
48 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
49 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
50 case 'V': |
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 /* do the buffer stuffs */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
53 if ( buffer == NULL ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
54 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
55 buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
56 #if 0 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
57 printf ( "Allocated for %dx%d image %d bytes\n", width, height, |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
58 width * height + ( width * height ) / 2 ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
59 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
60 } |
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 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
63 if ( previous_buffer == NULL ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
64 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
65 previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
66 #if 0 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
67 printf ( "Allocated for %dx%d image %d bytes\n", width, height, |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
68 width * height + ( width * height ) / 2 ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
69 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
70 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
71 #endif |
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 if (((encodedh->comptype == '2') || |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
74 (encodedh->comptype == '3')) && !is_lzo_inited) |
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 /* frame using lzo, init lzo first if not inited */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
77 if ( lzo_init() != LZO_E_OK ) |
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 fprintf ( stderr, "%s\n", "lzo_init() failed !!!" ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
80 return NULL; |
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 is_lzo_inited = 1; |
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 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
85 switch(encodedh->comptype) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
86 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
87 case '0': /* raw YUV420 */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
88 memcpy(decoded, encoded + 12, width*height*3/2); |
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 '1': /* RTJpeg */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
91 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
92 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
93 case '2': /* RTJpeg with LZO */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
94 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
95 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
96 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
97 printf ( "Error decompressing\n" ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
98 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
99 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
100 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
101 case '3': /* raw YUV420 with LZO */ |
3810 | 102 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, decoded, &out_len, NULL ); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
103 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
104 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
105 printf ( "Error decompressing\n" ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
106 } |
3810 | 107 // memcpy(decoded, buffer, width*height*3/2); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
108 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
109 case 'N': /* black frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
110 memset ( decoded, 0, width * height ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
111 memset ( decoded + width * height, 127, width * height / 2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
112 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
113 case 'L': /* copy last frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
114 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
115 memcpy ( decoded, previous_buffer, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
116 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
117 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
118 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
119 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
120 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
121 memcpy(previous_buffer, decoded, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
122 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
123 break; |
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 default: |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
126 printf("Unknown chunk: %c\n", encodedh->frametype); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
127 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
128 } |