static QWORD WINAPI ASAP_GetLength(void *inst, DWORD mode) { ASAPSTREAM *stream = (ASAPSTREAM *) inst; if (mode != BASS_POS_BYTE) errorn(BASS_ERROR_NOTAVAIL); noerrorn((stream->duration * (ASAP_SAMPLE_RATE / 100) / 10) << stream->asap.module_info.channels); // assumes 16-bit }
static ssize_t data_pcre_t_compare(data_t *data, fastcall_compare *fargs){ // {{{ ssize_t ret; int ovector[1 * 3]; void *data_ptr; uintmax_t data_size; data_t freeit; pcre_t *fdata = (pcre_t *)data->ptr; if(fargs->data2 == NULL) return errorn(ENOSYS); if( (ret = data_make_flat(fargs->data2, FORMAT(native), &freeit, &data_ptr, &data_size)) < 0){ data_free(&freeit); return ret; } if(pcre_exec( fdata->re, NULL, data_ptr, data_size, 0, fdata->options, ovector, (sizeof(ovector) / sizeof(ovector[0])) ) < 0){ fargs->result = 1; // not match }else{ fargs->result = 0; // match } data_free(&freeit); return 0; } // }}}
static QWORD WINAPI ASAP_SetPosition(void *inst, QWORD pos, DWORD mode) { ASAPSTREAM *stream = (ASAPSTREAM *) inst; if ((BYTE) mode != BASS_POS_BYTE) errorn(BASS_ERROR_NOTAVAIL); ASAP_Seek(&stream->asap, bytes_to_duration(stream, pos)); return pos; }
static ssize_t data_pcre_t_enum(data_t *data, fastcall_enum *fargs){ // {{{ ssize_t ret; int ovector[1 * 3]; void *data_ptr; uintmax_t data_size; data_t freeit; data_t *deref; uintmax_t offset = 0; pcre_t *fdata = (pcre_t *)data->ptr; if(fdata->data == NULL) return errorn(ENOSYS); if( (ret = data_make_flat(fdata->data, FORMAT(native), &freeit, &data_ptr, &data_size)) < 0){ data_free(&freeit); return ret; } // deref fdata->data data_realholder(ret, fdata->data, deref); if(ret < 0){ data_free(&freeit); return ret; } while(1){ if(pcre_exec( fdata->re, NULL, data_ptr, data_size, offset, fdata->options, ovector, (sizeof(ovector) / sizeof(ovector[0])) ) < 0) goto exit; data_t d_item = DATA_HEAP_SLICET(deref, ovector[0], ovector[1] - ovector[0]); fastcall_push r_push_item = { { 3, ACTION_PUSH }, &d_item }; ret = data_query(fargs->dest, &r_push_item); data_free(&d_item); if(ret < 0) goto exit; offset = ovector[1]; } ret = 0; exit:; fastcall_push r_push_end = { { 3, ACTION_PUSH }, NULL }; data_query(fargs->dest, &r_push_end); data_free(&freeit); return ret; } // }}}
static ssize_t shmem_init(ipc_shmem_userdata *userdata){ // {{{ size_t i; sem_init(&userdata->shmaddr->sem_written, 1, 0); sem_init(&userdata->shmaddr->sem_free, 1, userdata->shmaddr->nitems); for(i=0; i<userdata->shmaddr->nitems; i++){ if(sem_init(&userdata->shmblocks[i].sem_done, 1, 0) != 0) return errorn(EFAULT); userdata->shmblocks[i].data_rel_ptr = i * userdata->shmaddr->item_size; } return 0; } // }}}
static ssize_t shmem_block_status(ipc_shmem_userdata *userdata, ipc_shmem_block *block, size_t old_status, size_t new_status){ // {{{ if(__sync_bool_compare_and_swap(&block->status, old_status, new_status)){ switch(new_status){ case STATUS_FREE: sem_post(&userdata->shmaddr->sem_free); break; case STATUS_WRITTEN: sem_post(&userdata->shmaddr->sem_written); break; case STATUS_EXEC_DONE: sem_post(&block->sem_done); break; default: break; } return 0; } return errorn(EFAULT); } // }}}