annotate spudec.c @ 3400:c91d9c4512c5

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