summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-10-11 18:16:09 +0200
committerwm4 <wm4@nowhere>2014-10-11 18:16:09 +0200
commit46b16cf2063ea9a5032feead581ebe77e8001604 (patch)
tree35869267e45acf2f2b6c5e2b922356cfe968fbf2 /video
parent54e2ca809cb3312385f5ed017ec91ee8bb232742 (diff)
downloadmpv-46b16cf2063ea9a5032feead581ebe77e8001604.tar.bz2
mpv-46b16cf2063ea9a5032feead581ebe77e8001604.tar.xz
vf_vapoursynth: factor stuff
Diffstat (limited to 'video')
-rw-r--r--video/filter/vf_vapoursynth.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/video/filter/vf_vapoursynth.c b/video/filter/vf_vapoursynth.c
index ecab4c1f1e..ea5b3fe1cc 100644
--- a/video/filter/vf_vapoursynth.c
+++ b/video/filter/vf_vapoursynth.c
@@ -114,8 +114,8 @@ static int mp_from_vs(VSPresetFormat vs)
return pfNone;
}
-static void copy_mp_to_vs_frame_props(struct vf_priv_s *p, VSMap *map,
- struct mp_image *img)
+static void copy_mp_to_vs_frame_props_map(struct vf_priv_s *p, VSMap *map,
+ struct mp_image *img)
{
struct mp_image_params *params = &img->params;
if (params->d_w > 0 && params->d_h > 0) {
@@ -151,6 +151,25 @@ static void copy_mp_to_vs_frame_props(struct vf_priv_s *p, VSMap *map,
!!(img->fields & MP_IMGFIELD_TOP_FIRST), 0);
}
+static int set_vs_frame_props(struct vf_priv_s *p, VSFrameRef *frame,
+ struct mp_image *img, int dur_num, int dur_den)
+{
+ VSMap *map = p->vsapi->getFramePropsRW(frame);
+ if (!map)
+ return -1;
+ p->vsapi->propSetInt(map, "_DurationNum", dur_num, 0);
+ p->vsapi->propSetInt(map, "_DurationDen", dur_den, 0);
+ copy_mp_to_vs_frame_props_map(p, map, img);
+ return 0;
+}
+
+static VSFrameRef *alloc_vs_frame(struct vf_priv_s *p, struct mp_image_params *fmt)
+{
+ const VSFormat *vsfmt =
+ p->vsapi->getFormatPreset(mp_to_vs(fmt->imgfmt), p->vscore);
+ return p->vsapi->newVideoFrame(vsfmt, fmt->w, fmt->h, NULL, p->vscore);
+}
+
static struct mp_image map_vs_frame(struct vf_priv_s *p, const VSFrameRef *ref,
bool w)
{
@@ -406,23 +425,16 @@ static const VSFrameRef *VS_CC infiltGetFrame(int frameno, int activationReason,
}
if (frameno < p->in_frameno + p->num_buffered) {
struct mp_image *img = p->buffered[frameno - p->in_frameno];
- const VSFormat *vsfmt =
- vsapi->getFormatPreset(mp_to_vs(img->imgfmt), core);
- ret = vsapi->newVideoFrame(vsfmt, img->w, img->h, NULL, core);
+ ret = alloc_vs_frame(p, &img->params);
if (!ret) {
p->vsapi->setFilterError("Could not allocate VS frame", frameCtx);
break;
}
struct mp_image vsframe = map_vs_frame(p, ret, true);
mp_image_copy(&vsframe, img);
- VSMap *map = p->vsapi->getFramePropsRW(ret);
- if (map) {
- int res = 1e6;
- int dur = img->pts * res + 0.5;
- p->vsapi->propSetInt(map, "_DurationNum", dur, 0);
- p->vsapi->propSetInt(map, "_DurationDen", res, 0);
- copy_mp_to_vs_frame_props(p, map, img);
- }
+ int res = 1e6;
+ int dur = img->pts * res + 0.5;
+ set_vs_frame_props(p, ret, img, dur, res);
break;
}
pthread_cond_wait(&p->wakeup, &p->lock);