Mercurial > mplayer.hg
annotate nuppelvideo.c @ 5304:6175c9cfab11
Support for decoder specific config from mp4 header for AAC decoder.
author | atmos4 |
---|---|
date | Sun, 24 Mar 2002 03:08:20 +0000 |
parents | d60dcc0223ac |
children |
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; |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
30 static unsigned char *buffer = 0; /* for RTJpeg with LZO decompress */ |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
31 #ifdef KEEP_BUFFER |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
32 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
|
33 #endif |
5104 | 34 static int is_lzo_inited = 0; |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
35 |
3810 | 36 // printf("frametype: %c, comtype: %c, encoded_size: %d, width: %d, height: %d\n", |
37 // encodedh->frametype, encodedh->comptype, encoded_size, width, height); | |
3804
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 switch(encodedh->frametype) |
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 case 'D': /* additional data for compressors */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
42 { |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
43 /* tables are in encoded */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
44 if (encodedh->comptype == 'R') |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
45 { |
3810 | 46 RTjpeg_init_decompress ( encoded+12, width, height ); |
5104 | 47 mp_msg(MSGT_DECVIDEO, MSGL_V, "Found RTjpeg tables (size: %d, width: %d, height: %d)\n", |
3810 | 48 encoded_size-12, width, height); |
3804
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 break; |
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 case 'V': |
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 #ifdef KEEP_BUFFER |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
55 if (!previous_buffer) |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
56 previous_buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
57 #endif |
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 if (((encodedh->comptype == '2') || |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
60 (encodedh->comptype == '3')) && !is_lzo_inited) |
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 /* frame using lzo, init lzo first if not inited */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
63 if ( lzo_init() != LZO_E_OK ) |
5104 | 64 { |
65 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "LZO init failed\n"); | |
4384 | 66 return; |
3804
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 is_lzo_inited = 1; |
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 |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
71 switch(encodedh->comptype) |
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 case '0': /* raw YUV420 */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
74 memcpy(decoded, encoded + 12, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
75 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
76 case '1': /* RTJpeg */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
77 RTjpeg_decompressYUV420 ( ( __s8 * ) encoded + 12, decoded ); |
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 '2': /* RTJpeg with LZO */ |
4644
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
80 if (!buffer) |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
81 buffer = ( unsigned char * ) malloc ( width * height + ( width * height ) / 2 ); |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
82 if (!buffer) |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
83 { |
5104 | 84 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
|
85 break; |
c19fe4030bd4
break if error in decompressing, moved buffer allocating
alex
parents:
4384
diff
changeset
|
86 } |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
87 r = lzo1x_decompress ( encoded + 12, encodedh->packetlength, buffer, &out_len, NULL ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
88 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
89 { |
5104 | 90 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
91 break; | |
3804
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
92 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
93 RTjpeg_decompressYUV420 ( ( __s8 * ) buffer, decoded ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
94 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
95 case '3': /* raw YUV420 with LZO */ |
3810 | 96 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
|
97 if ( r != LZO_E_OK ) |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
98 { |
5104 | 99 mp_msg(MSGT_DECVIDEO, MSGL_ERR, "Nuppelvideo: error decompressing\n"); |
100 break; | |
3804
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 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
103 case 'N': /* black frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
104 memset ( decoded, 0, width * height ); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
105 memset ( decoded + width * height, 127, width * height / 2); |
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 'L': /* copy last frame */ |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
108 #ifdef KEEP_BUFFER |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
109 memcpy ( decoded, previous_buffer, width*height*3/2); |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
110 #endif |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
111 break; |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
112 } |
53ed66a4f0bf
NuppelVideo decoder added, based on Panagiotis Issaris' patch
alex
parents:
diff
changeset
|
113 |
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(previous_buffer, decoded, 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 default: |
5104 | 120 mp_msg(MSGT_DECVIDEO, MSGL_V, "Nuppelvideo: unknwon frametype: %c\n", |
121 encodedh->frametype); | |
3804
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 } |