2010-07-10 13:45:09 +00:00
|
|
|
/*
|
2012-08-16 15:21:21 +00:00
|
|
|
* This file is part of mplayer2.
|
2010-07-10 13:45:09 +00:00
|
|
|
*
|
2012-08-16 15:21:21 +00:00
|
|
|
* mplayer2 is free software; you can redistribute it and/or modify
|
2010-07-10 13:45:09 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-08-16 15:21:21 +00:00
|
|
|
* mplayer2 is distributed in the hope that it will be useful,
|
2010-07-10 13:45:09 +00:00
|
|
|
* 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
|
2012-08-16 15:21:21 +00:00
|
|
|
* with mplayer2. If not, see <http://www.gnu.org/licenses/>.
|
2010-07-10 13:45:09 +00:00
|
|
|
*/
|
|
|
|
|
2012-08-16 15:21:21 +00:00
|
|
|
#include <stdlib.h>
|
2012-10-04 15:16:47 +00:00
|
|
|
#include <assert.h>
|
sub: fix crash with certain uses of --vf=sub
If, for some reason, the subtitle renderer attempts to render a
subtitle before SD_CTRL_SET_VIDEO_PARAMS was called, it passed a
value calculated from invalid values. This can happen with --vf=sub
and --start. The crash happens if 1. there was a subtitle packet that
falls into the timestamp of the rendered video frame, 2. the playloop
hasn't informed the subtitle decoder about the video resolution yet
(normally unneeded, because that is used for weird corner cases only,
so this code is a bit fuzzy), and 3. something actually requests a
frame to be drawn from the subtitle renderer, like with vf_sub.
The actual crash was due to passing NaN as pixel aspect to libass,
which then created glyphs with ridiculous sizes, involving a few
integer overflows and unchecked mallocs.
The sd_lavc.c and sd_spu.c cases probably don't crash, but I'm not
sure, and it's better fix them anyway.
Not bothering with sd_spu.c, this crap is for compatibility and will
be removed soon.
Note that this would have been no problem, had the code checked whether
SD_CTRL_SET_VIDEO_PARAMS was actually called. This commit adds such a
check (although it basically checks after using the parameters).
Regression since 49caa0a7 and 633fde4a.
2014-01-26 17:58:40 +00:00
|
|
|
#include <math.h>
|
2012-08-16 15:21:21 +00:00
|
|
|
|
2010-07-10 13:45:09 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2013-07-15 01:00:58 +00:00
|
|
|
#include <libavutil/common.h>
|
2014-02-13 21:54:15 +00:00
|
|
|
#include <libavutil/intreadwrite.h>
|
2010-07-10 13:45:09 +00:00
|
|
|
|
2012-08-31 12:42:30 +00:00
|
|
|
#include "talloc.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
|
|
|
#include "common/av_common.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2013-11-01 12:15:59 +00:00
|
|
|
#include "video/mp_image.h"
|
2014-02-13 21:54:15 +00:00
|
|
|
#include "video/csputils.h"
|
2012-08-16 15:21:21 +00:00
|
|
|
#include "sd.h"
|
2012-10-04 15:16:40 +00:00
|
|
|
#include "dec_sub.h"
|
2010-07-10 13:45:09 +00:00
|
|
|
|
2014-06-17 22:18:37 +00:00
|
|
|
#define MAX_QUEUE 4
|
|
|
|
|
|
|
|
struct sub {
|
|
|
|
bool valid;
|
|
|
|
AVSubtitle avsub;
|
2012-08-31 12:42:30 +00:00
|
|
|
int count;
|
|
|
|
struct sub_bitmap *inbitmaps;
|
2012-10-04 15:16:47 +00:00
|
|
|
struct osd_bmp_indexed *imgs;
|
2012-12-12 21:56:41 +00:00
|
|
|
double pts;
|
2012-08-31 12:42:30 +00:00
|
|
|
double endpts;
|
2014-06-17 22:18:37 +00:00
|
|
|
int64_t id;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sd_lavc_priv {
|
|
|
|
AVCodecContext *avctx;
|
2014-08-24 10:26:34 +00:00
|
|
|
struct sub subs[MAX_QUEUE]; // most recent event first
|
2014-06-17 22:18:37 +00:00
|
|
|
struct sub_bitmap *outbitmaps;
|
|
|
|
int64_t displayed_id;
|
|
|
|
int64_t new_id;
|
2013-11-01 12:15:59 +00:00
|
|
|
struct mp_image_params video_params;
|
2012-08-31 12:42:30 +00:00
|
|
|
};
|
|
|
|
|
2013-04-28 19:12:11 +00:00
|
|
|
static bool supports_format(const char *format)
|
2012-10-02 21:28:18 +00:00
|
|
|
{
|
2013-04-28 19:12:11 +00:00
|
|
|
enum AVCodecID cid = mp_codec_to_av_codec_id(format);
|
2013-04-15 19:25:21 +00:00
|
|
|
// Supported codecs must be known to decode to paletted bitmaps
|
|
|
|
switch (cid) {
|
|
|
|
case AV_CODEC_ID_DVB_SUBTITLE:
|
|
|
|
case AV_CODEC_ID_HDMV_PGS_SUBTITLE:
|
|
|
|
case AV_CODEC_ID_XSUB:
|
|
|
|
case AV_CODEC_ID_DVD_SUBTITLE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-06 17:05:20 +00:00
|
|
|
static void get_resolution(struct sd *sd, int wh[2])
|
2013-04-15 19:25:21 +00:00
|
|
|
{
|
2015-01-06 17:05:20 +00:00
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
|
|
|
enum AVCodecID codec = priv->avctx->codec_id;
|
|
|
|
int *w = &wh[0], *h = &wh[1];
|
|
|
|
*w = priv->avctx->width;
|
|
|
|
*h = priv->avctx->height;
|
|
|
|
if (codec == AV_CODEC_ID_DVD_SUBTITLE) {
|
|
|
|
if (*w <= 0 || *h <= 0) {
|
|
|
|
*w = priv->video_params.w;
|
|
|
|
*h = priv->video_params.h;
|
|
|
|
}
|
2012-10-02 21:28:18 +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 */
|
|
|
|
// For HD files in MKV the VobSub resolution can be higher though,
|
|
|
|
// see largeres_vobsub.mkv
|
|
|
|
if (*w <= 720 && *h <= 576) {
|
|
|
|
*w = 720;
|
|
|
|
*h = (*h == 480 || *h == 240) ? 480 : 576;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Hope that PGS subs set these and 720/576 works for dvb subs
|
|
|
|
if (!*w)
|
|
|
|
*w = 720;
|
|
|
|
if (!*h)
|
|
|
|
*h = 576;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 21:54:15 +00:00
|
|
|
static void set_mp4_vobsub_idx(AVCodecContext *avctx, char *src, int w, int h)
|
|
|
|
{
|
|
|
|
char pal_s[128];
|
|
|
|
int pal_s_pos = 0;
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
unsigned int e = AV_RB32(src + i * 4);
|
|
|
|
|
|
|
|
// lavc doesn't accept YUV palette - "does god hate me?"
|
|
|
|
struct mp_csp_params csp = MP_CSP_PARAMS_DEFAULTS;
|
|
|
|
csp.int_bits_in = 8;
|
|
|
|
csp.int_bits_out = 8;
|
2015-01-06 15:49:53 +00:00
|
|
|
struct mp_cmat cmatrix;
|
|
|
|
mp_get_yuv2rgb_coeffs(&csp, &cmatrix);
|
2014-02-13 21:54:15 +00:00
|
|
|
int c[3] = {(e >> 16) & 0xff, (e >> 8) & 0xff, e & 0xff};
|
2015-01-06 15:49:53 +00:00
|
|
|
mp_map_int_color(&cmatrix, 8, c);
|
2014-02-13 21:54:15 +00:00
|
|
|
e = (c[2] << 16) | (c[1] << 8) | c[0];
|
|
|
|
|
|
|
|
snprintf(pal_s + pal_s_pos, sizeof(pal_s) - pal_s_pos, "%06x%s", e,
|
|
|
|
i != 15 ? ", " : "");
|
|
|
|
pal_s_pos = strlen(pal_s);
|
|
|
|
if (pal_s_pos >= sizeof(pal_s))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[256] = "";
|
|
|
|
snprintf(buf, sizeof(buf), "size: %dx%d\npalette: %s\n", w, h, pal_s);
|
|
|
|
mp_lavc_set_extradata(avctx, buf, strlen(buf));
|
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static int init(struct sd *sd)
|
2010-07-10 13:45:09 +00:00
|
|
|
{
|
2012-08-31 12:42:30 +00:00
|
|
|
struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv);
|
2013-06-01 17:44:12 +00:00
|
|
|
enum AVCodecID cid = mp_codec_to_av_codec_id(sd->codec);
|
2012-08-16 15:21:21 +00:00
|
|
|
AVCodecContext *ctx = NULL;
|
|
|
|
AVCodec *sub_codec = avcodec_find_decoder(cid);
|
|
|
|
if (!sub_codec)
|
|
|
|
goto error;
|
|
|
|
ctx = avcodec_alloc_context3(sub_codec);
|
|
|
|
if (!ctx)
|
|
|
|
goto error;
|
2014-01-11 00:28:18 +00:00
|
|
|
mp_lavc_set_extradata(ctx, sd->extradata, sd->extradata_len);
|
2014-02-13 21:54:15 +00:00
|
|
|
if (sd->extradata_len == 64 && sd->sub_stream_w && sd->sub_stream_h &&
|
|
|
|
cid == AV_CODEC_ID_DVD_SUBTITLE)
|
|
|
|
{
|
|
|
|
set_mp4_vobsub_idx(ctx, sd->extradata, sd->sub_stream_w, sd->sub_stream_h);
|
|
|
|
}
|
2012-08-16 15:21:21 +00:00
|
|
|
if (avcodec_open2(ctx, sub_codec, NULL) < 0)
|
|
|
|
goto error;
|
2012-08-31 12:42:30 +00:00
|
|
|
priv->avctx = ctx;
|
2013-06-01 17:44:12 +00:00
|
|
|
sd->priv = priv;
|
2014-06-17 22:18:37 +00:00
|
|
|
priv->displayed_id = -1;
|
2012-08-16 15:21:21 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
2013-12-21 18:06:37 +00:00
|
|
|
MP_FATAL(sd, "Could not open libavcodec subtitle decoder\n");
|
2012-08-16 15:21:21 +00:00
|
|
|
av_free(ctx);
|
2012-08-31 12:42:30 +00:00
|
|
|
talloc_free(priv);
|
2012-08-16 15:21:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-06-17 22:18:37 +00:00
|
|
|
static void clear_sub(struct sub *sub)
|
2012-08-31 12:42:30 +00:00
|
|
|
{
|
2014-06-17 22:18:37 +00:00
|
|
|
sub->count = 0;
|
|
|
|
sub->pts = MP_NOPTS_VALUE;
|
|
|
|
sub->endpts = MP_NOPTS_VALUE;
|
|
|
|
if (sub->valid)
|
|
|
|
avsubtitle_free(&sub->avsub);
|
|
|
|
sub->valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void alloc_sub(struct sd_lavc_priv *priv)
|
|
|
|
{
|
|
|
|
clear_sub(&priv->subs[MAX_QUEUE - 1]);
|
|
|
|
for (int n = MAX_QUEUE - 1; n > 0; n--)
|
|
|
|
priv->subs[n] = priv->subs[n - 1];
|
|
|
|
// clear only some fields; the memory allocs can be reused
|
|
|
|
priv->subs[0].valid = false;
|
|
|
|
priv->subs[0].count = 0;
|
|
|
|
priv->subs[0].id = priv->new_id++;
|
2012-08-31 12:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static void decode(struct sd *sd, struct demux_packet *packet)
|
2012-08-16 15:21:21 +00:00
|
|
|
{
|
2013-06-28 23:38:21 +00:00
|
|
|
struct MPOpts *opts = sd->opts;
|
2013-06-01 17:44:12 +00:00
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
2012-08-31 12:42:30 +00:00
|
|
|
AVCodecContext *ctx = priv->avctx;
|
2013-06-01 17:44:12 +00:00
|
|
|
double pts = packet->pts;
|
|
|
|
double duration = packet->duration;
|
2012-08-16 15:21:21 +00:00
|
|
|
AVSubtitle sub;
|
|
|
|
AVPacket pkt;
|
2010-07-11 09:40:46 +00:00
|
|
|
|
2013-10-31 17:16:30 +00:00
|
|
|
// libavformat sets duration==0, even if the duration is unknown.
|
|
|
|
// Assume there are no bitmap subs that actually use duration==0 for
|
|
|
|
// hidden subtitle events.
|
|
|
|
if (duration == 0)
|
|
|
|
duration = -1;
|
|
|
|
|
2014-08-14 21:45:58 +00:00
|
|
|
if (pts == MP_NOPTS_VALUE)
|
2014-06-17 22:18:37 +00:00
|
|
|
MP_WARN(sd, "Subtitle with unknown start time.\n");
|
|
|
|
|
2010-07-10 13:45:09 +00:00
|
|
|
av_init_packet(&pkt);
|
2013-06-01 17:44:12 +00:00
|
|
|
pkt.data = packet->buffer;
|
|
|
|
pkt.size = packet->len;
|
2012-08-16 15:21:21 +00:00
|
|
|
int got_sub;
|
|
|
|
int res = avcodec_decode_subtitle2(ctx, &sub, &got_sub, &pkt);
|
|
|
|
if (res < 0 || !got_sub)
|
|
|
|
return;
|
2014-06-17 22:18:37 +00:00
|
|
|
|
2011-01-14 12:05:22 +00:00
|
|
|
if (pts != MP_NOPTS_VALUE) {
|
2014-12-21 22:55:00 +00:00
|
|
|
if (sub.end_display_time > sub.start_display_time &&
|
|
|
|
sub.end_display_time != UINT32_MAX)
|
|
|
|
{
|
2011-01-16 18:51:48 +00:00
|
|
|
duration = (sub.end_display_time - sub.start_display_time) / 1000.0;
|
2014-12-21 22:55:00 +00:00
|
|
|
}
|
2011-01-14 12:05:22 +00:00
|
|
|
pts += sub.start_display_time / 1000.0;
|
2010-07-10 13:45:09 +00:00
|
|
|
}
|
2011-01-16 18:51:48 +00:00
|
|
|
double endpts = MP_NOPTS_VALUE;
|
|
|
|
if (pts != MP_NOPTS_VALUE && duration >= 0)
|
|
|
|
endpts = pts + duration;
|
2014-06-17 22:18:37 +00:00
|
|
|
|
|
|
|
// set end time of previous sub
|
|
|
|
if (priv->subs[0].endpts == MP_NOPTS_VALUE || priv->subs[0].endpts > pts)
|
|
|
|
priv->subs[0].endpts = pts;
|
|
|
|
|
|
|
|
alloc_sub(priv);
|
|
|
|
struct sub *current = &priv->subs[0];
|
|
|
|
|
|
|
|
current->valid = true;
|
|
|
|
current->pts = pts;
|
|
|
|
current->endpts = endpts;
|
|
|
|
current->avsub = sub;
|
|
|
|
|
2014-06-19 16:46:06 +00:00
|
|
|
MP_TARRAY_GROW(priv, current->inbitmaps, sub.num_rects);
|
|
|
|
MP_TARRAY_GROW(priv, current->imgs, sub.num_rects);
|
|
|
|
|
2014-06-17 22:18:37 +00:00
|
|
|
for (int i = 0; i < sub.num_rects; i++) {
|
|
|
|
struct AVSubtitleRect *r = sub.rects[i];
|
|
|
|
struct sub_bitmap *b = ¤t->inbitmaps[current->count];
|
|
|
|
struct osd_bmp_indexed *img = ¤t->imgs[current->count];
|
|
|
|
if (r->type != SUBTITLE_BITMAP) {
|
2013-12-21 18:06:37 +00:00
|
|
|
MP_ERR(sd, "unsupported subtitle type from libavcodec\n");
|
2014-06-17 22:18:37 +00:00
|
|
|
continue;
|
2010-07-10 13:45:09 +00:00
|
|
|
}
|
2014-06-17 22:18:37 +00:00
|
|
|
if (!(r->flags & AV_SUBTITLE_FLAG_FORCED) && opts->forced_subs_only)
|
|
|
|
continue;
|
|
|
|
if (r->w <= 0 || r->h <= 0)
|
|
|
|
continue;
|
|
|
|
img->bitmap = r->pict.data[0];
|
|
|
|
assert(r->nb_colors > 0);
|
|
|
|
assert(r->nb_colors * 4 <= sizeof(img->palette));
|
|
|
|
memcpy(img->palette, r->pict.data[1], r->nb_colors * 4);
|
|
|
|
b->bitmap = img;
|
|
|
|
b->stride = r->pict.linesize[0];
|
|
|
|
b->w = r->w;
|
|
|
|
b->h = r->h;
|
|
|
|
b->x = r->x;
|
|
|
|
b->y = r->y;
|
|
|
|
current->count++;
|
2010-07-10 13:45:09 +00:00
|
|
|
}
|
2012-08-16 15:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
|
2012-08-31 12:42:30 +00:00
|
|
|
struct sub_bitmaps *res)
|
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
2013-11-01 15:02:47 +00:00
|
|
|
struct MPOpts *opts = sd->opts;
|
2012-08-31 12:42:30 +00:00
|
|
|
|
2014-06-17 22:18:37 +00:00
|
|
|
struct sub *current = NULL;
|
|
|
|
for (int n = 0; n < MAX_QUEUE; n++) {
|
|
|
|
struct sub *sub = &priv->subs[n];
|
2014-06-19 16:46:06 +00:00
|
|
|
if (!sub->valid)
|
|
|
|
continue;
|
2014-06-17 22:18:37 +00:00
|
|
|
if (pts == MP_NOPTS_VALUE ||
|
|
|
|
((sub->pts == MP_NOPTS_VALUE || pts >= sub->pts) &&
|
|
|
|
(sub->endpts == MP_NOPTS_VALUE || pts < sub->endpts)))
|
|
|
|
{
|
2014-12-21 23:00:18 +00:00
|
|
|
// Ignore "trailing" subtitles with unknown length after 1 minute.
|
|
|
|
if (sub->endpts == MP_NOPTS_VALUE && pts >= sub->pts + 60)
|
|
|
|
break;
|
2014-06-17 22:18:37 +00:00
|
|
|
current = sub;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!current)
|
2012-12-12 21:56:41 +00:00
|
|
|
return;
|
2014-06-17 22:18:37 +00:00
|
|
|
|
|
|
|
MP_TARRAY_GROW(priv, priv->outbitmaps, current->count);
|
|
|
|
for (int n = 0; n < current->count; n++)
|
|
|
|
priv->outbitmaps[n] = current->inbitmaps[n];
|
Add prelimimary (basic, possibly broken) dvdnav support
This readds a more or less completely new dvdnav implementation, though
it's based on the code from before commit 41fbcee. Note that this is
rather basic, and might be broken or not quite usable in many cases.
Most importantly, navigation highlights are not correctly implemented.
This would require changes in the FFmpeg dvdsub decoder (to apply a
different internal CLUT), so supporting it is not really possible right
now. And in fact, I don't think I ever want to support it, because it's
a very small gain for a lot of work. Instead, mpv will display fake
highlights, which are an approximate bounding box around the real
highlights.
Some things like mouse input or switching audio/subtitles stream using
the dvdnav VM are not supported.
Might be quite fragile on transitions: if dvdnav initiates a transition,
and doesn't give us enough mpeg data to initialize video playback, the
player will just quit.
This is added only because some users seem to want it. I don't intend to
make mpv a good DVD player, so the very basic minimum will have to do.
How about you just convert your DVD to proper video files?
2013-12-12 00:44:28 +00:00
|
|
|
|
2012-08-31 12:42:30 +00:00
|
|
|
res->parts = priv->outbitmaps;
|
2014-06-17 22:18:37 +00:00
|
|
|
res->num_parts = current->count;
|
|
|
|
if (priv->displayed_id != current->id)
|
2012-08-31 12:42:30 +00:00
|
|
|
res->bitmap_id = ++res->bitmap_pos_id;
|
2014-06-17 22:18:37 +00:00
|
|
|
priv->displayed_id = current->id;
|
2012-10-04 15:16:47 +00:00
|
|
|
res->format = SUBBITMAP_INDEXED;
|
2013-12-11 22:15:29 +00:00
|
|
|
|
2014-10-21 09:37:32 +00:00
|
|
|
double video_par = 0;
|
2013-12-11 22:15:29 +00:00
|
|
|
if (priv->avctx->codec_id == AV_CODEC_ID_DVD_SUBTITLE &&
|
|
|
|
opts->stretch_dvd_subs) {
|
|
|
|
// For DVD subs, try to keep the subtitle PAR at display PAR.
|
sub: fix crash with certain uses of --vf=sub
If, for some reason, the subtitle renderer attempts to render a
subtitle before SD_CTRL_SET_VIDEO_PARAMS was called, it passed a
value calculated from invalid values. This can happen with --vf=sub
and --start. The crash happens if 1. there was a subtitle packet that
falls into the timestamp of the rendered video frame, 2. the playloop
hasn't informed the subtitle decoder about the video resolution yet
(normally unneeded, because that is used for weird corner cases only,
so this code is a bit fuzzy), and 3. something actually requests a
frame to be drawn from the subtitle renderer, like with vf_sub.
The actual crash was due to passing NaN as pixel aspect to libass,
which then created glyphs with ridiculous sizes, involving a few
integer overflows and unchecked mallocs.
The sd_lavc.c and sd_spu.c cases probably don't crash, but I'm not
sure, and it's better fix them anyway.
Not bothering with sd_spu.c, this crap is for compatibility and will
be removed soon.
Note that this would have been no problem, had the code checked whether
SD_CTRL_SET_VIDEO_PARAMS was actually called. This commit adds such a
check (although it basically checks after using the parameters).
Regression since 49caa0a7 and 633fde4a.
2014-01-26 17:58:40 +00:00
|
|
|
double par =
|
2013-12-11 22:15:29 +00:00
|
|
|
(priv->video_params.d_w / (double)priv->video_params.d_h)
|
|
|
|
/ (priv->video_params.w / (double)priv->video_params.h);
|
sub: fix crash with certain uses of --vf=sub
If, for some reason, the subtitle renderer attempts to render a
subtitle before SD_CTRL_SET_VIDEO_PARAMS was called, it passed a
value calculated from invalid values. This can happen with --vf=sub
and --start. The crash happens if 1. there was a subtitle packet that
falls into the timestamp of the rendered video frame, 2. the playloop
hasn't informed the subtitle decoder about the video resolution yet
(normally unneeded, because that is used for weird corner cases only,
so this code is a bit fuzzy), and 3. something actually requests a
frame to be drawn from the subtitle renderer, like with vf_sub.
The actual crash was due to passing NaN as pixel aspect to libass,
which then created glyphs with ridiculous sizes, involving a few
integer overflows and unchecked mallocs.
The sd_lavc.c and sd_spu.c cases probably don't crash, but I'm not
sure, and it's better fix them anyway.
Not bothering with sd_spu.c, this crap is for compatibility and will
be removed soon.
Note that this would have been no problem, had the code checked whether
SD_CTRL_SET_VIDEO_PARAMS was actually called. This commit adds such a
check (although it basically checks after using the parameters).
Regression since 49caa0a7 and 633fde4a.
2014-01-26 17:58:40 +00:00
|
|
|
if (isnormal(par))
|
|
|
|
video_par = par;
|
2013-12-11 22:15:29 +00:00
|
|
|
}
|
2014-10-21 09:37:32 +00:00
|
|
|
if (priv->avctx->codec_id == AV_CODEC_ID_HDMV_PGS_SUBTITLE)
|
|
|
|
video_par = -1;
|
Add prelimimary (basic, possibly broken) dvdnav support
This readds a more or less completely new dvdnav implementation, though
it's based on the code from before commit 41fbcee. Note that this is
rather basic, and might be broken or not quite usable in many cases.
Most importantly, navigation highlights are not correctly implemented.
This would require changes in the FFmpeg dvdsub decoder (to apply a
different internal CLUT), so supporting it is not really possible right
now. And in fact, I don't think I ever want to support it, because it's
a very small gain for a lot of work. Instead, mpv will display fake
highlights, which are an approximate bounding box around the real
highlights.
Some things like mouse input or switching audio/subtitles stream using
the dvdnav VM are not supported.
Might be quite fragile on transitions: if dvdnav initiates a transition,
and doesn't give us enough mpeg data to initialize video playback, the
player will just quit.
This is added only because some users seem to want it. I don't intend to
make mpv a good DVD player, so the very basic minimum will have to do.
How about you just convert your DVD to proper video files?
2013-12-12 00:44:28 +00:00
|
|
|
int insize[2];
|
|
|
|
get_resolution(sd, insize);
|
|
|
|
osd_rescale_bitmaps(res, insize[0], insize[1], d, video_par);
|
2012-08-31 12:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static void reset(struct sd *sd)
|
2012-08-16 15:21:21 +00:00
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
2012-08-31 12:42:30 +00:00
|
|
|
|
2014-08-14 21:45:58 +00:00
|
|
|
for (int n = 0; n < MAX_QUEUE; n++)
|
|
|
|
clear_sub(&priv->subs[n]);
|
2012-08-16 15:21:21 +00:00
|
|
|
// lavc might not do this right for all codecs; may need close+reopen
|
2012-08-31 12:42:30 +00:00
|
|
|
avcodec_flush_buffers(priv->avctx);
|
2010-07-10 13:45:09 +00:00
|
|
|
}
|
2012-08-16 15:21:21 +00:00
|
|
|
|
2013-06-01 17:44:12 +00:00
|
|
|
static void uninit(struct sd *sd)
|
2012-08-16 15:21:21 +00:00
|
|
|
{
|
2013-06-01 17:44:12 +00:00
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
2012-08-31 12:42:30 +00:00
|
|
|
|
2014-06-17 22:18:37 +00:00
|
|
|
for (int n = 0; n < MAX_QUEUE; n++)
|
|
|
|
clear_sub(&priv->subs[n]);
|
2012-08-31 12:42:30 +00:00
|
|
|
avcodec_close(priv->avctx);
|
2014-01-11 00:28:18 +00:00
|
|
|
av_free(priv->avctx->extradata);
|
2012-08-31 12:42:30 +00:00
|
|
|
av_free(priv->avctx);
|
|
|
|
talloc_free(priv);
|
2012-08-16 15:21:21 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 12:15:59 +00:00
|
|
|
static int control(struct sd *sd, enum sd_ctrl cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
|
|
|
switch (cmd) {
|
|
|
|
case SD_CTRL_SET_VIDEO_PARAMS:
|
|
|
|
priv->video_params = *(struct mp_image_params *)arg;
|
|
|
|
return CONTROL_OK;
|
Add prelimimary (basic, possibly broken) dvdnav support
This readds a more or less completely new dvdnav implementation, though
it's based on the code from before commit 41fbcee. Note that this is
rather basic, and might be broken or not quite usable in many cases.
Most importantly, navigation highlights are not correctly implemented.
This would require changes in the FFmpeg dvdsub decoder (to apply a
different internal CLUT), so supporting it is not really possible right
now. And in fact, I don't think I ever want to support it, because it's
a very small gain for a lot of work. Instead, mpv will display fake
highlights, which are an approximate bounding box around the real
highlights.
Some things like mouse input or switching audio/subtitles stream using
the dvdnav VM are not supported.
Might be quite fragile on transitions: if dvdnav initiates a transition,
and doesn't give us enough mpeg data to initialize video playback, the
player will just quit.
This is added only because some users seem to want it. I don't intend to
make mpv a good DVD player, so the very basic minimum will have to do.
How about you just convert your DVD to proper video files?
2013-12-12 00:44:28 +00:00
|
|
|
case SD_CTRL_GET_RESOLUTION:
|
|
|
|
get_resolution(sd, arg);
|
|
|
|
return CONTROL_OK;
|
2013-11-01 12:15:59 +00:00
|
|
|
default:
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-16 15:21:21 +00:00
|
|
|
const struct sd_functions sd_lavc = {
|
2013-06-03 19:49:39 +00:00
|
|
|
.name = "lavc",
|
2013-04-28 19:12:11 +00:00
|
|
|
.supports_format = supports_format,
|
2012-08-16 15:21:21 +00:00
|
|
|
.init = init,
|
|
|
|
.decode = decode,
|
2012-08-31 12:42:30 +00:00
|
|
|
.get_bitmaps = get_bitmaps,
|
2013-11-01 12:15:59 +00:00
|
|
|
.control = control,
|
2012-08-16 15:21:21 +00:00
|
|
|
.reset = reset,
|
|
|
|
.uninit = uninit,
|
|
|
|
};
|