1 /*****************************************************************************
2 * vdr.c: VDR recordings access plugin
3 *****************************************************************************
4 * Copyright (C) 2010 Tobias Güntner
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
22 VDR splits recordings into multiple files and stores each recording in a
23 separate directory. If VLC opens a normal directory, the filesystem module
24 will add all files to the playlist. If, however, VLC opens a VDR recording,
25 this module will join all files within that directory and provide a single
26 continuous stream instead.
28 VDR recordings have either of two directory layouts:
30 /path/to/0000-00-00.00.00.00.00.rec/
31 001.vdr, 002.vdr, 003.vdr, ...
32 index.vdr, info.vdr, marks.vdr, ...
34 /path/to/0000-00-00.00.00.0-0.rec/
35 00001.ts, 00002.ts, 00003.ts, ...
36 index, info, marks, ...
37 See http://www.vdr-wiki.de/ and http://www.tvdr.de/ for more information.
40 /*****************************************************************************
42 *****************************************************************************/
48 #include <sys/types.h>
57 #include <vlc_common.h>
58 #include <vlc_plugin.h>
59 #include <vlc_access.h>
60 #include <vlc_input.h>
62 #include <vlc_charset.h>
63 #include <vlc_dialog.h>
64 #include <vlc_configuration.h>
66 /*****************************************************************************
68 *****************************************************************************/
69 static int Open ( vlc_object_t
* );
70 static void Close( vlc_object_t
* );
72 #define HELP_TEXT N_("Support for VDR recordings (http://www.tvdr.de/).")
74 #define CHAPTER_OFFSET_TEXT N_("Chapter offset in ms")
75 #define CHAPTER_OFFSET_LONGTEXT N_( \
76 "Move all chapters. This value should be set in milliseconds." )
78 #define FPS_TEXT N_("Frame rate")
79 #define FPS_LONGTEXT N_( \
80 "Default frame rate for chapter import." )
83 set_category( CAT_INPUT
)
84 set_shortname( N_("VDR") )
86 set_subcategory( SUBCAT_INPUT_ACCESS
)
87 set_description( N_("VDR recordings") )
88 add_integer( "vdr-chapter-offset", 0,
89 CHAPTER_OFFSET_TEXT
, CHAPTER_OFFSET_LONGTEXT
, true )
90 add_float_with_range( "vdr-fps", 25, 1, 1000,
91 FPS_TEXT
, FPS_LONGTEXT
, true )
92 set_capability( "access", 60 )
94 add_shortcut( "directory" )
96 add_shortcut( "file" )
97 set_callbacks( Open
, Close
)
100 /*****************************************************************************
101 * Local prototypes, constants, structures
102 *****************************************************************************/
104 /* minimum chapter size in seconds */
105 #define MIN_CHAPTER_SIZE 5
107 TYPEDEF_ARRAY( uint64_t, size_array_t
);
111 /* file sizes of all parts */
112 size_array_t file_sizes
;
113 uint64_t size
; /* total size */
115 /* index and fd of current open file */
116 unsigned i_current_file
;
123 input_title_t
*p_marks
;
124 unsigned cur_seekpoint
;
127 /* file format: true=TS, false=PES */
131 #define CURRENT_FILE_SIZE ARRAY_VAL(p_sys->file_sizes, p_sys->i_current_file)
132 #define FILE_SIZE(pos) ARRAY_VAL(p_sys->file_sizes, pos)
133 #define FILE_COUNT (unsigned)p_sys->file_sizes.i_size
135 static int Control( access_t
*, int, va_list );
136 static ssize_t
Read( access_t
*p_access
, uint8_t *p_buffer
, size_t i_len
);
137 static int Seek( access_t
*p_access
, uint64_t i_pos
);
138 static void FindSeekpoint( access_t
*p_access
);
139 static bool ScanDirectory( access_t
*p_access
);
140 static char *GetFilePath( access_t
*p_access
, unsigned i_file
);
141 static bool ImportNextFile( access_t
*p_access
);
142 static bool SwitchFile( access_t
*p_access
, unsigned i_file
);
143 static void OptimizeForRead( int fd
);
144 static void UpdateFileSize( access_t
*p_access
);
145 static FILE *OpenRelativeFile( access_t
*p_access
, const char *psz_file
);
146 static bool ReadLine( char **ppsz_line
, size_t *pi_size
, FILE *p_file
);
147 static void ImportMeta( access_t
*p_access
);
148 static void ImportMarks( access_t
*p_access
);
149 static bool ReadIndexRecord( FILE *p_file
, bool b_ts
, int64_t i_frame
,
150 uint64_t *pi_offset
, uint16_t *pi_file_num
);
151 static int64_t ParseFrameNumber( const char *psz_line
, float fps
);
152 static const char *BaseName( const char *psz_path
);
154 /*****************************************************************************
156 *****************************************************************************/
157 static int Open( vlc_object_t
*p_this
)
159 access_t
*p_access
= (access_t
*)p_this
;
161 if( !p_access
->psz_filepath
)
164 /* Some tests can be skipped if this module was explicitly requested.
165 * That way, the user can play "corrupt" recordings if necessary
166 * and we can avoid false positives in the general case. */
167 bool b_strict
= strcmp( p_access
->psz_access
, "vdr" );
169 /* Do a quick test based on the directory name to see if this
170 * directory might contain a VDR recording. We can be reasonably
171 * sure if ScanDirectory() actually finds files. */
174 char psz_extension
[4];
176 const char *psz_name
= BaseName( p_access
->psz_filepath
);
177 if( sscanf( psz_name
, "%*u-%*u-%*u.%*u.%*u.%*u%*[-.]%*u.%3s%n",
178 psz_extension
, &i_length
) != 1 || strcasecmp( psz_extension
, "rec" ) ||
179 ( psz_name
[i_length
] != DIR_SEP_CHAR
&& psz_name
[i_length
] != '\0' ) )
183 /* Only directories can be recordings */
185 if( vlc_stat( p_access
->psz_filepath
, &st
) ||
186 !S_ISDIR( st
.st_mode
) )
190 STANDARD_READ_ACCESS_INIT
;
192 p_sys
->cur_seekpoint
= 0;
193 p_sys
->fps
= var_InheritFloat( p_access
, "vdr-fps" );
194 ARRAY_INIT( p_sys
->file_sizes
);
196 /* Import all files and prepare playback. */
197 if( !ScanDirectory( p_access
) ||
198 !SwitchFile( p_access
, 0 ) )
207 /*****************************************************************************
208 * Close files and free resources
209 *****************************************************************************/
210 static void Close( vlc_object_t
* p_this
)
212 access_t
*p_access
= (access_t
*)p_this
;
213 access_sys_t
*p_sys
= p_access
->p_sys
;
215 if( p_sys
->fd
!= -1 )
217 ARRAY_RESET( p_sys
->file_sizes
);
220 vlc_meta_Delete( p_sys
->p_meta
);
222 vlc_input_title_Delete( p_sys
->p_marks
);
226 /*****************************************************************************
227 * Determine format and import files
228 *****************************************************************************/
229 static bool ScanDirectory( access_t
*p_access
)
231 access_sys_t
*p_sys
= p_access
->p_sys
;
233 /* find first part and determine directory format */
234 p_sys
->b_ts_format
= true;
235 if( !ImportNextFile( p_access
) )
237 p_sys
->b_ts_format
= !p_sys
->b_ts_format
;
238 if( !ImportNextFile( p_access
) )
242 /* get all remaining parts */
243 while( ImportNextFile( p_access
) )
246 /* import meta data etc. */
247 ImportMeta( p_access
);
249 /* cut marks depend on meta data and file sizes */
250 ImportMarks( p_access
);
255 /*****************************************************************************
256 * Control input stream
257 *****************************************************************************/
258 static int Control( access_t
*p_access
, int i_query
, va_list args
)
260 access_sys_t
*p_sys
= p_access
->p_sys
;
261 input_title_t
***ppp_title
;
268 case ACCESS_CAN_SEEK
:
269 case ACCESS_CAN_FASTSEEK
:
270 case ACCESS_CAN_PAUSE
:
271 case ACCESS_CAN_CONTROL_PACE
:
272 *va_arg( args
, bool* ) = true;
275 case ACCESS_GET_PTS_DELAY
:
276 pi64
= va_arg( args
, int64_t * );
277 *pi64
= INT64_C(1000)
278 * var_InheritInteger( p_access
, "file-caching" );
281 case ACCESS_SET_PAUSE_STATE
:
285 case ACCESS_GET_TITLE_INFO
:
286 /* return a copy of our seek points */
287 if( !p_sys
->p_marks
)
289 ppp_title
= va_arg( args
, input_title_t
*** );
290 *va_arg( args
, int* ) = 1;
291 *ppp_title
= malloc( sizeof( input_title_t
* ) );
294 **ppp_title
= vlc_input_title_Duplicate( p_sys
->p_marks
);
297 case ACCESS_GET_TITLE
:
298 *va_arg( args
, unsigned * ) = 0;
301 case ACCESS_GET_SEEKPOINT
:
302 *va_arg( args
, unsigned * ) = p_sys
->cur_seekpoint
;
305 case ACCESS_SET_TITLE
:
306 /* ignore - only one title */
309 case ACCESS_SET_SEEKPOINT
:
310 i
= va_arg( args
, int );
311 return Seek( p_access
, p_sys
->p_marks
->seekpoint
[i
]->i_byte_offset
);
313 case ACCESS_GET_META
:
316 p_meta
= va_arg( args
, vlc_meta_t
* );
317 vlc_meta_Merge( p_meta
, p_sys
->p_meta
);
326 /*****************************************************************************
327 * Read and concatenate files
328 *****************************************************************************/
329 static ssize_t
Read( access_t
*p_access
, uint8_t *p_buffer
, size_t i_len
)
331 access_sys_t
*p_sys
= p_access
->p_sys
;
333 if( p_sys
->fd
== -1 )
336 p_access
->info
.b_eof
= true;
340 ssize_t i_ret
= read( p_sys
->fd
, p_buffer
, i_len
);
345 p_access
->info
.i_pos
+= i_ret
;
346 UpdateFileSize( p_access
);
347 FindSeekpoint( p_access
);
350 else if( i_ret
== 0 )
352 /* check for new files in case the recording is still active */
353 if( p_sys
->i_current_file
>= FILE_COUNT
- 1 )
354 ImportNextFile( p_access
);
356 SwitchFile( p_access
, p_sys
->i_current_file
+ 1 );
359 else if( errno
== EINTR
)
361 /* try again later */
366 /* abort on read error */
367 msg_Err( p_access
, "failed to read (%s)", vlc_strerror_c(errno
) );
368 dialog_Fatal( p_access
, _("File reading failed"),
369 _("VLC could not read the file (%s)."),
370 vlc_strerror(errno
) );
371 SwitchFile( p_access
, -1 );
376 /*****************************************************************************
377 * Seek to a specific location in a file
378 *****************************************************************************/
379 static int Seek( access_t
*p_access
, uint64_t i_pos
)
381 access_sys_t
*p_sys
= p_access
->p_sys
;
383 /* might happen if called by ACCESS_SET_SEEKPOINT */
384 i_pos
= __MIN( i_pos
, p_sys
->size
);
386 p_access
->info
.i_pos
= i_pos
;
387 p_access
->info
.b_eof
= false;
389 /* find correct chapter */
390 FindSeekpoint( p_access
);
392 /* find correct file */
394 while( i_file
< FILE_COUNT
- 1 &&
395 i_pos
>= FILE_SIZE( i_file
) )
397 i_pos
-= FILE_SIZE( i_file
);
400 if( !SwitchFile( p_access
, i_file
) )
403 /* adjust position within that file */
404 return lseek( p_sys
->fd
, i_pos
, SEEK_SET
) != -1 ?
405 VLC_SUCCESS
: VLC_EGENERIC
;
408 /*****************************************************************************
409 * Change the chapter index to match the current position
410 *****************************************************************************/
411 static void FindSeekpoint( access_t
*p_access
)
413 access_sys_t
*p_sys
= p_access
->p_sys
;
414 if( !p_sys
->p_marks
)
417 int new_seekpoint
= p_sys
->cur_seekpoint
;
418 if( p_access
->info
.i_pos
< (uint64_t)p_sys
->p_marks
->
419 seekpoint
[p_sys
->cur_seekpoint
]->i_byte_offset
)
421 /* i_pos moved backwards, start fresh */
425 /* only need to check the following seekpoints */
426 while( new_seekpoint
+ 1 < p_sys
->p_marks
->i_seekpoint
&&
427 p_access
->info
.i_pos
>= (uint64_t)p_sys
->p_marks
->
428 seekpoint
[new_seekpoint
+ 1]->i_byte_offset
)
433 p_sys
->cur_seekpoint
= new_seekpoint
;
436 /*****************************************************************************
437 * Returns the path of a certain part
438 *****************************************************************************/
439 static char *GetFilePath( access_t
*p_access
, unsigned i_file
)
442 if( asprintf( &psz_path
, p_access
->p_sys
->b_ts_format
?
443 "%s" DIR_SEP
"%05u.ts" : "%s" DIR_SEP
"%03u.vdr",
444 p_access
->psz_filepath
, i_file
+ 1 ) == -1 )
450 /*****************************************************************************
451 * Check if another part exists and import it
452 *****************************************************************************/
453 static bool ImportNextFile( access_t
*p_access
)
455 access_sys_t
*p_sys
= p_access
->p_sys
;
457 char *psz_path
= GetFilePath( p_access
, FILE_COUNT
);
462 if( vlc_stat( psz_path
, &st
) )
464 msg_Dbg( p_access
, "could not stat %s: %s", psz_path
,
465 vlc_strerror_c(errno
) );
469 if( !S_ISREG( st
.st_mode
) )
471 msg_Dbg( p_access
, "%s is not a regular file", psz_path
);
475 msg_Dbg( p_access
, "%s exists", psz_path
);
478 ARRAY_APPEND( p_sys
->file_sizes
, st
.st_size
);
479 p_sys
->size
+= st
.st_size
;
484 /*****************************************************************************
485 * Close the current file and open another
486 *****************************************************************************/
487 static bool SwitchFile( access_t
*p_access
, unsigned i_file
)
489 access_sys_t
*p_sys
= p_access
->p_sys
;
491 /* requested file already open? */
492 if( p_sys
->fd
!= -1 && p_sys
->i_current_file
== i_file
)
496 if( p_sys
->fd
!= -1 )
503 if( i_file
>= FILE_COUNT
)
505 p_sys
->i_current_file
= i_file
;
508 char *psz_path
= GetFilePath( p_access
, i_file
);
511 p_sys
->fd
= vlc_open( psz_path
, O_RDONLY
);
513 if( p_sys
->fd
== -1 )
515 msg_Err( p_access
, "Failed to open %s: %s", psz_path
,
516 vlc_strerror_c(errno
) );
520 /* cannot handle anything except normal files */
522 if( fstat( p_sys
->fd
, &st
) || !S_ISREG( st
.st_mode
) )
524 msg_Err( p_access
, "%s is not a regular file", psz_path
);
528 OptimizeForRead( p_sys
->fd
);
530 msg_Dbg( p_access
, "opened %s", psz_path
);
535 dialog_Fatal (p_access
, _("File reading failed"), _("VLC could not"
536 " open the file \"%s\" (%s)."), psz_path
, vlc_strerror(errno
) );
537 if( p_sys
->fd
!= -1 )
546 /*****************************************************************************
547 * Some tweaks to speed up read()
548 *****************************************************************************/
549 static void OptimizeForRead( int fd
)
551 /* cf. Open() in file access module */
553 #ifdef HAVE_POSIX_FADVISE
554 posix_fadvise( fd
, 0, 4096, POSIX_FADV_WILLNEED
);
555 posix_fadvise( fd
, 0, 0, POSIX_FADV_NOREUSE
);
558 fcntl( fd
, F_RDAHEAD
, 1 );
561 fcntl( fd
, F_NOCACHE
, 0 );
565 /*****************************************************************************
566 * Fix size if the (last) part is still growing
567 *****************************************************************************/
568 static void UpdateFileSize( access_t
*p_access
)
570 access_sys_t
*p_sys
= p_access
->p_sys
;
573 if( p_sys
->size
>= p_access
->info
.i_pos
)
576 /* TODO: not sure if this can happen or what to do in this case */
577 if( fstat( p_sys
->fd
, &st
) )
579 if( (uint64_t)st
.st_size
<= CURRENT_FILE_SIZE
)
582 p_sys
->size
-= CURRENT_FILE_SIZE
;
583 CURRENT_FILE_SIZE
= st
.st_size
;
584 p_sys
->size
+= CURRENT_FILE_SIZE
;
587 /*****************************************************************************
588 * Open file relative to base directory for reading.
589 *****************************************************************************/
590 static FILE *OpenRelativeFile( access_t
*p_access
, const char *psz_file
)
592 /* build path and add extension */
594 if( asprintf( &psz_path
, "%s" DIR_SEP
"%s%s",
595 p_access
->psz_filepath
, psz_file
,
596 p_access
->p_sys
->b_ts_format
? "" : ".vdr" ) == -1 )
599 FILE *file
= vlc_fopen( psz_path
, "rb" );
601 msg_Warn( p_access
, "Failed to open %s: %s", psz_path
,
602 vlc_strerror_c(errno
) );
608 /*****************************************************************************
609 * Read a line of text. Returns false on error or EOF.
610 *****************************************************************************/
611 static bool ReadLine( char **ppsz_line
, size_t *pi_size
, FILE *p_file
)
613 ssize_t read
= getline( ppsz_line
, pi_size
, p_file
);
617 /* automatically free buffer on eof */
623 if( read
> 0 && (*ppsz_line
)[ read
- 1 ] == '\n' )
624 (*ppsz_line
)[ read
- 1 ] = '\0';
625 EnsureUTF8( *ppsz_line
);
630 /*****************************************************************************
632 *****************************************************************************/
633 static void ImportMeta( access_t
*p_access
)
635 access_sys_t
*p_sys
= p_access
->p_sys
;
637 FILE *infofile
= OpenRelativeFile( p_access
, "info" );
641 vlc_meta_t
*p_meta
= vlc_meta_New();
642 p_sys
->p_meta
= p_meta
;
651 char *psz_title
= NULL
, *psz_smalltext
= NULL
, *psz_date
= NULL
;
653 while( ReadLine( &line
, &line_len
, infofile
) )
655 if( !isalpha( (unsigned char)line
[0] ) || line
[1] != ' ' )
659 char *text
= line
+ 2;
663 char *psz_name
= strchr( text
, ' ' );
667 vlc_meta_AddExtra( p_meta
, "Channel", psz_name
+ 1 );
669 vlc_meta_AddExtra( p_meta
, "Transponder", text
);
672 else if( tag
== 'E' )
674 unsigned i_id
, i_start
, i_length
;
675 if( sscanf( text
, "%u %u %u", &i_id
, &i_start
, &i_length
) == 3 )
679 time_t start
= i_start
;
680 localtime_r( &start
, &tm
);
683 strftime( str
, sizeof(str
), "%Y-%m-%d %H:%M", &tm
);
684 vlc_meta_AddExtra( p_meta
, "Date", str
);
686 psz_date
= strdup( str
);
688 /* display in minutes */
689 i_length
= ( i_length
+ 59 ) / 60;
690 snprintf( str
, sizeof(str
), "%u:%02u", i_length
/ 60, i_length
% 60 );
691 vlc_meta_AddExtra( p_meta
, "Duration", str
);
695 else if( tag
== 'T' )
698 psz_title
= strdup( text
);
699 vlc_meta_AddExtra( p_meta
, "Title", text
);
702 else if( tag
== 'S' )
704 free( psz_smalltext
);
705 psz_smalltext
= strdup( text
);
706 vlc_meta_AddExtra( p_meta
, "Info", text
);
709 else if( tag
== 'D' )
711 for( char *p
= text
; *p
; ++p
)
716 vlc_meta_SetDescription( p_meta
, text
);
719 /* FPS are required to convert between timestamps and frames */
720 else if( tag
== 'F' )
722 float fps
= atof( text
);
725 vlc_meta_AddExtra( p_meta
, "Frame Rate", text
);
728 else if( tag
== 'P' )
730 vlc_meta_AddExtra( p_meta
, "Priority", text
);
733 else if( tag
== 'L' )
735 vlc_meta_AddExtra( p_meta
, "Lifetime", text
);
739 /* create a meaningful title */
741 ( psz_title
? strlen( psz_title
) : 0 ) +
742 ( psz_smalltext
? strlen( psz_smalltext
) : 0 ) +
743 ( psz_date
? strlen( psz_date
) : 0 );
744 char *psz_display
= malloc( i_len
);
750 strcat( psz_display
, psz_title
);
751 if( psz_title
&& psz_smalltext
)
752 strcat( psz_display
, " - " );
754 strcat( psz_display
, psz_smalltext
);
755 if( ( psz_title
|| psz_smalltext
) && psz_date
)
757 strcat( psz_display
, " (" );
758 strcat( psz_display
, psz_date
);
759 strcat( psz_display
, ")" );
762 vlc_meta_SetTitle( p_meta
, psz_display
);
767 free( psz_smalltext
);
773 /*****************************************************************************
774 * Import cut marks and convert them to seekpoints (chapters).
775 *****************************************************************************/
776 static void ImportMarks( access_t
*p_access
)
778 access_sys_t
*p_sys
= p_access
->p_sys
;
780 FILE *marksfile
= OpenRelativeFile( p_access
, "marks" );
784 FILE *indexfile
= OpenRelativeFile( p_access
, "index" );
791 /* get the length of this recording (index stores 8 bytes per frame) */
793 if( fstat( fileno( indexfile
), &st
) )
799 int64_t i_frame_count
= st
.st_size
/ 8;
801 /* Put all cut marks in a "dummy" title */
802 input_title_t
*p_marks
= vlc_input_title_New();
809 p_marks
->psz_name
= strdup( _("VDR Cut Marks") );
810 p_marks
->i_length
= i_frame_count
* (int64_t)( CLOCK_FREQ
/ p_sys
->fps
);
811 p_marks
->i_size
= p_sys
->size
;
813 /* offset for chapter positions */
814 int i_chapter_offset
= p_sys
->fps
/ 1000 *
815 var_InheritInteger( p_access
, "vdr-chapter-offset" );
817 /* minimum chapter size in frames */
818 int i_min_chapter_size
= p_sys
->fps
* MIN_CHAPTER_SIZE
;
820 /* the last chapter started at this frame (init to 0 so
821 * we skip useless chapters near the beginning as well) */
822 int64_t i_prev_chapter
= 0;
824 /* parse lines of the form "0:00:00.00 foobar" */
827 while( ReadLine( &line
, &line_len
, marksfile
) )
829 int64_t i_frame
= ParseFrameNumber( line
, p_sys
->fps
);
831 /* skip chapters which are near the end or too close to each other */
832 if( i_frame
- i_prev_chapter
< i_min_chapter_size
||
833 i_frame
>= i_frame_count
- i_min_chapter_size
)
835 i_prev_chapter
= i_frame
;
837 /* move chapters (simple workaround for inaccurate cut marks) */
838 if( i_frame
> -i_chapter_offset
)
839 i_frame
+= i_chapter_offset
;
844 uint16_t i_file_number
;
845 if( !ReadIndexRecord( indexfile
, p_sys
->b_ts_format
,
846 i_frame
, &i_offset
, &i_file_number
) )
848 if( i_file_number
< 1 || i_file_number
> FILE_COUNT
)
851 /* add file sizes to get the "global" offset */
852 seekpoint_t
*sp
= vlc_seekpoint_New();
855 sp
->i_time_offset
= i_frame
* (int64_t)( CLOCK_FREQ
/ p_sys
->fps
);
856 sp
->i_byte_offset
= i_offset
;
857 for( int i
= 0; i
+ 1 < i_file_number
; ++i
)
858 sp
->i_byte_offset
+= FILE_SIZE( i
);
859 sp
->psz_name
= strdup( line
);
861 TAB_APPEND( p_marks
->i_seekpoint
, p_marks
->seekpoint
, sp
);
864 /* add a chapter at the beginning if missing */
865 if( p_marks
->i_seekpoint
> 0 && p_marks
->seekpoint
[0]->i_byte_offset
> 0 )
867 seekpoint_t
*sp
= vlc_seekpoint_New();
870 sp
->i_byte_offset
= 0;
871 sp
->i_time_offset
= 0;
872 sp
->psz_name
= strdup( _("Start") );
873 TAB_INSERT( p_marks
->i_seekpoint
, p_marks
->seekpoint
, sp
, 0 );
877 if( p_marks
->i_seekpoint
> 0 )
878 p_sys
->p_marks
= p_marks
;
880 vlc_input_title_Delete( p_marks
);
886 /*****************************************************************************
887 * Lookup frame offset in index file
888 *****************************************************************************/
889 static bool ReadIndexRecord( FILE *p_file
, bool b_ts
, int64_t i_frame
,
890 uint64_t *pi_offset
, uint16_t *pi_file_num
)
892 uint8_t index_record
[8];
893 if( fseek( p_file
, sizeof(index_record
) * i_frame
, SEEK_SET
) != 0 )
895 if( fread( &index_record
, sizeof(index_record
), 1, p_file
) < 1 )
898 /* VDR usually (only?) runs on little endian machines, but VLC has a
899 * broader audience. See recording.* in VDR source for data layout. */
902 uint64_t i_index_entry
= GetQWLE( &index_record
);
903 *pi_offset
= i_index_entry
& UINT64_C(0xFFFFFFFFFF);
904 *pi_file_num
= i_index_entry
>> 48;
908 *pi_offset
= GetDWLE( &index_record
);
909 *pi_file_num
= index_record
[5];
915 /*****************************************************************************
916 * Convert time stamp from file to frame number
917 *****************************************************************************/
918 static int64_t ParseFrameNumber( const char *psz_line
, float fps
)
920 unsigned h
, m
, s
, f
, n
;
922 /* hour:min:sec.frame (frame is optional) */
923 n
= sscanf( psz_line
, "%u:%u:%u.%u", &h
, &m
, &s
, &f
);
928 int64_t i_seconds
= (int64_t)h
* 3600 + (int64_t)m
* 60 + s
;
929 return (int64_t)( i_seconds
* (double)fps
) + __MAX(1, f
) - 1;
932 /* only a frame number */
933 int64_t i_frame
= strtoll( psz_line
, NULL
, 10 );
934 return __MAX(1, i_frame
) - 1;
937 /*****************************************************************************
938 * Return the last path component (including trailing separators)
939 *****************************************************************************/
940 static const char *BaseName( const char *psz_path
)
942 const char *psz_name
= psz_path
+ strlen( psz_path
);
944 /* skip superfluous separators at the end */
945 while( psz_name
> psz_path
&& psz_name
[-1] == DIR_SEP_CHAR
)
948 /* skip last component */
949 while( psz_name
> psz_path
&& psz_name
[-1] != DIR_SEP_CHAR
)