annotate spudec.c @ 3506:3d906972dafd

--with-x11{inc,lib}dir configure option broken, can't select a specific X11 include/lib directory for mplayer compilation solaris has pthread stub routines in libc, try to verify that the _ld_pthread option used really produces a working threaded binary.
author jkeil
date Sat, 15 Dec 2001 18:35:06 +0000
parents 5d3cbbf63d18
children ba98028ddc27
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"
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
15
3180
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
16 #ifdef USE_DVDREAD
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
17
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
18 #include <errno.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
19 #include <stdio.h>
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
20 #include <stdlib.h>
3175
3538c34117a3 unistd.h required at least by FreeBSD
nexus
parents: 3166
diff changeset
21 #include <unistd.h>
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
22 #include "spudec.h"
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
23
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
24 typedef struct {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
25 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
26 unsigned char* packet;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
27 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
28 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
29 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
30 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
31 int palette[4];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
32 int alpha[4];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
33 int now_pts;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
34 int start_pts, end_pts;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
35 int start_col, end_col;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
36 int start_row, end_row;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
37 int width, height, stride;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
38 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
39 processed (for RLE decoding) for
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
40 even and odd lines */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
41 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
42 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
43 unsigned char *image; /* Grayscale value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
44 unsigned char *aimage; /* Alpha value */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
45 } spudec_handle_t;
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
46
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
47 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
48 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
49 return (p[0] << 8) + p[1];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
50 }
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 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
53 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
54 return (get_be16(p) << 8) + p[2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
55 }
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 static void next_line(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
58 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
59 if (this->current_nibble[this->deinterlace_oddness] % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
60 this->current_nibble[this->deinterlace_oddness]++;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
61 this->deinterlace_oddness = (this->deinterlace_oddness + 1) % 2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
62 }
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 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
65 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
66 unsigned char nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
67 int *nibblep = this->current_nibble + this->deinterlace_oddness;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
68 if (*nibblep / 2 >= this->control_start) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
69 fprintf(stderr, "ERROR: get_nibble past end of packet\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
70 return 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
71 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
72 nib = this->packet[*nibblep / 2];
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
73 if (*nibblep % 2)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
74 nib &= 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
75 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
76 nib >>= 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
77 ++*nibblep;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
78 return nib;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
79 }
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 static inline int mkalpha(int i)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
82 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
83 /* In mplayer's alpha planes, 0 is transparent, then 1 is nearly
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
84 opaque upto 255 which is transparent */
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
85 switch (i) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
86 case 0xf:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
87 return 1;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
88 case 0:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
89 return 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
90 default:
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
91 return (0xf - i) << 4;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
92 }
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 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
96 {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
97 int cmap[4], alpha[4];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
98 int i, x, y;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
99
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
100 for (i = 0; i < 4; ++i) {
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
101 alpha[i] = mkalpha(this->alpha[i]);
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
102 if (alpha[i] == 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
103 cmap[i] = 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
104 else {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
105 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
106 if (cmap[i] < 0)
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
107 cmap[i] = 0;
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
108 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
109 }
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
110
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
111 if (this->image_size < this->stride * this->height) {
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
112 if (this->image != NULL) {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
113 free(this->image);
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
114 this->image_size = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
115 }
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
116 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
117 if (this->image) {
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
118 this->image_size = this->stride * this->height;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
119 this->aimage = this->image + this->image_size;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
120 }
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 if (this->image == NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
123 return;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
124
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
125 /* Kludge: draw_alpha needs width multiple of 8. */
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
126 if (this->width < this->stride)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
127 for (y = 0; y < this->height; ++y)
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
128 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
129
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
130 i = this->current_nibble[1];
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
131 x = 0;
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
132 y = 0;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
133 while (this->current_nibble[0] < i
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
134 && this->current_nibble[1] / 2 < this->control_start
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
135 && y < this->height) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
136 int len, color;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
137 unsigned int rle = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
138 rle = get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
139 if (rle < 0x04) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
140 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
141 if (rle < 0x10) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
142 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
143 if (rle < 0x040) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
144 rle = (rle << 4) | get_nibble(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
145 if (rle < 0x0004)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
146 rle |= ((this->width - x) << 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
147 }
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 }
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
150 color = 3 - (rle & 0x3);
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
151 len = rle >> 2;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
152 if (len > this->width - x || len == 0)
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
153 len = this->width - x;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
154 /* FIXME have to use palette and alpha map*/
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
155 memset(this->image + y * this->stride + x, cmap[color], len);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
156 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
157 x += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
158 if (x >= this->width) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
159 next_line(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
160 x = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
161 ++y;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
162 }
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 static void spudec_process_control(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
167 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
168 int a,b; /* Temporary vars */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
169 int date, type;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
170 int off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
171 int start_off = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
172 int next_off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
173
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
174 this->control_start = get_be16(this->packet + 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
175 next_off = this->control_start;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
176 while (start_off != next_off) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
177 start_off = next_off;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
178 date = get_be16(this->packet + start_off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
179 next_off = get_be16(this->packet + start_off + 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
180 printf("date=%d\n", date);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
181 off = start_off + 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
182 for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
183 printf("cmd=%d ",type);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
184 switch(type) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
185 case 0x00:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
186 /* Menu ID, 1 byte */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
187 printf("Menu ID\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
188 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
189 case 0x01:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
190 /* Start display */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
191 printf("Start display!\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
192 this->start_pts = this->now_pts + date;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
193 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
194 case 0x02:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
195 /* Stop display */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
196 printf("Stop display!\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
197 this->end_pts = this->now_pts + date;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
198 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
199 case 0x03:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
200 /* Palette */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
201 this->palette[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
202 this->palette[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
203 this->palette[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
204 this->palette[3] = this->packet[off + 1] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
205 printf("Palette %d, %d, %d, %d\n",
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
206 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
207 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
208 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
209 case 0x04:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
210 /* Alpha */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
211 this->alpha[0] = this->packet[off] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
212 this->alpha[1] = this->packet[off] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
213 this->alpha[2] = this->packet[off + 1] >> 4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
214 this->alpha[3] = this->packet[off + 1] & 0xf;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
215 printf("Alpha %d, %d, %d, %d\n",
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
216 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
217 off+=2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
218 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
219 case 0x05:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
220 /* Co-ords */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
221 a = get_be24(this->packet + off);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
222 b = get_be24(this->packet + off + 3);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
223 this->start_col = a >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
224 this->end_col = a & 0xfff;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
225 this->width = this->end_col - this->start_col + 1;
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
226 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
227 this->start_row = b >> 12;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
228 this->end_row = b & 0xfff;
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
229 this->height = this->end_row - this->start_row /* + 1 */;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
230 printf("Coords col: %d - %d row: %d - %d (%dx%d)\n",
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
231 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
232 this->width, this->height);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
233 off+=6;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
234 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
235 case 0x06:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
236 /* Graphic lines */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
237 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
238 this->current_nibble[1] = 2 * get_be16(this->packet + off + 2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
239 printf("Graphic offset 1: %d offset 2: %d\n",
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
240 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
241 off+=4;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
242 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
243 case 0xff:
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
244 /* All done, bye-bye */
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
245 printf("Done!\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
246 return;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
247 break;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
248 default:
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
249 printf("spudec: Error determining control type 0x%02x. Skipping %d bytes.\n",
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
250 type, next_off - off);
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
251 goto next_control;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
252 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
253 }
3402
5d3cbbf63d18 Patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>:
pl
parents: 3183
diff changeset
254 next_control:
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
255 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
256 }
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 static void spudec_decode(spudec_handle_t *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
259 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
260 spudec_process_control(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
261 spudec_process_data(this);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
262 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
263
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
264
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
265 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
266 {
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
267 spudec_handle_t *spu = (spudec_handle_t*)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
268 spudec_heartbeat(this, pts100);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
269 if (spu->packet_offset == 0) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
270 unsigned int len2 = get_be16(packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
271 // Start new fragment
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
272 if (spu->packet_reserve < len2) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
273 if (spu->packet != NULL)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
274 free(spu->packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
275 spu->packet = malloc(len2);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
276 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
277 }
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
278 if (spu->packet != NULL) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
279 spu->deinterlace_oddness = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
280 spu->packet_size = len2;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
281 memcpy(spu->packet, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
282 spu->packet_offset = len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
283 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
284 } else {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
285 // Continue current fragment
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
286 if (spu->packet_size < spu->packet_offset + len)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
287 fprintf(stderr,"invalid fragment\n");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
288 else {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
289 memcpy(spu->packet + spu->packet_offset, packet, len);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
290 spu->packet_offset += len;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
291 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
292 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
293 if (spu->packet_offset == spu->packet_size) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
294 spudec_decode(spu);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
295 spu->packet_offset = 0;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
296 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
297 }
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
298
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
299 void spudec_heartbeat(void *this, int pts100)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
300 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
301 ((spudec_handle_t *)this)->now_pts = pts100;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
302 }
560
28ae99036574 Separated dvdsub code to be able to work with it easier
lgb
parents:
diff changeset
303
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
304 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
305 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
306 spudec_handle_t *spu = (spudec_handle_t *)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
307 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
308 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
309 spu->image, spu->aimage, spu->stride);
561
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
310 }
36fd71db0d33 spudec_decode() moved from mplayer.c to spudec.c
arpi_esp
parents: 560
diff changeset
311
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
312 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
313 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
314 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
315 if (this) {
3166
69ad1e3db38c Palette support for SPU decoder.
atmos4
parents: 3038
diff changeset
316 this->dvd_info = dvd_info;
3034
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
317 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
318 else
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
319 perror("FATAL: spudec_init: calloc");
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
320 return this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
321 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
322
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
323 void spudec_free(void *this)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
324 {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
325 spudec_handle_t *spu = (spudec_handle_t*)this;
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
326 if (spu) {
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
327 if (spu->packet)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
328 free(spu->packet);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
329 if (spu->image)
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
330 free(spu->image);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
331 free(spu);
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
332 }
24d3dca4e813 DVD sub patch by Kim Minh Kaplan <kmkaplan@selfoffice.com>
arpi
parents: 673
diff changeset
333 }
3180
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
334
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
335 #endif /* USE_DVDREAD */
d53f70e3c794 spudec_new has a dvd_priv_t as an argument, which is defined in
pl
parents: 3175
diff changeset
336