2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* Skeleton of function spudec_process_controll() is from xine sources.
|
|
|
|
* Further works:
|
|
|
|
* LGB,... (yeah, try to improve it and insert your name here! ;-)
|
|
|
|
*
|
|
|
|
* Kim Minh Kaplan
|
|
|
|
* implement fragments reassembly, RLE decoding.
|
|
|
|
* read brightness from the IFO.
|
|
|
|
*
|
|
|
|
* For information on SPU format see <URL:http://sam.zoy.org/doc/dvd/subtitles/>
|
|
|
|
* and <URL:http://members.aol.com/mpucoder/DVD/spu.html>
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-11-20 18:36:50 +00:00
|
|
|
*/
|
2010-01-30 23:24:23 +00:00
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
#include <errno.h>
|
2002-01-10 17:17:37 +00:00
|
|
|
#include <limits.h>
|
2001-04-21 15:38:01 +00:00
|
|
|
#include <stdio.h>
|
2001-11-20 18:36:50 +00:00
|
|
|
#include <stdlib.h>
|
2001-11-28 08:08:03 +00:00
|
|
|
#include <unistd.h>
|
2002-05-29 19:27:06 +00:00
|
|
|
#include <string.h>
|
2002-01-10 17:17:37 +00:00
|
|
|
#include <math.h>
|
2012-09-28 19:38:52 +00:00
|
|
|
#include <assert.h>
|
2012-02-01 18:01:16 +00:00
|
|
|
|
2012-08-15 20:23:02 +00:00
|
|
|
#include <libavutil/common.h>
|
2012-02-01 18:01:16 +00:00
|
|
|
#include <libavutil/intreadwrite.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
2012-02-01 18:01:16 +00:00
|
|
|
|
2001-04-21 15:38:01 +00:00
|
|
|
#include "spudec.h"
|
2012-09-28 19:38:52 +00:00
|
|
|
#include "sub.h"
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_common.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/csputils.h"
|
2003-01-24 10:24:07 +00:00
|
|
|
|
2012-04-22 21:52:39 +00:00
|
|
|
typedef struct spu_packet_t packet_t;
|
|
|
|
struct spu_packet_t {
|
2010-07-10 13:45:09 +00:00
|
|
|
int is_decoded;
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned char *packet;
|
2010-07-10 13:45:09 +00:00
|
|
|
int data_len;
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned int palette[4];
|
|
|
|
unsigned int alpha[4];
|
|
|
|
unsigned int control_start; /* index of start of control data */
|
|
|
|
unsigned int current_nibble[2]; /* next data nibble (4 bits) to be
|
|
|
|
processed (for RLE decoding) for
|
|
|
|
even and odd lines */
|
|
|
|
int deinterlace_oddness; /* 0 or 1, index into current_nibble */
|
2010-07-26 17:15:56 +00:00
|
|
|
unsigned int start_col;
|
|
|
|
unsigned int start_row;
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned int width, height, stride;
|
|
|
|
unsigned int start_pts, end_pts;
|
2003-01-08 18:36:36 +00:00
|
|
|
packet_t *next;
|
|
|
|
};
|
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
typedef struct {
|
2003-02-16 15:26:30 +00:00
|
|
|
packet_t *queue_head;
|
|
|
|
packet_t *queue_tail;
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int global_palette[16];
|
|
|
|
unsigned int orig_frame_width, orig_frame_height;
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned char* packet;
|
|
|
|
size_t packet_reserve; /* size of the memory pointed to by packet */
|
|
|
|
unsigned int packet_offset; /* end of the currently assembled fragment */
|
|
|
|
unsigned int packet_size; /* size of the packet once all fragments are assembled */
|
2007-12-11 10:12:58 +00:00
|
|
|
int packet_pts; /* PTS for this packet */
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int palette[4];
|
|
|
|
unsigned int alpha[4];
|
2002-04-25 18:46:44 +00:00
|
|
|
unsigned int cuspal[4];
|
|
|
|
unsigned int custom;
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int now_pts;
|
|
|
|
unsigned int start_pts, end_pts;
|
2010-07-26 17:15:56 +00:00
|
|
|
unsigned int start_col;
|
|
|
|
unsigned int start_row;
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int width, height, stride;
|
2001-11-20 18:36:50 +00:00
|
|
|
size_t image_size; /* Size of the image buffer */
|
|
|
|
unsigned char *image; /* Grayscale value */
|
2010-07-26 19:41:04 +00:00
|
|
|
unsigned int pal_start_col, pal_start_row;
|
|
|
|
unsigned int pal_width, pal_height;
|
2010-07-24 21:24:20 +00:00
|
|
|
unsigned char *pal_image; /* palette entry value */
|
2002-05-17 23:47:27 +00:00
|
|
|
int auto_palette; /* 1 if we lack a palette and must use an heuristic. */
|
|
|
|
int font_start_level; /* Darkest value used for the computed font */
|
2002-07-24 16:47:29 +00:00
|
|
|
int spu_changed;
|
2003-09-21 14:21:43 +00:00
|
|
|
unsigned int forced_subs_only; /* flag: 0=display all subtitle, !0 display only forced subtitles */
|
|
|
|
unsigned int is_forced_sub; /* true if current subtitle is a forced subtitle */
|
2010-07-26 19:41:04 +00:00
|
|
|
|
2012-10-08 00:05:59 +00:00
|
|
|
struct sub_bitmap sub_part, borrowed_sub_part;
|
2012-10-04 15:16:47 +00:00
|
|
|
struct osd_bmp_indexed borrowed_bmp;
|
2001-11-20 18:36:50 +00:00
|
|
|
} spudec_handle_t;
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
static void spudec_queue_packet(spudec_handle_t *this, packet_t *packet)
|
2003-01-08 18:36:36 +00:00
|
|
|
{
|
2003-02-16 15:26:30 +00:00
|
|
|
if (this->queue_head == NULL)
|
|
|
|
this->queue_head = packet;
|
2003-01-08 18:36:36 +00:00
|
|
|
else
|
2003-02-16 15:26:30 +00:00
|
|
|
this->queue_tail->next = packet;
|
|
|
|
this->queue_tail = packet;
|
2003-01-08 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
static packet_t *spudec_dequeue_packet(spudec_handle_t *this)
|
2003-01-08 18:36:36 +00:00
|
|
|
{
|
2003-02-16 15:26:30 +00:00
|
|
|
packet_t *retval = this->queue_head;
|
2003-01-08 18:36:36 +00:00
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
this->queue_head = retval->next;
|
|
|
|
if (this->queue_head == NULL)
|
|
|
|
this->queue_tail = NULL;
|
2003-01-08 18:36:36 +00:00
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
return retval;
|
2003-01-08 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
static void spudec_free_packet(packet_t *packet)
|
2003-01-08 18:36:36 +00:00
|
|
|
{
|
2010-11-07 12:47:40 +00:00
|
|
|
free(packet->packet);
|
2003-02-16 15:26:30 +00:00
|
|
|
free(packet);
|
2003-01-08 18:36:36 +00:00
|
|
|
}
|
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
static inline unsigned int get_be16(const unsigned char *p)
|
|
|
|
{
|
|
|
|
return (p[0] << 8) + p[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int get_be24(const unsigned char *p)
|
|
|
|
{
|
|
|
|
return (get_be16(p) << 8) + p[2];
|
|
|
|
}
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
static void next_line(packet_t *packet)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
2003-02-16 15:26:30 +00:00
|
|
|
if (packet->current_nibble[packet->deinterlace_oddness] % 2)
|
|
|
|
packet->current_nibble[packet->deinterlace_oddness]++;
|
|
|
|
packet->deinterlace_oddness = (packet->deinterlace_oddness + 1) % 2;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
static inline unsigned char get_nibble(packet_t *packet)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
|
|
|
unsigned char nib;
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned int *nibblep = packet->current_nibble + packet->deinterlace_oddness;
|
2003-01-08 18:36:36 +00:00
|
|
|
if (*nibblep / 2 >= packet->control_start) {
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN, "SPUdec: ERROR: get_nibble past end of packet\n");
|
2001-11-20 18:36:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
nib = packet->packet[*nibblep / 2];
|
2001-11-20 18:36:50 +00:00
|
|
|
if (*nibblep % 2)
|
|
|
|
nib &= 0xf;
|
|
|
|
else
|
|
|
|
nib >>= 4;
|
|
|
|
++*nibblep;
|
|
|
|
return nib;
|
|
|
|
}
|
|
|
|
|
2010-07-10 10:22:28 +00:00
|
|
|
static int spudec_alloc_image(spudec_handle_t *this, int stride, int height)
|
|
|
|
{
|
|
|
|
if (this->width > stride) // just a safeguard
|
|
|
|
this->width = stride;
|
|
|
|
this->stride = stride;
|
|
|
|
this->height = height;
|
|
|
|
if (this->image_size < this->stride * this->height) {
|
|
|
|
if (this->image != NULL) {
|
|
|
|
free(this->image);
|
2012-10-30 18:53:58 +00:00
|
|
|
this->image = NULL;
|
2010-07-24 21:40:06 +00:00
|
|
|
free(this->pal_image);
|
2012-10-30 18:53:58 +00:00
|
|
|
this->pal_image = NULL;
|
2010-07-10 10:22:28 +00:00
|
|
|
this->image_size = 0;
|
2010-07-26 19:41:04 +00:00
|
|
|
this->pal_width = this->pal_height = 0;
|
2010-07-10 10:22:28 +00:00
|
|
|
}
|
2010-07-24 21:40:06 +00:00
|
|
|
this->image = malloc(2 * this->stride * this->height);
|
2010-07-10 10:22:28 +00:00
|
|
|
if (this->image) {
|
|
|
|
this->image_size = this->stride * this->height;
|
2010-07-24 21:40:06 +00:00
|
|
|
// use stride here as well to simplify reallocation checks
|
|
|
|
this->pal_image = malloc(this->stride * this->height);
|
2010-07-10 10:22:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return this->image != NULL;
|
|
|
|
}
|
|
|
|
|
2012-10-08 00:05:59 +00:00
|
|
|
static void setup_palette(spudec_handle_t *spu, uint32_t palette[256])
|
|
|
|
{
|
2012-11-12 22:24:01 +00:00
|
|
|
memset(palette, 0, sizeof(*palette) * 256);
|
2012-10-07 22:14:51 +00:00
|
|
|
struct mp_csp_params csp = MP_CSP_PARAMS_DEFAULTS;
|
2012-10-25 19:23:18 +00:00
|
|
|
csp.int_bits_in = 8;
|
|
|
|
csp.int_bits_out = 8;
|
2012-10-07 22:14:51 +00:00
|
|
|
float cmatrix[3][4];
|
|
|
|
mp_get_yuv2rgb_coeffs(&csp, cmatrix);
|
2012-10-08 00:05:59 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
int alpha = spu->alpha[i];
|
|
|
|
// extend 4 -> 8 bit
|
|
|
|
alpha |= alpha << 4;
|
|
|
|
if (spu->custom && (spu->cuspal[i] >> 31) != 0)
|
|
|
|
alpha = 0;
|
|
|
|
int color = spu->custom ? spu->cuspal[i] :
|
|
|
|
spu->global_palette[spu->palette[i]];
|
2012-10-25 17:37:47 +00:00
|
|
|
int c[3] = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff};
|
2012-10-25 19:23:18 +00:00
|
|
|
mp_map_int_color(cmatrix, 8, c);
|
2012-10-07 22:14:51 +00:00
|
|
|
// R and G swapped, possibly due to vobsub_palette_to_yuv()
|
2012-10-25 17:37:47 +00:00
|
|
|
palette[i] = (alpha << 24u) | (c[2] << 16) | (c[1] << 8) | c[0];
|
2010-07-24 21:24:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 00:05:59 +00:00
|
|
|
static void crop_image(struct sub_bitmap *part)
|
|
|
|
{
|
|
|
|
if (part->w < 1 || part->h < 1)
|
|
|
|
return;
|
|
|
|
struct osd_bmp_indexed *bmp = part->bitmap;
|
|
|
|
bool invisible[256];
|
|
|
|
for (int n = 0; n < 256; n++)
|
|
|
|
invisible[n] = !(bmp->palette[n] >> 24);
|
|
|
|
int y0 = 0, y1 = part->h, x0 = part->w, x1 = 0;
|
|
|
|
bool y_all_invisible = true;
|
|
|
|
for (int y = 0; y < part->h; y++) {
|
|
|
|
uint8_t *pixels = bmp->bitmap + part->stride * y;
|
|
|
|
int cur = 0;
|
|
|
|
while (cur < part->w && invisible[pixels[cur]])
|
|
|
|
cur++;
|
|
|
|
int start_visible = cur;
|
|
|
|
int last_visible = -1;
|
|
|
|
while (cur < part->w) {
|
|
|
|
if (!invisible[pixels[cur]])
|
|
|
|
last_visible = cur;
|
|
|
|
cur++;
|
|
|
|
}
|
|
|
|
x0 = FFMIN(x0, start_visible);
|
|
|
|
x1 = FFMAX(x1, last_visible);
|
|
|
|
bool all_invisible = last_visible == -1;
|
|
|
|
if (all_invisible) {
|
|
|
|
if (y_all_invisible)
|
|
|
|
y0 = y;
|
|
|
|
} else {
|
|
|
|
y_all_invisible = false;
|
|
|
|
y1 = y + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bmp->bitmap += x0 + y0 * part->stride;
|
|
|
|
part->w = FFMAX(x1 - x0, 0);
|
|
|
|
part->h = FFMAX(y1 - y0, 0);
|
|
|
|
part->x += x0;
|
|
|
|
part->y += y0;
|
2010-07-26 19:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void spudec_process_data(spudec_handle_t *this, packet_t *packet)
|
|
|
|
{
|
|
|
|
unsigned int i, x, y;
|
|
|
|
uint8_t *dst;
|
|
|
|
|
|
|
|
if (!spudec_alloc_image(this, packet->stride, packet->height))
|
2001-11-20 18:36:50 +00:00
|
|
|
return;
|
2001-12-09 16:56:23 +00:00
|
|
|
|
2010-07-26 19:41:04 +00:00
|
|
|
this->pal_start_col = packet->start_col;
|
|
|
|
this->pal_start_row = packet->start_row;
|
|
|
|
this->pal_height = packet->height;
|
|
|
|
this->pal_width = packet->width;
|
|
|
|
this->stride = packet->stride;
|
|
|
|
memcpy(this->palette, packet->palette, sizeof(this->palette));
|
|
|
|
memcpy(this->alpha, packet->alpha, sizeof(this->alpha));
|
|
|
|
|
2003-02-16 15:26:30 +00:00
|
|
|
i = packet->current_nibble[1];
|
2001-12-09 16:56:23 +00:00
|
|
|
x = 0;
|
|
|
|
y = 0;
|
2010-07-24 21:34:13 +00:00
|
|
|
dst = this->pal_image;
|
2003-02-16 15:26:30 +00:00
|
|
|
while (packet->current_nibble[0] < i
|
|
|
|
&& packet->current_nibble[1] / 2 < packet->control_start
|
2010-07-26 19:41:04 +00:00
|
|
|
&& y < this->pal_height) {
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int len, color;
|
2001-11-20 18:36:50 +00:00
|
|
|
unsigned int rle = 0;
|
2003-02-16 15:26:30 +00:00
|
|
|
rle = get_nibble(packet);
|
2001-11-20 18:36:50 +00:00
|
|
|
if (rle < 0x04) {
|
2010-07-25 09:41:30 +00:00
|
|
|
if (rle == 0) {
|
2003-02-16 15:26:30 +00:00
|
|
|
rle = (rle << 4) | get_nibble(packet);
|
2010-07-25 09:41:30 +00:00
|
|
|
if (rle < 0x04)
|
2003-02-16 15:26:30 +00:00
|
|
|
rle = (rle << 4) | get_nibble(packet);
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2010-07-25 09:41:30 +00:00
|
|
|
rle = (rle << 4) | get_nibble(packet);
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2001-11-27 20:16:45 +00:00
|
|
|
color = 3 - (rle & 0x3);
|
2001-11-20 18:36:50 +00:00
|
|
|
len = rle >> 2;
|
|
|
|
x += len;
|
2010-07-26 19:41:04 +00:00
|
|
|
if (len == 0 || x >= this->pal_width) {
|
|
|
|
len += this->pal_width - x;
|
2003-02-16 15:26:30 +00:00
|
|
|
next_line(packet);
|
2001-11-20 18:36:50 +00:00
|
|
|
x = 0;
|
|
|
|
++y;
|
|
|
|
}
|
2010-07-24 21:34:13 +00:00
|
|
|
memset(dst, color, len);
|
|
|
|
dst += len;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2012-10-08 00:05:59 +00:00
|
|
|
|
|
|
|
struct sub_bitmap *sub_part = &this->sub_part;
|
|
|
|
struct osd_bmp_indexed *bmp = &this->borrowed_bmp;
|
|
|
|
bmp->bitmap = this->pal_image;
|
|
|
|
setup_palette(this, bmp->palette);
|
|
|
|
sub_part->bitmap = bmp;
|
|
|
|
sub_part->stride = this->pal_width;
|
|
|
|
sub_part->w = this->pal_width;
|
|
|
|
sub_part->h = this->pal_height;
|
|
|
|
sub_part->x = this->pal_start_col;
|
|
|
|
sub_part->y = this->pal_start_row;
|
|
|
|
crop_image(sub_part);
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2001-04-21 15:38:01 +00:00
|
|
|
|
2002-04-29 21:31:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This function tries to create a usable palette.
|
2003-10-04 17:29:08 +00:00
|
|
|
It determines how many non-transparent colors are used, and assigns different
|
2002-04-29 21:31:56 +00:00
|
|
|
gray scale values to each color.
|
|
|
|
I tested it with four streams and even got something readable. Half of the
|
|
|
|
times I got black characters with white around and half the reverse.
|
|
|
|
*/
|
2003-02-16 15:26:30 +00:00
|
|
|
static void compute_palette(spudec_handle_t *this, packet_t *packet)
|
2002-04-29 21:31:56 +00:00
|
|
|
{
|
|
|
|
int used[16],i,cused,start,step,color;
|
|
|
|
|
|
|
|
memset(used, 0, sizeof(used));
|
|
|
|
for (i=0; i<4; i++)
|
2003-02-16 15:26:30 +00:00
|
|
|
if (packet->alpha[i]) /* !Transparent? */
|
|
|
|
used[packet->palette[i]] = 1;
|
2002-04-29 21:31:56 +00:00
|
|
|
for (cused=0, i=0; i<16; i++)
|
|
|
|
if (used[i]) cused++;
|
|
|
|
if (!cused) return;
|
|
|
|
if (cused == 1) {
|
|
|
|
start = 0x80;
|
|
|
|
step = 0;
|
|
|
|
} else {
|
2012-10-23 20:17:21 +00:00
|
|
|
start = 72;
|
|
|
|
step = (0xF0-start)/(cused-1);
|
2002-04-29 21:31:56 +00:00
|
|
|
}
|
|
|
|
memset(used, 0, sizeof(used));
|
|
|
|
for (i=0; i<4; i++) {
|
2003-02-16 15:26:30 +00:00
|
|
|
color = packet->palette[i];
|
|
|
|
if (packet->alpha[i] && !used[color]) { /* not assigned? */
|
2002-04-29 21:31:56 +00:00
|
|
|
used[color] = 1;
|
|
|
|
this->global_palette[color] = start<<16;
|
|
|
|
start += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-11 10:12:58 +00:00
|
|
|
static void spudec_process_control(spudec_handle_t *this, int pts100)
|
2001-04-21 15:38:01 +00:00
|
|
|
{
|
2010-02-06 19:57:45 +00:00
|
|
|
int a,b,c,d; /* Temporary vars */
|
2002-01-10 17:17:37 +00:00
|
|
|
unsigned int date, type;
|
|
|
|
unsigned int off;
|
|
|
|
unsigned int start_off = 0;
|
|
|
|
unsigned int next_off;
|
2007-11-30 18:08:33 +00:00
|
|
|
unsigned int start_pts = 0;
|
|
|
|
unsigned int end_pts = 0;
|
|
|
|
unsigned int current_nibble[2] = {0, 0};
|
2003-02-16 15:26:30 +00:00
|
|
|
unsigned int control_start;
|
|
|
|
unsigned int display = 0;
|
|
|
|
unsigned int start_col = 0;
|
|
|
|
unsigned int end_col = 0;
|
|
|
|
unsigned int start_row = 0;
|
|
|
|
unsigned int end_row = 0;
|
|
|
|
unsigned int width = 0;
|
|
|
|
unsigned int height = 0;
|
|
|
|
unsigned int stride = 0;
|
|
|
|
|
|
|
|
control_start = get_be16(this->packet + 2);
|
|
|
|
next_off = control_start;
|
2001-11-20 18:36:50 +00:00
|
|
|
while (start_off != next_off) {
|
|
|
|
start_off = next_off;
|
2003-02-16 15:26:30 +00:00
|
|
|
date = get_be16(this->packet + start_off) * 1024;
|
|
|
|
next_off = get_be16(this->packet + start_off + 2);
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2, "date=%d\n", date);
|
2001-11-20 18:36:50 +00:00
|
|
|
off = start_off + 4;
|
2003-02-16 15:26:30 +00:00
|
|
|
for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) {
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2, "cmd=%d ",type);
|
2001-11-20 18:36:50 +00:00
|
|
|
switch(type) {
|
|
|
|
case 0x00:
|
|
|
|
/* Menu ID, 1 byte */
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n");
|
2002-04-03 18:14:21 +00:00
|
|
|
/* shouldn't a Menu ID type force display start? */
|
2007-12-11 10:12:58 +00:00
|
|
|
start_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date;
|
2003-09-21 14:21:43 +00:00
|
|
|
end_pts = UINT_MAX;
|
|
|
|
display = 1;
|
|
|
|
this->is_forced_sub=~0; // current subtitle is forced
|
2001-11-20 18:36:50 +00:00
|
|
|
break;
|
|
|
|
case 0x01:
|
|
|
|
/* Start display */
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Start display!\n");
|
2007-12-11 10:12:58 +00:00
|
|
|
start_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date;
|
2003-02-16 15:26:30 +00:00
|
|
|
end_pts = UINT_MAX;
|
|
|
|
display = 1;
|
2003-09-21 14:21:43 +00:00
|
|
|
this->is_forced_sub=0;
|
2001-11-20 18:36:50 +00:00
|
|
|
break;
|
|
|
|
case 0x02:
|
|
|
|
/* Stop display */
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Stop display!\n");
|
2007-12-11 10:12:58 +00:00
|
|
|
end_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date;
|
2001-11-20 18:36:50 +00:00
|
|
|
break;
|
|
|
|
case 0x03:
|
|
|
|
/* Palette */
|
2003-02-16 15:26:30 +00:00
|
|
|
this->palette[0] = this->packet[off] >> 4;
|
|
|
|
this->palette[1] = this->packet[off] & 0xf;
|
|
|
|
this->palette[2] = this->packet[off + 1] >> 4;
|
|
|
|
this->palette[3] = this->packet[off + 1] & 0xf;
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Palette %d, %d, %d, %d\n",
|
2001-11-20 18:36:50 +00:00
|
|
|
this->palette[0], this->palette[1], this->palette[2], this->palette[3]);
|
|
|
|
off+=2;
|
|
|
|
break;
|
|
|
|
case 0x04:
|
|
|
|
/* Alpha */
|
2010-02-06 19:57:45 +00:00
|
|
|
a = this->packet[off] >> 4;
|
|
|
|
b = this->packet[off] & 0xf;
|
|
|
|
c = this->packet[off + 1] >> 4;
|
|
|
|
d = this->packet[off + 1] & 0xf;
|
|
|
|
// Note: some DVDs change these values to create a fade-in/fade-out effect
|
|
|
|
// We can not handle this, so just keep the highest value during the display time.
|
|
|
|
if (display) {
|
|
|
|
a = FFMAX(a, this->alpha[0]);
|
|
|
|
b = FFMAX(b, this->alpha[1]);
|
|
|
|
c = FFMAX(c, this->alpha[2]);
|
|
|
|
d = FFMAX(d, this->alpha[3]);
|
|
|
|
}
|
|
|
|
this->alpha[0] = a;
|
|
|
|
this->alpha[1] = b;
|
|
|
|
this->alpha[2] = c;
|
|
|
|
this->alpha[3] = d;
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Alpha %d, %d, %d, %d\n",
|
2001-11-20 18:36:50 +00:00
|
|
|
this->alpha[0], this->alpha[1], this->alpha[2], this->alpha[3]);
|
|
|
|
off+=2;
|
|
|
|
break;
|
|
|
|
case 0x05:
|
|
|
|
/* Co-ords */
|
2003-02-16 15:26:30 +00:00
|
|
|
a = get_be24(this->packet + off);
|
|
|
|
b = get_be24(this->packet + off + 3);
|
|
|
|
start_col = a >> 12;
|
|
|
|
end_col = a & 0xfff;
|
|
|
|
width = (end_col < start_col) ? 0 : end_col - start_col + 1;
|
|
|
|
stride = (width + 7) & ~7; /* Kludge: draw_alpha needs width multiple of 8 */
|
|
|
|
start_row = b >> 12;
|
|
|
|
end_row = b & 0xfff;
|
|
|
|
height = (end_row < start_row) ? 0 : end_row - start_row /* + 1 */;
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Coords col: %d - %d row: %d - %d (%dx%d)\n",
|
2003-02-16 15:26:30 +00:00
|
|
|
start_col, end_col, start_row, end_row,
|
|
|
|
width, height);
|
2001-11-20 18:36:50 +00:00
|
|
|
off+=6;
|
|
|
|
break;
|
|
|
|
case 0x06:
|
|
|
|
/* Graphic lines */
|
2003-02-16 15:26:30 +00:00
|
|
|
current_nibble[0] = 2 * get_be16(this->packet + off);
|
|
|
|
current_nibble[1] = 2 * get_be16(this->packet + off + 2);
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Graphic offset 1: %d offset 2: %d\n",
|
2003-02-16 15:26:30 +00:00
|
|
|
current_nibble[0] / 2, current_nibble[1] / 2);
|
2001-11-20 18:36:50 +00:00
|
|
|
off+=4;
|
|
|
|
break;
|
|
|
|
default:
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN,"spudec: Error determining control type 0x%02x. Skipping %d bytes.\n",
|
2001-12-09 16:56:23 +00:00
|
|
|
type, next_off - off);
|
|
|
|
goto next_control;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2001-04-21 15:38:01 +00:00
|
|
|
}
|
2001-12-09 16:56:23 +00:00
|
|
|
next_control:
|
2007-12-11 10:12:58 +00:00
|
|
|
if (!display)
|
|
|
|
continue;
|
|
|
|
if (end_pts == UINT_MAX && start_off != next_off) {
|
|
|
|
end_pts = get_be16(this->packet + next_off) * 1024;
|
|
|
|
end_pts = 1 - pts100 >= end_pts ? 0 : pts100 + end_pts - 1;
|
|
|
|
}
|
|
|
|
if (end_pts > 0) {
|
2003-02-16 15:26:30 +00:00
|
|
|
packet_t *packet = calloc(1, sizeof(packet_t));
|
|
|
|
int i;
|
|
|
|
packet->start_pts = start_pts;
|
2007-12-11 10:12:58 +00:00
|
|
|
packet->end_pts = end_pts;
|
2003-02-16 15:26:30 +00:00
|
|
|
packet->current_nibble[0] = current_nibble[0];
|
|
|
|
packet->current_nibble[1] = current_nibble[1];
|
|
|
|
packet->start_row = start_row;
|
|
|
|
packet->start_col = start_col;
|
|
|
|
packet->width = width;
|
|
|
|
packet->height = height;
|
|
|
|
packet->stride = stride;
|
|
|
|
packet->control_start = control_start;
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
packet->alpha[i] = this->alpha[i];
|
|
|
|
packet->palette[i] = this->palette[i];
|
|
|
|
}
|
|
|
|
packet->packet = malloc(this->packet_size);
|
|
|
|
memcpy(packet->packet, this->packet, this->packet_size);
|
|
|
|
spudec_queue_packet(this, packet);
|
|
|
|
}
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
}
|
2001-04-21 15:38:01 +00:00
|
|
|
|
2007-12-11 10:12:58 +00:00
|
|
|
static void spudec_decode(spudec_handle_t *this, int pts100)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
2012-08-06 23:26:11 +00:00
|
|
|
spudec_process_control(this, pts100);
|
2001-04-21 15:38:01 +00:00
|
|
|
}
|
|
|
|
|
2002-05-25 17:40:40 +00:00
|
|
|
int spudec_changed(void * this)
|
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t * spu = this;
|
2008-05-16 09:42:28 +00:00
|
|
|
return spu->spu_changed || spu->now_pts > spu->end_pts;
|
2002-05-25 17:40:40 +00:00
|
|
|
}
|
2001-11-20 18:36:50 +00:00
|
|
|
|
2007-12-11 10:12:58 +00:00
|
|
|
void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pts100)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2001-12-28 19:20:12 +00:00
|
|
|
// spudec_heartbeat(this, pts100);
|
2002-01-10 17:17:37 +00:00
|
|
|
if (len < 2) {
|
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: packet too short\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
spu->packet_pts = pts100;
|
|
|
|
if (spu->packet_offset == 0) {
|
|
|
|
unsigned int len2 = get_be16(packet);
|
2001-11-20 18:36:50 +00:00
|
|
|
// Start new fragment
|
2003-02-16 15:26:30 +00:00
|
|
|
if (spu->packet_reserve < len2) {
|
2010-11-07 12:47:40 +00:00
|
|
|
free(spu->packet);
|
2003-02-16 15:26:30 +00:00
|
|
|
spu->packet = malloc(len2);
|
|
|
|
spu->packet_reserve = spu->packet != NULL ? len2 : 0;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
if (spu->packet != NULL) {
|
|
|
|
spu->packet_size = len2;
|
2002-01-10 17:17:37 +00:00
|
|
|
if (len > len2) {
|
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid frag len / len2: %d / %d \n", len, len2);
|
|
|
|
return;
|
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
memcpy(spu->packet, packet, len);
|
|
|
|
spu->packet_offset = len;
|
|
|
|
spu->packet_pts = pts100;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Continue current fragment
|
2003-02-16 15:26:30 +00:00
|
|
|
if (spu->packet_size < spu->packet_offset + len){
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n");
|
2003-02-16 15:26:30 +00:00
|
|
|
spu->packet_size = spu->packet_offset = 0;
|
2003-02-16 01:23:10 +00:00
|
|
|
return;
|
2001-12-25 20:32:02 +00:00
|
|
|
} else {
|
2003-02-16 15:26:30 +00:00
|
|
|
memcpy(spu->packet + spu->packet_offset, packet, len);
|
|
|
|
spu->packet_offset += len;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2001-04-21 17:31:32 +00:00
|
|
|
}
|
2001-12-28 01:03:57 +00:00
|
|
|
#if 1
|
|
|
|
// check if we have a complete packet (unfortunatelly packet_size is bad
|
|
|
|
// for some disks)
|
All right: The patch adresses two issues which I found, when I analyzed
the input from some DVDs with known subtitle-dropouts:
1. The packet-size at the beginning of the packet, which is used to
check, whether we got all fragments, is sometimes one byte too long. It
seems to be always padded to an even number, while the actual size can
be odd.
2. The original algorythm used to assemble the fragments relies on the
timestamps to check, whether a new packet begins. This has proven to be
unrelieable on some disks. So instead, I use the timestamp only to
check, whether it's been too long (defined as 0,01sec) since the last
fragment, which is probably indicating a broken packet, and normaly
starting a new packet when the last one has been finished.
patch by Christof Buergi <christof@buergi.lugs.ch>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7744 b3059339-0415-0410-9bf9-f77b7e298cf2
2002-10-15 00:47:17 +00:00
|
|
|
// [cb] packet_size is padded to be even -> may be one byte too long
|
2003-02-16 15:26:30 +00:00
|
|
|
if ((spu->packet_offset == spu->packet_size) ||
|
|
|
|
((spu->packet_offset + 1) == spu->packet_size)){
|
2002-04-30 19:20:34 +00:00
|
|
|
unsigned int x=0,y;
|
2003-02-16 15:26:30 +00:00
|
|
|
while(x+4<=spu->packet_offset){
|
|
|
|
y=get_be16(spu->packet+x+2); // next control pointer
|
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUtest: x=%d y=%d off=%d size=%d\n",x,y,spu->packet_offset,spu->packet_size);
|
2001-12-28 01:03:57 +00:00
|
|
|
if(x>=4 && x==y){ // if it points to self - we're done!
|
|
|
|
// we got it!
|
2003-02-16 15:26:30 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",spu->packet_offset,spu->packet_size);
|
|
|
|
spudec_decode(spu, pts100);
|
|
|
|
spu->packet_offset = 0;
|
|
|
|
break;
|
2001-12-28 01:03:57 +00:00
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
if(y<=x || y>=spu->packet_size){ // invalid?
|
2001-12-28 01:24:49 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x);
|
2003-02-16 15:26:30 +00:00
|
|
|
spu->packet_size = spu->packet_offset = 0;
|
|
|
|
break;
|
2001-12-28 01:03:57 +00:00
|
|
|
}
|
|
|
|
x=y;
|
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
// [cb] packet is done; start new packet
|
|
|
|
spu->packet_offset = 0;
|
2001-12-28 01:03:57 +00:00
|
|
|
}
|
|
|
|
#else
|
2001-11-20 18:36:50 +00:00
|
|
|
if (spu->packet_offset == spu->packet_size) {
|
2003-02-16 15:26:30 +00:00
|
|
|
spudec_decode(spu, pts100);
|
|
|
|
spu->packet_offset = 0;
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
2001-12-28 01:03:57 +00:00
|
|
|
#endif
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
void spudec_set_changed(void *this)
|
|
|
|
{
|
|
|
|
spudec_handle_t *spu = this;
|
|
|
|
|
|
|
|
spu->spu_changed = 1;
|
|
|
|
}
|
|
|
|
|
2001-12-25 20:32:02 +00:00
|
|
|
void spudec_reset(void *this) // called after seek
|
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2003-02-16 15:26:30 +00:00
|
|
|
while (spu->queue_head)
|
|
|
|
spudec_free_packet(spudec_dequeue_packet(spu));
|
2002-01-10 17:17:37 +00:00
|
|
|
spu->now_pts = 0;
|
2003-02-16 15:26:30 +00:00
|
|
|
spu->end_pts = 0;
|
|
|
|
spu->packet_size = spu->packet_offset = 0;
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
spudec_set_changed(spu);
|
2001-12-25 20:32:02 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 17:17:37 +00:00
|
|
|
void spudec_heartbeat(void *this, unsigned int pts100)
|
2009-07-06 23:26:13 +00:00
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2003-01-08 18:36:36 +00:00
|
|
|
spu->now_pts = pts100;
|
|
|
|
|
2010-07-10 12:53:05 +00:00
|
|
|
// TODO: detect and handle broken timestamps (e.g. due to wrapping)
|
2003-02-16 15:26:30 +00:00
|
|
|
while (spu->queue_head != NULL && pts100 >= spu->queue_head->start_pts) {
|
|
|
|
packet_t *packet = spudec_dequeue_packet(spu);
|
|
|
|
spu->start_pts = packet->start_pts;
|
|
|
|
spu->end_pts = packet->end_pts;
|
2010-07-10 13:45:09 +00:00
|
|
|
if (packet->is_decoded) {
|
|
|
|
free(spu->image);
|
|
|
|
spu->image_size = packet->data_len;
|
|
|
|
spu->image = packet->packet;
|
|
|
|
packet->packet = NULL;
|
|
|
|
spu->width = packet->width;
|
|
|
|
spu->height = packet->height;
|
|
|
|
spu->stride = packet->stride;
|
|
|
|
spu->start_col = packet->start_col;
|
|
|
|
spu->start_row = packet->start_row;
|
|
|
|
} else {
|
2010-07-11 09:05:22 +00:00
|
|
|
if (spu->auto_palette)
|
|
|
|
compute_palette(spu, packet);
|
|
|
|
spudec_process_data(spu, packet);
|
2010-07-10 13:45:09 +00:00
|
|
|
}
|
2003-02-16 15:26:30 +00:00
|
|
|
spudec_free_packet(packet);
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
spudec_set_changed(spu);
|
2003-02-16 15:26:30 +00:00
|
|
|
}
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
|
2002-04-15 19:17:12 +00:00
|
|
|
int spudec_visible(void *this){
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2003-02-16 15:26:30 +00:00
|
|
|
int ret=(spu->start_pts <= spu->now_pts &&
|
|
|
|
spu->now_pts < spu->end_pts &&
|
|
|
|
spu->height > 0);
|
2002-04-15 19:17:12 +00:00
|
|
|
// printf("spu visible: %d \n",ret);
|
2013-04-28 23:19:56 +00:00
|
|
|
if ((spu->forced_subs_only) && !(spu->is_forced_sub))
|
|
|
|
ret = 0;
|
2002-04-15 19:17:12 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-09-21 14:21:43 +00:00
|
|
|
void spudec_set_forced_subs_only(void * const this, const unsigned int flag)
|
|
|
|
{
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
spudec_handle_t *spu = this;
|
|
|
|
if (!!flag != !!spu->forced_subs_only) {
|
|
|
|
spu->forced_subs_only = !!flag;
|
|
|
|
spudec_set_changed(spu);
|
|
|
|
}
|
2003-09-21 14:21:43 +00:00
|
|
|
}
|
|
|
|
|
VO, sub: refactor
Remove VFCTRL_DRAW_OSD, VFCAP_EOSD_FILTER, VFCAP_EOSD_RGBA, VFCAP_EOSD,
VOCTRL_DRAW_EOSD, VOCTRL_GET_EOSD_RES, VOCTRL_QUERY_EOSD_FORMAT.
Remove draw_osd_with_eosd(), which rendered the OSD by calling
VOCTRL_DRAW_EOSD. Change VOs to call osd_draw() directly, which takes
a callback as argument. (This basically works like the old OSD API,
except multiple OSD bitmap formats are supported and caching is
possible.)
Remove all mentions of "eosd". It's simply "osd" now.
Make OSD size per-OSD-object, as they can be different when using
vf_sub. Include display_par/video_par in resolution change detection.
Fix the issue with margin borders in vo_corevideo.
2012-10-19 17:25:18 +00:00
|
|
|
void spudec_get_indexed(void *this, struct mp_osd_res *dim,
|
2013-11-01 15:02:47 +00:00
|
|
|
double xstretch, double ystretch,
|
2012-10-04 15:16:47 +00:00
|
|
|
struct sub_bitmaps *res)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2012-10-04 15:16:47 +00:00
|
|
|
*res = (struct sub_bitmaps) { .format = SUBBITMAP_INDEXED };
|
|
|
|
struct sub_bitmap *part = &spu->borrowed_sub_part;
|
|
|
|
res->parts = part;
|
2012-10-08 00:05:59 +00:00
|
|
|
*part = spu->sub_part;
|
|
|
|
// Empty subs do happen when cropping
|
|
|
|
bool empty = part->w < 1 || part->h < 1;
|
|
|
|
if (spudec_visible(spu) && !empty) {
|
2012-10-04 15:16:47 +00:00
|
|
|
double xscale = (double) (dim->w - dim->ml - dim->mr) / spu->orig_frame_width;
|
|
|
|
double yscale = (double) (dim->h - dim->mt - dim->mb) / spu->orig_frame_height;
|
2013-11-01 15:02:47 +00:00
|
|
|
part->x = part->x * xscale * xstretch + dim->ml + dim->w * (0.5 - 0.5 * xstretch);
|
|
|
|
part->y = part->y * yscale * ystretch + dim->mt + dim->h * (0.5 - 0.5 * ystretch);
|
|
|
|
part->dw = part->w * xscale * xstretch;
|
|
|
|
part->dh = part->h * yscale * ystretch;
|
2012-10-04 15:16:47 +00:00
|
|
|
res->num_parts = 1;
|
2012-10-08 00:05:59 +00:00
|
|
|
res->scaled = true;
|
2003-09-21 14:21:43 +00:00
|
|
|
}
|
2012-10-16 05:26:45 +00:00
|
|
|
if (spu->spu_changed) {
|
|
|
|
res->bitmap_id = res->bitmap_pos_id = 1;
|
|
|
|
spu->spu_changed = 0;
|
2002-01-10 17:17:37 +00:00
|
|
|
}
|
2002-04-29 21:31:56 +00:00
|
|
|
}
|
|
|
|
|
2012-12-08 12:59:49 +00:00
|
|
|
static unsigned int vobsub_palette_to_yuv(unsigned int pal)
|
|
|
|
{
|
|
|
|
int r, g, b, y, u, v;
|
|
|
|
// Palette in idx file is not rgb value, it was calculated by wrong formula.
|
|
|
|
// Here's reversed formula of the one used to generate palette in idx file.
|
|
|
|
r = pal >> 16 & 0xff;
|
|
|
|
g = pal >> 8 & 0xff;
|
|
|
|
b = pal & 0xff;
|
|
|
|
y = av_clip_uint8( 0.1494 * r + 0.6061 * g + 0.2445 * b);
|
|
|
|
u = av_clip_uint8( 0.6066 * r - 0.4322 * g - 0.1744 * b + 128);
|
|
|
|
v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
|
|
|
|
y = y * 219 / 255 + 16;
|
|
|
|
return y << 16 | u << 8 | v;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int vobsub_rgb_to_yuv(unsigned int rgb)
|
|
|
|
{
|
|
|
|
int r, g, b, y, u, v;
|
|
|
|
r = rgb >> 16 & 0xff;
|
|
|
|
g = rgb >> 8 & 0xff;
|
|
|
|
b = rgb & 0xff;
|
|
|
|
y = ( 0.299 * r + 0.587 * g + 0.114 * b) * 219 / 255 + 16.5;
|
|
|
|
u = (-0.16874 * r - 0.33126 * g + 0.5 * b) * 224 / 255 + 128.5;
|
|
|
|
v = ( 0.5 * r - 0.41869 * g - 0.08131 * b) * 224 / 255 + 128.5;
|
|
|
|
return y << 16 | u << 8 | v;
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:51:22 +00:00
|
|
|
static void spudec_parse_extradata(spudec_handle_t *this,
|
|
|
|
uint8_t *extradata, int extradata_len)
|
2001-11-20 18:36:50 +00:00
|
|
|
{
|
2008-10-27 22:51:22 +00:00
|
|
|
uint8_t *buffer, *ptr;
|
|
|
|
unsigned int *pal = this->global_palette, *cuspal = this->cuspal;
|
|
|
|
unsigned int tridx;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (extradata_len == 16*4) {
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
pal[i] = AV_RB32(extradata + i*4);
|
|
|
|
this->auto_palette = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ptr = buffer = malloc(extradata_len+1)))
|
|
|
|
return;
|
|
|
|
memcpy(buffer, extradata, extradata_len);
|
|
|
|
buffer[extradata_len] = 0;
|
|
|
|
|
|
|
|
do {
|
2010-02-14 13:57:30 +00:00
|
|
|
if (*ptr == '#')
|
|
|
|
continue;
|
|
|
|
if (!strncmp(ptr, "size: ", 6))
|
|
|
|
sscanf(ptr + 6, "%dx%d", &this->orig_frame_width, &this->orig_frame_height);
|
|
|
|
if (!strncmp(ptr, "palette: ", 9) &&
|
|
|
|
sscanf(ptr + 9, "%x, %x, %x, %x, %x, %x, %x, %x, "
|
|
|
|
"%x, %x, %x, %x, %x, %x, %x, %x",
|
2008-10-27 22:51:22 +00:00
|
|
|
&pal[ 0], &pal[ 1], &pal[ 2], &pal[ 3],
|
|
|
|
&pal[ 4], &pal[ 5], &pal[ 6], &pal[ 7],
|
|
|
|
&pal[ 8], &pal[ 9], &pal[10], &pal[11],
|
|
|
|
&pal[12], &pal[13], &pal[14], &pal[15]) == 16) {
|
|
|
|
for (i=0; i<16; i++)
|
|
|
|
pal[i] = vobsub_palette_to_yuv(pal[i]);
|
|
|
|
this->auto_palette = 0;
|
|
|
|
}
|
|
|
|
if (!strncasecmp(ptr, "forced subs: on", 15))
|
|
|
|
this->forced_subs_only = 1;
|
2010-02-14 13:57:30 +00:00
|
|
|
if (!strncmp(ptr, "custom colors: ON, tridx: ", 26) &&
|
|
|
|
sscanf(ptr + 26, "%x, colors: %x, %x, %x, %x",
|
2008-10-27 22:51:22 +00:00
|
|
|
&tridx, cuspal+0, cuspal+1, cuspal+2, cuspal+3) == 5) {
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
cuspal[i] = vobsub_rgb_to_yuv(cuspal[i]);
|
|
|
|
if (tridx & (1 << (12-4*i)))
|
|
|
|
cuspal[i] |= 1 << 31;
|
|
|
|
}
|
|
|
|
this->custom = 1;
|
|
|
|
}
|
|
|
|
} while ((ptr=strchr(ptr,'\n')) && *++ptr);
|
|
|
|
|
|
|
|
free(buffer);
|
2001-11-20 18:36:50 +00:00
|
|
|
}
|
|
|
|
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
void *spudec_new_scaled(unsigned int frame_width, unsigned int frame_height, uint8_t *extradata, int extradata_len)
|
2002-04-25 18:46:44 +00:00
|
|
|
{
|
|
|
|
spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));
|
|
|
|
if (this){
|
2008-10-27 22:51:22 +00:00
|
|
|
this->orig_frame_height = frame_height;
|
2010-07-11 09:39:06 +00:00
|
|
|
this->orig_frame_width = frame_width;
|
2008-10-27 22:51:22 +00:00
|
|
|
// set up palette:
|
sub: add sd_spu.c to wrap spudec, cleanup mplayer.c
This unifies the subtitle rendering path. Now all subtitle rendering
goes through sd_ass.c/sd_lavc.c/sd_spu.c.
Before that commit, the spudec.h functions were used directly in
mplayer.c, which introduced many special cases. Add sd_spu.c, which is
just a small wrapper connecting the new subtitle render API with the
dusty old vobsub decoder in spudec.c.
One detail that changes is that we always pass the palette as extra
data, instead of passing the libdvdread palette as pointer to spudec
directly. This is a bit roundabout, but actually makes the code simpler
and more elegant: the difference between DVD and non-DVD dvdsubs is
reduced.
Ideally, we would just delete spudec.c and use libavcodec's DVD sub
decoder. However, DVD playback with demux_mpg produces packets
incompatible to lavc. There are incompatibilities the other way around
as well: packets from libavformat's vobsub demuxer are incompatible to
spudec.c. So we define a new subtitle codec name for demux_mpg subs,
"dvd_subtitle_mpg", which only sd_spu can decode.
There is actually code in spudec.c to "assemble" fragments into complete
packets, but using the whole spudec.c is easier than trying to move this
code into demux_mpg to fix subtitle packets.
As additional complication, Libav 9.x can't decode DVD subs correctly,
so use sd_spu in that case as well.
2013-04-28 23:13:22 +00:00
|
|
|
this->auto_palette = 1;
|
2008-10-27 22:51:22 +00:00
|
|
|
if (extradata)
|
|
|
|
spudec_parse_extradata(this, extradata, extradata_len);
|
2002-08-06 13:32:55 +00:00
|
|
|
/* XXX Although the video frame is some size, the SPU frame is
|
|
|
|
always maximum size i.e. 720 wide and 576 or 480 high */
|
2010-05-31 21:15:20 +00:00
|
|
|
// For HD files in MKV the VobSub resolution can be higher though,
|
|
|
|
// see largeres_vobsub.mkv
|
|
|
|
if (this->orig_frame_width <= 720 && this->orig_frame_height <= 576) {
|
2010-05-31 21:16:02 +00:00
|
|
|
this->orig_frame_width = 720;
|
|
|
|
if (this->orig_frame_height == 480 || this->orig_frame_height == 240)
|
|
|
|
this->orig_frame_height = 480;
|
|
|
|
else
|
|
|
|
this->orig_frame_height = 576;
|
2010-05-31 21:15:20 +00:00
|
|
|
}
|
2002-04-25 18:46:44 +00:00
|
|
|
}
|
|
|
|
else
|
2002-05-17 23:47:27 +00:00
|
|
|
mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc");
|
2002-04-25 18:46:44 +00:00
|
|
|
return this;
|
|
|
|
}
|
2002-04-29 21:31:56 +00:00
|
|
|
|
2001-11-20 18:36:50 +00:00
|
|
|
void spudec_free(void *this)
|
|
|
|
{
|
2010-07-11 12:48:54 +00:00
|
|
|
spudec_handle_t *spu = this;
|
2001-11-20 18:36:50 +00:00
|
|
|
if (spu) {
|
2003-02-16 15:26:30 +00:00
|
|
|
while (spu->queue_head)
|
|
|
|
spudec_free_packet(spudec_dequeue_packet(spu));
|
2010-07-24 21:43:29 +00:00
|
|
|
free(spu->packet);
|
|
|
|
spu->packet = NULL;
|
|
|
|
free(spu->image);
|
|
|
|
spu->image = NULL;
|
2010-07-24 21:40:06 +00:00
|
|
|
free(spu->pal_image);
|
2010-07-24 21:43:29 +00:00
|
|
|
spu->pal_image = NULL;
|
|
|
|
spu->image_size = 0;
|
2010-07-26 19:41:04 +00:00
|
|
|
spu->pal_width = spu->pal_height = 0;
|
2001-11-20 18:36:50 +00:00
|
|
|
free(spu);
|
|
|
|
}
|
|
|
|
}
|