>From 63d51b2565a8dd35eb0eee4f2553993ed179236b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janne=20Kujanp=C3=A4=C3=A4?= <jikuja@iki.fi>
Date: Sat, 24 Sep 2011 23:57:15 +0300
Subject: [PATCH 2/2] vdr access: added option to alter chapter generation

Added option to disable chapter generation or only to to pick odd
numbered cutmarks from marks-file. Defaulting to generate one
chaptermark per one cutmark.
---
 modules/access/vdr.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/modules/access/vdr.c b/modules/access/vdr.c
index f42f4bd..00bbc4e 100644
--- a/modules/access/vdr.c
+++ b/modules/access/vdr.c
@@ -93,6 +93,12 @@ static void Close( vlc_object_t * );
 #define FPS_TEXT N_("Frame rate")
 #define FPS_LONGTEXT N_( \
     "Default frame rate for chapter import." )
+#define GENERATE_CHAPTERS_TEXT N_("Generate chapters from cutmarks")
+static const int pi_index[] = {0,1,2};
+
+static const char *const ppsz_indexes[] = { N_("all"),
+                                            N_("none"),
+                                            N_("only odd numbered") };
 
 vlc_module_begin ()
     set_category( CAT_INPUT )
@@ -100,10 +106,14 @@ vlc_module_begin ()
     set_help( HELP_TEXT )
     set_subcategory( SUBCAT_INPUT_ACCESS )
     set_description( N_("VDR recordings") )
+    add_usage_hint( N_("/file/to/vdr/recording/dir") )
     add_integer( "vdr-chapter-offset", 0,
         CHAPTER_OFFSET_TEXT, CHAPTER_OFFSET_LONGTEXT, true )
     add_float_with_range( "vdr-fps", 25, 1, 1000,
         FPS_TEXT, FPS_LONGTEXT, true )
+    add_integer( "vdr-generate-chapters", 0,
+        GENERATE_CHAPTERS_TEXT, 0, true )
+    change_integer_list( pi_index, ppsz_indexes )
     set_capability( "access", 60 )
     add_shortcut( "vdr" )
     add_shortcut( "directory" )
@@ -136,6 +146,7 @@ struct access_sys_t
 
     /* file format: true=TS, false=PES */
     bool b_ts_format;
+    int i_gen_chapters;
 };
 
 #define CURRENT_FILE_SIZE ARRAY_VAL(p_sys->file_sizes, p_sys->i_current_file)
@@ -272,9 +283,12 @@ static bool ScanDirectory( access_t *p_access, bool b_strict )
     /* import meta data etc. */
     ImportMeta( p_access );
 
+    p_sys->i_gen_chapters = var_InheritInteger( p_access, "vdr-generate-chapters" );
     /* cut marks depend on meta data and file sizes */
-    ImportMarks( p_access );
-
+    if( 1 != p_sys->i_gen_chapters )
+    {
+        ImportMarks( p_access );
+    }
     return true;
 }
 
@@ -852,6 +866,8 @@ static void ImportMarks( access_t *p_access )
     }
     p_marks->psz_name = strdup( _("VDR Cut Marks") );
 
+    int i_marks_line_count = 0;
+
     /* offset for chapter positions */
     int i_chapter_offset = p_sys->fps / 1000 *
         var_InheritInteger( p_access, "vdr-chapter-offset" );
@@ -859,10 +875,24 @@ static void ImportMarks( access_t *p_access )
     /* parse lines of the form "0:00:00.00 foobar" */
     char *line = NULL;
     size_t line_len;
+
+    /* loop and read single cutmark from marks-file */
     while( ReadLine( &line, &line_len, marksfile ) )
     {
+        i_marks_line_count++;
+        /* convert single cutmark timestamp into real frame number */
         int64_t i_frame = ParseFrameNumber( line, p_sys->fps );
 
+        /* Skip chapermark creation from even cutmark if option set to "odd" */
+        if ( 2 == p_sys->i_gen_chapters  && (i_marks_line_count % 2) == 0 )
+        {
+            msg_Dbg( p_access, "frame:  %"PRId64": even cutmark, not " \
+                "generating chaptermark", i_frame );
+            continue;
+        }
+
+        msg_Dbg( p_access, "frame:  %"PRId64": generating chaptermark", i_frame );
+
         /* move chapters (simple workaround for inaccurate cut marks) */
         if( i_frame > -i_chapter_offset )
             i_frame += i_chapter_offset;
-- 
1.7.6.3

