>From 7d3a365a05958cbcd10b7e1533db451f1ba87b94 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: smart autodetect for chapter generation

Disable chaptermark generation only if edited files are detected
and only for even numbered cutmarks
---
 modules/access/vdr.c |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/modules/access/vdr.c b/modules/access/vdr.c
index 867d909..1668f27 100644
--- a/modules/access/vdr.c
+++ b/modules/access/vdr.c
@@ -826,6 +826,7 @@ static void ImportMeta( access_t *p_access )
 static void ImportMarks( access_t *p_access )
 {
     access_sys_t *p_sys = p_access->p_sys;
+    seekpoint_t *sp = NULL;
 
     FILE *marksfile = OpenRelativeFile( p_access, "marks" );
     if( !marksfile )
@@ -855,10 +856,30 @@ static void ImportMarks( access_t *p_access )
     /* parse lines of the form "0:00:00.00 foobar" */
     char *line = NULL;
     size_t line_len;
+
+    int64_t i_last_frame = -1;
+
+    /*  read single cutmark from marks-file */
     while( ReadLine( &line, &line_len, marksfile ) )
     {
+        /* convert single cutmark timestamp into real frame number */
         int64_t i_frame = ParseFrameNumber( line, p_sys->fps );
 
+        /* Doesn't need  overflow check. 2^64 with 25FPS => 23,3*10^9 years
+         * After cut process VDR will retain cutmarks in marks-file even parts
+         * of the the is cut out. After processing there will be cutmarks near
+         * each other. With VDR 1.7.20 gap between marks is 12-15 frames.
+         * Autodetect when playing edited file and generate chaptermarks only
+         * for odd numbered cutmarks*/
+        if ( i_frame - i_last_frame < 45 )
+        {
+            msg_Info( p_access, "Detected %"PRId64" frames between cutmarks. "\
+                "Deleting previously generated chapter mark.", i_frame - i_last_frame );
+            TAB_REMOVE( p_marks->i_seekpoint, p_marks->seekpoint, sp );
+            vlc_seekpoint_Delete(sp);
+        }
+        i_last_frame = i_frame;
+
         /* move chapters (simple workaround for inaccurate cut marks) */
         if( i_frame > -i_chapter_offset )
             i_frame += i_chapter_offset;
@@ -874,7 +895,7 @@ static void ImportMarks( access_t *p_access )
             continue;
 
         /* add file sizes to get the "global" offset */
-        seekpoint_t *sp = vlc_seekpoint_New();
+        sp = vlc_seekpoint_New();
         if( !sp )
             continue;
         sp->i_time_offset = i_frame * (int64_t)( CLOCK_FREQ / p_sys->fps );
-- 
1.7.6.3

