Mercurial > mplayer.hg
annotate libmpcodecs/native/nuppelvideo.c @ 21569:685b7a8e6992
Better default CFLAGS for non-gnu, non-intel compilers
author | reimar |
---|---|
date | Sun, 10 Dec 2006 22:12:48 +0000 |
parents | fa99b3d31d13 |
children | fc27312ae599 |
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" |
21372 | 16 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
17 #include "mpbswap.h" |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
18 |
17012 | 19 #include "../libvo/fastmemcpy.h" |
3810 | 20 |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
21 #include "libmpdemux/nuppelvideo.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
22 #include "RTjpegN.h" |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
23 #include "minilzo.h" |
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 #define KEEP_BUFFER |
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 void decode_nuv( unsigned char *encoded, int encoded_size, |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
28 unsigned char *decoded, int width, int height) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
29 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
30 int r; |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
31 unsigned int out_len = width * height + ( width * height ) / 2; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
32 struct rtframeheader *encodedh = ( struct rtframeheader* ) encoded; |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
33 static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */ |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
34 #ifdef KEEP_BUFFER |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
35 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
|
36 #endif |
5104 | 37 static int is_lzo_inited = 0; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
38 |
3810 | 39 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n", |
40 // encodedh->frametype, encodedh->comptype, encoded_size, width, height); | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
41 |
14896
9ddae5897422
Make nuv files work on bigendian (but old nuv files created with mencoder
reimar
parents:
7127
diff
changeset
|
42 le2me_rtframeheader(encodedh); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
43 switch(encodedh->frametype) |
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 case 'D': /* additional data for compressors */ |
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 /* tables are in encoded */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
48 if (encodedh->comptype == 'R') |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
49 { |
7127 | 50 RTjpeg_init_decompress ( (unsigned long *)(encoded+12), width, height ); |
5104 | 51 mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n", |
3810 | 52 encoded_size-12, width, height); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
53 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
54 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
55 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
56 case 'V': |
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 #ifdef KEEP_BUFFER |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
59 if (!previous_buffer) |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
60 previous_buffer = ( unsigned char * ) malloc ( out_len ); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
61 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
62 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
63 if (((encodedh->comptype == '2') || |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
64 (encodedh->comptype == '3')) && !is_lzo_inited) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
65 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
66 /* frame using lzo, init lzo first if not inited */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
67 if ( lzo_init() != LZO_E_OK ) |
5104 | 68 { |
69 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n"); | |
4384 | 70 return; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
71 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
72 is_lzo_inited = 1; |
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 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
75 switch(encodedh->comptype) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
76 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
77 case '0': /* raw YUV420 */ |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
78 memcpy(decoded, encoded + 12, out_len); |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
79 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
80 case '1': /* RTJpeg */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
81 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
82 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
83 case '2': /* RTJpeg with LZO */ |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
84 if (!buffer) |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
85 buffer = ( unsigned char * ) malloc ( out_len ); |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
86 if (!buffer) |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
87 { |
5104 | 88 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
|
89 break; |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
90 } |
18068
c34ffa6f5fa8
10l, we should really, really use lzo1x_decompress_safe instead of lzo1x_decompress
reimar
parents:
17012
diff
changeset
|
91 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
|
92 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
93 { |
5104 | 94 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
95 break; | |
3804
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 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
98 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
99 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
|
100 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
|
101 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
102 { |
5104 | 103 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
104 break; | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
105 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
106 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
107 case 'N': /* black frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
108 memset ( decoded, 0, width * height ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
109 memset ( decoded + width * height, 127, width * height / 2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
110 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
111 case 'L': /* copy last frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
112 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
113 memcpy ( decoded, previous_buffer, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
114 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
115 break; |
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 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
118 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
119 memcpy(previous_buffer, decoded, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
120 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
121 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
122 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
123 default: |
5104 | 124 mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n", |
125 encodedh->frametype); | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
126 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
127 } |