Example #1
0
/*****************************************************************************
 * Seek to a specific location in a file
 *****************************************************************************/
static int Seek( access_t *p_access, uint64_t i_pos )
{
    access_sys_t *p_sys = p_access->p_sys;

    /* might happen if called by ACCESS_SET_SEEKPOINT */
    i_pos = __MIN( i_pos, p_sys->size );

    p_sys->offset = i_pos;
    p_access->info.b_eof = false;

    /* find correct chapter */
    FindSeekpoint( p_access );

    /* find correct file */
    unsigned i_file = 0;
    while( i_file < FILE_COUNT - 1 &&
           i_pos >= FILE_SIZE( i_file ) )
    {
        i_pos -= FILE_SIZE( i_file );
        i_file++;
    }
    if( !SwitchFile( p_access, i_file ) )
        return VLC_EGENERIC;

    /* adjust position within that file */
    return lseek( p_sys->fd, i_pos, SEEK_SET ) != -1 ?
        VLC_SUCCESS : VLC_EGENERIC;
}
Example #2
0
void valueCopy(dplVal *to, dplVal *from) {
	if(from->isArray == TRUE) {
		arrayValueCopy(to, from);
	}
	else {
		to->type = from->type;

		switch(from->type) {
			case IS_INT:
				to->value.ival = INT_VALUE(from);
			break;
			case IS_DOUBLE:
				to->value.dval = DOUBLE_VALUE(from);
			break;
			case IS_BOOL:
				to->value.boolval = BOOL_VALUE(from);
			break;
			case IS_STRING:
				to->value.str.val = strdup(STR_VALUE(from));
				to->value.str.len = STR_LEN(from);
			break;
			case IS_FILE:
				FILE_PATH(to) = strdup(FILE_PATH(from));
				FILE_HANDLE(to) = FILE_HANDLE(from);
				FILE_SIZE(to) = FILE_SIZE(from);
				FILE_DATA(to) = FILE_DATA(from);
			break;
		}
	}
}
Example #3
0
/*****************************************************************************
 * Import cut marks and convert them to seekpoints (chapters).
 *****************************************************************************/
