static void set_length (GValue * value, int list, int row) { int len = aud_playlist_entry_get_length (list, row, TRUE); if (len) { char s[16]; str_format_time (s, sizeof s, len); g_value_set_string (value, s); } else g_value_set_string (value, ""); }
/***************************************************************************** * Open: open the file *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_access_out_t *p_access = (sout_access_out_t*)p_this; sout_access_out_sys_t *p_sys; char *psz_idx; config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg ); if( !p_access->psz_path ) { msg_Err( p_access, "no file name specified" ); return VLC_EGENERIC; } if( unlikely( !( p_sys = calloc ( 1, sizeof( *p_sys ) ) ) ) ) return VLC_ENOMEM; p_sys->i_seglen = var_GetInteger( p_access, SOUT_CFG_PREFIX "seglen" ); /* Try to get within asked segment length */ p_sys->i_seglenm = CLOCK_FREQ * p_sys->i_seglen; p_sys->block_buffer = NULL; p_sys->i_numsegs = var_GetInteger( p_access, SOUT_CFG_PREFIX "numsegs" ); p_sys->i_initial_segment = var_GetInteger( p_access, SOUT_CFG_PREFIX "initial-segment-number" ); p_sys->b_splitanywhere = var_GetBool( p_access, SOUT_CFG_PREFIX "splitanywhere" ); p_sys->b_delsegs = var_GetBool( p_access, SOUT_CFG_PREFIX "delsegs" ); p_sys->b_ratecontrol = var_GetBool( p_access, SOUT_CFG_PREFIX "ratecontrol") ; p_sys->b_caching = var_GetBool( p_access, SOUT_CFG_PREFIX "caching") ; p_sys->b_generate_iv = var_GetBool( p_access, SOUT_CFG_PREFIX "generate-iv") ; p_sys->segments_t = vlc_array_new(); p_sys->stuffing_size = 0; p_sys->i_opendts = VLC_TS_INVALID; p_sys->psz_indexPath = NULL; psz_idx = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "index" ); if ( psz_idx ) { char *psz_tmp; psz_tmp = str_format_time( psz_idx ); free( psz_idx ); if ( !psz_tmp ) { free( p_sys ); return VLC_ENOMEM; } path_sanitize( psz_tmp ); p_sys->psz_indexPath = psz_tmp; vlc_unlink( p_sys->psz_indexPath ); } p_sys->psz_indexUrl = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "index-url" ); p_sys->psz_keyfile = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "key-loadfile" ); p_sys->key_uri = var_GetNonEmptyString( p_access, SOUT_CFG_PREFIX "key-uri" ); p_access->p_sys = p_sys; if( p_sys->psz_keyfile && ( LoadCryptFile( p_access ) < 0 ) ) { free( p_sys->psz_indexUrl ); free( p_sys->psz_indexPath ); free( p_sys ); msg_Err( p_access, "Encryption init failed" ); return VLC_EGENERIC; } else if( !p_sys->psz_keyfile && ( CryptSetup( p_access, NULL ) < 0 ) ) { free( p_sys->psz_indexUrl ); free( p_sys->psz_indexPath ); free( p_sys ); msg_Err( p_access, "Encryption init failed" ); return VLC_EGENERIC; } p_sys->i_handle = -1; p_sys->i_segment = p_sys->i_initial_segment > 0 ? p_sys->i_initial_segment -1 : 0; p_sys->psz_cursegPath = NULL; p_access->pf_write = Write; p_access->pf_seek = Seek; p_access->pf_control = Control; return VLC_SUCCESS; }
/***************************************************************************** * Open: open the file *****************************************************************************/ static int Open( vlc_object_t *p_this ) { sout_access_out_t *p_access = (sout_access_out_t*)p_this; int fd; config_ChainParse( p_access, SOUT_CFG_PREFIX, ppsz_sout_options, p_access->p_cfg ); if( !p_access->psz_path ) { msg_Err( p_access, "no file name specified" ); return VLC_EGENERIC; } bool overwrite = var_GetBool (p_access, SOUT_CFG_PREFIX"overwrite"); bool append = var_GetBool( p_access, SOUT_CFG_PREFIX "append" ); if (!strcmp (p_access->psz_access, "fd")) { char *end; fd = strtol (p_access->psz_path, &end, 0); if (!*p_access->psz_path || *end) { msg_Err (p_access, "invalid file descriptor: %s", p_access->psz_path); return VLC_EGENERIC; } fd = vlc_dup (fd); if (fd == -1) { msg_Err (p_access, "cannot use file descriptor: %s", vlc_strerror_c(errno)); return VLC_EGENERIC; } } else if( !strcmp( p_access->psz_path, "-" ) ) { #if defined( _WIN32 ) || defined( __OS2__ ) setmode (STDOUT_FILENO, O_BINARY); #endif fd = vlc_dup (STDOUT_FILENO); if (fd == -1) { msg_Err (p_access, "cannot use standard output: %s", vlc_strerror_c(errno)); return VLC_EGENERIC; } msg_Dbg( p_access, "using stdout" ); } else { const char *path = p_access->psz_path; char *buf = NULL; if (var_InheritBool (p_access, SOUT_CFG_PREFIX"format")) { buf = str_format_time (path); path_sanitize (buf); path = buf; } int flags = O_RDWR | O_CREAT | O_LARGEFILE; if (!overwrite) flags |= O_EXCL; if (!append) flags |= O_TRUNC; #ifdef O_SYNC if (var_GetBool (p_access, SOUT_CFG_PREFIX"sync")) flags |= O_SYNC; #endif do { fd = vlc_open (path, flags, 0666); if (fd != -1) break; if (fd == -1) msg_Err (p_access, "cannot create %s: %s", path, vlc_strerror_c(errno)); if (overwrite || errno != EEXIST) break; flags &= ~O_EXCL; } while (vlc_dialog_wait_question (p_access, VLC_DIALOG_QUESTION_NORMAL, _("Keep existing file"), _("Overwrite"), NULL, path, _("The output file already exists. " "If recording continues, the file will be " "overridden and its content will be lost.")) == 1); free (buf); if (fd == -1) return VLC_EGENERIC; } struct stat st; if (fstat (fd, &st)) { msg_Err (p_access, "write error: %s", vlc_strerror_c(errno)); close (fd); return VLC_EGENERIC; } p_access->pf_read = Read; if (S_ISREG(st.st_mode) || S_ISBLK(st.st_mode)) { p_access->pf_write = Write; p_access->pf_seek = Seek; } #ifdef S_ISSOCK else if (S_ISSOCK(st.st_mode)) { p_access->pf_write = Send; p_access->pf_seek = NoSeek; } #endif else { p_access->pf_write = WritePipe; p_access->pf_seek = NoSeek; } p_access->pf_control = Control; p_access->p_sys = (void *)(intptr_t)fd; msg_Dbg( p_access, "file access output opened (%s)", p_access->psz_path ); if (append) lseek (fd, 0, SEEK_END); return VLC_SUCCESS; }
/**************************************************************************** * Filter: the whole thing **************************************************************************** * This function outputs subpictures at regular time intervals. ****************************************************************************/ static subpicture_t *Filter( filter_t *p_filter, mtime_t date ) { filter_sys_t *p_sys = p_filter->p_sys; subpicture_t *p_spu = NULL; video_format_t fmt; vlc_mutex_lock( &p_sys->lock ); if( p_sys->last_time + p_sys->i_refresh > date ) goto out; if( p_sys->filepath != NULL ) { char *fmt = MarqueeReadFile( p_filter, p_sys->filepath ); if( fmt != NULL ) { free( p_sys->format ); p_sys->format = fmt; } } char *msg = str_format_time( p_sys->format ? p_sys->format : "" ); if( unlikely( msg == NULL ) ) goto out; if( p_sys->message != NULL && !strcmp( msg, p_sys->message ) ) { free( msg ); goto out; } free( p_sys->message ); p_sys->message = msg; p_spu = filter_NewSubpicture( p_filter ); if( !p_spu ) goto out; memset( &fmt, 0, sizeof(video_format_t) ); fmt.i_chroma = VLC_CODEC_TEXT; fmt.i_width = fmt.i_height = 0; fmt.i_x_offset = 0; fmt.i_y_offset = 0; p_spu->p_region = subpicture_region_New( &fmt ); if( !p_spu->p_region ) { p_filter->pf_sub_buffer_del( p_filter, p_spu ); p_spu = NULL; goto out; } p_sys->last_time = date; p_spu->p_region->psz_text = strdup( msg ); p_spu->i_start = date; p_spu->i_stop = p_sys->i_timeout == 0 ? 0 : date + p_sys->i_timeout * 1000; p_spu->b_ephemer = true; /* where to locate the string: */ if( p_sys->i_pos < 0 ) { /* set to an absolute xy */ p_spu->p_region->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP; p_spu->b_absolute = true; } else { /* set to one of the 9 relative locations */ p_spu->p_region->i_align = p_sys->i_pos; p_spu->b_absolute = false; } p_spu->p_region->i_x = p_sys->i_xoff; p_spu->p_region->i_y = p_sys->i_yoff; p_spu->p_region->p_style = text_style_Duplicate( p_sys->p_style ); out: vlc_mutex_unlock( &p_sys->lock ); return p_spu; }
int vout_snapshot_SaveImage(char **name, int *sequential, const block_t *image, vlc_object_t *object, const vout_snapshot_save_cfg_t *cfg) { /* */ char *filename; DIR *pathdir = vlc_opendir(cfg->path); if (pathdir != NULL) { /* The use specified a directory path */ closedir(pathdir); /* */ char *prefix = NULL; if (cfg->prefix_fmt) prefix = str_format_time(cfg->prefix_fmt); if (prefix) filename_sanitize(prefix); else { prefix = strdup("vlcsnap-"); if (!prefix) goto error; } if (cfg->is_sequential) { for (int num = cfg->sequence; ; num++) { struct stat st; if (asprintf(&filename, "%s" DIR_SEP "%s%05d.%s", cfg->path, prefix, num, cfg->format) < 0) { free(prefix); goto error; } if (vlc_stat(filename, &st)) { *sequential = num; break; } free(filename); } } else { struct tm curtime; time_t lcurtime = time(NULL) ; if (!localtime_r(&lcurtime, &curtime)) { const unsigned int id = (image->i_pts / 100000) & 0xFFFFFF; msg_Warn(object, "failed to get current time. Falling back to legacy snapshot naming"); if (asprintf(&filename, "%s" DIR_SEP "%s%u.%s", cfg->path, prefix, id, cfg->format) < 0) filename = NULL; } else { /* suffix with the last decimal digit in 10s of seconds resolution * FIXME gni ? */ const int id = (image->i_pts / (100*1000)) & 0xFF; char buffer[128]; if (!strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss", &curtime)) strcpy(buffer, "error"); if (asprintf(&filename, "%s" DIR_SEP "%s%s%1u.%s", cfg->path, prefix, buffer, id, cfg->format) < 0) filename = NULL; } } free(prefix); } else { /* The user specified a full path name (including file name) */ filename = str_format_time(cfg->path); path_sanitize(filename); } if (!filename) goto error; /* Save the snapshot */ FILE *file = vlc_fopen(filename, "wb"); if (!file) { msg_Err(object, "Failed to open '%s'", filename); free(filename); goto error; } if (fwrite(image->p_buffer, image->i_buffer, 1, file) != 1) { msg_Err(object, "Failed to write to '%s'", filename); fclose(file); free(filename); goto error; } fclose(file); /* */ if (name) *name = filename; else free(filename); return VLC_SUCCESS; error: msg_Err(object, "could not save snapshot"); return VLC_EGENERIC; }
int vout_snapshot_SaveImage(char **name, int *sequential, const block_t *image, vlc_object_t *object, const vout_snapshot_save_cfg_t *cfg) { /* */ char *filename; DIR *pathdir = vlc_opendir(cfg->path); if (pathdir != NULL) { /* The use specified a directory path */ closedir(pathdir); /* */ char *prefix = NULL; if (cfg->prefix_fmt) prefix = str_format_time(cfg->prefix_fmt); if (prefix) filename_sanitize(prefix); else { prefix = strdup("vlcsnap-"); if (!prefix) goto error; } if (cfg->is_sequential) { for (int num = cfg->sequence; ; num++) { struct stat st; if (asprintf(&filename, "%s" DIR_SEP "%s%05d.%s", cfg->path, prefix, num, cfg->format) < 0) { free(prefix); goto error; } if (vlc_stat(filename, &st)) { *sequential = num; break; } free(filename); } } else { struct timeval tv; struct tm curtime; char buffer[128]; gettimeofday(&tv, NULL); if (localtime_r(&tv.tv_sec, &curtime) == NULL) gmtime_r(&tv.tv_sec, &curtime); if (strftime(buffer, sizeof(buffer), "%Y-%m-%d-%Hh%Mm%Ss", &curtime) == 0) strcpy(buffer, "error"); if (asprintf(&filename, "%s" DIR_SEP "%s%s%03lu.%s", cfg->path, prefix, buffer, tv.tv_usec / 1000, cfg->format) < 0) filename = NULL; } free(prefix); } else { /* The user specified a full path name (including file name) */ filename = str_format_time(cfg->path); path_sanitize(filename); } if (!filename) goto error; /* Save the snapshot */ FILE *file = vlc_fopen(filename, "wb"); if (!file) { msg_Err(object, "Failed to open '%s'", filename); free(filename); goto error; } if (fwrite(image->p_buffer, image->i_buffer, 1, file) != 1) { msg_Err(object, "Failed to write to '%s'", filename); fclose(file); free(filename); goto error; } fclose(file); /* */ if (name) *name = filename; else free(filename); return VLC_SUCCESS; error: msg_Err(object, "could not save snapshot"); return VLC_EGENERIC; }