本文整理汇总了C++中write_buffer函数的典型用法代码示例。如果您正苦于以下问题:C++ write_buffer函数的具体用法?C++ write_buffer怎么用?C++ write_buffer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_buffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dsound_play_thread
// playing thread
static DWORD __stdcall dsound_play_thread(void *param) {
// primary buffer caps
DSBCAPS caps;
caps.dwSize = sizeof(caps);
primary_buffer->GetCaps(&caps);
// primary buffer format
WAVEFORMATEX format;
primary_buffer->GetFormat(&format, sizeof(format), NULL);
// timer resolustion
timeBeginPeriod(1);
// temp buffer for vsti process
float output_buffer[2][4096];
// data write posision
int write_position = 0;
// start playing primary buffer
primary_buffer->Play(0, 0, DSBPLAY_LOOPING);
while (dsound_thread) {
DWORD play_pos, write_pos;
// get current position
primary_buffer->GetCurrentPosition(&play_pos, &write_pos);
// size left in buffer to write.
int data_buffer_size = (caps.dwBufferBytes + write_position - write_pos) % caps.dwBufferBytes;
// write buffer size
int write_buffer_size = buffer_size * format.nBlockAlign;
// size left in buffer
int write_size = write_buffer_size - data_buffer_size;
// maybe data buffer is underflowed.
if (write_size < 0) {
write_size = (caps.dwBufferBytes + write_pos + write_buffer_size - write_position) % caps.dwBufferBytes;
}
// write data at least 32 samles
if (write_size >= 32 * format.nBlockAlign) {
//printf("%8d, %8d, %8d, %8d, %8d\n", timeGetTime(), (caps.dwBufferBytes + write_position + write_size - write_pos) % caps.dwBufferBytes, write_pos, write_size, write_buffer_size);
// samples
uint samples = write_size / format.nBlockAlign;
if (export_rendering()) {
memset(output_buffer[0], 0, samples * sizeof(float));
memset(output_buffer[1], 0, samples * sizeof(float));
} else {
// update
song_update(1000.0 * (double)samples / (double)format.nSamplesPerSec);
// call vsti process func
vsti_update_config((float)format.nSamplesPerSec, 4096);
vsti_process(output_buffer[0], output_buffer[1], samples);
}
// lock primary buffer
void *ptr1, *ptr2;
DWORD size1, size2;
HRESULT hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);
// device lost, restore and try again
if (DSERR_BUFFERLOST == hr) {
primary_buffer->Restore();
hr = primary_buffer->Lock(write_position, write_size, &ptr1, &size1, &ptr2, &size2, 0);
}
// lock succeeded
if (SUCCEEDED(hr)) {
float *left = output_buffer[0];
float *right = output_buffer[1];
uint samples1 = size1 / format.nBlockAlign;
uint samples2 = size2 / format.nBlockAlign;
if (ptr1) write_buffer((short *)ptr1, left, right, samples1);
if (ptr2) write_buffer((short *)ptr2, left + samples1, right + samples1, samples2);
hr = primary_buffer->Unlock(ptr1, size1, ptr2, size2);
write_position = (write_position + write_size) % caps.dwBufferBytes;
}
} else {
Sleep(1);
}
}
// stop sound buffer
primary_buffer->Stop();
// timer resolustion
timeEndPeriod(10);
//.........这里部分代码省略.........
示例2: writePRT
bool writePRT(const char* filename,const ParticlesData& p,const bool /*compressed*/,std::ostream* errorStream)
{
/// Krakatoa pukes on 0 particle files for some reason so don't export at all....
int numParts = p.numParticles();
if (numParts)
{
std::unique_ptr<std::ostream> output(
new std::ofstream(filename,std::ios::out|std::ios::binary));
if (!*output) {
if(errorStream) *errorStream <<"Partio Unable to open file "<<filename<<std::endl;
return false;
}
FileHeadder header;
memcpy(header.magic, magic, sizeof(magic));
memcpy(header.signature, signature, sizeof(signature));
header.headersize = 0x38;
header.version = 1;
header.numParticles = p.numParticles();
int reserve = 4;
output->write((char*)&header,sizeof(FileHeadder));
write<LITEND>(*output, reserve);
write<LITEND>(*output, (int)p.numAttributes());
reserve = 0x2c;
write<LITEND>(*output, reserve);
std::vector<ParticleAttribute> attrs;
int offset = 0;
for (int i=0;i<p.numAttributes();i++) {
ParticleAttribute attr;
p.attributeInfo(i,attr);
Channel ch;
memset(&ch, 0, sizeof(Channel));
memcpy((char*)ch.name, attr.name.c_str(), attr.name.size());
ch.offset = offset;
switch (attr.type) {
case FLOAT: ch.type=4; ch.arity=attr.count; offset += sizeof(float)*attr.count; break;
case INT: ch.type=1; ch.arity=attr.count; offset += sizeof(int)*attr.count; break;
case VECTOR: ch.type=4; ch.arity=attr.count; offset += sizeof(float)*attr.count; break;
case INDEXEDSTR:; break;
case NONE:;break;
}
if (ch.arity) {
#ifdef AUTO_CASES
if (ch.name[0] >= 'a' && ch.name[0] <= 'z') {
ch.name[0] -= 0x20;
}
#endif
output->write((char*)&ch,sizeof(Channel));
attrs.push_back(attr);
}
}
z_stream z;
z.zalloc = Z_NULL;z.zfree = Z_NULL;z.opaque = Z_NULL;
if (deflateInit( &z, Z_DEFAULT_COMPRESSION ) != Z_OK) {
if(errorStream) *errorStream<<"Zlib deflateInit error"<<std::endl;
return false;
}
char out_buf[OUT_BUFSIZE+10];
for (int particleIndex=0;particleIndex<p.numParticles();particleIndex++) {
for (unsigned int attrIndex=0;attrIndex<attrs.size();attrIndex++) {
if (attrs[attrIndex].type==Partio::INT) {
const int* data=p.data<int>(attrs[attrIndex],particleIndex);
if (!write_buffer(*output, z, (char*)out_buf, (void*)data, sizeof(int)*attrs[attrIndex].count, false, errorStream))
return false;
} else if (attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR) {
const float* data=p.data<float>(attrs[attrIndex],particleIndex);
if (!write_buffer(*output, z, (char*)out_buf, (void*)data, sizeof(int)*attrs[attrIndex].count, false, errorStream))
return false;
}
}
}
write_buffer(*output, z, (char*)out_buf, 0, 0, true, errorStream);
if (deflateEnd( &z ) != Z_OK) {
if(errorStream) *errorStream<<"Zlib deflateEnd error"<<std::endl;
return false;
}
// success
}// end if numParticles > 0
return true;
}
示例3: LUKS_hdr_backup
int LUKS_hdr_backup(const char *backup_file, struct crypt_device *ctx)
{
struct device *device = crypt_metadata_device(ctx);
struct luks_phdr hdr;
int fd, devfd, r = 0;
size_t hdr_size;
size_t buffer_size;
ssize_t ret;
char *buffer = NULL;
r = LUKS_read_phdr(&hdr, 1, 0, ctx);
if (r)
return r;
hdr_size = LUKS_device_sectors(&hdr) << SECTOR_SHIFT;
buffer_size = size_round_up(hdr_size, crypt_getpagesize());
buffer = crypt_safe_alloc(buffer_size);
if (!buffer || hdr_size < LUKS_ALIGN_KEYSLOTS || hdr_size > buffer_size) {
r = -ENOMEM;
goto out;
}
log_dbg(ctx, "Storing backup of header (%zu bytes) and keyslot area (%zu bytes).",
sizeof(hdr), hdr_size - LUKS_ALIGN_KEYSLOTS);
log_dbg(ctx, "Output backup file size: %zu bytes.", buffer_size);
devfd = device_open(ctx, device, O_RDONLY);
if (devfd < 0) {
log_err(ctx, _("Device %s is not a valid LUKS device."), device_path(device));
r = -EINVAL;
goto out;
}
if (read_lseek_blockwise(devfd, device_block_size(ctx, device), device_alignment(device),
buffer, hdr_size, 0) < (ssize_t)hdr_size) {
r = -EIO;
goto out;
}
/* Wipe unused area, so backup cannot contain old signatures */
if (hdr.keyblock[0].keyMaterialOffset * SECTOR_SIZE == LUKS_ALIGN_KEYSLOTS)
memset(buffer + sizeof(hdr), 0, LUKS_ALIGN_KEYSLOTS - sizeof(hdr));
fd = open(backup_file, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR);
if (fd == -1) {
if (errno == EEXIST)
log_err(ctx, _("Requested header backup file %s already exists."), backup_file);
else
log_err(ctx, _("Cannot create header backup file %s."), backup_file);
r = -EINVAL;
goto out;
}
ret = write_buffer(fd, buffer, buffer_size);
close(fd);
if (ret < (ssize_t)buffer_size) {
log_err(ctx, _("Cannot write header backup file %s."), backup_file);
r = -EIO;
goto out;
}
r = 0;
out:
crypt_memzero(&hdr, sizeof(hdr));
crypt_safe_free(buffer);
return r;
}
示例4: memory
/*!
@abstract Sort an unsorted BAM file based on the chromosome order
and the leftmost position of an alignment
@param is_by_qname whether to sort by query name
@param fn name of the file to be sorted
@param prefix prefix of the output and the temporary files; upon
sucessess, prefix.bam will be written.
@param max_mem approxiate maximum memory (very inaccurate)
@param full_path the given output path is the full path and not just the prefix
@discussion It may create multiple temporary subalignment files
and then merge them by calling bam_merge_core(). This function is
NOT thread safe.
*/
void bam_sort_core_ext(int is_by_qname, const char *fn, const char *prefix, size_t _max_mem, int is_stdout, int n_threads, int level, int full_path)
{
int ret, i, n_files = 0;
size_t mem, max_k, k, max_mem;
bam_header_t *header;
bamFile fp;
bam1_t *b, **buf;
char *fnout = 0;
char const *suffix = ".bam";
if (full_path) suffix += 4;
if (n_threads < 2) n_threads = 1;
g_is_by_qname = is_by_qname;
max_k = k = 0; mem = 0;
max_mem = _max_mem * n_threads;
buf = 0;
fp = strcmp(fn, "-")? bam_open(fn, "r") : bam_dopen(fileno(stdin), "r");
if (fp == 0) {
fprintf(stderr, "[bam_sort_core] fail to open file %s\n", fn);
return;
}
header = bam_header_read(fp);
if (is_by_qname) change_SO(header, "queryname");
else change_SO(header, "coordinate");
// write sub files
for (;;) {
if (k == max_k) {
size_t old_max = max_k;
max_k = max_k? max_k<<1 : 0x10000;
buf = realloc(buf, max_k * sizeof(void*));
memset(buf + old_max, 0, sizeof(void*) * (max_k - old_max));
}
if (buf[k] == 0) buf[k] = (bam1_t*)calloc(1, sizeof(bam1_t));
b = buf[k];
if ((ret = bam_read1(fp, b)) < 0) break;
if (b->data_len < b->m_data>>2) { // shrink
b->m_data = b->data_len;
kroundup32(b->m_data);
b->data = realloc(b->data, b->m_data);
}
mem += sizeof(bam1_t) + b->m_data + sizeof(void*) + sizeof(void*); // two sizeof(void*) for the data allocated to pointer arrays
++k;
if (mem >= max_mem) {
n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads);
mem = k = 0;
}
}
if (ret != -1)
fprintf(stderr, "[bam_sort_core] truncated file. Continue anyway.\n");
// output file name
fnout = calloc(strlen(prefix) + 20, 1);
if (is_stdout) sprintf(fnout, "-");
else sprintf(fnout, "%s%s", prefix, suffix);
// write the final output
if (n_files == 0) { // a single block
char mode[8];
strcpy(mode, "w");
if (level >= 0) sprintf(mode + 1, "%d", level < 9? level : 9);
ks_mergesort(sort, k, buf, 0);
write_buffer(fnout, mode, k, buf, header, n_threads);
} else { // then merge
char **fns;
n_files = sort_blocks(n_files, k, buf, prefix, header, n_threads);
fprintf(stderr, "[bam_sort_core] merging from %d files...\n", n_files);
fns = (char**)calloc(n_files, sizeof(char*));
for (i = 0; i < n_files; ++i) {
fns[i] = (char*)calloc(strlen(prefix) + 20, 1);
sprintf(fns[i], "%s.%.4d%s", prefix, i, suffix);
}
bam_merge_core2(is_by_qname, fnout, 0, n_files, fns, 0, 0, n_threads, level);
for (i = 0; i < n_files; ++i) {
unlink(fns[i]);
free(fns[i]);
}
free(fns);
}
free(fnout);
// free
for (k = 0; k < max_k; ++k) {
if (!buf[k]) continue;
free(buf[k]->data);
free(buf[k]);
}
free(buf);
bam_header_destroy(header);
//.........这里部分代码省略.........
示例5: Q_UNUSED
void nbody_engine_cuda_bh_tex::fcompute(const nbcoord_t& t, const memory* _y, memory* _f)
{
Q_UNUSED(t);
const smemory* y = dynamic_cast<const smemory*>(_y);
smemory* f = dynamic_cast<smemory*>(_f);
if(y == NULL)
{
qDebug() << "y is not smemory";
return;
}
if(f == NULL)
{
qDebug() << "f is not smemory";
return;
}
advise_compute_count();
size_t count = m_data->get_count();
std::vector<nbcoord_t> host_y(y->size() / sizeof(nbcoord_t));
std::vector<nbcoord_t> host_mass(count);
read_buffer(host_y.data(), y);
read_buffer(host_mass.data(), m_mass);
const nbcoord_t* rx = host_y.data();
const nbcoord_t* ry = rx + count;
const nbcoord_t* rz = rx + 2 * count;
const nbcoord_t* mass = host_mass.data();
nbody_space_heap heap;
heap.build(count, rx, ry, rz, mass, m_distance_to_node_radius_ratio);
size_t tree_size = heap.get_radius_sqr().size();
if(m_dev_indites == NULL)
{
m_dev_tree_xyzr = dynamic_cast<smemory*>(create_buffer(tree_size * sizeof(nbcoord_t) * 4));
m_dev_tree_mass = dynamic_cast<smemory*>(create_buffer(tree_size * sizeof(nbcoord_t)));
m_dev_indites = dynamic_cast<smemory*>(create_buffer(tree_size * sizeof(int)));
}
const nbcoord_t* dev_y = static_cast<const nbcoord_t*>(y->data());
nbcoord_t* dev_f = static_cast<nbcoord_t*>(f->data());
int* dev_indites = static_cast<int*>(m_dev_indites->data());
static_assert(sizeof(vertex4<nbcoord_t>) == sizeof(nbcoord_t) * 4,
"sizeof(vertex4) must be equal to sizeof(nbcoord_t)*4");
std::vector<vertex4<nbcoord_t>> host_tree_xyzr(tree_size);
std::vector<int> host_indites(tree_size);
#pragma omp parallel for
for(size_t n = 0; n < tree_size; ++n)
{
host_tree_xyzr[n].x = heap.get_mass_center()[n].x;
host_tree_xyzr[n].y = heap.get_mass_center()[n].y;
host_tree_xyzr[n].z = heap.get_mass_center()[n].z;
host_tree_xyzr[n].w = heap.get_radius_sqr()[n];
host_indites[n] = static_cast<int>(heap.get_body_n()[n]);
}
write_buffer(m_dev_tree_xyzr, host_tree_xyzr.data());
write_buffer(m_dev_tree_mass, heap.get_mass().data());
write_buffer(m_dev_indites, host_indites.data());
if(m_tree_layout == etl_heap)
{
fcompute_heap_bh_tex(0, static_cast<int>(count), static_cast<int>(tree_size), dev_f,
m_dev_tree_xyzr->tex(4), m_dev_tree_mass->tex(),
dev_indites, get_block_size());
}
else if(m_tree_layout == etl_heap_stackless)
{
fcompute_heap_bh_stackless(0, static_cast<int>(count), static_cast<int>(tree_size), dev_f,
m_dev_tree_xyzr->tex(4), m_dev_tree_mass->tex(),
dev_indites, get_block_size());
}
fcompute_xyz(dev_y, dev_f, static_cast<int>(count), get_block_size());
}
示例6: write_byte
static int write_byte(dest_t *dest, unsigned char val)
{
return write_buffer(dest, &val, 1);
}
示例7: svr_save_xml
int svr_save_xml(
struct server *ps,
int mode)
{
char *id = "svr_save_xml";
char buf[MAXLINE<<8];
dynamic_string *ds;
int fds;
int rc;
int len;
int i;
fds = open(path_svrdb, O_WRONLY | O_CREAT | O_Sync | O_TRUNC, 0600);
if (fds < 0)
{
log_err(errno,id,msg_svdbopen);
return(-1);
}
/* write the sv_qs info */
snprintf(buf,sizeof(buf),
"<server_db>\n<numjobs>%d</numjobs>\n<numque>%d</numque>\n<nextjobid>%d</nextjobid>\n<savetime>%ld</savetime>\n",
ps->sv_qs.sv_numjobs,
ps->sv_qs.sv_numque,
ps->sv_qs.sv_jobidnumber,
time_now);
len = strlen(buf);
if ((rc = write_buffer(buf,len,fds)))
return(rc);
/* write the attribute info */
snprintf(buf,sizeof(buf),"<attributes>");
if ((rc = write_buffer(buf,strlen(buf),fds)))
return(rc);
if ((ds = get_dynamic_string(-1, NULL)) == NULL)
{
log_err(ENOMEM, id, "");
return(ENOMEM);
}
i = 0;
while (i != SRV_ATR_LAST)
{
if (ps->sv_attr[i].at_flags & ATR_VFLAG_SET)
{
buf[0] = '\0';
clear_dynamic_string(ds);
if ((rc = attr_to_str(ds, svr_attr_def + i, ps->sv_attr[i], TRUE) != 0))
{
if (rc != NO_ATTR_DATA)
{
/* ERROR */
snprintf(log_buffer,sizeof(log_buffer),
"Not enough space to print attribute %s",
svr_attr_def[i].at_name);
log_err(-1,id,log_buffer);
free_dynamic_string(ds);
return(rc);
}
}
else
{
snprintf(buf,sizeof(buf),"<%s>%s</%s>\n",
svr_attr_def[i].at_name,
ds->str,
svr_attr_def[i].at_name);
if (buf[0] != '\0')
{
if ((rc = write_buffer(buf,strlen(buf),fds)))
{
free_dynamic_string(ds);
return(rc);
}
}
}
}
i++;
}
free_dynamic_string(ds);
snprintf(buf,sizeof(buf),"</attributes>\n");
if ((rc = write_buffer(buf,strlen(buf),fds)))
return(rc);
/* close the server_db */
snprintf(buf,sizeof(buf),"</server_db>");
if ((rc = write_buffer(buf,strlen(buf),fds)))
return(rc);
//.........这里部分代码省略.........
示例8: while
void RecordVideo::run()
{
// Number of frames for user to know about.
gui->reset_video();
// Wait for trigger
trigger_lock->lock("RecordVideo::run");
while( !done && !write_result ) {
if( recording_paused ) {
pause_record_lock->unlock();
record_paused_lock->lock();
}
if( done ) break;
VideoDevice *vdevice = record->vdevice;
VFrame *capture_frame = get_buffer();
vdevice->set_field_order(record->reverse_interlace);
// Capture a frame
grab_result = read_buffer(capture_frame);
if( done ) break;
if( vdevice->config_updated() ) {
flush_buffer();
delete_buffer();
config_update();
gui->reset_video();
record->record_monitor->reconfig();
continue;
}
if( grab_result ) {
Timer::delay(250);
continue;
}
decompress_buffer(capture_frame);
record->resync();
write_buffer();
if( record->monitor_video && capture_frame->get_data() )
if( !writing_file || !record->is_behind() )
record->record_monitor->update(capture_frame);
if( writing_file && record->fill_underrun_frames ) {
VFrame *last_frame = capture_frame;
int fill = record->dropped;
while( --fill >= 0 ) {
capture_frame = get_buffer();
capture_frame->copy_from(last_frame);
last_frame = capture_frame;
write_buffer();
}
}
else
record->written_frames += record->dropped;
if( record->single_frame ) {
record->single_frame = 0;
record->stop_writing_file();
}
if( done ) break;
if( !done ) done = write_result;
if( done ) break;
record->check_batch_complete();
}
SET_TRACE
flush_buffer();
delete_buffer();
SET_TRACE
//TRACE("RecordVideo::run 2");
if( write_result ) {
ErrorBox error_box(PROGRAM_NAME ": Error",
mwindow->gui->get_abs_cursor_x(1),
mwindow->gui->get_abs_cursor_y(1));
error_box.create_objects(_("No space left on disk."));
error_box.run_window();
}
SET_TRACE
}
示例9: write_buffer_truehd
/* Adapted from libavformat/spdifenc.c:
* It seems Dolby TrueHD frames have to be encapsulated in MAT frames before
* they can be encapsulated in IEC 61937.
* Here we encapsulate 24 TrueHD frames in a single MAT frame, padding them
* to achieve constant rate.
* The actual format of a MAT frame is unknown, but the below seems to work.
* However, it seems it is not actually necessary for the 24 TrueHD frames to
* be in an exact alignment with the MAT frame
*/
static int write_buffer_truehd( filter_t *p_filter, block_t *p_in_buf )
{
#define TRUEHD_FRAME_OFFSET 2560
filter_sys_t *p_sys = p_filter->p_sys;
if( !p_sys->p_out_buf
&& write_init( p_filter, p_in_buf, 61440, 61440 / 16 ) )
return SPDIF_ERROR;
int i_padding = 0;
if( p_sys->truehd.i_frame_count == 0 )
{
static const char p_mat_start_code[20] = {
0x07, 0x9E, 0x00, 0x03, 0x84, 0x01, 0x01, 0x01, 0x80, 0x00,
0x56, 0xA5, 0x3B, 0xF4, 0x81, 0x83, 0x49, 0x80, 0x77, 0xE0
};
write_data( p_filter, p_mat_start_code, 20, true );
/* We need to include the S/PDIF header in the first MAT frame */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 20
- SPDIF_HEADER_SIZE;
}
else if( p_sys->truehd.i_frame_count == 11 )
{
/* The middle mat code need to be at the ((2560 * 12) - 4) offset */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 4;
}
else if( p_sys->truehd.i_frame_count == 12 )
{
static const char p_mat_middle_code[12] = {
0xC3, 0xC1, 0x42, 0x49, 0x3B, 0xFA,
0x82, 0x83, 0x49, 0x80, 0x77, 0xE0
};
write_data( p_filter, p_mat_middle_code, 12, true );
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - ( 12 - 4 );
}
else if( p_sys->truehd.i_frame_count == 23 )
{
static const char p_mat_end_code[16] = {
0xC3, 0xC2, 0xC0, 0xC4, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x97, 0x11
};
/* The end mat code need to be at the ((2560 * 24) - 24) offset */
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer - 24;
if( i_padding < 0 || p_in_buf->i_buffer + i_padding >
p_sys->p_out_buf->i_buffer - p_sys->i_out_offset )
return SPDIF_ERROR;
write_buffer( p_filter, p_in_buf );
write_padding( p_filter, i_padding );
write_data( p_filter, p_mat_end_code, 16, true );
write_finalize( p_filter, IEC61937_TRUEHD, 1 /* in bytes */ );
p_sys->truehd.i_frame_count = 0;
return SPDIF_SUCCESS;
}
else
i_padding = TRUEHD_FRAME_OFFSET - p_in_buf->i_buffer;
if( i_padding < 0 || p_in_buf->i_buffer + i_padding >
p_sys->p_out_buf->i_buffer - p_sys->i_out_offset )
return SPDIF_ERROR;
write_buffer( p_filter, p_in_buf );
write_padding( p_filter, i_padding );
p_sys->truehd.i_frame_count++;
return SPDIF_MORE_DATA;
}
示例10: serialize_krb5_ctx
int
serialize_krb5_ctx(gss_ctx_id_t ctx, gss_buffer_desc *buf, int32_t *endtime)
{
char *p, *end;
static int constant_one = 1;
static int constant_zero = 0;
unsigned char fakeseed[16];
uint32_t algorithm;
if (!(buf->value = calloc(1, MAX_CTX_LEN)))
goto out_err;
p = buf->value;
end = buf->value + MAX_CTX_LEN;
/* initiate: 1 => initiating 0 => accepting */
if (ctx->more_flags & LOCAL) {
if (WRITE_BYTES(&p, end, constant_one)) goto out_err;
}
else {
if (WRITE_BYTES(&p, end, constant_zero)) goto out_err;
}
/* seed_init: not used by kernel code */
if (WRITE_BYTES(&p, end, constant_zero)) goto out_err;
/* seed: not used by kernel code */
memset(&fakeseed, 0, sizeof(fakeseed));
if (write_bytes(&p, end, &fakeseed, 16)) goto out_err;
/* signalg */
algorithm = 0; /* SGN_ALG_DES_MAC_MD5 XXX */
if (WRITE_BYTES(&p, end, algorithm)) goto out_err;
/* sealalg */
algorithm = 0; /* SEAL_ALG_DES XXX */
if (WRITE_BYTES(&p, end, algorithm)) goto out_err;
/* endtime */
if (WRITE_BYTES(&p, end, ctx->lifetime)) goto out_err;
if (endtime)
*endtime = ctx->lifetime;
/* seq_send */
if (WRITE_BYTES(&p, end, ctx->auth_context->local_seqnumber))
goto out_err;
/* mech_used */
if (write_buffer(&p, end, (gss_buffer_desc*)&krb5oid)) goto out_err;
/* enc: derive the encryption key and copy it into buffer */
if (write_heimdal_enc_key(&p, end, ctx)) goto out_err;
/* seq: get the sequence number key and copy it into buffer */
if (write_heimdal_seq_key(&p, end, ctx)) goto out_err;
buf->length = p - (char *)buf->value;
printerr(2, "serialize_krb5_ctx: returning buffer "
"with %d bytes\n", buf->length);
return 0;
out_err:
printerr(0, "ERROR: failed exporting Heimdal krb5 ctx to kernel\n");
if (buf->value) free(buf->value);
buf->length = 0;
return -1;
}
示例11: ctf_gen
caddr_t
ctf_gen(iiburst_t *iiburst, size_t *resszp, int do_compress)
{
ctf_buf_t *buf = ctf_buf_new();
ctf_header_t h;
caddr_t outbuf;
int i;
target_requires_swap = do_compress & CTF_SWAP_BYTES;
do_compress &= ~CTF_SWAP_BYTES;
/*
* Prepare the header, and create the CTF output buffers. The data
* object section and function section are both lists of 2-byte
* integers; we pad these out to the next 4-byte boundary if needed.
*/
h.cth_magic = CTF_MAGIC;
h.cth_version = CTF_VERSION;
h.cth_flags = do_compress ? CTF_F_COMPRESS : 0;
h.cth_parlabel = strtab_insert(&buf->ctb_strtab,
iiburst->iib_td->td_parlabel);
h.cth_parname = strtab_insert(&buf->ctb_strtab,
iiburst->iib_td->td_parname);
h.cth_lbloff = 0;
(void) list_iter(iiburst->iib_td->td_labels, write_label,
buf);
pad_buffer(buf, 2);
h.cth_objtoff = ctf_buf_cur(buf);
for (i = 0; i < iiburst->iib_nobjts; i++)
write_objects(iiburst->iib_objts[i], buf);
pad_buffer(buf, 2);
h.cth_funcoff = ctf_buf_cur(buf);
for (i = 0; i < iiburst->iib_nfuncs; i++)
write_functions(iiburst->iib_funcs[i], buf);
pad_buffer(buf, 4);
h.cth_typeoff = ctf_buf_cur(buf);
(void) list_iter(iiburst->iib_types, write_type, buf);
debug(2, "CTF wrote %d types\n", list_count(iiburst->iib_types));
h.cth_stroff = ctf_buf_cur(buf);
h.cth_strlen = strtab_size(&buf->ctb_strtab);
if (target_requires_swap) {
SWAP_16(h.cth_preamble.ctp_magic);
SWAP_32(h.cth_parlabel);
SWAP_32(h.cth_parname);
SWAP_32(h.cth_lbloff);
SWAP_32(h.cth_objtoff);
SWAP_32(h.cth_funcoff);
SWAP_32(h.cth_typeoff);
SWAP_32(h.cth_stroff);
SWAP_32(h.cth_strlen);
}
/*
* We only do compression for ctfmerge, as ctfconvert is only
* supposed to be used on intermediary build objects. This is
* significantly faster.
*/
if (do_compress)
outbuf = write_compressed_buffer(&h, buf, resszp);
else
outbuf = write_buffer(&h, buf, resszp);
ctf_buf_free(buf);
return (outbuf);
}
示例12: printer_execute_ccw
/*-------------------------------------------------------------------*/
static void printer_execute_ccw (DEVBLK *dev, BYTE code, BYTE flags,
BYTE chained, U32 count, BYTE prevcode, int ccwseq,
BYTE *iobuf, BYTE *more, BYTE *unitstat, U32 *residual)
{
int rc = 0; /* Return code */
U32 i; /* Loop counter */
U32 num; /* Number of bytes to move */
char *eor; /* -> end of record string */
char *nls = "\n\n\n"; /* -> new lines */
BYTE c; /* Print character */
char hex[3]; /* for hex conversion */
char wbuf[150];
/* Reset flags at start of CCW chain */
if (chained == 0)
{
dev->diaggate = 0;
}
/* Open the device file if necessary */
if (dev->fd < 0 && !IS_CCW_SENSE(code))
rc = open_printer (dev);
else
{
/* If printer stopped, return intervention required */
if (dev->stopdev && !IS_CCW_SENSE(code))
rc = -1;
else
rc = 0;
}
if (rc < 0)
{
/* Set unit check with intervention required */
dev->sense[0] = SENSE_IR;
*unitstat = CSW_UC;
return;
}
/* Process depending on CCW opcode */
switch (code) {
case 0x01: /* Write No Space */
case 0x09: /* Write and Space 1 Line */
case 0x11: /* Write and Space 2 Lines */
case 0x19: /* Write and Space 3 Lines */
case 0x89: /* Write and Skip to Channel 1 */
case 0x91: /* Write and Skip to Channel 2 */
case 0x99: /* Write and Skip to Channel 3 */
case 0xA1: /* Write and Skip to Channel 4 */
case 0xA9: /* Write and Skip to Channel 5 */
case 0xB1: /* Write and Skip to Channel 6 */
case 0xB9: /* Write and Skip to Channel 7 */
case 0xC1: /* Write and Skip to Channel 8 */
case 0xC9: /* Write and Skip to Channel 9 */
case 0xD1: /* Write and Skip to Channel 10 */
case 0xD9: /* Write and Skip to Channel 11 */
case 0xE1: /* Write and Skip to Channel 12 */
if (dev->rawcc)
{
sprintf(hex,"%02x",code);
write_buffer(dev, hex, 2, unitstat);
if (*unitstat != 0) return;
WRITE_LINE();
write_buffer(dev, "\n", 1, unitstat);
if (*unitstat == 0)
*unitstat = CSW_CE | CSW_DE;
return;
}
if ( dev->browse && dev->ccpend && ((chained & CCW_FLAGS_CD) == 0) )
{
dev->ccpend = 0;
/* dev->currline++; */
write_buffer(dev, "\n", 1, unitstat);
if (*unitstat != 0) return;
}
WRITE_LINE();
if ((flags & CCW_FLAGS_CD) == 0)
{
if ( code <= 0x80 ) /* line control */
{
coun = code / 8;
if ( coun == 0 )
{
dev->chskip = 1;
if ( dev->browse )
{
dev->ccpend = 1;
*unitstat = 0;
}
else
write_buffer(dev, "\r", 1, unitstat);
if (*unitstat == 0)
*unitstat = CSW_CE | CSW_DE;
return;
}
//.........这里部分代码省略.........
示例13: menu_main
void menu_main(void)
{
static uint8_t main_cursor = LINE0; // These are now static so as to remember the main menu position
static uint8_t main_top = MAINSTART;
static uint8_t main_temp = 0;
static uint8_t old_menu = 0;
button = NONE;
// Wait until user's finger is off button 1
while(BUTTON1 == 0)
{
_delay_ms(50);
}
while(button != BACK)
{
// Clear buffer before each update
clear_buffer(buffer);
// Print menu
print_menu_frame(0); // Frame
for (uint8_t i = 0; i < 4; i++)
{
LCD_Display_Text(main_top+i,(const unsigned char*)Verdana8,ITEMOFFSET,(uint8_t)pgm_read_byte(&lines[i])); // Lines
}
print_cursor(main_cursor); // Cursor
write_buffer(buffer,1);
// Poll buttons when idle
poll_buttons(true);
// Handle menu changes
update_menu(MAINITEMS, MAINSTART, 0, button, &main_cursor, &main_top, &main_temp);
// If main menu item has changed, reset submenu positions
// and flag to submenus that positions need to be reset
if (main_temp != old_menu)
{
cursor = LINE0;
menu_temp = 0;
old_menu = main_temp;
menu_flag = 1;
}
// If ENTER pressed, jump to menu
if (button == ENTER)
{
do_main_menu_item(main_temp);
button = NONE;
// Wait until user's finger is off button 1
while(BUTTON1 == 0)
{
_delay_ms(50);
}
}
}
// menu_beep(1);
}
示例14: save_attr_xml
int save_attr_xml(
struct attribute_def *padef, /* pbs_attribute definition array */
pbs_attribute *pattr, /* ptr to pbs_attribute value array */
int numattr, /* number of attributes in array */
int fds) /* file descriptor where attributes are written */
{
int i;
int rc;
char buf[MAXLINE<<8];
char log_buf[LOCAL_LOG_BUF_SIZE];
dynamic_string *ds = get_dynamic_string(-1, NULL);
/* write the opening tag for attributes */
snprintf(buf,sizeof(buf),"<attributes>\n");
if ((rc = write_buffer(buf,strlen(buf),fds)) != 0)
return(rc);
for (i = 0; i < numattr; i++)
{
if (pattr[i].at_flags & ATR_VFLAG_SET)
{
buf[0] = '\0';
clear_dynamic_string(ds);
if ((rc = attr_to_str(ds, padef+i, pattr[i], TRUE)) != 0)
{
if (rc != NO_ATTR_DATA)
{
/* ERROR */
snprintf(log_buf,sizeof(log_buf),
"Not enough space to print pbs_attribute %s",
padef[i].at_name);
free_dynamic_string(ds);
return(rc);
}
}
else
{
snprintf(buf,sizeof(buf),"<%s>%s</%s>\n",
padef[i].at_name,
ds->str,
padef[i].at_name);
if ((rc = write_buffer(buf,strlen(buf),fds)) != 0)
{
free_dynamic_string(ds);
return(rc);
}
}
}
} /* END for each pbs_attribute */
free_dynamic_string(ds);
/* close the attributes */
snprintf(buf,sizeof(buf),"</attributes>\n");
rc = write_buffer(buf,strlen(buf),fds);
/* we can just return this since its the last write */
return(rc);
} /* END save_attr_xml() */
示例15: write_long
static int write_long(dest_t *dest, glui32 val)
{
unsigned char buf[4];
Write4(buf, val);
return write_buffer(dest, buf, 4);
}