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
|
|
|
|
2012-08-31 12:42:30 +00:00
|
|
|
struct sd_lavc_priv {
|
|
|
|
AVCodecContext *avctx;
|
2012-10-04 15:16:47 +00:00
|
|
|
AVSubtitle sub;
|
|
|
|
bool have_sub;
|
2012-08-31 12:42:30 +00:00
|
|
|
int count;
|
|
|
|
struct sub_bitmap *inbitmaps;
|
|
|
|
struct sub_bitmap *outbitmaps;
|
2012-10-04 15:16:47 +00:00
|
|
|
struct osd_bmp_indexed *imgs;
|
2012-08-31 12:42:30 +00:00
|
|
|
bool bitmaps_changed;
|
2012-12-12 21:56:41 +00:00
|
|
|
double pts;
|
2012-08-31 12:42:30 +00:00
|
|
|
double endpts;
|
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:
|
2013-06-01 17:40:09 +00:00
|
|
|
// lavc dvdsubdec doesn't read color/resolution on Libav 9.1 and below,
|
|
|
|
// so fall back to sd_spu in this case. Never use sd_spu with new ffmpeg;
|
|
|
|
// spudec can't handle ffmpeg .idx demuxing (added to lavc in 54.79.100).
|
|
|
|
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(54, 40, 0)
|
2013-04-15 19:25:21 +00:00
|
|
|
case AV_CODEC_ID_DVD_SUBTITLE:
|
2013-06-01 17:40:09 +00:00
|
|
|
#endif
|
2013-04-15 19:25:21 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void guess_resolution(enum AVCodecID type, int *w, int *h)
|
|
|
|
{
|
|
|
|
if (type == AV_CODEC_ID_DVD_SUBTITLE) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
static void get_resolution(struct sd *sd, int wh[2])
|
|
|
|
{
|
|
|
|
struct sd_lavc_priv *priv = sd->priv;
|
|
|
|
wh[0] = priv->avctx->width;
|
|
|
|
wh[1] = priv->avctx->height;
|
2014-02-14 14:44:13 +00:00
|
|
|
if (wh[0] <= 0 || wh[1] <= 0) {
|
|
|
|
wh[0] = priv->video_params.w;
|
|
|
|
wh[1] = priv->video_params.h;
|
|
|
|
}
|
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
|
|
|
guess_resolution(priv->avctx->codec_id, &wh[0], &wh[1]);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
float cmatrix[3][4];
|
|
|
|
mp_get_yuv2rgb_coeffs(&csp, cmatrix);
|
|
|
|
int c[3] = {(e >> 16) & 0xff, (e >> 8) & 0xff, e & 0xff};
|
|
|
|
mp_map_int_color(cmatrix, 8, c);
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-31 12:42:30 +00:00
|
|
|
static void clear(struct sd_lavc_priv *priv)
|
|
|
|
{
|
|
|
|
priv->count = 0;
|
|
|
|
talloc_free(priv->inbitmaps);
|
|
|
|
talloc_free(priv->outbitmaps);
|
|
|
|
priv->inbitmaps = priv->outbitmaps = NULL;
|
2012-10-04 15:16:47 +00:00
|
|
|
talloc_free(priv->imgs);
|
|
|
|
priv->imgs = NULL;
|
2012-08-31 12:42:30 +00:00
|
|
|
priv->bitmaps_changed = true;
|
2012-12-12 21:56:41 +00:00
|
|
|
priv->pts = MP_NOPTS_VALUE;
|
2012-08-31 12:42:30 +00:00
|
|
|
priv->endpts = MP_NOPTS_VALUE;
|
2012-10-04 15:16:47 +00:00
|
|
|
if (priv->have_sub)
|
|
|
|
avsubtitle_free(&priv->sub);
|
|
|
|
priv->have_sub = false;
|
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;
|
|
|
|
|
2012-08-31 12:42:30 +00:00
|
|
|
clear(priv);
|
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;
|
2011-01-14 12:05:22 +00:00
|
|
|
pkt.pts = pts * 1000;
|
2011-01-16 18:51:48 +00:00
|
|
|
if (duration >= 0)
|
|
|
|
pkt.convergence_duration = duration * 1000;
|
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;
|
2012-10-04 15:16:47 +00:00
|
|
|
priv->sub = sub;
|
|
|
|
priv->have_sub = true;
|
2011-01-14 12:05:22 +00:00
|
|
|
if (pts != MP_NOPTS_VALUE) {
|
2010-07-10 13:45:09 +00:00
|
|
|
if (sub.end_display_time > sub.start_display_time)
|
2011-01-16 18:51:48 +00:00
|
|
|
duration = (sub.end_display_time - sub.start_display_time) / 1000.0;
|
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;
|
2012-08-16 15:21:21 +00:00
|
|
|
if (sub.num_rects > 0) {
|
2010-07-10 13:45:09 +00:00
|
|
|
switch (sub.rects[0]->type) {
|
|
|
|
case SUBTITLE_BITMAP:
|
2013-06-28 23:38:21 +00:00
|
|
|
priv->count = 0;
|
|
|
|
priv->pts = pts;
|
|
|
|
priv->endpts = endpts;
|
2012-08-31 12:42:30 +00:00
|
|
|
priv->inbitmaps = talloc_array(priv, struct sub_bitmap,
|
|
|
|
sub.num_rects);
|
2012-10-04 15:16:47 +00:00
|
|
|
priv->imgs = talloc_array(priv, struct osd_bmp_indexed,
|
|
|
|
sub.num_rects);
|
2012-08-31 12:42:30 +00:00
|
|
|
for (int i = 0; i < sub.num_rects; i++) {
|
|
|
|
struct AVSubtitleRect *r = sub.rects[i];
|
2014-01-29 15:52:40 +00:00
|
|
|
struct sub_bitmap *b = &priv->inbitmaps[priv->count];
|
|
|
|
struct osd_bmp_indexed *img = &priv->imgs[priv->count];
|
2013-06-28 23:38:21 +00:00
|
|
|
if (!(r->flags & AV_SUBTITLE_FLAG_FORCED) &&
|
|
|
|
opts->forced_subs_only)
|
|
|
|
continue;
|
2014-01-29 15:52:40 +00:00
|
|
|
if (r->w == 0 || r->h == 0)
|
|
|
|
continue;
|
2012-10-04 15:16:47 +00:00
|
|
|
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];
|
2012-08-31 12:42:30 +00:00
|
|
|
b->w = r->w;
|
|
|
|
b->h = r->h;
|
|
|
|
b->x = r->x;
|
|
|
|
b->y = r->y;
|
2013-06-28 23:38:21 +00:00
|
|
|
priv->count++;
|
2012-08-31 12:42:30 +00:00
|
|
|
}
|
2010-07-10 13:45:09 +00:00
|
|
|
break;
|
2011-01-14 12:05:22 +00:00
|
|
|
default:
|
2013-12-21 18:06:37 +00:00
|
|
|
MP_ERR(sd, "unsupported subtitle type from libavcodec\n");
|
2010-07-10 13:45:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2012-12-12 21:56:41 +00:00
|
|
|
if (priv->pts != MP_NOPTS_VALUE && pts < priv->pts)
|
|
|
|
return;
|
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
|
|
|
if (priv->endpts != MP_NOPTS_VALUE && (pts >= priv->endpts ||
|
|
|
|
pts < priv->endpts - 300))
|
2012-08-31 12:42:30 +00:00
|
|
|
clear(priv);
|
2013-12-11 22:15:29 +00:00
|
|
|
size_t size = talloc_get_size(priv->inbitmaps);
|
|
|
|
if (!priv->outbitmaps)
|
|
|
|
priv->outbitmaps = talloc_size(priv, size);
|
|
|
|
memcpy(priv->outbitmaps, priv->inbitmaps, size);
|
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;
|
2012-09-28 19:19:36 +00:00
|
|
|
res->num_parts = priv->count;
|
2012-08-31 12:42:30 +00:00
|
|
|
if (priv->bitmaps_changed)
|
|
|
|
res->bitmap_id = ++res->bitmap_pos_id;
|
|
|
|
priv->bitmaps_changed = false;
|
2012-10-04 15:16:47 +00:00
|
|
|
res->format = SUBBITMAP_INDEXED;
|
2013-12-11 22:15:29 +00:00
|
|
|
|
|
|
|
double video_par = -1;
|
|
|
|
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
|
|
|
}
|
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
|
|
|
|
2012-12-12 21:56:41 +00:00
|
|
|
if (priv->pts == MP_NOPTS_VALUE)
|
|
|
|
clear(priv);
|
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
|
|
|
|
2012-10-04 15:16:47 +00:00
|
|
|
clear(priv);
|
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,
|
|
|
|
};
|