2011-01-16 18:03:08 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "demux/stheader.h"
|
2013-06-01 17:54:18 +00:00
|
|
|
#include "sd.h"
|
|
|
|
#include "sub.h"
|
|
|
|
#include "dec_sub.h"
|
|
|
|
#include "subreader.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "core/options.h"
|
2013-06-01 17:44:55 +00:00
|
|
|
#include "core/mp_msg.h"
|
2011-01-16 18:03:08 +00:00
|
|
|
|
|
|
|
extern const struct sd_functions sd_ass;
|
2012-08-16 15:21:21 +00:00
|
|
|
extern const struct sd_functions sd_lavc;
|
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
|
|
|
extern const struct sd_functions sd_spu;
|
2013-06-01 17:44:55 +00:00
|
|
|
extern const struct sd_functions sd_movtext;
|
2013-06-01 17:54:18 +00:00
|
|
|
extern const struct sd_functions sd_srt;
|
|
|
|
extern const struct sd_functions sd_microdvd;
|
2013-06-01 17:54:31 +00:00
|
|
|
extern const struct sd_functions sd_lavc_conv;
|
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
|
|
|
|
|
|
|
static const struct sd_functions *sd_list[] = {
|
|
|
|
#ifdef CONFIG_ASS
|
|
|
|
&sd_ass,
|
|
|
|
#endif
|
|
|
|
&sd_lavc,
|
|
|
|
&sd_spu,
|
2013-06-01 17:44:55 +00:00
|
|
|
&sd_movtext,
|
2013-06-01 17:54:18 +00:00
|
|
|
&sd_srt,
|
|
|
|
&sd_microdvd,
|
2013-06-01 17:54:31 +00:00
|
|
|
&sd_lavc_conv,
|
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
|
|
|
NULL
|
|
|
|
};
|
2011-01-16 18:03:08 +00:00
|
|
|
|
2013-06-01 17:54:18 +00:00
|
|
|
#define MAX_NUM_SD 3
|
2013-06-01 17:44:55 +00:00
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
struct dec_sub {
|
|
|
|
struct MPOpts *opts;
|
|
|
|
struct sd init_sd;
|
|
|
|
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd *sd[MAX_NUM_SD];
|
|
|
|
int num_sd;
|
2013-06-01 17:44:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct dec_sub *sub_create(struct MPOpts *opts)
|
|
|
|
{
|
|
|
|
struct dec_sub *sub = talloc_zero(NULL, struct dec_sub);
|
|
|
|
sub->opts = opts;
|
|
|
|
return sub;
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:55 +00:00
|
|
|
static void sub_uninit(struct dec_sub *sub)
|
|
|
|
{
|
|
|
|
sub_reset(sub);
|
|
|
|
for (int n = 0; n < sub->num_sd; n++) {
|
|
|
|
if (sub->sd[n]->driver->uninit)
|
|
|
|
sub->sd[n]->driver->uninit(sub->sd[n]);
|
|
|
|
talloc_free(sub->sd[n]);
|
|
|
|
}
|
|
|
|
sub->num_sd = 0;
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
void sub_destroy(struct dec_sub *sub)
|
|
|
|
{
|
|
|
|
if (!sub)
|
|
|
|
return;
|
2013-06-01 17:44:55 +00:00
|
|
|
sub_uninit(sub);
|
2013-06-01 17:44:12 +00:00
|
|
|
talloc_free(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sub_is_initialized(struct dec_sub *sub)
|
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
return !!sub->num_sd;
|
2013-06-01 17:44:12 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd *sub_get_last_sd(struct dec_sub *sub)
|
2013-06-01 17:44:12 +00:00
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
return sub->num_sd ? sub->sd[sub->num_sd - 1] : NULL;
|
2013-06-01 17:44:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sub_set_video_res(struct dec_sub *sub, int w, int h)
|
|
|
|
{
|
|
|
|
sub->init_sd.sub_video_w = w;
|
|
|
|
sub->init_sd.sub_video_h = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_set_extradata(struct dec_sub *sub, void *data, int data_len)
|
|
|
|
{
|
|
|
|
sub->init_sd.extradata = data_len ? talloc_memdup(sub, data, data_len) : NULL;
|
|
|
|
sub->init_sd.extradata_len = data_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_set_ass_renderer(struct dec_sub *sub, struct ass_library *ass_library,
|
|
|
|
struct ass_renderer *ass_renderer)
|
|
|
|
{
|
|
|
|
sub->init_sd.ass_library = ass_library;
|
|
|
|
sub->init_sd.ass_renderer = ass_renderer;
|
|
|
|
}
|
|
|
|
|
2013-06-03 19:49:39 +00:00
|
|
|
static void print_chain(struct dec_sub *sub)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_OSD, MSGL_V, "Subtitle filter chain: ");
|
|
|
|
for (int n = 0; n < sub->num_sd; n++) {
|
|
|
|
struct sd *sd = sub->sd[n];
|
|
|
|
mp_msg(MSGT_OSD, MSGL_V, "%s%s (%s)", n > 0 ? " -> " : "",
|
|
|
|
sd->driver->name, sd->codec);
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_OSD, MSGL_V, "\n");
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:54:18 +00:00
|
|
|
// Subtitles read with subreader.c
|
|
|
|
static void read_sub_data(struct dec_sub *sub, struct sub_data *subdata)
|
|
|
|
{
|
|
|
|
assert(sub_accept_packets_in_advance(sub));
|
|
|
|
char *temp = NULL;
|
|
|
|
|
2013-06-02 20:35:00 +00:00
|
|
|
struct sd *sd = sub_get_last_sd(sub);
|
|
|
|
|
|
|
|
sd->no_remove_duplicates = true;
|
|
|
|
|
2013-06-01 17:54:18 +00:00
|
|
|
for (int i = 0; i < subdata->sub_num; i++) {
|
|
|
|
subtitle *st = &subdata->subtitles[i];
|
|
|
|
// subdata is in 10 ms ticks, pts is in seconds
|
|
|
|
double t = subdata->sub_uses_time ? 0.01 : (1 / subdata->fallback_fps);
|
|
|
|
|
|
|
|
int len = 0;
|
|
|
|
for (int j = 0; j < st->lines; j++)
|
|
|
|
len += st->text[j] ? strlen(st->text[j]) : 0;
|
|
|
|
|
|
|
|
len += 2 * st->lines; // '\N', including the one after the last line
|
|
|
|
len += 6; // {\anX}
|
|
|
|
len += 1; // '\0'
|
|
|
|
|
|
|
|
if (talloc_get_size(temp) < len) {
|
|
|
|
talloc_free(temp);
|
|
|
|
temp = talloc_array(NULL, char, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *p = temp;
|
|
|
|
char *end = p + len;
|
|
|
|
|
|
|
|
if (st->alignment)
|
|
|
|
p += snprintf(p, end - p, "{\\an%d}", st->alignment);
|
|
|
|
|
|
|
|
for (int j = 0; j < st->lines; j++)
|
|
|
|
p += snprintf(p, end - p, "%s\\N", st->text[j]);
|
|
|
|
|
|
|
|
if (st->lines > 0)
|
|
|
|
p -= 2; // remove last "\N"
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
struct demux_packet pkt = {0};
|
|
|
|
pkt.pts = st->start * t;
|
|
|
|
pkt.duration = (st->end - st->start) * t;
|
|
|
|
pkt.buffer = temp;
|
|
|
|
pkt.len = strlen(temp);
|
|
|
|
|
|
|
|
sub_decode(sub, &pkt);
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:54:31 +00:00
|
|
|
// Hack for broken FFmpeg packet format: make sd_ass keep the subtitle
|
|
|
|
// events on reset(), even though broken FFmpeg ASS packets were received
|
|
|
|
// (from sd_lavc_conv.c). Normally, these events are removed on seek/reset,
|
|
|
|
// but this is obviously unwanted in this case.
|
|
|
|
if (sd && sd->driver->fix_events)
|
|
|
|
sd->driver->fix_events(sd);
|
|
|
|
|
2013-06-02 20:35:00 +00:00
|
|
|
sd->no_remove_duplicates = false;
|
|
|
|
|
2013-06-01 17:54:18 +00:00
|
|
|
talloc_free(temp);
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static int sub_init_decoder(struct dec_sub *sub, struct sd *sd)
|
2011-01-16 18:03:08 +00:00
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
sd->driver = NULL;
|
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
|
|
|
for (int n = 0; sd_list[n]; n++) {
|
2013-06-01 17:44:12 +00:00
|
|
|
if (sd_list[n]->supports_format(sd->codec)) {
|
|
|
|
sd->driver = sd_list[n];
|
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
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-01-16 18:03:08 +00:00
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
if (!sd->driver)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (sd->driver->init(sd) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sub_init_from_sh(struct dec_sub *sub, struct sh_sub *sh)
|
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
assert(!sub->num_sd);
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
if (sh->extradata && !sub->init_sd.extradata)
|
|
|
|
sub_set_extradata(sub, sh->extradata, sh->extradata_len);
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd init_sd = sub->init_sd;
|
|
|
|
init_sd.codec = sh->gsh->codec;
|
|
|
|
init_sd.ass_track = sh->track;
|
|
|
|
|
|
|
|
while (sub->num_sd < MAX_NUM_SD) {
|
|
|
|
struct sd *sd = talloc(NULL, struct sd);
|
|
|
|
*sd = init_sd;
|
|
|
|
sd->opts = sub->opts;
|
|
|
|
if (sub_init_decoder(sub, sd) < 0) {
|
|
|
|
talloc_free(sd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sub->sd[sub->num_sd] = sd;
|
|
|
|
sub->num_sd++;
|
|
|
|
// Try adding new converters until a decoder is reached
|
2013-06-01 17:54:18 +00:00
|
|
|
if (sd->driver->get_bitmaps || sd->driver->get_text) {
|
2013-06-03 19:49:39 +00:00
|
|
|
print_chain(sub);
|
2013-06-01 17:54:18 +00:00
|
|
|
if (sh->sub_data)
|
|
|
|
read_sub_data(sub, sh->sub_data);
|
2013-06-01 17:44:55 +00:00
|
|
|
return;
|
2013-06-01 17:54:18 +00:00
|
|
|
}
|
2013-06-01 17:44:55 +00:00
|
|
|
init_sd = (struct sd) {
|
|
|
|
.codec = sd->output_codec,
|
2013-06-02 21:01:37 +00:00
|
|
|
.converted_from = sd->codec,
|
2013-06-01 17:44:55 +00:00
|
|
|
.extradata = sd->output_extradata,
|
|
|
|
.extradata_len = sd->output_extradata_len,
|
|
|
|
.ass_library = sub->init_sd.ass_library,
|
|
|
|
.ass_renderer = sub->init_sd.ass_renderer,
|
|
|
|
};
|
2011-01-16 18:03:08 +00:00
|
|
|
}
|
2013-06-01 17:44:55 +00:00
|
|
|
|
|
|
|
sub_uninit(sub);
|
|
|
|
mp_msg(MSGT_OSD, MSGL_ERR, "Could not find subtitle decoder for format '%s'.\n",
|
|
|
|
sh->gsh->codec ? sh->gsh->codec : "<unknown>");
|
2011-01-16 18:03:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
bool sub_accept_packets_in_advance(struct dec_sub *sub)
|
2013-04-28 19:12:11 +00:00
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
// Converters are assumed to always accept packets in advance
|
|
|
|
struct sd *sd = sub_get_last_sd(sub);
|
|
|
|
return sd && sd->driver->accept_packets_in_advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void decode_next(struct dec_sub *sub, int n, struct demux_packet *packet)
|
|
|
|
{
|
|
|
|
struct sd *sd = sub->sd[n];
|
|
|
|
sd->driver->decode(sd, packet);
|
|
|
|
if (n + 1 >= sub->num_sd || !sd->driver->get_converted)
|
|
|
|
return;
|
|
|
|
while (1) {
|
|
|
|
struct demux_packet *next =
|
|
|
|
sd->driver->get_converted ? sd->driver->get_converted(sd) : NULL;
|
|
|
|
if (!next)
|
|
|
|
break;
|
|
|
|
decode_next(sub, n + 1, next);
|
|
|
|
}
|
2013-04-28 19:12:11 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
void sub_decode(struct dec_sub *sub, struct demux_packet *packet)
|
2011-01-16 18:03:08 +00:00
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
if (sub->num_sd > 0)
|
|
|
|
decode_next(sub, 0, packet);
|
2011-01-16 18:03:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
void sub_get_bitmaps(struct dec_sub *sub, struct mp_osd_res dim, double pts,
|
2012-10-04 15:16:36 +00:00
|
|
|
struct sub_bitmaps *res)
|
2012-08-25 18:22:39 +00:00
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
struct MPOpts *opts = sub->opts;
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd *sd = sub_get_last_sd(sub);
|
2012-08-25 18:22:39 +00:00
|
|
|
|
2012-10-04 15:16:36 +00:00
|
|
|
*res = (struct sub_bitmaps) {0};
|
2013-06-01 17:44:55 +00:00
|
|
|
if (sd && opts->sub_visibility) {
|
|
|
|
if (sd->driver->get_bitmaps)
|
|
|
|
sd->driver->get_bitmaps(sd, dim, pts, res);
|
2012-08-25 18:22:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
bool sub_has_get_text(struct dec_sub *sub)
|
2013-04-28 19:12:11 +00:00
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd *sd = sub_get_last_sd(sub);
|
|
|
|
return sd && sd->driver->get_text;
|
2013-04-28 19:12:11 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
char *sub_get_text(struct dec_sub *sub, double pts)
|
2011-01-16 18:03:08 +00:00
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
struct MPOpts *opts = sub->opts;
|
2013-06-01 17:44:55 +00:00
|
|
|
struct sd *sd = sub_get_last_sd(sub);
|
2013-06-01 17:44:12 +00:00
|
|
|
char *text = NULL;
|
2013-06-01 17:44:55 +00:00
|
|
|
if (sd && opts->sub_visibility) {
|
|
|
|
if (sd->driver->get_text)
|
|
|
|
text = sd->driver->get_text(sd, pts);
|
2012-08-25 18:22:39 +00:00
|
|
|
}
|
2013-06-01 17:44:12 +00:00
|
|
|
return text;
|
2011-01-16 18:03:08 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
void sub_reset(struct dec_sub *sub)
|
2011-01-16 18:03:08 +00:00
|
|
|
{
|
2013-06-01 17:44:55 +00:00
|
|
|
for (int n = 0; n < sub->num_sd; n++) {
|
|
|
|
if (sub->sd[n]->driver->reset)
|
|
|
|
sub->sd[n]->driver->reset(sub->sd[n]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_PACKETS 10
|
|
|
|
#define MAX_BYTES 10000
|
|
|
|
|
|
|
|
struct sd_conv_buffer {
|
|
|
|
struct demux_packet pkt[MAX_PACKETS];
|
|
|
|
int num_pkt;
|
|
|
|
int read_pkt;
|
|
|
|
char buffer[MAX_BYTES];
|
|
|
|
int cur_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
void sd_conv_add_packet(struct sd *sd, void *data, int data_len, double pts,
|
|
|
|
double duration)
|
|
|
|
{
|
|
|
|
if (!sd->sd_conv_buffer)
|
|
|
|
sd->sd_conv_buffer = talloc_zero(sd, struct sd_conv_buffer);
|
|
|
|
struct sd_conv_buffer *buf = sd->sd_conv_buffer;
|
|
|
|
if (buf->num_pkt >= MAX_PACKETS || buf->cur_buffer + data_len + 1 > MAX_BYTES)
|
|
|
|
goto out_of_space;
|
|
|
|
if (buf->read_pkt == buf->num_pkt)
|
|
|
|
sd_conv_def_reset(sd);
|
|
|
|
assert(buf->read_pkt == 0); // no mixing of reading/adding allowed
|
|
|
|
struct demux_packet *pkt = &buf->pkt[buf->num_pkt++];
|
|
|
|
*pkt = (struct demux_packet) {
|
|
|
|
.buffer = &buf->buffer[buf->cur_buffer],
|
|
|
|
.len = data_len,
|
|
|
|
.pts = pts,
|
|
|
|
.duration = duration,
|
|
|
|
};
|
|
|
|
memcpy(pkt->buffer, data, data_len);
|
|
|
|
pkt->buffer[data_len] = 0;
|
|
|
|
buf->cur_buffer += data_len + 1;
|
|
|
|
return;
|
|
|
|
|
|
|
|
out_of_space:
|
|
|
|
mp_msg(MSGT_OSD, MSGL_ERR, "Subtitle too big.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
struct demux_packet *sd_conv_def_get_converted(struct sd *sd)
|
|
|
|
{
|
|
|
|
struct sd_conv_buffer *buf = sd->sd_conv_buffer;
|
|
|
|
if (buf && buf->read_pkt < buf->num_pkt)
|
|
|
|
return &buf->pkt[buf->read_pkt++];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sd_conv_def_reset(struct sd *sd)
|
|
|
|
{
|
|
|
|
struct sd_conv_buffer *buf = sd->sd_conv_buffer;
|
|
|
|
if (buf) {
|
|
|
|
buf->read_pkt = buf->num_pkt = 0;
|
|
|
|
buf->cur_buffer = 0;
|
|
|
|
}
|
2011-01-16 18:03:08 +00:00
|
|
|
}
|