static rsexp compile_application (RState* r, rsexp expr, rsexp next) { rsexp proc, args, code; if (!validate_application (r, expr)) return R_FAILURE; proc = r_car (expr); args = r_cdr (expr); r_gc_scope_open (r); ensure_or_goto (code = emit_apply (r), exit); ensure_or_goto (code = compile (r, proc, code), exit); while (!r_null_p (args)) { ensure_or_goto (code = emit_arg (r, code), exit); ensure_or_goto (code = compile (r, r_car (args), code), exit); args = r_cdr (args); } if (!tail_p (r, next)) code = emit_frame (r, next, code); exit: r_gc_scope_close_and_protect (r, code); return code; }
/** * Return 0 if ownership of 'data' has been transfered from caller */ static void submit_au(vdec_decoder_t *vdd, struct vdec_au *au, void *data, size_t len, int drop_non_ref, video_decoder_t *vd) { vdec_pic_t *vp; if(data != NULL && vdd->filter_aud) len = filter_aud(data, len); au->packet_addr = (intptr_t)data; au->packet_size = len; hts_mutex_lock(&vdd->mtx); vdd->submitted_au = 1; int r = vdec_decode_au(vdd->handle, drop_non_ref ? VDEC_DECODER_MODE_SKIP_NON_REF : VDEC_DECODER_MODE_NORMAL, au); if(r == 0) { while(vdd->submitted_au) { if(hts_cond_wait_timeout(&vdd->audone, &vdd->mtx, 5000)) { panic("Cell video decoder lockup"); } } } if(data == NULL) { // When we want to flush out all frames from the decoder // we just wait for them by sleeping. Lame but kinda works hts_mutex_unlock(&vdd->mtx); usleep(100000); hts_mutex_lock(&vdd->mtx); } while((vp = LIST_FIRST(&vdd->pictures)) != NULL) { // data == NULL means that we should do a complete flush if(vdd->flush_to < vp->order && data != NULL) break; LIST_REMOVE(vp, link); vdd->num_pictures--; hts_mutex_unlock(&vdd->mtx); emit_frame(vd, vp); hts_mutex_lock(&vdd->mtx); free(vp); } while(vdd->num_pictures > 16) { vp = LIST_FIRST(&vdd->pictures); assert(vp != NULL); release_picture(vp); vdd->num_pictures--; } hts_mutex_unlock(&vdd->mtx); }
void hdlc16::insert_bit( bool bit ) { assert( bit == 0 || bit == 1 ); last_8_bits = ( last_8_bits << 1 ) | ( bit & 1 ); if( num_contig_ones == 5 && bit == 0 ) { /*skip stuffed bit*/ } else { if( bitlocked ) { bitbuf.push_back( bit ); if( bitbuf.size() > 24 ) { //only insert from 24 bits back //this skips the frame CRC(16bit), //and skips the end framer byte(8bit) crc.insert( bitbuf[ bitbuf.size() - 25 ] ); } } if( valid_frame() ) { frames::frame frame = emit_frame(); frames::buffer buffer; buffer.push_back( frame ); broadcast( buffer ); } if( last_8_bits == HDLC_FRAMER ) { bitbuf.clear(); bitlocked = true; } } if( bit == 1 ) { num_contig_ones++; } else { num_contig_ones = 0; } }
int main(int argc, char **argv) { AVFrame *src_frame = av_frame_alloc(); if (!src_frame) { perror("Could not allocate frame"); return 1; } avcodec_register_all(); av_register_all(); AVPacket packet; int ret; if ((ret = open_input_file(argv[1])) >= 0) { /* read all packets */ while ((ret = av_read_frame(pFormatContext, &packet)) >= 0) { if (packet.stream_index != iAudioStream) continue; avcodec_get_frame_defaults(src_frame); int got_frame = 0; ret = avcodec_decode_audio4(pDecoderContext, src_frame, &got_frame, &packet); if (ret < 0) { av_log(NULL, AV_LOG_ERROR, "Error decoding audio\n"); continue; } if (got_frame) { emit_frame(src_frame); } av_free_packet(&packet); } } if (pDecoderContext) avcodec_close(pDecoderContext); avformat_close_input(&pFormatContext); // av_frame_free(&src_frame); // This causes a segfault "double free or corruption (!prev)." if (ret < 0 && ret != AVERROR_EOF) { char buf[1024]; av_strerror(ret, buf, sizeof(buf)); fprintf(stderr, "Error occurred: %s\n", buf); return 1; } return 0; }
void ReplayAudioIngest::process_packet(IOAudioPacket *pkt) { PlanarAudioPacket<int16_t> *planar = pkt->make_planar<int16_t>( ); /* * iterate through our map and pull out channels. Load FIFO for each. * Then, emit transformed frames until the FIFO can't provide * any more data. */ for (channel_entry &ch : channel_map) { /* ignore mappings for channels above the number we have */ if (ch.channel_no < planar->channels( )) { int16_t *ch_samples = planar->channel(ch.channel_no); size_t n_samples = planar->size_samples( ); ch.fifo->add_packed_samples(ch_samples, n_samples); } while (ch.fifo->fill_samples( ) >= fft_size) { emit_frame(ch); } } }
void emitter_tick(void) { flist_node* fn = flist_tick(emitter.fl); while (fn != NULL) { emitter.frame_counts[fn->type] += 1; switch (fn->type) { case VIS_FTYPE_EMIT: emit_frame(fn->data.frame); break; case VIS_FTYPE_EXIT: command_str(emitter.commands, "exit"); break; case VIS_FTYPE_PLAY: audio_play(); break; case VIS_FTYPE_CMD: command_str(emitter.commands, fn->data.cmd); break; case VIS_FTYPE_BGCOLOR: drawer_bgcolor(emitter.drawer, fn->data.color[0], fn->data.color[1], fn->data.color[2]); break; case VIS_FTYPE_MUTATE: plist_foreach(emitter.particles, do_mutate_fn, fn->data.method); break; case VIS_FTYPE_SCRIPTCB: script_run_cb(fn->data.scriptcb->owner, fn->data.scriptcb, NULL); break; case VIS_FTYPE_FRAMESEEK: flist_goto_frame(emitter.fl, fn->data.frameseek); break; case VIS_MAX_FTYPE: break; } /* do not process next node if this is a frame seek */ fn = fn->type != VIS_FTYPE_FRAMESEEK ? flist_node_next(fn) : NULL; } }
static rsexp compile_call_cc (RState* r, rsexp expr, rsexp next) { rsexp code; if (!validate_call_cc (r, expr)) return R_FAILURE; r_gc_scope_open (r); ensure_or_goto (code = emit_apply (r), exit); ensure_or_goto (code = compile (r, r_cadr (expr), code), exit); ensure_or_goto (code = emit_arg (r, code), exit); ensure_or_goto (code = emit_capture_cc (r, code), exit); if (!tail_p (r, next)) code = emit_frame (r, next, code); exit: r_gc_scope_close_and_protect (r, code); return code; }
static void vtb_decode(struct media_codec *mc, struct video_decoder *vd, struct media_queue *mq, struct media_buf *mb, int reqsize) { vtb_decoder_t *vtbd = mc->opaque; VTDecodeInfoFlags infoflags; int flags = kVTDecodeFrame_EnableAsynchronousDecompression | kVTDecodeFrame_EnableTemporalProcessing; OSStatus status; CMBlockBufferRef block_buf; CMSampleBufferRef sample_buf; vtbd->vtbd_vd = vd; status = CMBlockBufferCreateWithMemoryBlock(kCFAllocatorDefault, mb->mb_data, mb->mb_size, kCFAllocatorNull, NULL, 0, mb->mb_size, 0, &block_buf); if(status) { TRACE(TRACE_ERROR, "VTB", "Data buffer allocation error %d", status); return; } CMSampleTimingInfo ti; ti.duration = CMTimeMake(mb->mb_duration, 1000000); ti.presentationTimeStamp = CMTimeMake(mb->mb_pts, 1000000); ti.decodeTimeStamp = CMTimeMake(mb->mb_dts, 1000000); status = CMSampleBufferCreate(kCFAllocatorDefault, block_buf, TRUE, 0, 0, vtbd->vtbd_fmt, 1, 1, &ti, 0, NULL, &sample_buf); CFRelease(block_buf); if(status) { TRACE(TRACE_ERROR, "VTB", "Sample buffer allocation error %d", status); return; } void *frame_opaque = &vd->vd_reorder[vd->vd_reorder_ptr]; copy_mbm_from_mb(frame_opaque, mb); vd->vd_reorder_ptr = (vd->vd_reorder_ptr + 1) & VIDEO_DECODER_REORDER_MASK; if(mb->mb_skip) flags |= kVTDecodeFrame_DoNotOutputFrame; status = VTDecompressionSessionDecodeFrame(vtbd->vtbd_session, sample_buf, flags, frame_opaque, &infoflags); CFRelease(sample_buf); if(status) { TRACE(TRACE_ERROR, "VTB", "Decoding error %d", status); } hts_mutex_lock(&vtbd->vtbd_mutex); if(vtbd->vtbd_flush_to != PTS_UNSET) { vtb_frame_t *vf; while((vf = LIST_FIRST(&vtbd->vtbd_frames)) != NULL) { if(vtbd->vtbd_flush_to < vf->vf_mbm.mbm_pts) break; LIST_REMOVE(vf, vf_link); hts_mutex_unlock(&vtbd->vtbd_mutex); emit_frame(vtbd, vf, mq); hts_mutex_lock(&vtbd->vtbd_mutex); CFRelease(vf->vf_buf); free(vf); } } hts_mutex_unlock(&vtbd->vtbd_mutex); }
static void vda_decode(struct media_codec *mc, struct video_decoder *vd, struct media_queue *mq, struct media_buf *mb, int reqsize) { vda_decoder_t *vdad = mc->opaque; CFDictionaryRef user_info; CFDataRef coded_frame; const int num_kvs = 6; CFStringRef keys[num_kvs]; CFNumberRef values[num_kvs]; const int keyframe = mb->mb_keyframe; const int drive_clock = mb->mb_drive_clock; vda_frame_t *vf; int i; uint8_t skip = mb->mb_skip; vdad->vdad_vd = vd; coded_frame = CFDataCreate(kCFAllocatorDefault, mb->mb_data, mb->mb_size); keys[0] = CFSTR("pts"); keys[1] = CFSTR("duration"); keys[2] = CFSTR("keyframe"); keys[3] = CFSTR("epoch"); keys[4] = CFSTR("drive_clock"); keys[5] = CFSTR("skip"); values[0] = CFNumberCreate(NULL, kCFNumberSInt64Type, &mb->mb_pts); values[1] = CFNumberCreate(NULL, kCFNumberSInt32Type, &mb->mb_duration); values[2] = CFNumberCreate(NULL, kCFNumberSInt32Type, &keyframe); values[3] = CFNumberCreate(NULL, kCFNumberSInt8Type, &mb->mb_epoch); values[4] = CFNumberCreate(NULL, kCFNumberSInt8Type, &drive_clock); values[5] = CFNumberCreate(NULL, kCFNumberSInt8Type, &skip); user_info = CFDictionaryCreate(kCFAllocatorDefault, (const void **)keys, (const void **)values, num_kvs, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); for(i = 0; i < num_kvs; i++) CFRelease(values[i]); uint32_t flags = 0; VDADecoderDecode(vdad->vdad_decoder, flags, coded_frame, user_info); CFRelease(user_info); CFRelease(coded_frame); hts_mutex_lock(&vdad->vdad_mutex); if(vdad->vdad_flush_to != PTS_UNSET) { while((vf = LIST_FIRST(&vdad->vdad_frames)) != NULL) { if(vdad->vdad_flush_to < vf->vf_pts) break; LIST_REMOVE(vf, vf_link); hts_mutex_unlock(&vdad->vdad_mutex); emit_frame(vdad, vf, mq); hts_mutex_lock(&vdad->vdad_mutex); CFRelease(vf->vf_buf); free(vf); } } hts_mutex_unlock(&vdad->vdad_mutex); }