summaryrefslogtreecommitdiffstats
path: root/sub/sd_lavc.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-06-01 19:44:12 +0200
committerwm4 <wm4@nowhere>2013-06-01 19:44:16 +0200
commit02ce316ade9ba932ad405383278d6b01c54e5fc4 (patch)
tree4151e307fafc30a4079d4cd79c3d85d92df35105 /sub/sd_lavc.c
parent27d383918a3d63559c85ca96b2162a13234f2abc (diff)
downloadmpv-02ce316ade9ba932ad405383278d6b01c54e5fc4.tar.bz2
mpv-02ce316ade9ba932ad405383278d6b01c54e5fc4.tar.xz
sub: refactor
Make the sub decoder stuff independent from sh_sub (except for initialization of course). Sub decoders now access a struct sd only, instead of getting access to sh_sub. The glue code in dec_sub.c is similarily independent from osd. Some simplifications are made. For example, the switch_id stuff is unneeded: the frontend code just has to make sure to call osd_changed() any time subtitles are switched. This is also preparation for introducing subtitle converters. It's much cleaner to completely separate demuxer header/renderer glue/decoders for this purpose, especially since sub converters might completely change how demuxer headers have to be interpreted. Also pass data as demux_packets. Currently, this doesn't help much, but libavcodec converters might need scary stuff like packet side data, so it's perhaps better to go with passing packets.
Diffstat (limited to 'sub/sd_lavc.c')
-rw-r--r--sub/sd_lavc.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index 4c7dfd12a5..9f8db2d877 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -81,12 +81,10 @@ static void guess_resolution(enum AVCodecID type, int *w, int *h)
}
}
-static int init(struct sh_sub *sh, struct osd_state *osd)
+static int init(struct sd *sd)
{
- if (sh->initialized)
- return 0;
struct sd_lavc_priv *priv = talloc_zero(NULL, struct sd_lavc_priv);
- enum AVCodecID cid = mp_codec_to_av_codec_id(sh->gsh->codec);
+ enum AVCodecID cid = mp_codec_to_av_codec_id(sd->codec);
AVCodecContext *ctx = NULL;
AVCodec *sub_codec = avcodec_find_decoder(cid);
if (!sub_codec)
@@ -94,12 +92,12 @@ static int init(struct sh_sub *sh, struct osd_state *osd)
ctx = avcodec_alloc_context3(sub_codec);
if (!ctx)
goto error;
- ctx->extradata_size = sh->extradata_len;
- ctx->extradata = sh->extradata;
+ ctx->extradata_size = sd->extradata_len;
+ ctx->extradata = sd->extradata;
if (avcodec_open2(ctx, sub_codec, NULL) < 0)
goto error;
priv->avctx = ctx;
- sh->context = priv;
+ sd->priv = priv;
return 0;
error:
@@ -126,18 +124,19 @@ static void clear(struct sd_lavc_priv *priv)
priv->have_sub = false;
}
-static void decode(struct sh_sub *sh, struct osd_state *osd, void *data,
- int data_len, double pts, double duration)
+static void decode(struct sd *sd, struct demux_packet *packet)
{
- struct sd_lavc_priv *priv = sh->context;
+ struct sd_lavc_priv *priv = sd->priv;
AVCodecContext *ctx = priv->avctx;
+ double pts = packet->pts;
+ double duration = packet->duration;
AVSubtitle sub;
AVPacket pkt;
clear(priv);
av_init_packet(&pkt);
- pkt.data = data;
- pkt.size = data_len;
+ pkt.data = packet->buffer;
+ pkt.size = packet->len;
pkt.pts = pts * 1000;
if (duration >= 0)
pkt.convergence_duration = duration * 1000;
@@ -189,11 +188,10 @@ static void decode(struct sh_sub *sh, struct osd_state *osd, void *data,
}
}
-static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd,
- struct mp_osd_res d, double pts,
+static void get_bitmaps(struct sd *sd, struct mp_osd_res d, double pts,
struct sub_bitmaps *res)
{
- struct sd_lavc_priv *priv = sh->context;
+ struct sd_lavc_priv *priv = sd->priv;
if (priv->pts != MP_NOPTS_VALUE && pts < priv->pts)
return;
@@ -225,9 +223,9 @@ static void get_bitmaps(struct sh_sub *sh, struct osd_state *osd,
res->scaled = xscale != 1 || yscale != 1;
}
-static void reset(struct sh_sub *sh, struct osd_state *osd)
+static void reset(struct sd *sd)
{
- struct sd_lavc_priv *priv = sh->context;
+ struct sd_lavc_priv *priv = sd->priv;
if (priv->pts == MP_NOPTS_VALUE)
clear(priv);
@@ -235,9 +233,9 @@ static void reset(struct sh_sub *sh, struct osd_state *osd)
avcodec_flush_buffers(priv->avctx);
}
-static void uninit(struct sh_sub *sh)
+static void uninit(struct sd *sd)
{
- struct sd_lavc_priv *priv = sh->context;
+ struct sd_lavc_priv *priv = sd->priv;
clear(priv);
avcodec_close(priv->avctx);
@@ -251,6 +249,5 @@ const struct sd_functions sd_lavc = {
.decode = decode,
.get_bitmaps = get_bitmaps,
.reset = reset,
- .switch_off = reset,
.uninit = uninit,
};