[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39750] trunk/blender/source/blender/imbuf /intern: == Sequencer ==

Peter Schlaile peter at schlaile.de
Sun Aug 28 17:09:59 CEST 2011


Revision: 39750
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39750
Author:   schlaile
Date:     2011-08-28 15:09:58 +0000 (Sun, 28 Aug 2011)
Log Message:
-----------
== Sequencer ==

Forgotten files for proxy commit. Sorry.

Added Paths:
-----------
    trunk/blender/source/blender/imbuf/intern/IMB_indexer.h
    trunk/blender/source/blender/imbuf/intern/indexer.c
    trunk/blender/source/blender/imbuf/intern/indexer_dv.c

Added: trunk/blender/source/blender/imbuf/intern/IMB_indexer.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/IMB_indexer.h	                        (rev 0)
+++ trunk/blender/source/blender/imbuf/intern/IMB_indexer.h	2011-08-28 15:09:58 UTC (rev 39750)
@@ -0,0 +1,135 @@
+/**
+ * IMB_indexer.h
+ *
+ * $Id: IMB_indexer.h 
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Contributor(s): Peter Schlaile
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+
+#ifndef IMB_INDEXER_H
+#define IMB_INDEXER_H
+
+#ifdef WIN32
+#include <io.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "BKE_utildefines.h"
+#include "IMB_anim.h"
+
+/*
+  seperate animation index files to solve the following problems:
+
+  a) different timecodes within one file (like DTS/PTS, Timecode-Track, 
+     "implicit" timecodes within DV-files and HDV-files etc.)
+  b) seeking difficulties within ffmpeg for files with timestamp holes
+  c) broken files that miss several frames / have varying framerates
+  d) use proxies accordingly
+
+  ... we need index files, that provide us with 
+  
+  the binary(!) position, where we have to seek into the file *and*
+  the continuous frame number (ignoring the holes) starting from the 
+  beginning of the file, so that we know, which proxy frame to serve.
+
+  This index has to be only built once for a file and is written into
+  the BL_proxy directory structure for later reuse in different blender files.
+
+*/
+
+typedef struct anim_index_entry {
+	int frameno;
+	unsigned long long seek_pos;
+	unsigned long long seek_pos_dts;
+	unsigned long long pts;
+} anim_index_entry;
+
+struct anim_index {
+	char name[256];
+
+	int num_entries;
+	struct anim_index_entry * entries;
+};
+
+struct anim_index_builder;
+
+typedef struct anim_index_builder {
+	FILE * fp;
+	char name[FILE_MAXDIR + FILE_MAXFILE];
+	char temp_name[FILE_MAXDIR + FILE_MAXFILE];
+
+	void * private_data;
+
+	void (*delete_priv_data)(struct anim_index_builder * idx);
+	void (*proc_frame)(struct anim_index_builder * idx, 
+			   unsigned char * buffer,
+			   int data_size, 
+			   struct anim_index_entry * entry);
+} anim_index_builder;
+
+anim_index_builder * IMB_index_builder_create(const char * name);
+void IMB_index_builder_add_entry(anim_index_builder * fp, 
+				 int frameno, unsigned long long seek_pos,
+				 unsigned long long seek_pos_dts,
+				 unsigned long long pts);
+
+void IMB_index_builder_proc_frame(anim_index_builder * fp, 
+				  unsigned char * buffer,
+				  int data_size,
+				  int frameno, unsigned long long seek_pos,
+				  unsigned long long seek_pos_dts,
+				  unsigned long long pts);
+
+void IMB_index_builder_finish(anim_index_builder * fp, int rollback);
+
+struct anim_index * IMB_indexer_open(const char * name);
+unsigned long long IMB_indexer_get_seek_pos(
+	struct anim_index * idx, int frameno_index);
+unsigned long long IMB_indexer_get_seek_pos_dts(
+	struct anim_index * idx, int frameno_index);
+
+int IMB_indexer_get_frame_index(struct anim_index * idx, int frameno);
+unsigned long long IMB_indexer_get_pts(struct anim_index * idx, 
+				       int frame_index);
+int IMB_indexer_get_duration(struct anim_index * idx);
+
+int IMB_indexer_can_scan(struct anim_index * idx, 
+			 int old_frame_index, int new_frame_index);
+
+void IMB_indexer_close(struct anim_index * idx);
+
+void IMB_free_indices(struct anim * anim);
+
+int IMB_anim_index_get_frame_index(
+	struct anim * anim, IMB_Timecode_Type tc, int position);
+
+struct anim * IMB_anim_open_proxy(
+	struct anim * anim, IMB_Proxy_Size preview_size);
+struct anim_index * IMB_anim_open_index(
+	struct anim * anim, IMB_Timecode_Type tc);
+
+int IMB_proxy_size_to_array_index(IMB_Proxy_Size pr_size);
+int IMB_timecode_to_array_index(IMB_Timecode_Type tc);
+
+#endif

