summaryrefslogtreecommitdiffstats
path: root/sub/sd_lavc.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-15 21:25:21 +0200
committerwm4 <wm4@nowhere>2013-04-20 23:28:27 +0200
commit331982b99ce3b50b95ac340eb17c6116913480f3 (patch)
treeb0e0c14521f509a883c0420d9e6277c0329eb773 /sub/sd_lavc.c
parent5ac50f88c90167e9ade0c998ac62e935e259acee (diff)
downloadmpv-331982b99ce3b50b95ac340eb17c6116913480f3.tar.bz2
mpv-331982b99ce3b50b95ac340eb17c6116913480f3.tar.xz
sub, demux: identify subtitle types with the codec name
Get rid of the 1-char subtitle type field. Use sh_stream->codec instead just like audio and video do. Use codec names as defined by libavcodec for simplicity, even if they're somewhat verbose and annoying. Note that ffmpeg might switch to "ass" as codec name for ASS, so we don't bother with the current silly "ssa" name.
Diffstat (limited to 'sub/sd_lavc.c')
-rw-r--r--sub/sd_lavc.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index e3f7af408a..1665e36749 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -22,6 +22,7 @@
#include "talloc.h"
#include "core/mp_msg.h"
+#include "core/av_common.h"
#include "demux/stheader.h"
#include "sd.h"
#include "dec_sub.h"
@@ -40,9 +41,24 @@ struct sd_lavc_priv {
double endpts;
};
-static void guess_resolution(char type, int *w, int *h)
+static bool probe(struct sh_sub *sh)
{
- if (type == 'v') {
+ enum AVCodecID cid = mp_codec_to_av_codec_id(sh->gsh->codec);
+ // 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;
+ }
+}
+
+static void guess_resolution(enum AVCodecID type, int *w, int *h)
+{
+ if (type == AV_CODEC_ID_DVD_SUBTITLE) {
/* 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,
@@ -65,17 +81,7 @@ static int init(struct sh_sub *sh, struct osd_state *osd)
if (sh->initialized)
return 0;
struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv);
- enum AVCodecID cid = AV_CODEC_ID_NONE;
- switch (sh->type) {
- case 'b':
- cid = AV_CODEC_ID_DVB_SUBTITLE; break;
- case 'p':
- cid = AV_CODEC_ID_HDMV_PGS_SUBTITLE; break;
- case 'x':
- cid = AV_CODEC_ID_XSUB; break;
- case 'v':
- cid = AV_CODEC_ID_DVD_SUBTITLE; break;
- }
+ enum AVCodecID cid = mp_codec_to_av_codec_id(sh->gsh->codec);
AVCodecContext *ctx = NULL;
AVCodec *sub_codec = avcodec_find_decoder(cid);
if (!sub_codec)
@@ -194,7 +200,7 @@ static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd,
talloc_get_size(priv->inbitmaps));
int inw = priv->avctx->width;
int inh = priv->avctx->height;
- guess_resolution(sh->type, &inw, &inh);
+ guess_resolution(priv->avctx->codec_id, &inw, &inh);
double xscale = (double) (d.w - d.ml - d.mr) / inw;
double yscale = (double) (d.h - d.mt - d.mb) / inh;
for (int i = 0; i < priv->count; i++) {
@@ -235,6 +241,7 @@ static void uninit(struct sh_sub *sh)
}
const struct sd_functions sd_lavc = {
+ .probe = probe,
.init = init,
.decode = decode,
.get_bitmaps = get_bitmaps,