static block_t *Block(access_t *access) { access_t *a = GetAccess(access); if (a == NULL) return NULL; if (likely(a->pf_block != NULL)) return vlc_access_Block(a); if (a->pf_read == NULL) { access->info.b_eof = true; return NULL; } /* Emulate pf_block in case of mixed pf_read and bf_block */ block_t *block = block_Alloc(4096); if (unlikely(block == NULL)) return NULL; ssize_t ret = vlc_access_Read(a, block->p_buffer, block->i_buffer); if (ret >= 0) { block->i_buffer = ret; access->info.i_pos += ret; } else { block_Release(block); block = NULL; } return block; }
/* Read access */ static ssize_t AStreamReadStream(stream_t *s, void *buf, size_t len) { stream_sys_t *sys = s->p_sys; input_thread_t *input = s->p_input; ssize_t val = 0; do { if (vlc_access_Eof(sys->access)) return 0; if (vlc_killed()) return -1; val = vlc_access_Read(sys->access, buf, len); if (val == 0) return 0; /* EOF */ } while (val < 0); if (input != NULL) { uint64_t total; vlc_mutex_lock(&input->p->counters.counters_lock); stats_Update(input->p->counters.p_read_bytes, val, &total); stats_Update(input->p->counters.p_input_bitrate, total, NULL); stats_Update(input->p->counters.p_read_packets, 1, NULL); vlc_mutex_unlock(&input->p->counters.counters_lock); } return val; }
static ssize_t Read(access_t *access, uint8_t *buf, size_t len) { access_t *a = GetAccess(access); if (a == NULL) return 0; /* NOTE: Since we recreate the underlying access, the access method can * change. We need to check it. For instance, a path could point to a * regular file during Open() yet point to a directory here and now. */ if (unlikely(a->pf_read == NULL)) { access->info.b_eof = true; return 0; } ssize_t ret = vlc_access_Read(a, buf, len); if (ret >= 0) access->info.i_pos += ret; return ret; }