/************************************************************************ * LoadCryptFile: Try to parse key_uri and keyfile-location from file ************************************************************************/ static int LoadCryptFile( sout_access_out_t *p_access ) { sout_access_out_sys_t *p_sys = p_access->p_sys; FILE *stream = vlc_fopen( p_sys->psz_keyfile, "rt" ); char *key_file=NULL,*key_uri=NULL; if( unlikely( stream == NULL ) ) { msg_Err( p_access, "Unable to open keyloadfile %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); return VLC_EGENERIC; } //First read key_uri ssize_t len = getline( &key_uri, &(size_t){0}, stream ); if( unlikely( len == -1 ) ) { msg_Err( p_access, "Cannot read %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); clearerr( stream ); fclose( stream ); free( key_uri ); return VLC_EGENERIC; } //Strip the newline from uri, maybe scanf would be better? key_uri[len-1]='\0'; len = getline( &key_file, &(size_t){0}, stream ); if( unlikely( len == -1 ) ) { msg_Err( p_access, "Cannot read %s: %s", p_sys->psz_keyfile, vlc_strerror_c(errno) ); clearerr( stream ); fclose( stream ); free( key_uri ); free( key_file ); return VLC_EGENERIC; } // Strip the last newline from filename key_file[len-1]='\0'; fclose( stream ); int returncode = VLC_SUCCESS; if( !p_sys->key_uri || strcmp( p_sys->key_uri, key_uri ) ) { if( p_sys->key_uri ) { free( p_sys->key_uri ); p_sys->key_uri = NULL; } p_sys->key_uri = strdup( key_uri ); returncode = CryptSetup( p_access, key_file ); } free( key_file ); free( key_uri ); return returncode; }
static block_t *Shoot(demux_t *demux) { demux_sys_t *sys = demux->p_sys; int fd = vlc_memfd(); if (fd == -1) { msg_Err(demux, "buffer creation error: %s", vlc_strerror_c(errno)); return NULL; } /* NOTE: one extra line for overflow if screen-left > 0 */ uint32_t pitch = 4u * sys->width; size_t size = (pitch * (sys->height + 1) + sys->pagemask) & ~sys->pagemask; block_t *block = NULL; if (ftruncate(fd, size) < 0) { msg_Err(demux, "buffer allocation error: %s", vlc_strerror_c(errno)); goto out; } struct wl_shm_pool *pool = wl_shm_create_pool(sys->shm, fd, size); if (pool == NULL) goto out; struct wl_buffer *buffer; buffer = wl_shm_pool_create_buffer(pool, 0, sys->width, sys->height, pitch, WL_SHM_FORMAT_XRGB8888); wl_shm_pool_destroy(pool); if (buffer == NULL) goto out; sys->done = false; screenshooter_shoot(sys->screenshooter, sys->output, buffer); while (!sys->done) wl_display_roundtrip(sys->display); wl_buffer_destroy(buffer); block = block_File(fd, true); if (block != NULL) { size_t skip = (sys->y * sys->width + sys->x) * 4; block->p_buffer += skip; block->i_buffer -= skip; } out: vlc_close(fd); return block; }
int playlist_Export( playlist_t * p_playlist, const char *psz_filename, bool b_playlist, const char *psz_type ) { playlist_export_t *p_export = vlc_custom_create( p_playlist, sizeof( *p_export ), "playlist export" ); if( unlikely(p_export == NULL) ) return VLC_ENOMEM; msg_Dbg( p_export, "saving %s to file %s", b_playlist ? "playlist" : "media library", psz_filename ); int ret = VLC_EGENERIC; /* Prepare the playlist_export_t structure */ p_export->base_url = vlc_path2uri( psz_filename, NULL ); p_export->p_file = vlc_fopen( psz_filename, "wt" ); if( p_export->p_file == NULL ) { msg_Err( p_export, "could not create playlist file %s: %s", psz_filename, vlc_strerror_c(errno) ); goto out; } module_t *p_module; /* And call the module ! All work is done now */ playlist_Lock( p_playlist ); p_export->p_root = b_playlist ? p_playlist->p_playing : p_playlist->p_media_library; p_module = module_need( p_export, "playlist export", psz_type, true ); playlist_Unlock( p_playlist ); if( p_module != NULL ) { module_unneed( p_export, p_module ); if( !ferror( p_export->p_file ) ) ret = VLC_SUCCESS; else msg_Err( p_playlist, "could not write playlist file: %s", vlc_strerror_c(errno) ); } else msg_Err( p_playlist, "could not export playlist" ); fclose( p_export->p_file ); out: free( p_export->base_url ); vlc_object_release( p_export ); return ret; }
int playlist_Export( playlist_t * p_playlist, const char *psz_filename, playlist_item_t *p_export_root, const char *psz_type ) { if( p_export_root == NULL ) return VLC_EGENERIC; playlist_export_t *p_export = vlc_custom_create( p_playlist, sizeof( *p_export ), "playlist export" ); if( unlikely(p_export == NULL) ) return VLC_ENOMEM; msg_Dbg( p_export, "saving %s to file %s", p_export_root->p_input->psz_name, psz_filename ); int ret = VLC_EGENERIC; /* Prepare the playlist_export_t structure */ p_export->p_root = p_export_root; p_export->psz_filename = psz_filename; p_export->p_file = vlc_fopen( psz_filename, "wt" ); if( p_export->p_file == NULL ) { msg_Err( p_export, "could not create playlist file %s: %s", psz_filename, vlc_strerror_c(errno) ); goto out; } module_t *p_module; /* And call the module ! All work is done now */ playlist_Lock( p_playlist ); p_module = module_need( p_export, "playlist export", psz_type, true ); playlist_Unlock( p_playlist ); if( p_module != NULL ) { module_unneed( p_export, p_module ); if( !ferror( p_export->p_file ) ) ret = VLC_SUCCESS; else msg_Err( p_playlist, "could not write playlist file: %s", vlc_strerror_c(errno) ); } else msg_Err( p_playlist, "could not export playlist" ); fclose( p_export->p_file ); out: vlc_object_release( p_export ); return ret; }
static ssize_t Send(sout_access_out_t *access, block_t *block) { int fd = (intptr_t)access->p_sys; size_t total = 0; while (block != NULL) { if (block->i_buffer == 0) { block_t *next = block->p_next; block_Release(block); block = next; continue; } /* TODO: vectorized I/O with sendmsg() */ ssize_t val = send(fd, block->p_buffer, block->i_buffer, MSG_NOSIGNAL); if (val <= 0) { /* FIXME: errno is meaningless if val is zero */ if (errno == EINTR) continue; block_ChainRelease(block); msg_Err(access, "cannot write: %s", vlc_strerror_c(errno)); return -1; } total += val; assert((size_t)val <= block->i_buffer); block->p_buffer += val; block->i_buffer -= val; } return total; }
/***************************************************************************** * Check if another part exists and import it *****************************************************************************/ static bool ImportNextFile( access_t *p_access ) { access_sys_t *p_sys = p_access->p_sys; char *psz_path = GetFilePath( p_access, FILE_COUNT ); if( !psz_path ) return false; struct stat st; if( vlc_stat( psz_path, &st ) ) { msg_Dbg( p_access, "could not stat %s: %s", psz_path, vlc_strerror_c(errno) ); free( psz_path ); return false; } if( !S_ISREG( st.st_mode ) ) { msg_Dbg( p_access, "%s is not a regular file", psz_path ); free( psz_path ); return false; } msg_Dbg( p_access, "%s exists", psz_path ); free( psz_path ); ARRAY_APPEND( p_sys->file_sizes, st.st_size ); p_sys->size += st.st_size; return true; }
/***************************************************************************** * Write: standard write on a file descriptor. *****************************************************************************/ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer ) { size_t i_write = 0; while( p_buffer ) { ssize_t val = write ((intptr_t)p_access->p_sys, p_buffer->p_buffer, p_buffer->i_buffer); if (val <= 0) { if (errno == EINTR) continue; block_ChainRelease (p_buffer); msg_Err( p_access, "cannot write: %s", vlc_strerror_c(errno) ); return -1; } if ((size_t)val >= p_buffer->i_buffer) { block_t *p_next = p_buffer->p_next; block_Release (p_buffer); p_buffer = p_next; } else { p_buffer->p_buffer += val; p_buffer->i_buffer -= val; } i_write += val; } return i_write; }
/***************************************************************************** * Write: *****************************************************************************/ static ssize_t Write(sout_access_out_t *p_access, block_t *p_buffer) { sout_access_out_sys_t *p_sys = (sout_access_out_sys_t*)p_access->p_sys; size_t i_write = 0; int val; while (p_buffer != NULL) { block_t *p_next = p_buffer->p_next; avio_write(p_sys->context, p_buffer->p_buffer, p_buffer->i_buffer); avio_flush(p_sys->context); if ((val = p_sys->context->error) != 0) { p_sys->context->error = 0; /* FIXME? */ goto error; } i_write += p_buffer->i_buffer; block_Release(p_buffer); p_buffer = p_next; } return i_write; error: msg_Err(p_access, "Wrote only %zu bytes: %s", i_write, vlc_strerror_c(AVUNERROR(val))); block_ChainRelease( p_buffer ); return i_write; }
static void* Raw1394EventThread( void *obj ) { event_thread_t *p_ev = (event_thread_t *)obj; access_t *p_access = (access_t *) p_ev->p_access; access_sys_t *p_sys = (access_sys_t *) p_access->p_sys; int result = 0; int canc = vlc_savecancel(); AVCPlay( p_access, p_sys->i_node ); vlc_cleanup_push( Raw1394EventThreadCleanup, p_ev ); vlc_restorecancel( canc ); for( ;; ) { while( ( result = poll( &p_sys->raw1394_poll, 1, -1 ) ) < 0 ) { if( errno != EINTR ) msg_Err( p_access, "poll error: %s", vlc_strerror_c(errno) ); } if( result > 0 && ( ( p_sys->raw1394_poll.revents & POLLIN ) || ( p_sys->raw1394_poll.revents & POLLPRI ) ) ) { canc = vlc_savecancel(); result = raw1394_loop_iterate( p_sys->p_raw1394 ); vlc_restorecancel( canc ); } } vlc_cleanup_pop(); vlc_assert_unreachable(); }
/***************************************************************************** * config_CreateDir: Create configuration directory if it doesn't exist. *****************************************************************************/ int config_CreateDir( vlc_object_t *p_this, const char *psz_dirname ) { if( !psz_dirname || !*psz_dirname ) return -1; if( vlc_mkdir( psz_dirname, 0700 ) == 0 ) return 0; switch( errno ) { case EEXIST: return 0; case ENOENT: { /* Let's try to create the parent directory */ char psz_parent[strlen( psz_dirname ) + 1], *psz_end; strcpy( psz_parent, psz_dirname ); psz_end = strrchr( psz_parent, DIR_SEP_CHAR ); if( psz_end && psz_end != psz_parent ) { *psz_end = '\0'; if( config_CreateDir( p_this, psz_parent ) == 0 ) { if( !vlc_mkdir( psz_dirname, 0700 ) ) return 0; } } } } msg_Warn( p_this, "could not create %s: %s", psz_dirname, vlc_strerror_c(errno) ); return -1; }
/** * Saves a module cache to disk, and release cache data from memory. */ void CacheSave (vlc_object_t *p_this, const char *dir, module_cache_t *entries, size_t n) { char *filename = NULL, *tmpname = NULL; if (asprintf (&filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1) goto out; if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1) goto out; msg_Dbg (p_this, "saving plugins cache %s", filename); FILE *file = vlc_fopen (tmpname, "wb"); if (file == NULL) { if (errno != EACCES && errno != ENOENT) msg_Warn (p_this, "cannot create %s: %s", tmpname, vlc_strerror_c(errno)); goto out; } if (CacheSaveBank (file, entries, n)) { msg_Warn (p_this, "cannot write %s: %s", tmpname, vlc_strerror_c(errno)); clearerr (file); fclose (file); vlc_unlink (tmpname); goto out; } #if !defined( _WIN32 ) && !defined( __OS2__ ) vlc_rename (tmpname, filename); /* atomically replace old cache */ fclose (file); #else vlc_unlink (filename); fclose (file); vlc_rename (tmpname, filename); #endif out: free (filename); free (tmpname); for (size_t i = 0; i < n; i++) free (entries[i].path); free (entries); }
static void wakeup_main_loop( void *p_data ) { intf_thread_t *p_intf = (intf_thread_t*) p_data; if( !write( p_intf->p_sys->p_pipe_fds[PIPE_IN], "\0", 1 ) ) msg_Err( p_intf, "Could not wake up the main loop: %s", vlc_strerror_c(errno) ); }
/***************************************************************************** * Close the current file and open another *****************************************************************************/ static bool SwitchFile( access_t *p_access, unsigned i_file ) { access_sys_t *p_sys = p_access->p_sys; /* requested file already open? */ if( p_sys->fd != -1 && p_sys->i_current_file == i_file ) return true; /* close old file */ if( p_sys->fd != -1 ) { close( p_sys->fd ); p_sys->fd = -1; } /* switch */ if( i_file >= FILE_COUNT ) return false; p_sys->i_current_file = i_file; /* open new file */ char *psz_path = GetFilePath( p_access, i_file ); if( !psz_path ) return false; p_sys->fd = vlc_open( psz_path, O_RDONLY ); if( p_sys->fd == -1 ) { msg_Err( p_access, "Failed to open %s: %s", psz_path, vlc_strerror_c(errno) ); goto error; } /* cannot handle anything except normal files */ struct stat st; if( fstat( p_sys->fd, &st ) || !S_ISREG( st.st_mode ) ) { msg_Err( p_access, "%s is not a regular file", psz_path ); goto error; } OptimizeForRead( p_sys->fd ); msg_Dbg( p_access, "opened %s", psz_path ); free( psz_path ); return true; error: dialog_Fatal (p_access, _("File reading failed"), _("VLC could not" " open the file \"%s\" (%s)."), psz_path, vlc_strerror(errno) ); if( p_sys->fd != -1 ) { close( p_sys->fd ); p_sys->fd = -1; } free( psz_path ); return false; }
static int ImageWriteUrl( image_handler_t *p_image, picture_t *p_pic, video_format_t *p_fmt_in, video_format_t *p_fmt_out, const char *psz_url ) { block_t *p_block; FILE *file; if( !p_fmt_out->i_chroma ) { /* Try to guess format from file name */ p_fmt_out->i_chroma = image_Ext2Fourcc( psz_url ); } file = vlc_fopen( psz_url, "wb" ); if( !file ) { msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); return VLC_EGENERIC; } p_block = ImageWrite( p_image, p_pic, p_fmt_in, p_fmt_out ); int err = 0; if( p_block ) { if( fwrite( p_block->p_buffer, p_block->i_buffer, 1, file ) != 1 ) err = errno; block_Release( p_block ); } if( fclose( file ) && !err ) err = errno; if( err ) { errno = err; msg_Err( p_image->p_parent, "%s: %s", psz_url, vlc_strerror_c(errno) ); } return err ? VLC_EGENERIC : VLC_SUCCESS; }
libvlc_media_t *libvlc_media_new_path( libvlc_instance_t *p_instance, const char *path ) { char *mrl = vlc_path2uri( path, NULL ); if( unlikely(mrl == NULL) ) { libvlc_printerr( "%s", vlc_strerror_c(errno) ); return NULL; } libvlc_media_t *m = libvlc_media_new_location( p_instance, mrl ); free( mrl ); return m; }
/** Finds a frontend of the correct type */ static int dvb_open_frontend (dvb_device_t *d) { if (d->frontend != -1) return 0; int fd = dvb_open_node (d, "frontend", O_RDWR); if (fd == -1) { msg_Err (d->obj, "cannot access frontend: %s", vlc_strerror_c(errno)); return -1; } d->frontend = fd; return 0; }
/***************************************************************************** * Mux: multiplex available data in input fifos *****************************************************************************/ static int Mux( sout_mux_t *p_mux ) { sout_mux_sys_t *p_sys = p_mux->p_sys; if( p_sys->b_error ) return VLC_EGENERIC; if( p_sys->b_write_header ) { int error; msg_Dbg( p_mux, "writing header" ); char *psz_opts = var_GetNonEmptyString( p_mux, "sout-avformat-options" ); AVDictionary *options = NULL; if (psz_opts) { vlc_av_get_options(psz_opts, &options); free(psz_opts); } av_dict_set( &p_sys->oc->metadata, "encoding_tool", "VLC "VERSION, 0 ); error = avformat_write_header( p_sys->oc, options ? &options : NULL); AVDictionaryEntry *t = NULL; while ((t = av_dict_get(options, "", t, AV_DICT_IGNORE_SUFFIX))) { msg_Err( p_mux, "Unknown option \"%s\"", t->key ); } av_dict_free(&options); if( error < 0 ) { msg_Err( p_mux, "could not write header: %s", vlc_strerror_c(AVUNERROR(error)) ); p_sys->b_write_header = false; p_sys->b_error = true; return VLC_EGENERIC; } avio_flush( p_sys->oc->pb ); p_sys->b_write_header = false; } for( ;; ) { mtime_t i_dts; int i_stream = sout_MuxGetStream( p_mux, 1, &i_dts ); if( i_stream < 0 ) return VLC_SUCCESS; MuxBlock( p_mux, p_mux->pp_inputs[i_stream] ); } return VLC_SUCCESS; }
/** * Cleanup a libvlc instance. The instance is not completely deallocated * \param p_libvlc the instance to clean */ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); /* Ask the interfaces to stop and destroy them */ msg_Dbg( p_libvlc, "removing all interfaces" ); libvlc_Quit( p_libvlc ); intf_DestroyAll( p_libvlc ); #ifdef ENABLE_VLM /* Destroy VLM if created in libvlc_InternalInit */ if( priv->p_vlm ) { vlm_Delete( priv->p_vlm ); } #endif /* Free playlist now, all threads are gone */ playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist; if( p_playlist != NULL ) playlist_Destroy( p_playlist ); #if !defined( _WIN32 ) && !defined( __OS2__ ) char *pidfile = var_InheritString( p_libvlc, "pidfile" ); if( pidfile != NULL ) { msg_Dbg( p_libvlc, "removing PID file %s", pidfile ); if( unlink( pidfile ) ) msg_Warn( p_libvlc, "cannot remove PID file %s: %s", pidfile, vlc_strerror_c(errno) ); free( pidfile ); } #endif if (priv->parser != NULL) playlist_preparser_Delete(priv->parser); vlc_DeinitActions( p_libvlc, priv->actions ); /* Save the configuration */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) config_AutoSaveConfigFile( VLC_OBJECT(p_libvlc) ); /* Free module bank. It is refcounted, so we call this each time */ module_EndBank (true); vlc_LogDeinit (p_libvlc); #if defined(_WIN32) || defined(__OS2__) system_End( ); #endif }
/***************************************************************************** * Read: *****************************************************************************/ static ssize_t Read( stream_t *p_access, void *p_buffer, size_t i_len ) { access_sys_t *p_sys = p_access->p_sys; int i_read; i_read = smbc_read( p_sys->i_smb, p_buffer, i_len ); if( i_read < 0 ) { msg_Err( p_access, "read failed (%s)", vlc_strerror_c(errno) ); i_read = 0; } return i_read; }
static char *MarqueeReadFile( filter_t *obj, const char *path ) { FILE *stream = vlc_fopen( path, "rt" ); if( stream == NULL ) { msg_Err( obj, "cannot open %s: %s", path, vlc_strerror_c(errno) ); return NULL; } char *line = NULL; ssize_t len = getline( &line, &(size_t){ 0 }, stream ); if( len == -1 ) { msg_Err( obj, "cannot read %s: %s", path, vlc_strerror_c(errno) ); clearerr( stream ); line = NULL; } fclose( stream ); if( len >= 1 && line[len - 1] == '\n' ) line[--len] = '\0'; return line; }
/***************************************************************************** * Open file relative to base directory for reading. *****************************************************************************/ static FILE *OpenRelativeFile( access_t *p_access, const char *psz_file ) { /* build path and add extension */ char *psz_path; if( asprintf( &psz_path, "%s" DIR_SEP "%s%s", p_access->psz_filepath, psz_file, p_access->p_sys->b_ts_format ? "" : ".vdr" ) == -1 ) return NULL; FILE *file = vlc_fopen( psz_path, "rb" ); if( !file ) msg_Warn( p_access, "Failed to open %s: %s", psz_path, vlc_strerror_c(errno) ); free( psz_path ); return file; }
/***************************************************************************** * Read and concatenate files *****************************************************************************/ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) { access_sys_t *p_sys = p_access->p_sys; if( p_sys->fd == -1 ) { /* no more data */ p_access->info.b_eof = true; return 0; } ssize_t i_ret = read( p_sys->fd, p_buffer, i_len ); if( i_ret > 0 ) { /* success */ p_sys->offset += i_ret; UpdateFileSize( p_access ); FindSeekpoint( p_access ); return i_ret; } else if( i_ret == 0 ) { /* check for new files in case the recording is still active */ if( p_sys->i_current_file >= FILE_COUNT - 1 ) ImportNextFile( p_access ); /* play next file */ SwitchFile( p_access, p_sys->i_current_file + 1 ); return -1; } else if( errno == EINTR ) { /* try again later */ return -1; } else { /* abort on read error */ msg_Err( p_access, "failed to read (%s)", vlc_strerror_c(errno) ); dialog_Fatal( p_access, _("File reading failed"), _("VLC could not read the file (%s)."), vlc_strerror(errno) ); SwitchFile( p_access, -1 ); return 0; } }
int playlist_MLDump( playlist_t *p_playlist ) { char *psz_temp; psz_temp = config_GetUserDir( VLC_DATA_DIR ); if( !psz_temp ) /* XXX: This should never happen */ { msg_Err( p_playlist, "no data directory, cannot save media library") ; return VLC_EGENERIC; } char psz_dirname[ strlen( psz_temp ) + sizeof( DIR_SEP "ml.xspf")]; strcpy( psz_dirname, psz_temp ); free( psz_temp ); if( config_CreateDir( (vlc_object_t *)p_playlist, psz_dirname ) ) { return VLC_EGENERIC; } strcat( psz_dirname, DIR_SEP "ml.xspf" ); if ( asprintf( &psz_temp, "%s.tmp%"PRIu32, psz_dirname, (uint32_t)getpid() ) < 1 ) return VLC_EGENERIC; int i_ret = playlist_Export( p_playlist, psz_temp, p_playlist->p_media_library, "export-xspf" ); if ( i_ret != VLC_SUCCESS ) { vlc_unlink( psz_temp ); free( psz_temp ); return i_ret; } i_ret = vlc_rename( psz_temp, psz_dirname ); free( psz_temp ); if( i_ret == -1 ) { msg_Err( p_playlist, "could not rename %s.tmp: %s", psz_dirname, vlc_strerror_c(errno) ); return VLC_EGENERIC; } return VLC_SUCCESS; }
int dvb_add_pid (dvb_device_t *d, uint16_t pid) { if (d->budget) return 0; #ifdef USE_DMX if (pid == 0 || ioctl (d->demux, DMX_ADD_PID, &pid) >= 0) return 0; #else for (size_t i = 0; i < MAX_PIDS; i++) { if (d->pids[i].pid == pid) return 0; if (d->pids[i].fd != -1) continue; int fd = dvb_open_node (d, "demux", O_RDONLY); if (fd == -1) goto error; /* We need to filter at least one PID. The tap for TS demultiplexing * cannot be configured otherwise. So add the PAT. */ struct dmx_pes_filter_params param; param.pid = pid; param.input = DMX_IN_FRONTEND; param.output = DMX_OUT_TS_TAP; param.pes_type = DMX_PES_OTHER; param.flags = DMX_IMMEDIATE_START; if (ioctl (fd, DMX_SET_PES_FILTER, ¶m) < 0) { vlc_close (fd); goto error; } d->pids[i].fd = fd; d->pids[i].pid = pid; return 0; } errno = EMFILE; error: #endif msg_Err (d->obj, "cannot add PID 0x%04"PRIu16": %s", pid, vlc_strerror_c(errno)); return -1; }
/***************************************************************************** * Read: *****************************************************************************/ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len ) { access_sys_t *p_sys = p_access->p_sys; int i_read; if( p_access->info.b_eof ) return 0; i_read = smbc_read( p_sys->i_smb, p_buffer, i_len ); if( i_read < 0 ) { msg_Err( p_access, "read failed (%s)", vlc_strerror_c(errno) ); p_access->info.b_eof = true; return -1; } if( i_read == 0 ) p_access->info.b_eof = true; return i_read; }
/***************************************************************************** * Seek: try to go at the right place *****************************************************************************/ static int Seek( stream_t *p_access, uint64_t i_pos ) { access_sys_t *p_sys = p_access->p_sys; int64_t i_ret; if( i_pos >= INT64_MAX ) return VLC_EGENERIC; msg_Dbg( p_access, "seeking to %"PRId64, i_pos ); i_ret = smbc_lseek( p_sys->i_smb, i_pos, SEEK_SET ); if( i_ret == -1 ) { msg_Err( p_access, "seek failed (%s)", vlc_strerror_c(errno) ); return VLC_EGENERIC; } return VLC_SUCCESS; }
static bool DisplayError(vlc_object_t *obj, struct wl_display *display) { int val = wl_display_get_error(display); if (val == 0) return false; if (val == EPROTO) { const struct wl_interface *iface; uint32_t id; val = wl_display_get_protocol_error(display, &iface, &id); msg_Err(obj, "display protocol error %d on %s object %"PRIu32, val, iface->name, id); } else msg_Err(obj, "display fatal error: %s", vlc_strerror_c(val)); return true; }
/* Wait for data */ static int AccessPoll (access_t *access) { access_sys_t *sys = access->p_sys; struct pollfd ufd; ufd.fd = sys->fd; ufd.events = POLLIN; switch (poll (&ufd, 1, 500)) { case -1: if (errno == EINTR) case 0: /* FIXME: kill this case (arbitrary timeout) */ return -1; msg_Err (access, "poll error: %s", vlc_strerror_c(errno)); access->info.b_eof = true; return -1; } return 0; }
static int Seek(stream_t *access, uint64_t position) { access_sys_t *sys = access->p_sys; int ret; #ifndef EOVERFLOW # define EOVERFLOW EFBIG #endif if (position > INT64_MAX) ret = AVERROR(EOVERFLOW); else ret = avio_seek(sys->context, position, SEEK_SET); if (ret < 0) { msg_Err(access, "Seek to %"PRIu64" failed: %s", position, vlc_strerror_c(AVUNERROR(ret))); if (sys->size < 0 || position != (uint64_t)sys->size) return VLC_EGENERIC; } return VLC_SUCCESS; }
static void Timer (void *data) { vlc_inhibit_t *ih = data; vlc_inhibit_sys_t *sys = ih->p_sys; char *argv[3] = { (char *)"xdg-screensaver", (char *)"reset", NULL }; pid_t pid; int err = posix_spawnp (&pid, "xdg-screensaver", NULL, &sys->attr, argv, environ); if (err == 0) { int status; while (waitpid (pid, &status, 0) == -1); } else msg_Warn (ih, "error starting xdg-screensaver: %s", vlc_strerror_c(err)); }