Added: trunk/blender/source/blender/imbuf/intern/indexer.c
===================================================================
--- trunk/blender/source/blender/imbuf/intern/indexer.c	                        (rev 0)
+++ trunk/blender/source/blender/imbuf/intern/indexer.c	2011-08-28 15:09:58 UTC (rev 39750)
@@ -0,0 +1,1135 @@
+/*
+ * $Id$
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+  * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Peter Schlaile <peter [at] schlaile [dot] de> 2011
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+*/
+
+#include "IMB_indexer.h"
+#include "IMB_anim.h"
+#include "AVI_avi.h"
+#include "imbuf.h"
+#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
+#include "BLI_blenlib.h"
+#include "BLI_math_base.h"
+#include "BLI_string.h"
+#include "MEM_guardedalloc.h"
+#include "DNA_userdef_types.h"
+#include "BKE_global.h"
+#include <stdlib.h>
+
+#ifdef WITH_FFMPEG
+
+#include "ffmpeg_compat.h"
+
+#endif //WITH_FFMPEG
+
+
+static char magic[] = "BlenMIdx";
+static char temp_ext [] = "_part";
+
+static int proxy_sizes[] = { IMB_PROXY_25, IMB_PROXY_50, IMB_PROXY_75,
+			     IMB_PROXY_100 };
+static float proxy_fac[] = { 0.25, 0.50, 0.75, 1.00 };
+static int tc_types[] = { IMB_TC_RECORD_RUN, IMB_TC_FREE_RUN,
+			  IMB_TC_INTERPOLATED_REC_DATE_FREE_RUN };
+
+#define INDEX_FILE_VERSION 1
+
+/* ---------------------------------------------------------------------- 
+   - special indexers
+   ---------------------------------------------------------------------- 
+ */
+
+extern void IMB_indexer_dv_new(anim_index_builder * idx);
+
+
+/* ----------------------------------------------------------------------
+   - time code index functions
+   ---------------------------------------------------------------------- */
+
+anim_index_builder * IMB_index_builder_create(const char * name)
+{
+
+	anim_index_builder * rv 
+		= MEM_callocN( sizeof(struct anim_index_builder), 
+			       "index builder");
+
+	fprintf(stderr, "Starting work on index: %s\n", name);
+
+	BLI_strncpy(rv->name, name, sizeof(rv->name));
+	BLI_strncpy(rv->temp_name, name, sizeof(rv->temp_name));
+
+	strcat(rv->temp_name, temp_ext);
+
+	BLI_make_existing_file(rv->temp_name);
+
+	rv->fp = fopen(rv->temp_name, "w");
+
+	if (!rv->fp) {
+		fprintf(stderr, "Couldn't open index target: %s! "
+			"Index build broken!\n", rv->temp_name);
+		MEM_freeN(rv);
+		return NULL;
+	}
+
+	fprintf(rv->fp, "%s%c%.3d", magic, (ENDIAN_ORDER==B_ENDIAN)?'V':'v',
+		INDEX_FILE_VERSION);
+
+	return rv;
+}
+
+void IMB_index_builder_add_entry(anim_index_builder * fp, 
+				 int frameno,unsigned long long seek_pos,
+				 unsigned long long seek_pos_dts,
+				 unsigned long long pts)
+{
+	fwrite(&frameno, sizeof(int), 1, fp->fp);
+	fwrite(&seek_pos, sizeof(unsigned long long), 1, fp->fp);
+	fwrite(&seek_pos_dts, sizeof(unsigned long long), 1, fp->fp);
+	fwrite(&pts, sizeof(unsigned long long), 1, fp->fp);
+}
+
+void IMB_index_builder_proc_frame(anim_index_builder * fp, 
+				  unsigned char * buffer,
+				  int data_size,
+				  int frameno, unsigned long long seek_pos,
+				  unsigned long long seek_pos_dts,
+				  unsigned long long pts)
+{
+	if (fp->proc_frame) {
+		anim_index_entry e;
+		e.frameno = frameno;
+		e.seek_pos = seek_pos;
+		e.seek_pos_dts = seek_pos_dts;
+		e.pts = pts;
+
+		fp->proc_frame(fp, buffer, data_size, &e);
+	} else {
+		IMB_index_builder_add_entry(fp, frameno, seek_pos,
+					    seek_pos_dts, pts);
+	}
+}
+
+void IMB_index_builder_finish(anim_index_builder * fp, int rollback)
+{
+	if (fp->delete_priv_data) {
+		fp->delete_priv_data(fp);
+	}
+
+	fclose(fp->fp);
+	
+	if (rollback) {
+		unlink(fp->temp_name);
+	} else {
+		rename(fp->temp_name, fp->name);
+	}
+
+	MEM_freeN(fp);
+}
+
+struct anim_index * IMB_indexer_open(const char * name)
+{
+	char header[13];
+	struct anim_index * idx;
+	FILE * fp = fopen(name, "rb");
+	int i;
+
+	if (!fp) {
+		return 0;
+	}
+
+	if (fread(header, 12, 1, fp) != 1) {
+		fclose(fp);
+		return 0;
+	}
+
+	header[12] = 0;
+
+	if (memcmp(header, magic, 8) != 0) {
+		fclose(fp);
+		return 0;
+	}
+
+	if (atoi(header+9) != INDEX_FILE_VERSION) {
+		fclose(fp);
+		return 0;
+	}
+
+	idx = MEM_callocN( sizeof(struct anim_index), "anim_index");
+
+	BLI_strncpy(idx->name, name, sizeof(idx->name));
+	
+       	fseek(fp, 0, SEEK_END);
+
+	idx->num_entries = (ftell(fp) - 12) 
+		/ (sizeof(int) // framepos
+		   + sizeof(unsigned long long) // seek_pos
+		   + sizeof(unsigned long long) // seek_pos_dts
+		   + sizeof(unsigned long long) // pts
+			);
+	
+	fseek(fp, 12, SEEK_SET);
+
+	idx->entries = MEM_callocN( sizeof(struct anim_index_entry) 
+				    * idx->num_entries, "anim_index_entries");
+
+	for (i = 0; i < idx->num_entries; i++) {
+		fread(&idx->entries[i].frameno, 
+		      sizeof(int), 1, fp);
+		fread(&idx->entries[i].seek_pos, 
+		      sizeof(unsigned long long), 1, fp);
+		fread(&idx->entries[i].seek_pos_dts, 
+		      sizeof(unsigned long long), 1, fp);
+		fread(&idx->entries[i].pts, 
+		      sizeof(unsigned long long), 1, fp);
+	}
+
+	if (((ENDIAN_ORDER == B_ENDIAN) != (header[8] == 'V'))) {
+		for (i = 0; i < idx->num_entries; i++) {
+			SWITCH_INT(idx->entries[i].frameno);
+			SWITCH_INT64(idx->entries[i].seek_pos);
+			SWITCH_INT64(idx->entries[i].seek_pos_dts);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list