[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55773] trunk/blender: Clip editor prefetch changes

Sergey Sharybin sergey.vfx at gmail.com
Thu Apr 4 11:50:38 CEST 2013


Revision: 55773
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55773
Author:   nazgul
Date:     2013-04-04 09:50:38 +0000 (Thu, 04 Apr 2013)
Log Message:
-----------
Clip editor prefetch changes

Made it an operator instead of automatic prefetching.
Filling the whole memory with frames is not always
desired behavior.

Now prefetching is available via P-key, or from Clip
panel in toolbox or from Clip menu.

Also enabled prefetching for non-proxied movies.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_clip.py
    trunk/blender/source/blender/blenkernel/intern/movieclip.c
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/space_clip/clip_draw.c
    trunk/blender/source/blender/editors/space_clip/clip_editor.c
    trunk/blender/source/blender/editors/space_clip/clip_intern.h
    trunk/blender/source/blender/editors/space_clip/clip_ops.c
    trunk/blender/source/blender/editors/space_clip/space_clip.c
    trunk/blender/source/blender/makesdna/DNA_movieclip_types.h

Modified: trunk/blender/release/scripts/startup/bl_ui/space_clip.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/release/scripts/startup/bl_ui/space_clip.py	2013-04-04 09:50:38 UTC (rev 55773)
@@ -886,6 +886,7 @@
 
         layout.operator("clip.set_viewport_background")
         layout.operator("clip.setup_tracking_scene")
+        layout.operator("clip.prefetch")
 
 
 class CLIP_MT_view(Menu):
@@ -945,6 +946,7 @@
         layout.operator("clip.open")
 
         if clip:
+            layout.operator("clip.prefetch")
             layout.operator("clip.reload")
             layout.menu("CLIP_MT_proxy")
 

Modified: trunk/blender/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/movieclip.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/blenkernel/intern/movieclip.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -1168,7 +1168,6 @@
 	free_buffers(clip);
 
 	clip->tracking.stabilization.ok = FALSE;
-	clip->prefetch_ok = FALSE;
 
 	/* update clip source */
 	detect_clip_source(clip);

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -6588,8 +6588,6 @@
 	clip->tracking.dopesheet.channels.first = clip->tracking.dopesheet.channels.last = NULL;
 	clip->tracking.dopesheet.coverage_segments.first = clip->tracking.dopesheet.coverage_segments.last = NULL;
 
