NWindowScreen::NWindowScreen(status_t *ret) : BWindowScreen("Example", B_8_BIT_640x480, ret), width(639), height(479), COLORS(256) { PRINT(("WindowScreen ctor.\n")); thread_is_locked = true; tid = 0; if(*ret == B_OK) { PRINT(("creating blocking sem and save_buffer area.\n")); // this semaphore controls the access to the WindowScreen sem = create_sem(0,"WindowScreen Access"); // this area is used to save the whole framebuffer when // switching workspaces. (better than malloc()). area = create_area("save", (void**)&save_buffer, B_ANY_ADDRESS, 640*480, B_NO_LOCK, B_READ_AREA|B_WRITE_AREA); // exit if an error occured. if((sem < B_OK) || (area < B_OK)) { PRINT(("create_area() or create_sem() failed\n")); *ret = B_ERROR; } else { PRINT(("calling Show().\n")); Show(); // let's go. See you in ScreenConnected. } } else { PRINT(("BWindowScreen base class ctor returned failure\n")); be_app->PostMessage(B_QUIT_REQUESTED); } // set the frame rate set_frame_rate(30.); }
void draw_streamers(ScreenBuffer *s, int frame) { s->dim(150); set_frame_rate(15); for (int i = 0; i < N_STREAMERS; ++i) { //printf("streamer %d: height %d v %d delay %d\n", i, streamers[i].y, streamers[i].v, streamers[i].delay); streamers[i].move(s); } }
/* open Video4Linux2 device and try to set up certain parameters */ MjpegCamera::MjpegCamera(const char *device) { buffers = NULL; n_buffers = 0; fd = open(device, O_RDWR); if (fd == -1) { throw POSIXError("open v4l device"); } set_image_format( ); set_frame_rate( ); map_frame_buffers( ); queue_all_buffers( ); }
blargg_err_t Nes_Emu::set_sample_rate( long rate, Multi_Buffer* new_buf ) { require( new_buf ); RETURN_ERR( auto_init() ); emu.impl->apu.volume( 1.0 ); // cancel any previous non-linearity RETURN_ERR( new_buf->set_sample_rate( rate, 1200 / frame_rate ) ); sound_buf = new_buf; sound_buf_changed_count = 0; if ( new_buf != default_sound_buf ) { delete default_sound_buf; default_sound_buf = NULL; } set_frame_rate( frame_rate ); return 0; }
void draw_lines(ScreenBuffer *s, int frame) { set_frame_rate(30); s->dim(240); //fall(); // broken! if ((frame % 10) == 0) { if (random(0, 2)) { // horizontal int y = random(0, HEIGHT); s->line(random(0, WIDTH), y, random(0, WIDTH), y, random_color()); } else { // vertical int x = random(0, WIDTH); s->line(x, random(0, HEIGHT), x, random(0, HEIGHT), random_color()); } } }
void draw_insane_lines(ScreenBuffer *s, int frame) { set_frame_rate(30); uint32_t c = random_color(); /* if (frame & 1) { // invert rect(0, 0, WIDTH, HEIGHT, c); c = 0; } else {*/ s->blank(); // } if (frame & 1) { // horizontal int y = random(0, HEIGHT); s->line(0, y, WIDTH, y, c); } else { // vertical for (uint8_t i = 0; i < 2; ++i) { int x = random(0, WIDTH); s->line(x, 0, x, HEIGHT, c); } } }
// extern int wifi_direct;// = 0;//1;//0; int HUServer::hu_handle_ServiceDiscoveryRequest (int chan, byte * buf, int len) { // Service Discovery Request HU::ServiceDiscoveryRequest request; if (!request.ParseFromArray(buf, len)) loge ("Service Discovery Request: %x", buf [2]); else logd ("Service Discovery Request: %s", request.phone_name().c_str()); // S 0 CTR b src: HU lft: 113 msg_type: 6 Service Discovery Response S 0 CTR b 00000000 0a 08 08 01 12 04 0a 02 08 0b 0a 13 08 02 1a 0f HU::ServiceDiscoveryResponse carInfo; carInfo.set_head_unit_name("Mazda Connect"); carInfo.set_car_model("Mazda"); carInfo.set_car_year("2016"); carInfo.set_car_serial("0001"); carInfo.set_driver_pos(true); carInfo.set_headunit_make("Mazda"); carInfo.set_headunit_model("Connect"); carInfo.set_sw_build("SWB1"); carInfo.set_sw_version("SWV1"); carInfo.set_can_play_native_media_during_vr(false); carInfo.set_hide_clock(false); carInfo.mutable_channels()->Reserve(AA_CH_MAX); HU::ChannelDescriptor* inputChannel = carInfo.add_channels(); inputChannel->set_channel_id(AA_CH_TOU); { auto inner = inputChannel->mutable_input_event_channel(); auto tsConfig = inner->mutable_touch_screen_config(); tsConfig->set_width(800); tsConfig->set_height(480); //No idea what these mean since they aren't the same as HU_INPUT_BUTTON inner->add_keycodes_supported(HUIB_MENU); // 0x01 Open menu inner->add_keycodes_supported(HUIB_MIC1); // 0x02 Mic inner->add_keycodes_supported(HUIB_HOME); // 0x03 AA home inner->add_keycodes_supported(HUIB_BACK); // 0x04 Back inner->add_keycodes_supported(HUIB_PHONE); // 0x05 Phone screen inner->add_keycodes_supported(HUIB_CALLEND); // 0x06 End call?? //inner->add_keycodes_supported(HUIB_NAV); // 0x07 Nav (This one is not correct) inner->add_keycodes_supported(HUIB_UP); // 0x13 Up inner->add_keycodes_supported(HUIB_DOWN); // 0x14 Down inner->add_keycodes_supported(HUIB_LEFT); // 0x15 Menu again inner->add_keycodes_supported(HUIB_RIGHT); // 0x16 Mic again inner->add_keycodes_supported(HUIB_ENTER); // 0x17 Select inner->add_keycodes_supported(HUIB_MIC); // 0x54 Mic again inner->add_keycodes_supported(HUIB_PLAYPAUSE); // 0x55 Play/Pause inner->add_keycodes_supported(HUIB_NEXT); // 0x57 Next track inner->add_keycodes_supported(HUIB_PREV); // 0x58 Prev Track inner->add_keycodes_supported(HUIB_SCROLLWHEEL); // Might as well include these even if we dont use them inner->add_keycodes_supported(HUIB_START); // 0x7E (126) Start media inner->add_keycodes_supported(HUIB_STOP); // 0x7F (127) Stop media callbacks.CustomizeInputConfig(*inner); } HU::ChannelDescriptor* sensorChannel = carInfo.add_channels(); sensorChannel->set_channel_id(AA_CH_SEN); { auto inner = sensorChannel->mutable_sensor_channel(); inner->add_sensor_list()->set_type(HU::SENSOR_TYPE_DRIVING_STATUS); inner->add_sensor_list()->set_type(HU::SENSOR_TYPE_NIGHT_DATA); inner->add_sensor_list()->set_type(HU::SENSOR_TYPE_LOCATION); callbacks.CustomizeSensorConfig(*inner); } HU::ChannelDescriptor* videoChannel = carInfo.add_channels(); videoChannel->set_channel_id(AA_CH_VID); { auto inner = videoChannel->mutable_output_stream_channel(); inner->set_type(HU::STREAM_TYPE_VIDEO); auto videoConfig = inner->add_video_configs(); videoConfig->set_resolution(HU::ChannelDescriptor::OutputStreamChannel::VideoConfig::VIDEO_RESOLUTION_800x480); videoConfig->set_frame_rate(HU::ChannelDescriptor::OutputStreamChannel::VideoConfig::VIDEO_FPS_30); videoConfig->set_margin_width(0); videoConfig->set_margin_height(0); videoConfig->set_dpi(140); inner->set_available_while_in_call(true); callbacks.CustomizeOutputChannel(AA_CH_VID, *inner); } HU::ChannelDescriptor* audioChannel0 = carInfo.add_channels(); audioChannel0->set_channel_id(AA_CH_AUD); { auto inner = audioChannel0->mutable_output_stream_channel(); inner->set_type(HU::STREAM_TYPE_AUDIO); inner->set_audio_type(HU::AUDIO_TYPE_MEDIA); auto audioConfig = inner->add_audio_configs(); audioConfig->set_sample_rate(48000); audioConfig->set_bit_depth(16); audioConfig->set_channel_count(2); inner->set_available_while_in_call(true); callbacks.CustomizeOutputChannel(AA_CH_AUD, *inner); } HU::ChannelDescriptor* audioChannel1 = carInfo.add_channels(); audioChannel1->set_channel_id(AA_CH_AU1); { auto inner = audioChannel1->mutable_output_stream_channel(); inner->set_type(HU::STREAM_TYPE_AUDIO); inner->set_audio_type(HU::AUDIO_TYPE_SPEECH); auto audioConfig = inner->add_audio_configs(); audioConfig->set_sample_rate(16000); audioConfig->set_bit_depth(16); audioConfig->set_channel_count(1); callbacks.CustomizeOutputChannel(AA_CH_AU1, *inner); } #ifdef PLAY_GUIDANCE_FROM_PHONE_SPEAKER HU::ChannelDescriptor* audioChannel2 = carInfo.add_channels(); audioChannel2->set_channel_id(AA_CH_AU2); { auto inner = audioChannel1->mutable_output_stream_channel(); inner->set_type(HU::STREAM_TYPE_AUDIO); inner->set_audio_type(HU::AUDIO_TYPE_SYSTEM); auto audioConfig = inner->add_audio_configs(); audioConfig->set_sample_rate(16000); audioConfig->set_bit_depth(16); audioConfig->set_channel_count(1); callbacks.CustomizeOutputChannel(AA_CH_AU2, *inner); } #endif HU::ChannelDescriptor* micChannel = carInfo.add_channels(); micChannel->set_channel_id(AA_CH_MIC); { auto inner = micChannel->mutable_input_stream_channel(); inner->set_type(HU::STREAM_TYPE_AUDIO); auto audioConfig = inner->mutable_audio_config(); audioConfig->set_sample_rate(16000); audioConfig->set_bit_depth(16); audioConfig->set_channel_count(1); callbacks.CustomizeInputChannel(AA_CH_MIC, *inner); } callbacks.CustomizeCarInfo(carInfo); std::string carBTAddress = callbacks.GetCarBluetoothAddress(); if (carBTAddress.size() > 0) { logw("Found BT address %s. Exposing Bluetooth service", carBTAddress.c_str()); HU::ChannelDescriptor* btChannel = carInfo.add_channels(); btChannel->set_channel_id(AA_CH_BT); { auto inner = btChannel->mutable_bluetooth_service(); inner->set_car_address(carBTAddress); inner->add_supported_pairing_methods(HU::ChannelDescriptor_BluetoothService::BLUETOOTH_PARING_METHOD_A2DP); inner->add_supported_pairing_methods(HU::ChannelDescriptor_BluetoothService::BLUETOOTH_PARING_METHOD_HFP); callbacks.CustomizeBluetoothService(AA_CH_BT, *inner); } } else { logw("No Bluetooth or finding BT address failed. Not exposing Bluetooth service"); } return hu_aap_enc_send_message(0, chan, HU_PROTOCOL_MESSAGE::ServiceDiscoveryResponse, carInfo); }
void draw_frame(ScreenBuffer *s, int frame) { set_frame_rate(70); s->rect(0, 0, WIDTH, HEIGHT, ((frame % 2) == 0) ? 0xFFFFFF : 0); }
/** Constructor. */ scaler (std::size_t frame_rate) { _st.clear (); _st.setChannels (sound::num_samples<Range>::value); set_frame_rate (frame_rate); }
long NWindowScreen::MyCode() { bigtime_t trgt = system_time() + frame_pause; srandom(system_time()); // beforehand stuff particle_count = 1024*2; particle_list = (particle *)malloc(sizeof(particle)*particle_count); for (uint32 i=0; i<particle_count; i++) { uint32 rand_max = 0xffffffff; particle_list[i].init_velocity = -((double)((rand_max>>1)+(random()%(rand_max>>1)))/rand_max)*3.333; // magic number particle_list[i].gravity = -(((double)((rand_max>>1)+(random()%(rand_max>>1)))/rand_max))*0.599; // more magic // make the particle initialy invisible and fixed, but at a random moment in time particle_list[i].lx = 0; particle_list[i].ly = 0; particle_list[i].last_draw = INVALID; particle_list[i].timeval = random() & 64; particle_list[i].x = 0; // this gets figured out at drawtime particle_list[i].y = 0; // same here particle_list[i].cos_z_theta = cos(random() % 360); // grab an angle } // the loop o' fun while (!(((NApplication*)be_app)->is_quitting)) { // try to sync with the vertical retrace if (BScreen(this).WaitForRetrace() != B_OK) { // snoze for a bit so that other threads can be happy. // We are realtime priority you know if (system_time() < trgt) snooze(trgt - system_time()); trgt = system_time() + frame_pause; } // gain access to the framebuffer before writing to it. acquire_sem(sem); // block until we're allowed to own the framebuffer /////////////////////////////// // do neat stuff here // ////////////////////////////// PRINT(("rendering a frame.\n")); // eye candy VII - particles! - my own cookin int32 x, y, cx,cy; set_frame_rate(60.); // woo. ntsc // calculate the center cx = width/2; cy = height/2; // palette test //set_frame_rate(0.1); //for(int i=0;i<256;i++) // draw_line(i,0,i,height, i); PRINT(("Starting particle drawing loop\n")); particle *s = particle_list; for (uint32 i=0; i<particle_count; i++) { PRINT(("drawing particle %d\r", i)); // save the old position s->lx = s->x; s->ly = s->y; PRINT(("cx=%d, cy=%d\n", cx,cy)); // move the particle // find y and x // (s->gravity/2)*(s->timeval*s->timeval) * 1.85 is magic y = s->y = (int32)(cy + (int32)((s->gravity/2)*(s->timeval*s->timeval)*1.94) + ((s->init_velocity - (s->gravity*s->timeval)) * s->timeval)); x = s->x = (int32)(cx + (int32)(s->timeval * s->cos_z_theta)); // 3d rotation // interate timeval s->timeval++; // sanity check if(x <= 0) goto erase_and_reset; if(x > width) goto erase_and_reset; if(y < 0) goto erase; // invisible + erase last position if(y > height) goto erase_and_reset; // erase the previous position, if necessary if (s->last_draw != INVALID) set_pixel(s->lx,s->ly,0); // if it's visible, then draw it. set_pixel(s->x,s->y, 169); s->last_draw = 1; goto loop; erase_and_reset: if((s->lx <= width) && (s->lx >= 0) && (s->ly <= height) && (s->ly >= 0)) set_pixel(s->lx, s->ly,0); s->x = 0; s->y = 0; s->lx = 0; s->ly = 0; s->timeval = 0; s->last_draw = INVALID; goto loop; erase: // erase it. if(s->last_draw != INVALID) set_pixel(s->lx, s->ly,0); s->lx = s->x; s->ly = s->y; s->last_draw = INVALID; loop: s++; //printf("end draw loop\n"); } PRINT(("frame done\n")); ////////////////////////////////// // stop doing neat stuff // ///////////////////////////////// // release the semaphore while waiting. gotta release it // at some point or nasty things will happen! release_sem(sem); // loop for another frame! } return B_OK; }
void setup_animation() { set_frame_rate(30); }
void loop() { int value; // display menu to user display_menu(); // wait for user to enter something while( !Serial.available() ) { delay(20); } // get character from user value = Serial.read(); switch( value ) { case 'c' : // display all config display_config(); break; case 'f' : // set frame rate set_frame_rate(); break; case 'i' : // display image display_image(); break; case 'I' : // display image continuously display_image_continuously(); break; case 'm' : // display motion display_motion(); break; case 'r' : // set resolution set_resolution(); break; case 's' : // set shutter speed set_shutter_speed(); break; case 'z' : // clear and reset everything flowSensor.clear_motion(); break; default: Serial.println("unrecognised command"); Serial.println(); break; } }
WebmExporter::WebmExporter(const exporter_settings& settings) : _success{false}, _settings(settings), _video_track{0}, _img{nullptr}, _frame_index{0} { if (!_writer.Open(settings.path.c_str())) { std::cerr << "couldn't open " << settings.path << " for writing" << std::endl; return; } if (!_segment.Init(&_writer)) { std::cerr << "couldn't initialise muxer segment" << std::endl; return; } _segment.set_mode(mkvmuxer::Segment::kFile); _segment.OutputCues(true); _segment.GetSegmentInfo()->set_writing_app("trance"); _video_track = _segment.AddVideoTrack(settings.width, settings.height, 0); if (!_video_track) { std::cerr << "couldn't add video track" << std::endl; return; } auto video = (mkvmuxer::VideoTrack*) _segment.GetTrackByNumber(_video_track); if (!video) { std::cerr << "couldn't get video track" << std::endl; return; } video->set_frame_rate(settings.fps); _segment.GetCues()->set_output_block_number(true); _segment.CuesTrack(_video_track); // See http://www.webmproject.org/docs/encoder-parameters. vpx_codec_enc_cfg_t cfg; if (vpx_codec_enc_config_default(vpx_codec_vp8_cx(), &cfg, 0)) { std::cerr << "couldn't get default codec config" << std::endl; return; } auto area = _settings.width * _settings.height; auto bitrate = (1 + 2 * (4 - _settings.quality)) * area / 1024; cfg.g_w = _settings.width; cfg.g_h = _settings.height; cfg.g_timebase.num = 1; cfg.g_timebase.den = _settings.fps; cfg.g_lag_in_frames = 24; cfg.g_threads = settings.threads; cfg.kf_min_dist = 0; cfg.kf_max_dist = 256; cfg.rc_target_bitrate = bitrate; if (vpx_codec_enc_init(&_codec, vpx_codec_vp8_cx(), &cfg, 0)) { codec_error("couldn't initialise encoder"); return; } _img = vpx_img_alloc(nullptr, VPX_IMG_FMT_I420, _settings.width, _settings.height, 16); if (!_img) { std::cerr << "couldn't allocate image for encoding" << std::endl; return; } _success = true; }