summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-11-05 14:25:04 +0100
committerwm4 <wm4@nowhere>2013-01-13 20:04:10 +0100
commitc54fc507da8edcc2c5d3bc3f50b0881d1c1406d7 (patch)
tree530d112301256e1c3ea50d7bb416b7ba2109130b /core
parent1c412169aca2f0ad38380b0c89f2485e6a256766 (diff)
downloadmpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.bz2
mpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.xz
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead of vf_get_image(). Remove filter "direct rendering". This was useful for vf_expand and (in rare cases) vf_sub: DR allowed these filters to pass a cropped image to the filters before them. Then, on filtering, the image was "uncropped", so that black bars could be added around the image without copying. This means that in some cases, vf_expand will be slower (-vf gradfun,expand for example). Note that another form of DR used for in-place filters has been replaced by simpler logic. Instead of trying to do DR, filters can check if the image is writeable (with mp_image_is_writeable()), and do true in-place if that's the case. This affects filters like vf_gradfun and vf_sub. Everything has to support strides now. If something doesn't, making a copy of the image data is required.
Diffstat (limited to 'core')
-rw-r--r--core/mp_talloc.h22
-rw-r--r--core/mplayer.c36
2 files changed, 44 insertions, 14 deletions
diff --git a/core/mp_talloc.h b/core/mp_talloc.h
index ff2b808125..1dcb0bce07 100644
--- a/core/mp_talloc.h
+++ b/core/mp_talloc.h
@@ -25,24 +25,34 @@
#define MP_TALLOC_ELEMS(p) (talloc_get_size(p) / sizeof((p)[0]))
#define MP_GROW_ARRAY(p, nextidx) do { \
if ((nextidx) == MP_TALLOC_ELEMS(p)) \
- p = talloc_realloc_size(NULL, p, talloc_get_size(p) * 2); } while (0)
+ (p) = talloc_realloc_size(NULL, p, talloc_get_size(p) * 2); } while (0)
#define MP_RESIZE_ARRAY(ctx, p, count) do { \
- p = talloc_realloc_size((ctx), p, (count) * sizeof(p[0])); } while (0)
+ (p) = talloc_realloc_size((ctx), p, (count) * sizeof((p)[0])); } while (0)
#define MP_TARRAY_GROW(ctx, p, nextidx) \
do { \
size_t nextidx_ = (nextidx); \
size_t nelems_ = MP_TALLOC_ELEMS(p); \
if (nextidx_ >= nelems_) \
- p = talloc_realloc_size((ctx), p, \
- (nextidx_ + 1) * sizeof((p)[0]) * 2);\
+ (p) = talloc_realloc_size(ctx, p, \
+ (nextidx_ + 1) * sizeof((p)[0]) * 2);\
} while (0)
#define MP_TARRAY_APPEND(ctx, p, idxvar, ...) \
do { \
MP_TARRAY_GROW(ctx, p, idxvar); \
- p[idxvar] = (MP_EXPAND_ARGS(__VA_ARGS__)); \
- idxvar++; \
+ (p)[(idxvar)] = (MP_EXPAND_ARGS(__VA_ARGS__));\
+ (idxvar)++; \
+ } while (0)
+
+// Doesn't actually free any memory, or do any other talloc calls.
+#define MP_TARRAY_REMOVE_AT(p, idxvar, at) \
+ do { \
+ size_t at_ = (at); \
+ assert(at_ <= (idxvar)); \
+ memmove((p) + at_, (p) + at_ + 1, \
+ ((idxvar) - at_ - 1) * sizeof((p)[0])); \
+ (idxvar)--; \
} while (0)
#define talloc_struct(ctx, type, ...) \
diff --git a/core/mplayer.c b/core/mplayer.c
index 008a783d73..48375ee9df 100644
--- a/core/mplayer.c
+++ b/core/mplayer.c
@@ -2442,6 +2442,28 @@ no_video:
return 0;
}
+static bool filter_output_queued_frame(struct MPContext *mpctx)
+{
+ struct sh_video *sh_video = mpctx->sh_video;
+ struct vo *video_out = mpctx->video_out;
+
+ struct mp_image *img = vf_chain_output_queued_frame(sh_video->vfilter);
+ if (img && video_out->config_ok)
+ vo_draw_image(video_out, img);
+ talloc_free(img);
+
+ return !!img;
+}
+
+static void filter_video(struct MPContext *mpctx, struct mp_image *frame)
+{
+ struct sh_video *sh_video = mpctx->sh_video;
+
+ frame->pts = sh_video->pts;
+ vf_filter_frame(sh_video->vfilter, frame);
+ filter_output_queued_frame(mpctx);
+}
+
static double update_video_nocorrect_pts(struct MPContext *mpctx)
{
struct sh_video *sh_video = mpctx->sh_video;
@@ -2451,7 +2473,7 @@ static double update_video_nocorrect_pts(struct MPContext *mpctx)
// In nocorrect-pts mode there is no way to properly time these frames
if (vo_get_buffered_frame(video_out, 0) >= 0)
break;
- if (vf_output_queued_frame(sh_video->vfilter))
+ if (filter_output_queued_frame(mpctx))
break;
unsigned char *packet = NULL;
frame_time = sh_video->next_frame_time;
@@ -2476,7 +2498,7 @@ static double update_video_nocorrect_pts(struct MPContext *mpctx)
decoded_frame = decode_video(sh_video, sh_video->ds->current, packet,
in_size, framedrop_type, sh_video->pts);
if (decoded_frame) {
- filter_video(sh_video, decoded_frame, sh_video->pts);
+ filter_video(mpctx, decoded_frame);
}
break;
}
@@ -2528,9 +2550,7 @@ static double update_video(struct MPContext *mpctx)
while (1) {
if (vo_get_buffered_frame(video_out, false) >= 0)
break;
- // XXX Time used in this call is not counted in any performance
- // timer now
- if (vf_output_queued_frame(sh_video->vfilter))
+ if (filter_output_queued_frame(mpctx))
break;
int in_size = 0;
unsigned char *buf = NULL;
@@ -2557,11 +2577,11 @@ static double update_video(struct MPContext *mpctx)
mpctx->hrseek_framedrop = false;
int framedrop_type = mpctx->hrseek_framedrop ? 1 :
check_framedrop(mpctx, sh_video->frametime);
- void *decoded_frame = decode_video(sh_video, pkt, buf, in_size,
- framedrop_type, pts);
+ struct mp_image *decoded_frame =
+ decode_video(sh_video, pkt, buf, in_size, framedrop_type, pts);
if (decoded_frame) {
determine_frame_pts(mpctx);
- filter_video(sh_video, decoded_frame, sh_video->pts);
+ filter_video(mpctx, decoded_frame);
} else if (!pkt) {
if (vo_get_buffered_frame(video_out, true) < 0)
return -1;