summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-06-17 17:48:05 +0200
committerwm4 <wm4@nowhere>2016-06-17 23:12:34 +0200
commit8986b37fe7261a2d99b8c27aeda3351f66e1b972 (patch)
treec253d516e230111f6fdebe2a56014ba8971232d7 /sub
parentd0bd39eb90811b25f063c4043a8cb08086e1de65 (diff)
downloadmpv-8986b37fe7261a2d99b8c27aeda3351f66e1b972.tar.bz2
mpv-8986b37fe7261a2d99b8c27aeda3351f66e1b972.tar.xz
sd_lavc: move AVSubtitle bitmap setup code into its own function
No functional changes.
Diffstat (limited to 'sub')
-rw-r--r--sub/sd_lavc.c78
1 files changed, 44 insertions, 34 deletions
diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c
index ab1b659ede..f24a73c395 100644
--- a/sub/sd_lavc.c
+++ b/sub/sd_lavc.c
@@ -176,6 +176,49 @@ static void alloc_sub(struct sd_lavc_priv *priv)
priv->subs[0].id = priv->new_id++;
}
+// Initialize sub from sub->avsub.
+static void read_sub_bitmaps(struct sd *sd, struct sub *sub)
+{
+ struct MPOpts *opts = sd->opts;
+ struct sd_lavc_priv *priv = sd->priv;
+ AVSubtitle *avsub = &sub->avsub;
+
+ MP_TARRAY_GROW(priv, sub->inbitmaps, avsub->num_rects);
+ MP_TARRAY_GROW(priv, sub->imgs, avsub->num_rects);
+
+ for (int i = 0; i < avsub->num_rects; i++) {
+ struct AVSubtitleRect *r = avsub->rects[i];
+ struct sub_bitmap *b = &sub->inbitmaps[sub->count];
+ struct osd_bmp_indexed *img = &sub->imgs[sub->count];
+ if (r->type != SUBTITLE_BITMAP) {
+ MP_ERR(sd, "unsupported subtitle type from libavcodec\n");
+ continue;
+ }
+ if (!(r->flags & AV_SUBTITLE_FLAG_FORCED) && opts->forced_subs_only)
+ continue;
+ if (r->w <= 0 || r->h <= 0)
+ continue;
+#if HAVE_AV_SUBTITLE_NOPICT
+ uint8_t **data = r->data;
+ int *linesize = r->linesize;
+#else
+ uint8_t **data = r->pict.data;
+ int *linesize = r->pict.linesize;
+#endif
+ img->bitmap = data[0];
+ assert(r->nb_colors > 0);
+ assert(r->nb_colors * 4 <= sizeof(img->palette));
+ memcpy(img->palette, data[1], r->nb_colors * 4);
+ b->bitmap = img;
+ b->stride = linesize[0];
+ b->w = r->w;
+ b->h = r->h;
+ b->x = r->x;
+ b->y = r->y;
+ sub->count++;
+ }
+}
+
static void decode(struct sd *sd, struct demux_packet *packet)
{
struct MPOpts *opts = sd->opts;
@@ -250,40 +293,7 @@ static void decode(struct sd *sd, struct demux_packet *packet)
current->endpts = endpts;
current->avsub = sub;
- MP_TARRAY_GROW(priv, current->inbitmaps, sub.num_rects);
- MP_TARRAY_GROW(priv, current->imgs, sub.num_rects);
-
- for (int i = 0; i < sub.num_rects; i++) {
- struct AVSubtitleRect *r = sub.rects[i];
- struct sub_bitmap *b = &current->inbitmaps[current->count];
- struct osd_bmp_indexed *img = &current->imgs[current->count];
- if (r->type != SUBTITLE_BITMAP) {
- MP_ERR(sd, "unsupported subtitle type from libavcodec\n");
- continue;
- }
- if (!(r->flags & AV_SUBTITLE_FLAG_FORCED) && opts->forced_subs_only)
- continue;
- if (r->w <= 0 || r->h <= 0)
- continue;
-#if HAVE_AV_SUBTITLE_NOPICT
- uint8_t **data = r->data;
- int *linesize = r->linesize;
-#else
- uint8_t **data = r->pict.data;
- int *linesize = r->pict.linesize;
-#endif
- img->bitmap = data[0];
- assert(r->nb_colors > 0);
- assert(r->nb_colors * 4 <= sizeof(img->palette));
- memcpy(img->palette, data[1], r->nb_colors * 4);
- b->bitmap = img;
- b->stride = linesize[0];
- b->w = r->w;
- b->h = r->h;
- b->x = r->x;
- b->y = r->y;
- current->count++;
- }
+ read_sub_bitmaps(sd, current);
if (pts != MP_NOPTS_VALUE) {
for (int n = 0; n < priv->num_seekpoints; n++) {