annotate spudec.c @ 4001:ae6f97724b84

fixed format 0x62 ADPCM audio
author melanson
date Sun, 06 Jan 2002 01:56:27 +0000
parents 32e488a4fc40
children a8e7238bb7b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
1 /* SPUdec.c
673
0fdcf08e7df8 (C) fixed
arpi_esp
parents: 561
diff changeset
2 Skeleton of function spudec_process_controll() is from xine sources.
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
3 Further works:
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
4 LGB,... (yeah, try to improve it and insert your name here! ;-)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
5
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
6 Kim Minh Kaplan
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
7 implement fragments reassembly, RLE decoding.
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
8 read brightness from the IFO.
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
9
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
10 For information on SPU format see <URL:http://sam.zoy.org/doc/dvd/subtitles/>
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
11 and <URL:http://members.aol.com/mpucoder/DVD/spu.html>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
12
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
13 */
3183
ce9acee4e129 Fix spudec compile with libdvdread enabled.
atmos4
parents: 3180
diff changeset
14 #include "config.h"
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
15 #include "mp_msg.h"
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
16
3180
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
17 #ifdef USE_DVDREAD
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
18
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
19 #include <errno.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
20 #include <stdio.h>
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
21 #include <stdlib.h>
3175
3538c34117a3 unistd.h required at least by FreeBSD
nexus
parents: 3166
diff changeset
22 #include <unistd.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
23 #include "spudec.h"
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
24
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
25 typedef struct {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
26 dvd_priv_t *dvd_info; /* Info from libmpdemux */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
27 unsigned char* packet;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
28 size_t packet_reserve; /* size of the memory pointed to by packet */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
29 int packet_offset; /* end of the currently assembled fragment */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
30 int packet_size; /* size of the packet once all fragments are assembled */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
31 int control_start; /* index of start of control data */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
32 int palette[4];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
33 int alpha[4];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
34 int now_pts;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
35 int start_pts, end_pts;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
36 int start_col, end_col;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
37 int start_row, end_row;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
38 int width, height, stride;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
39 int current_nibble[2]; /* next data nibble (4 bits) to be
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
40 processed (for RLE decoding) for
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
41 even and odd lines */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
42 int deinterlace_oddness; /* 0 or 1, index into current_nibble */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
43 size_t image_size; /* Size of the image buffer */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
44 unsigned char *image; /* Grayscale value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
45 unsigned char *aimage; /* Alpha value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
46 } spudec_handle_t;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
47
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
48 static inline unsigned int get_be16(const unsigned char *p)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
49 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
50 return (p[0] << 8) + p[1];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
51 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
52
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
53 static inline unsigned int get_be24(const unsigned char *p)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
54 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
55 return (get_be16(p) << 8) + p[2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
56 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
57
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
58 static void next_line(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
59 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
60 if (this->current_nibble[this->deinterlace_oddness] % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
61 this->current_nibble[this->deinterlace_oddness]++;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
62 this->deinterlace_oddness = (this->deinterlace_oddness + 1) % 2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
63 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
64
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
65 static inline unsigned char get_nibble(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
66 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
67 unsigned char nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
68 int *nibblep = this->current_nibble + this->deinterlace_oddness;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
69 if (*nibblep / 2 >= this->control_start) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
70 mp_msg(MSGT_SPUDEC,MSGL_WARN, "SPUdec: ERROR: get_nibble past end of packet\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
71 return 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
72 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
73 nib = this->packet[*nibblep / 2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
74 if (*nibblep % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
75 nib &= 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
76 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
77 nib >>= 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
78 ++*nibblep;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
79 return nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
80 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
81
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
82 static inline int mkalpha(int i)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
83 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
84 /* In mplayer's alpha planes, 0 is transparent, then 1 is nearly
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
85 opaque upto 255 which is transparent */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
86 switch (i) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
87 case 0xf:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
88 return 1;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
89 case 0:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
90 return 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
91 default:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
92 return (0xf - i) << 4;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
93 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
94 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
95
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
96 static void spudec_process_data(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
97 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
98 int cmap[4], alpha[4];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
99 int i, x, y;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
100
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
101 for (i = 0; i < 4; ++i) {
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
102 alpha[i] = mkalpha(this->alpha[i]);
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
103 if (alpha[i] == 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
104 cmap[i] = 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
105 else {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
106 cmap[i] = ((this->dvd_info->cur_pgc->palette[this->palette[i]] >> 16) & 0xff) - alpha[i];
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
107 if (cmap[i] < 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
108 cmap[i] = 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
109 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
110 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
111
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
112 if (this->image_size < this->stride * this->height) {
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
113 if (this->image != NULL) {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
114 free(this->image);
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
115 this->image_size = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
116 }
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
117 this->image = malloc(2 * this->stride * this->height);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
118 if (this->image) {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
119 this->image_size = this->stride * this->height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
120 this->aimage = this->image + this->image_size;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
121 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
122 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
123 if (this->image == NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
124 return;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
125
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
126 /* Kludge: draw_alpha needs width multiple of 8. */
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
127 if (this->width < this->stride)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
128 for (y = 0; y < this->height; ++y)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
129 memset(this->aimage + y * this->stride + this->width, 0, this->stride - this->width);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
130
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
131 i = this->current_nibble[1];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
132 x = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
133 y = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
134 while (this->current_nibble[0] < i
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
135 && this->current_nibble[1] / 2 < this->control_start
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
136 && y < this->height) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
137 int len, color;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
138 unsigned int rle = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
139 rle = get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
140 if (rle < 0x04) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
141 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
142 if (rle < 0x10) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
143 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
144 if (rle < 0x040) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
145 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
146 if (rle < 0x0004)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
147 rle |= ((this->width - x) << 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
148 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
149 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
150 }
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
151 color = 3 - (rle & 0x3);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
152 len = rle >> 2;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
153 if (len > this->width - x || len == 0)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
154 len = this->width - x;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
155 /* FIXME have to use palette and alpha map*/
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
156 memset(this->image + y * this->stride + x, cmap[color], len);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
157 memset(this->aimage + y * this->stride + x, alpha[color], len);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
158 x += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
159 if (x >= this->width) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
160 next_line(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
161 x = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
162 ++y;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
163 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
164 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
165 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
166
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
167 static void spudec_process_control(spudec_handle_t *this, int pts100)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
168 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
169 int a,b; /* Temporary vars */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
170 int date, type;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
171 int off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
172 int start_off = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
173 int next_off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
174
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
175 this->control_start = get_be16(this->packet + 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
176 next_off = this->control_start;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
177 while (start_off != next_off) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
178 start_off = next_off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
179 date = get_be16(this->packet + start_off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
180 next_off = get_be16(this->packet + start_off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
181 mp_msg(MSGT_SPUDEC,MSGL_DBG2, "date=%d\n", date);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
182 off = start_off + 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
183 for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) {
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
184 mp_msg(MSGT_SPUDEC,MSGL_DBG2, "cmd=%d ",type);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
185 switch(type) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
186 case 0x00:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
187 /* Menu ID, 1 byte */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
188 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
189 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
190 case 0x01:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
191 /* Start display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
192 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Start display!\n");
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
193 this->start_pts = pts100 + date;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
194 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
195 case 0x02:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
196 /* Stop display */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
197 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Stop display!\n");
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
198 this->end_pts = pts100 + date;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
199 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
200 case 0x03:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
201 /* Palette */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
202 this->palette[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
203 this->palette[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
204 this->palette[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
205 this->palette[3] = this->packet[off + 1] & 0xf;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
206 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Palette %d, %d, %d, %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
207 this->palette[0], this->palette[1], this->palette[2], this->palette[3]);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
208 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
209 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
210 case 0x04:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
211 /* Alpha */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
212 this->alpha[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
213 this->alpha[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
214 this->alpha[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
215 this->alpha[3] = this->packet[off + 1] & 0xf;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
216 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Alpha %d, %d, %d, %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
217 this->alpha[0], this->alpha[1], this->alpha[2], this->alpha[3]);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
218 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
219 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
220 case 0x05:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
221 /* Co-ords */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
222 a = get_be24(this->packet + off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
223 b = get_be24(this->packet + off + 3);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
224 this->start_col = a >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
225 this->end_col = a & 0xfff;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
226 this->width = this->end_col - this->start_col + 1;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
227 this->stride = (this->width + 7) & ~7; /* Kludge: draw_alpha needs width multiple of 8 */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
228 this->start_row = b >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
229 this->end_row = b & 0xfff;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
230 this->height = this->end_row - this->start_row /* + 1 */;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
231 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Coords col: %d - %d row: %d - %d (%dx%d)\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
232 this->start_col, this->end_col, this->start_row, this->end_row,
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
233 this->width, this->height);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
234 off+=6;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
235 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
236 case 0x06:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
237 /* Graphic lines */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
238 this->current_nibble[0] = 2 * get_be16(this->packet + off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
239 this->current_nibble[1] = 2 * get_be16(this->packet + off + 2);
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
240 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Graphic offset 1: %d offset 2: %d\n",
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
241 this->current_nibble[0] / 2, this->current_nibble[1] / 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
242 off+=4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
243 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
244 case 0xff:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
245 /* All done, bye-bye */
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
246 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Done!\n");
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
247 return;
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
248 // break;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
249 default:
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
250 mp_msg(MSGT_SPUDEC,MSGL_WARN,"spudec: Error determining control type 0x%02x. Skipping %d bytes.\n",
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
251 type, next_off - off);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
252 goto next_control;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
253 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
254 }
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
255 next_control:
3725
ba98028ddc27 fixes warnings
pl
parents: 3402
diff changeset
256 ;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
257 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
258 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
259
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
260 static void spudec_decode(spudec_handle_t *this,int pts100)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
261 {
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
262 spudec_process_control(this, pts100);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
263 spudec_process_data(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
264 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
265
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
266
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
267 void spudec_assemble(void *this, unsigned char *packet, int len, int pts100)
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
268 {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
269 spudec_handle_t *spu = (spudec_handle_t*)this;
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
270 // spudec_heartbeat(this, pts100);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
271 if (spu->packet_offset == 0) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
272 unsigned int len2 = get_be16(packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
273 // Start new fragment
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
274 if (spu->packet_reserve < len2) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
275 if (spu->packet != NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
276 free(spu->packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
277 spu->packet = malloc(len2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
278 spu->packet_reserve = spu->packet != NULL ? len2 : 0;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
279 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
280 if (spu->packet != NULL) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
281 spu->deinterlace_oddness = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
282 spu->packet_size = len2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
283 memcpy(spu->packet, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
284 spu->packet_offset = len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
285 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
286 } else {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
287 // Continue current fragment
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
288 if (spu->packet_size < spu->packet_offset + len){
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
289 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n");
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
290 spu->packet_size = spu->packet_offset = 0;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
291 } else {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
292 memcpy(spu->packet + spu->packet_offset, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
293 spu->packet_offset += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
294 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
295 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
296 #if 1
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
297 // check if we have a complete packet (unfortunatelly packet_size is bad
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
298 // for some disks)
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
299 // if (spu->packet_offset == spu->packet_size)
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
300 { int x=0,y;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
301 while(x>=0 && x+4<=spu->packet_offset){
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
302 y=get_be16(spu->packet+x+2); // next control pointer
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
303 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUtest: x=%d y=%d off=%d size=%d\n",x,y,spu->packet_offset,spu->packet_size);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
304 if(x>=4 && x==y){ // if it points to self - we're done!
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
305 // we got it!
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
306 mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",spu->packet_offset,spu->packet_size);
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
307 spudec_decode(spu, pts100);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
308 spu->packet_offset = 0;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
309 break;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
310 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
311 if(y<=x || y>=spu->packet_size){ // invalid?
3822
cdaacdac6571 printf->mp_msg
arpi
parents: 3820
diff changeset
312 mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x);
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
313 spu->packet_size = spu->packet_offset = 0;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
314 break;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
315 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
316 x=y;
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
317 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
318 }
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
319 #else
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
320 if (spu->packet_offset == spu->packet_size) {
3842
32e488a4fc40 dvdsub pts fix, based on patch by Kim Minh Kaplan
arpi
parents: 3822
diff changeset
321 spudec_decode(spu, pts100);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
322 spu->packet_offset = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
323 }
3820
8f7fab2e89bf more stable and reliable spudec packet reassembler
arpi
parents: 3744
diff changeset
324 #endif
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
325 }
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
326
3744
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
327 void spudec_reset(void *this) // called after seek
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
328 {
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
329 spudec_handle_t *spu = (spudec_handle_t*)this;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
330 spu->now_pts = -1;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
331 spu->packet_size = spu->packet_offset = 0;
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
332 }
d358f4a74690 dvd seeking -> subtitle disappearing bugs fixed
arpi
parents: 3725
diff changeset
333
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
334 void spudec_heartbeat(void *this, int pts100)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
335 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
336 ((spudec_handle_t *)this)->now_pts = pts100;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
337 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
338
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
339 void spudec_draw(void *this, void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride))
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
340 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
341 spudec_handle_t *spu = (spudec_handle_t *)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
342 if (spu->start_pts <= spu->now_pts && spu->now_pts < spu->end_pts && spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
343 draw_alpha(spu->start_col, spu->start_row, spu->width, spu->height,
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
344 spu->image, spu->aimage, spu->stride);
561
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
345 }
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
346
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
347 void *spudec_new(dvd_priv_t *dvd_info)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
348 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
349 spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
350 if (this) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
351 this->dvd_info = dvd_info;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
352 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
353 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
354 perror("FATAL: spudec_init: calloc");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
355 return this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
356 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
357
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
358 void spudec_free(void *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
359 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
360 spudec_handle_t *spu = (spudec_handle_t*)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
361 if (spu) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
362 if (spu->packet)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
363 free(spu->packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
364 if (spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
365 free(spu->image);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
366 free(spu);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
367 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
368 }
3180
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
369
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
370 #endif /* USE_DVDREAD */
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
371