static void ImportMarks( access_t *p_access )
{
    access_sys_t *p_sys = p_access->p_sys;

    FILE *marksfile = OpenRelativeFile( p_access, "marks" );
    if( !marksfile )
        return;

    FILE *indexfile = OpenRelativeFile( p_access, "index" );
    if( !indexfile )
    {
        fclose( marksfile );
        return;
    }

    /* get the length of this recording (index stores 8 bytes per frame) */
    struct stat st;
    if( fstat( fileno( indexfile ), &st ) )
    {
        fclose( marksfile );
        fclose( indexfile );
        return;
    }
    int64_t i_frame_count = st.st_size / 8;

    /* Put all cut marks in a "dummy" title */
    input_title_t *p_marks = vlc_input_title_New();
    if( !p_marks )
    {
        fclose( marksfile );
        fclose( indexfile );
        return;
    }
    p_marks->psz_name = strdup( _("VDR Cut Marks") );
    p_marks->i_length = i_frame_count * (int64_t)( CLOCK_FREQ / p_sys->fps );

    uint64_t *offsetv = NULL;
    size_t offsetc = 0;

    /* offset for chapter positions */
    int i_chapter_offset = p_sys->fps / 1000 *
        var_InheritInteger( p_access, "vdr-chapter-offset" );

    /* minimum chapter size in frames */
    int i_min_chapter_size = p_sys->fps * MIN_CHAPTER_SIZE;

    /* the last chapter started at this frame (init to 0 so
     * we skip useless chapters near the beginning as well) */
    int64_t i_prev_chapter = 0;

    /* parse lines of the form "0:00:00.00 foobar" */
    char *line = NULL;
    size_t line_len;
    while( ReadLine( &line, &line_len, marksfile ) )
    {
        int64_t i_frame = ParseFrameNumber( line, p_sys->fps );

        /* skip chapters which are near the end or too close to each other */
        if( i_frame - i_prev_chapter < i_min_chapter_size ||
            i_frame >= i_frame_count - i_min_chapter_size )
            continue;
        i_prev_chapter = i_frame;

        /* move chapters (simple workaround for inaccurate cut marks) */
        if( i_frame > -i_chapter_offset )
            i_frame += i_chapter_offset;
        else
            i_frame = 0;

        uint64_t i_offset;
        uint16_t i_file_number;
        if( !ReadIndexRecord( indexfile, p_sys->b_ts_format,
            i_frame, &i_offset, &i_file_number ) )
            continue;
        if( i_file_number < 1 || i_file_number > FILE_COUNT )
            continue;

        /* add file sizes to get the "global" offset */
        seekpoint_t *sp = vlc_seekpoint_New();
        if( !sp )
            continue;
        sp->i_time_offset = i_frame * (int64_t)( CLOCK_FREQ / p_sys->fps );
        sp->psz_name = strdup( line );

        TAB_APPEND( p_marks->i_seekpoint, p_marks->seekpoint, sp );
        TAB_APPEND( offsetc, offsetv, i_offset );

        for( int i = 0; i + 1 < i_file_number; ++i )
            offsetv[offsetc - 1] += FILE_SIZE( i );
    }

    /* add a chapter at the beginning if missing */
    if( p_marks->i_seekpoint > 0 && offsetv[0] > 0 )
    {
        seekpoint_t *sp = vlc_seekpoint_New();
        if( sp )
        {
            sp->i_time_offset = 0;
            sp->psz_name = strdup( _("Start") );
            TAB_INSERT( p_marks->i_seekpoint, p_marks->seekpoint, sp, 0 );
            TAB_INSERT( offsetc, offsetv, UINT64_C(0), 0 );
        }
    }

    if( p_marks->i_seekpoint > 0 )
    {
        p_sys->p_marks = p_marks;
        p_sys->offsets = offsetv;
    }
    else
    {
        vlc_input_title_Delete( p_marks );
        TAB_CLEAN( offsetc, offsetv );
    }

    fclose( marksfile );
    fclose( indexfile );
}
Example #4
0
static int list_file(direntry_t *entry, MainParam_t *mp)
{
	unsigned long size;
	int i;
	int Case;
	int r;

	wchar_t ext[4];
	wchar_t name[9];
	doscp_t *cp;

	if(!all && (entry->dir.attr & 0x6))
		return 0;

	if(concise && isSpecialW(entry->name))
		return 0;

	r=enterDirectory(entry->Dir);
	if (r)
		return ERROR_ONE;
	if (wide) {
		if(filesInDir % 5)
			putchar(' ');				
		else
			putchar('\n');
	}
	
	if(IS_DIR(entry)){
		size = 0;
	} else
		size = FILE_SIZE(&entry->dir);
	
	Case = entry->dir.Case;
	if(!(Case & (BASECASE | EXTCASE)) && 
	   mtools_ignore_short_case)
		Case |= BASECASE | EXTCASE;
	
	cp = GET_DOSCONVERT(entry->Dir);
	dos_to_wchar(cp, entry->dir.ext, ext, 3);
	if(Case & EXTCASE){
		for(i=0; i<3;i++)
			ext[i] = towlower(ext[i]);
	}
	ext[3] = '\0';
	dos_to_wchar(cp, entry->dir.name, name, 8);
	if(Case & BASECASE){
		for(i=0; i<8;i++)
			name[i] = towlower(name[i]);
	}
	name[8]='\0';
	if(wide){
		if(IS_DIR(entry))
			printf("[%s]%*s", global_shortname,
			       (int) (15 - 2 - strlen(global_shortname)), "");
		else
			printf("%-15s", global_shortname);
	} else if(!concise) {				
		char tmpBasename[4*8+1];
		char tmpExt[4*8+1];
		wchar_to_native(name,tmpBasename,8);
		wchar_to_native(ext,tmpExt,3);

		if (name[0] == ' ') 
			printf("             ");
		else if(mtools_dotted_dir)
			printf("%-12s ", global_shortname);
		else
			printf("%s %s ", tmpBasename, tmpExt);
		/* is a subdirectory */
		if(IS_DIR(entry))
			printf("<DIR>    ");
		else
			printf(" %8ld", (long) size);
		printf(" ");
		print_date(&entry->dir);
		printf("  ");
		print_time(&entry->dir);

		if(debug)
			printf(" %s %d ", tmpBasename, START(&entry->dir));
		
		if(*global_longname)
			printf(" %s", global_longname);
		printf("\n");
	} else {
		char tmp[4*MAX_VNAMELEN+1];
		wchar_to_native(entry->name,tmp,MAX_VNAMELEN);

		printf("%s/%s", dirPath, tmp);
		if(IS_DIR(entry))
			putchar('/');
		putchar('\n');
	}

	filesOnDrive++;
	filesInDir++;

	bytesOnDrive += (mt_size_t) size;
	bytesInDir += (mt_size_t) size;
	return GOT_ONE;
}
Example #5
0
static int list_file(direntry_t *entry, MainParam_t *mp)
{
	unsigned long size;
	int i;
	int Case;
	int r;

	if(!all && (entry->dir.attr & 0x6))
		return 0;

	if(concise && isSpecial(entry->name))
		return 0;

	r=enterDirectory(entry->Dir);
	if (r)
		return ERROR_ONE;
	if (wide) {
		if(filesInDir % 5)
			putchar(' ');				
		else
			putchar('\n');
	}
	
	if(IS_DIR(entry)){
		size = 0;
	} else
		size = FILE_SIZE(&entry->dir);
	
	Case = entry->dir.Case;
	if(!(Case & (BASECASE | EXTCASE)) && 
	   mtools_ignore_short_case)
		Case |= BASECASE | EXTCASE;
	
	if(Case & EXTCASE){
		for(i=0; i<3;i++)
			entry->dir.ext[i] = tolower(entry->dir.ext[i]);
	}
	to_unix(entry->dir.ext,3);
	if(Case & BASECASE){
		for(i=0; i<8;i++)
			entry->dir.name[i] = tolower(entry->dir.name[i]);
	}
	to_unix(entry->dir.name,8);
	if(wide){
		if(IS_DIR(entry))
			printf("[%s]%*s", shortname,
			       (int) (15 - 2 - strlen(shortname)), "");
		else
			printf("%-15s", shortname);
	} else if(!concise) {				
		/* is a subdirectory */
		if(mtools_dotted_dir)
			printf("%-13s", shortname);
		else
			printf("%-8.8s %-3.3s ",
			       entry->dir.name, 
			       entry->dir.ext);
		if(IS_DIR(entry))
			printf("<DIR>    ");
		else
			printf(" %8ld", (long) size);
		printf(" ");
		print_date(&entry->dir);
		printf("  ");
		print_time(&entry->dir);

		if(debug)
			printf(" %s %d ", entry->dir.name, START(&entry->dir));
		
		if(*longname)
			printf(" %s", longname);
		printf("\n");
	} else {
		printf("%s/%s", dirPath, entry->name);
		if(IS_DIR(entry))
			putchar('/');
		putchar('\n');
	}

	filesOnDrive++;
	filesInDir++;

	bytesOnDrive += (mt_size_t) size;
	bytesInDir += (mt_size_t) size;
	return GOT_ONE;
}