Mercurial > mplayer.hg
annotate libmpcodecs/native/nuppelvideo.c @ 18068:c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
author | reimar |
---|---|
date | Sun, 09 Apr 2006 18:25:35 +0000 |
parents | 6ff3379a0862 |
children | 1767c271d710 |
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> |
6238 | 12 #include <string.h> |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
13 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
14 #include "config.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
15 #include "mp_msg.h" |
14896
9ddae5897422
Make nuv files work on bigendian (but old nuv files created with mencoder
reimar
parents:
7127
diff
changeset
|
16 #include "bswap.h" |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
17 |
17012 | 18 #include "../libvo/fastmemcpy.h" |
3810 | 19 |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
20 #include "libmpdemux/nuppelvideo.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
21 #include "RTjpegN.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
22 #include "minilzo.h" |
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 #define KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
25 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
26 void decode_nuv( unsigned char *encoded, int encoded_size, |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
27 unsigned char *decoded, int width, int height) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
28 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
29 int r; |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
30 unsigned int out_len = width * height + ( width * height ) / 2; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
31 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded; |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
32 static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */ |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
33 #ifdef KEEP_BUFFER |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
34 static unsigned char *previous_buffer = 0; /* to support Last-frame-copy */ |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
35 #endif |
5104 | 36 static int is_lzo_inited = 0; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
37 |
3810 | 38 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n", |
39 // encodedh->frametype, encodedh->comptype, encoded_size, width, height); | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
40 |
14896
9ddae5897422
Make nuv files work on bigendian (but old nuv files created with mencoder
reimar
parents:
7127
diff
changeset
|
41 le2me_rtframeheader(encodedh); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
42 switch(encodedh->frametype) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
43 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
44 case 'D': /* additional data for compressors */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
45 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
46 /* tables are in encoded */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
47 if (encodedh->comptype == 'R') |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
48 { |
7127 | 49 RTjpeg_init_decompress ( (unsigned long *)(encoded+12), width, height ); |
5104 | 50 mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n", |
3810 | 51 encoded_size-12, width, height); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
52 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
53 break; |
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 case 'V': |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
56 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
57 #ifdef KEEP_BUFFER |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
58 if (!previous_buffer) |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
59 previous_buffer = ( unsigned char * ) malloc ( out_len ); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
60 #endif |
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 if (((encodedh->comptype == '2') || |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
63 (encodedh->comptype == '3')) && !is_lzo_inited) |
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 /* frame using lzo, init lzo first if not inited */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
66 if ( lzo_init() != LZO_E_OK ) |
5104 | 67 { |
68 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n"); | |
4384 | 69 return; |
3804
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 is_lzo_inited = 1; |
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 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
74 switch(encodedh->comptype) |
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 case '0': /* raw YUV420 */ |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
77 memcpy(decoded, encoded + 12, out_len); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
78 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
79 case '1': /* RTJpeg */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
80 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
81 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
82 case '2': /* RTJpeg with LZO */ |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
83 if (!buffer) |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
84 buffer = ( unsigned char * ) malloc ( out_len ); |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
85 if (!buffer) |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
86 { |
5104 | 87 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
88 break; |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
89 } |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
90 r = lzo1x_decompress_safe ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
91 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
92 { |
5104 | 93 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
94 break; | |
3804
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 */ |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
99 r = lzo1x_decompress_safe ( encoded + 12, encodedh->packetlength, decoded, &out_len, NULL ); |
3804
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 { |
5104 | 102 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
103 break; | |
3804
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 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: |
5104 | 123 mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n", |
124 encodedh->frametype); | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
125 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
126 } |