-	clip->prefetch_ok = FALSE;
-
 	link_list(fd, &tracking->objects);
 	
 	for (object = tracking->objects.first; object; object = object->next) {

Modified: trunk/blender/source/blender/editors/space_clip/clip_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_draw.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/editors/space_clip/clip_draw.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -1456,8 +1456,6 @@
 	if (ibuf) {
 		draw_movieclip_buffer(C, sc, ar, ibuf, width, height, zoomx, zoomy);
 		IMB_freeImBuf(ibuf);
-
-		clip_start_prefetch_job(C);
 	}
 	else {
 		ED_region_grid_draw(ar, zoomx, zoomy);

Modified: trunk/blender/source/blender/editors/space_clip/clip_editor.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_editor.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/editors/space_clip/clip_editor.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -605,26 +605,9 @@
 } PrefetchThread;
 
 /* check whether pre-fetching is allowed */
-static bool check_prefetch_allowed(void)
+static bool check_prefetch_break(void)
 {
-	wmWindowManager *wm;
-
-	/* if there's any job started, better to leave all CPU and
-	 * HDD bandwidth to it
-	 *
-	 * also, display transform could be needed during playback,
-	 * so better to avoid prefetching in this case and reserve
-	 * all the power for display transform
-	 */
-	for (wm = G.main->wm.first; wm; wm = wm->id.next) {
-		if (WM_jobs_has_running_except(wm, WM_JOB_TYPE_CLIP_PREFETCH))
-			return false;
-
-		if (ED_screen_animation_playing(wm))
-			return false;
-	}
-
-	return true;
+	return G.is_break;
 }
 
 /* read file for specified frame number to the memory */
@@ -706,7 +689,7 @@
 	unsigned char *mem = NULL;
 
 	BLI_spin_lock(&queue->spin);
-	if (!*queue->stop && check_prefetch_allowed() &&
+	if (!*queue->stop && !check_prefetch_break() &&
 	    IN_RANGE_INCL(queue->current_frame, queue->start_frame, queue->end_frame))
 	{
 		int current_frame;
@@ -848,7 +831,7 @@
 	MovieClipUser user = {0};
 	ImBuf *ibuf;
 
-	if (!check_prefetch_allowed() || *stop)
+	if (check_prefetch_break() || *stop)
 		return false;
 
 	user.framenr = frame;
@@ -968,26 +951,6 @@
 	int first_uncached_frame, end_frame;
 	int clip_len;
 
-	if (clip->prefetch_ok)
-		return true;
-
-	if (clip->source == MCLIP_SRC_MOVIE) {
-		/* for movies we only prefetch undistorted proxy,
-		 * in other cases prefetching could lead to issues
-		 * due to timecodes issues.
-		 */
-
-		if (clip->flag & MCLIP_USE_PROXY) {
-			MovieClipUser *user = &sc->user;
-
-			if ((user->render_flag & MCLIP_PROXY_RENDER_UNDISTORT) == 0)
-				return true;
-		}
-		else {
-			return true;
-		}
-	}
-
 	clip_len = BKE_movieclip_get_duration(clip);
 
 	/* check whether all the frames from prefetch range are cached */
@@ -1016,7 +979,6 @@
 	wmJob *wm_job;
 	PrefetchJob *pj;
 	SpaceClip *sc = CTX_wm_space_clip(C);
-	MovieClip *clip = ED_space_clip_get_clip(sc);
 
 	if (prefetch_check_early_out(C))
 		return;
@@ -1024,17 +986,6 @@
 	wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), CTX_wm_area(C), "Prefetching",
 	                     WM_JOB_PROGRESS, WM_JOB_TYPE_CLIP_PREFETCH);
 
-	if (WM_jobs_is_running(wm_job)) {
-		/* if job is already running, it'll call clip editor redraw when
-		 * it's finished, so cache line is nicely updated
-		 * this will also trigger call of this function, which will ensure
-		 * all needed frames are prefetched
-		 */
-		return;
-	}
-
-	clip->prefetch_ok = true;
-
 	/* create new job */
 	pj = MEM_callocN(sizeof(PrefetchJob), "prefetch job");
 	pj->clip = ED_space_clip_get_clip(sc);
@@ -1045,9 +996,11 @@
 	pj->render_flag = sc->user.render_flag;
 
 	WM_jobs_customdata_set(wm_job, pj, prefetch_freejob);
-	WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP, 0);
+	WM_jobs_timer(wm_job, 0.2, NC_MOVIECLIP | ND_DISPLAY, 0);
 	WM_jobs_callbacks(wm_job, prefetch_startjob, NULL, NULL, NULL);
 
+	G.is_break = FALSE;
+
 	/* and finally start the job */
 	WM_jobs_start(CTX_wm_manager(C), wm_job);
 }

Modified: trunk/blender/source/blender/editors/space_clip/clip_intern.h
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_intern.h	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/editors/space_clip/clip_intern.h	2013-04-04 09:50:38 UTC (rev 55773)
@@ -108,6 +108,8 @@
 
 void CLIP_OT_view_ndof(struct wmOperatorType *ot);
 
+void CLIP_OT_prefetch(struct wmOperatorType *ot);
+
 /* clip_toolbar.c */
 struct ARegion *ED_clip_has_properties_region(struct ScrArea *sa);
 void CLIP_OT_tools(struct wmOperatorType *ot);

Modified: trunk/blender/source/blender/editors/space_clip/clip_ops.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/clip_ops.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/editors/space_clip/clip_ops.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -1378,6 +1378,47 @@
 	ot->invoke = clip_view_ndof_invoke;
 }
 
