>From 5ab49722f39a85a1dd763276ec391ec5b4be4a69 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 |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/modules/access/vdr.c b/modules/access/vdr.c
index 5429c96..6793a92 100644
--- a/modules/access/vdr.c
+++ b/modules/access/vdr.c
@@ -93,6 +93,9 @@ 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_("Chaptermark generation")
+#define GENERATE_CHAPTERS_LONGTEXT N_( \
+    "Chaptermark generation: none, all, odd" )
 
 vlc_module_begin ()
     set_category( CAT_INPUT )
@@ -100,10 +103,13 @@ 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_string( "vdr-generate-chapters", "all",
+        GENERATE_CHAPTERS_TEXT, GENERATE_CHAPTERS_LONGTEXT, true )
     set_capability( "access", 60 )
     add_shortcut( "vdr" )
     add_shortcut( "directory" )
@@ -270,8 +276,12 @@ static bool ScanDirectory( access_t *p_access, bool b_strict )
     ImportMeta( p_access );
 
     /* cut marks depend on meta data and file sizes */
-    ImportMarks( p_access );
-
+    char *psz_tmp = var_InheritString( p_access, "vdr-generate-chapters" );
+    if( !psz_tmp || ( psz_tmp && strcasecmp( psz_tmp, "none" )) )
+    {
+        ImportMarks( p_access );
+    }
+    free( psz_tmp );
     return true;
 }
 
@@ -849,6 +859,9 @@ static void ImportMarks( access_t *p_access )
     }
     p_marks->psz_name = strdup( _("VDR Cut Marks") );
 
+    char *psz_generate_chapters = var_InheritString( p_access, "vdr-generate-chapters" );
+    int i_marks_line_count = 1;
+
     /* offset for chapter positions */
     int i_chapter_offset = p_sys->fps / 1000 *
         var_InheritInteger( p_access, "vdr-chapter-offset" );
@@ -856,10 +869,25 @@ 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 ( psz_generate_chapters && !strcasecmp( psz_generate_chapters, "odd" )
+            && (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