+/********************** Prefetch operator *********************/
+
+static int clip_prefetch_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+	/* no running blender, remove handler and pass through */
+	if (0 == WM_jobs_test(CTX_wm_manager(C), CTX_wm_area(C), WM_JOB_TYPE_CLIP_PREFETCH))
+		return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
+
+	/* running render */
+	switch (event->type) {
+		case ESCKEY:
+			return OPERATOR_RUNNING_MODAL;
+			break;
+	}
+
+	return OPERATOR_PASS_THROUGH;
+}
+
+static int clip_prefetch_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(_event))
+{
+	clip_start_prefetch_job(C);
+
+	/* add modal handler for ESC */
+	WM_event_add_modal_handler(C, op);
+
+	return OPERATOR_RUNNING_MODAL;
+}
+
+void CLIP_OT_prefetch(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Prefetch Frames";
+	ot->idname = "CLIP_OT_prefetch";
+	ot->description = "Prefetch frames from disk for faster playback/tracking";
+
+	/* api callbacks */
+	ot->poll = ED_space_clip_view_clip_poll;
+	ot->invoke = clip_prefetch_invoke;
+	ot->modal = clip_prefetch_modal;
+}
+
 /********************** macroses *********************/
 
 void ED_operatormacros_clip(void)

Modified: trunk/blender/source/blender/editors/space_clip/space_clip.c
===================================================================
--- trunk/blender/source/blender/editors/space_clip/space_clip.c	2013-04-04 09:48:06 UTC (rev 55772)
+++ trunk/blender/source/blender/editors/space_clip/space_clip.c	2013-04-04 09:50:38 UTC (rev 55773)
@@ -236,16 +236,6 @@
 	}
 }
 
-static void clip_prefetch_tag_refresh(ScrArea *sa)
-{
-	SpaceClip *sc = (SpaceClip *) sa->spacedata.first;
-	MovieClip *clip = ED_space_clip_get_clip(sc);
-
-	if (clip) {
-		clip->prefetch_ok = FALSE;
-	}
-}
-
 /* ******************** default callbacks for clip space ***************** */
 
 static SpaceLink *clip_new(const bContext *C)
@@ -358,7 +348,6 @@
 			switch (wmn->data) {
 				case ND_FRAME:
 					clip_scopes_tag_refresh(sa);
-					clip_prefetch_tag_refresh(sa);
 					/* no break! */
 
 				case ND_FRAME_RANGE:
@@ -367,19 +356,11 @@
 			}
 			break;
 		case NC_MOVIECLIP:
-			if (wmn->data == 0 && wmn->action == 0) {
-				/* a nit funky, happens from prefetch job to update
-				 * cache line and job progress
-				 */
-				ED_area_tag_redraw(sa);
-			}
-
 			switch (wmn->data) {
 				case ND_DISPLAY:
 				case ND_SELECT:
 					clip_scopes_tag_refresh(sa);
 					ED_area_tag_redraw(sa);
-					clip_prefetch_tag_refresh(sa);
 					break;
 			}
 			switch (wmn->action) {
@@ -423,7 +404,6 @@
 		case NC_SCREEN:
 			switch (wmn->data) {
 				case ND_ANIMPLAY:
-					clip_prefetch_tag_refresh(sa);
 					ED_area_tag_redraw(sa);
 					break;
 			}
@@ -432,7 +412,6 @@
 			if (wmn->data == ND_SPACE_CLIP) {
 				clip_scopes_tag_refresh(sa);
 				clip_stabilization_tag_refresh(sa);
-				clip_prefetch_tag_refresh(sa);
 				ED_area_tag_redraw(sa);
 			}
 			break;
@@ -442,10 +421,6 @@
 				ED_area_tag_redraw(sa);
 			}
 			break;
-		case NC_WM:
-			if (wmn->data == ND_FILEREAD)
-				clip_prefetch_tag_refresh(sa);
-			break;
 	}
 }
 
@@ -465,6 +440,7 @@
 	WM_operatortype_append(CLIP_OT_rebuild_proxy);
 	WM_operatortype_append(CLIP_OT_mode_set);
 	WM_operatortype_append(CLIP_OT_view_ndof);
+	WM_operatortype_append(CLIP_OT_prefetch);
 
 	/* ** clip_toolbar.c ** */
 	WM_operatortype_append(CLIP_OT_tools);
@@ -598,6 +574,9 @@
 	kmi = WM_keymap_add_item(keymap, "CLIP_OT_set_solver_keyframe", EKEY, KM_PRESS, 0, 0);
 	RNA_enum_set(kmi->ptr, "keyframe", 1);
 
+	/* io/playback */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list