cThrownSnowballEntity::cThrownSnowballEntity(cEntity * a_Creator, double a_X, double a_Y, double a_Z, const Vector3d & a_Speed) : super(pkSnowball, a_Creator, a_X, a_Y, a_Z, 0.25, 0.25), m_DestroyTimer(-1) { SetSpeed(a_Speed); }
void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { if (m_IsInGround) { // Already-grounded projectiles don't move at all return; } const Vector3d PerTickSpeed = GetSpeed() / 20; const Vector3d Pos = GetPosition(); const Vector3d NextPos = Pos + PerTickSpeed; // Test for entity collisions: cProjectileEntityCollisionCallback EntityCollisionCallback(this, Pos, NextPos); a_Chunk.ForEachEntity(EntityCollisionCallback); if (EntityCollisionCallback.HasHit()) { // An entity was hit: Vector3d HitPos = Pos + (NextPos - Pos) * EntityCollisionCallback.GetMinCoeff(); // DEBUG: LOGD("Projectile %d has hit an entity %d (%s) at {%.02f, %.02f, %.02f} (coeff %.03f)", m_UniqueID, EntityCollisionCallback.GetHitEntity()->GetUniqueID(), EntityCollisionCallback.GetHitEntity()->GetClass(), HitPos.x, HitPos.y, HitPos.z, EntityCollisionCallback.GetMinCoeff() ); OnHitEntity(*(EntityCollisionCallback.GetHitEntity()), HitPos); } // TODO: Test the entities in the neighboring chunks, too // Trace the tick's worth of movement as a line: cProjectileTracerCallback TracerCallback(this); if (!cLineBlockTracer::Trace(*m_World, TracerCallback, Pos, NextPos)) { // Something has been hit, abort all other processing return; } // The tracer also checks the blocks for slowdown blocks - water and lava - and stores it for later in its SlowdownCoeff // Update the position: SetPosition(NextPos); // Add slowdown and gravity effect to the speed: Vector3d NewSpeed(GetSpeed()); NewSpeed.y += m_Gravity / 20; NewSpeed *= TracerCallback.GetSlowdownCoeff(); SetSpeed(NewSpeed); SetYawFromSpeed(); SetPitchFromSpeed(); /* LOGD("Projectile %d: pos {%.02f, %.02f, %.02f}, speed {%.02f, %.02f, %.02f}, rot {%.02f, %.02f}", m_UniqueID, GetPosX(), GetPosY(), GetPosZ(), GetSpeedX(), GetSpeedY(), GetSpeedZ(), GetYaw(), GetPitch() ); */ }
void key_SetGpsConfig(void) { if (bKey == bKEY_ENTER) { if (enKeyboard == KBD_ENTER) { enKeyboard = KBD_POSTENTER; ShowHi(szMessage); Clear(); Show(); } else if (enKeyboard == KBD_POSTINPUT1) { enKeyboard = KBD_POSTENTER; uchar bPrt = GetCharLo(6,8); if (bPrt == 0) { bPortGps = 0; SaveCache(&chPortGps); Show(); } else if (bPrt <= bPORTS) { if (StreamPortDirect(bPrt-1) == 0) { bPortGps = 0; SaveCache(&chPortGps); Show(); } else { bPortGps = bPrt; SaveCache(&chPortGps); Show(); uchar ibPrt = bPrt - 1; mppoPorts[ibPrt].ibBaud = 3; mppoPorts[ibPrt].ibParity = 0; SetSpeed(ibPrt); SetDefaultDelay(ibPrt); } } else { enKeyboard = KBD_INPUT1; LongBeep(); ShowLo(szMask); } } else Beep(); } else if (bKey == bKEY_MINUS) ShowTimeDateGps(0); else if (bKey == bKEY_POINT) ShowTimeDateGps(1); else if (bKey < 10) { if ((enGlobal != GLB_WORK) && (enKeyboard == KBD_POSTENTER)) { enKeyboard = KBD_INPUT1; ShowLo(szMask); } if ((enKeyboard == KBD_INPUT1) || (enKeyboard == KBD_POSTINPUT1)) { enKeyboard = KBD_POSTINPUT1; ShiftLo(6,8); } } else Beep(); }
int main() { int i; printf("hello world\n"); printf("start of out_test\n"); Wait(SEC_1); // initialize if (!OutputInit()) printf("output init returned false\n"); ResetAllTachoCounts(OUT_ABCD); // OutputSetType(OUT_A, DEVICE_TYPE_TACHO); // OutputSetType(OUT_B, DEVICE_TYPE_TACHO); // OutputSetType(OUT_C, DEVICE_TYPE_MINITACHO); OutputSetTypes(DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO, DEVICE_TYPE_TACHO); SetPower(OUT_A, 90); SetSpeed(OUT_B, 40); SetPower(OUT_C, 60); SetPower(OUT_D, -60); On(OUT_ALL); bool isBusy = false; for(i=0; i < 10; i++) { printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C)); printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D)); Wait(SEC_1); isBusy = MotorBusy(OUT_ALL); printf("Any output isBusy = %d\n", (byte)isBusy); } // Wait(SEC_5); printf("Float(OUT_ALL)\n"); Float(OUT_ALL); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("ResetAllTachoCounts(OUT_ALL)\n"); ResetAllTachoCounts(OUT_ALL); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OUT_C: %d %d %d\n", MotorRotationCount(OUT_C), MotorTachoCount(OUT_C), MotorActualSpeed(OUT_C)); printf("OUT_D: %d %d %d\n", MotorRotationCount(OUT_D), MotorTachoCount(OUT_D), MotorActualSpeed(OUT_D)); printf("Wait(SEC_1)\n"); Wait(SEC_1); printf("RotateMotorNoWait(OUT_AB, 75, 7200)\n"); RotateMotorNoWait(OUT_AB, 75, 7200); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); isBusy = MotorBusy(OUT_AB); printf("A or B isBusy = %d\n", (byte)isBusy); printf("Wait(SEC_20)\n"); Wait(SEC_20); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("resetting all tacho counters\n"); ResetAllTachoCounts(OUT_ALL); printf("Wait(SEC_1)\n"); Wait(SEC_1); printf("OnForSync(OUT_AB, SEC_10, 75)\n"); OnForSync(OUT_AB, SEC_10, 75); for(i=0; i < 10; i++) { printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); isBusy = MotorBusy(OUT_AB); printf("A or B isBusy = %d\n", (byte)isBusy); isBusy = MotorBusy(OUT_CD); printf("C or D isBusy = %d\n", (byte)isBusy); Wait(SEC_1); } printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); // synchronized motor movement without tacho or time limitation printf("OnFwdSync(OUT_AB, 75)\n"); OnFwdSync(OUT_AB, 75); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("Off(OUT_AB)\n"); Off(OUT_AB); // stop with braking printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("Wait(SEC_1)\n"); Wait(SEC_1); /* * Turn ratio is how tight you turn and to what direction you turn * - 0 value is moving straight forward * - Negative values turns to the left * - Positive values turns to the right * - Value -100 stops the left motor * - Value +100 stops the right motor * - Values less than -100 makes the left motor run the opposite * direction of the right motor (Spin) * - Values greater than +100 makes the right motor run the opposite * direction of the left motor (Spin) */ printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE)\n"); OnFwdSyncEx(OUT_AB, 75, -20, RESET_NONE); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OnFwdSync(OUT_AB, 50, -50, RESET_NONE)"); OnFwdSyncEx(OUT_AB, 50, -50, RESET_NONE); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OnFwdSync(OUT_AB, 20, -100, RESET_NONE)\n"); OnFwdSyncEx(OUT_AB, 20, -100, RESET_NONE); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OnFwdSync(OUT_AB, 80, -150, RESET_NONE)\n"); OnFwdSyncEx(OUT_AB, 80, -150, RESET_NONE); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("OnFwdSync(OUT_AB, 30, -200, RESET_NONE)\n"); OnFwdSyncEx(OUT_AB, 30, -200, RESET_NONE); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("Off(OUT_AB)\n"); Off(OUT_AB); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); printf("ResetAllTachoCounts(OUT_AB)\n"); ResetAllTachoCounts(OUT_AB); printf("Wait(SEC_2)\n"); Wait(SEC_2); printf("OUT_A: %d %d %d\n", MotorRotationCount(OUT_A), MotorTachoCount(OUT_A), MotorActualSpeed(OUT_A)); printf("OUT_B: %d %d %d\n", MotorRotationCount(OUT_B), MotorTachoCount(OUT_B), MotorActualSpeed(OUT_B)); // a blocking version of RotateMotor (function call does not return // until the motor rotation is complete) printf("RotateMotor(OUT_AB, 75, 1800)"); RotateMotor(OUT_AB, 75, 1800); // 5 rotations // by the time the function above returns the motors are no longer busy isBusy = MotorBusy(OUT_AB); printf("A or B isBusy = %d\n", isBusy); // this call starts the motors running Forward without regulation or // synchronization and the function call does not return until the // specified amount of time has elapsed. // at the end of the elapsed time the motors are stopped with braking. printf("OnFor(OUT_AB, SEC_3)\n"); OnFor(OUT_AB, SEC_3); printf("Off(OUT_AB)\n"); Off(OUT_AB); printf("Wait(SEC_5)\n"); Wait(SEC_5); OutputClose(); OutputExit(); printf("end of out_test\n"); return 0; }
/* * Server waits until all nodes are ready then broadcasts a start * * signal. This is meant to only be used once. * */ void OMXPlayerSync::unpauseMovie () { playspeed_current = playspeed_normal; SetSpeed(playspeeds[playspeed_current] + jitter); }
/* * Initally we pause the movie then resume when all nodes are ready. * * Note, we never call this function more than once, hence why we * * don't need to include the jitter yet. * */ void OMXPlayerSync::pauseMovie () { playspeed_current = playspeed_slow_min; SetSpeed(playspeeds[playspeed_current]); }
/** * Set the PWM value. * * The PWM value is set using a range of -1.0 to 1.0, appropriately * scaling the value for the FPGA. * * @param speed The speed value between -1.0 and 1.0 to set. * @param syncGroup Unused interface. */ void Talon::Set(float speed, UINT8 syncGroup) { SetSpeed(speed); }
//int main(int argc, char *argv[]) int startVideo(OMX_TextureProvider* provider, OMX_VideoSurfaceElement* element) { #ifdef ENABLE_ORIGINAL signal(SIGINT, sig_handler); if (isatty(STDIN_FILENO)) { struct termios new_termios; tcgetattr(STDIN_FILENO, &orig_termios); new_termios = orig_termios; new_termios.c_lflag &= ~(ICANON | ECHO | ECHOCTL | ECHONL); new_termios.c_cflag |= HUPCL; new_termios.c_cc[VMIN] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &new_termios); atexit(restore_termios); } else { orig_fl = fcntl(STDIN_FILENO, F_GETFL); fcntl(STDIN_FILENO, F_SETFL, orig_fl | O_NONBLOCK); atexit(restore_fl); } #endif LOG_VERBOSE(LOG_TAG, "Starting video..."); std::string last_sub = ""; std::string m_filename; double m_incr = 0; CRBP g_RBP; COMXCore g_OMX; bool m_stats = false; bool m_dump_format = false; bool m_3d = false; bool m_refresh = false; double startpts = 0; m_player_video = new OMXPlayerVideo(provider); m_player_audio = new OMXPlayerAudio; m_player_subtitles = new OMXPlayerSubtitles; QObject::connect(m_player_video, SIGNAL(textureReady(uint)), element, SLOT(onTextureChanged(uint))); TV_GET_STATE_RESP_T tv_state; const int boost_on_downmix_opt = 0x200; #ifdef ENABLE_ORIGINAL struct option longopts[] = { { "info", no_argument, NULL, 'i' }, { "help", no_argument, NULL, 'h' }, { "aidx", required_argument, NULL, 'n' }, { "adev", required_argument, NULL, 'o' }, { "stats", no_argument, NULL, 's' }, { "passthrough", no_argument, NULL, 'p' }, { "deinterlace", no_argument, NULL, 'd' }, { "hw", no_argument, NULL, 'w' }, { "3d", no_argument, NULL, '3' }, { "hdmiclocksync", no_argument, NULL, 'y' }, { "refresh", no_argument, NULL, 'r' }, { "sid", required_argument, NULL, 't' }, { "pos", required_argument, NULL, 'l' }, { "font", required_argument, NULL, 0x100 }, { "font-size", required_argument, NULL, 0x101 }, { "align", required_argument, NULL, 0x102 }, { "boost-on-downmix", no_argument, NULL, boost_on_downmix_opt }, { 0, 0, 0, 0 } }; int c; while ((c = getopt_long(argc, argv, "wihnl:o:cslpd3yt:r", longopts, NULL)) != -1) { switch (c) { case 'r': m_refresh = true; break; case 'y': m_hdmi_clock_sync = true; break; case '3': m_3d = true; break; case 'd': m_Deinterlace = true; break; case 'w': m_use_hw_audio = true; break; case 'p': m_passthrough = true; break; case 's': m_stats = true; break; case 'o': deviceString = optarg; if(deviceString != "local" && deviceString != "hdmi") { print_usage(); return 0; } deviceString = "omx:" + deviceString; break; case 'i': m_dump_format = true; break; case 't': m_subtitle_index = atoi(optarg) - 1; if(m_subtitle_index < 0) m_subtitle_index = 0; m_show_subtitle = true; break; case 'n': m_audio_index_use = atoi(optarg) - 1; if(m_audio_index_use < 0) m_audio_index_use = 0; break; case 'l': m_seek_pos = atoi(optarg) ; if (m_seek_pos < 0) m_seek_pos = 0; break; case 0x100: m_font_path = optarg; break; case 0x101: { const int thousands = atoi(optarg); if (thousands > 0) m_font_size = thousands*0.001f; } break; case 0x102: if (!strcmp(optarg, "center")) m_centered = true; else m_centered = false; break; case boost_on_downmix_opt: m_boost_on_downmix = true; break; case 0: break; case 'h': print_usage(); return 0; break; case ':': return 0; break; default: return 0; break; } } if (optind >= argc) { print_usage(); return 0; } #endif //m_filename = argv[optind]; m_filename = "/home/pi/usb/big_buck_bunny_1080p_h264.mov"; #ifdef ENABLE_ORIGINAL CLog::Init("./"); #endif g_RBP.Initialize(); g_OMX.Initialize(); m_av_clock = new OMXClock(); m_thread_player = true; LOG_VERBOSE(LOG_TAG, "Opening video file..."); if(!m_omx_reader.Open(m_filename.c_str(), m_dump_format)) #if 0 goto do_exit; #endif return 0; #ifdef ENABLE_ORIGINAL if(m_dump_format) goto do_exit; #endif m_bMpeg = m_omx_reader.IsMpegVideo(); m_has_video = m_omx_reader.VideoStreamCount(); m_has_audio = m_omx_reader.AudioStreamCount(); m_has_subtitle = m_omx_reader.SubtitleStreamCount(); LOG_VERBOSE(LOG_TAG, "Initializing OMX clock..."); if(!m_av_clock->OMXInitialize(m_has_video, m_has_audio)) #if 0 goto do_exit; #endif return 0; if(m_hdmi_clock_sync && !m_av_clock->HDMIClockSync()) #if 0 goto do_exit; #endif return 0; m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio); m_omx_reader.GetHints(OMXSTREAM_VIDEO, m_hints_video); if(m_audio_index_use != -1) m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_audio_index_use); if(m_has_video && m_refresh) { memset(&tv_state, 0, sizeof(TV_GET_STATE_RESP_T)); m_BcmHost.vc_tv_get_state(&tv_state); if(m_filename.find("3DSBS") != string::npos) m_3d = true; SetVideoMode(m_hints_video.width, m_hints_video.height, m_hints_video.fpsrate, m_hints_video.fpsscale, m_3d); } // get display aspect TV_GET_STATE_RESP_T current_tv_state; memset(¤t_tv_state, 0, sizeof(TV_GET_STATE_RESP_T)); m_BcmHost.vc_tv_get_state(¤t_tv_state); if(current_tv_state.width && current_tv_state.height) m_display_aspect = (float)current_tv_state.width / (float)current_tv_state.height; // seek on start if (m_seek_pos !=0 && m_omx_reader.CanSeek()) { printf("Seeking start of video to %i seconds\n", m_seek_pos); m_omx_reader.SeekTime(m_seek_pos * 1000.0f, 0, &startpts); // from seconds to DVD_TIME_BASE } LOG_VERBOSE(LOG_TAG, "Opening video using OMX..."); uint textureId; if(m_has_video && !m_player_video->Open(m_hints_video, m_av_clock, textureId, m_Deinterlace, m_bMpeg, m_hdmi_clock_sync, m_thread_player, m_display_aspect)) #if 0 goto do_exit; #endif return 0; LOG_VERBOSE(LOG_TAG, "Opening subtitles using OMX..."); if(m_has_subtitle && !m_player_subtitles->Open(m_font_path, m_font_size, m_centered, m_av_clock)) #if 0 goto do_exit; #endif return 0; // This is an upper bound check on the subtitle limits. When we pulled the subtitle // index from the user we check to make sure that the value is larger than zero, but // we couldn't know without scanning the file if it was too high. If this is the case // then we replace the subtitle index with the maximum value possible. if(m_has_subtitle && m_subtitle_index > (m_omx_reader.SubtitleStreamCount() - 1)) { m_subtitle_index = m_omx_reader.SubtitleStreamCount() - 1; } // Here we actually enable the subtitle streams if we have one available. if (m_show_subtitle && m_has_subtitle && m_subtitle_index <= (m_omx_reader.SubtitleStreamCount() - 1)) m_omx_reader.SetActiveStream(OMXSTREAM_SUBTITLE, m_subtitle_index); m_omx_reader.GetHints(OMXSTREAM_AUDIO, m_hints_audio); LOG_VERBOSE(LOG_TAG, "Opening audio using OMX..."); if(m_has_audio && !m_player_audio->Open(m_hints_audio, m_av_clock, &m_omx_reader, "omx:hdmi", m_passthrough, m_use_hw_audio, m_boost_on_downmix, m_thread_player)) #if 0 goto do_exit; #endif return 0; LOG_VERBOSE(LOG_TAG, "Executing clock..."); m_av_clock->SetSpeed(DVD_PLAYSPEED_NORMAL); m_av_clock->OMXStateExecute(); m_av_clock->OMXStart(); struct timespec starttime, endtime; printf("Subtitle count : %d state %s : index %d\n", m_omx_reader.SubtitleStreamCount(), m_show_subtitle ? "on" : "off", (m_omx_reader.SubtitleStreamCount() > 0) ? m_subtitle_index + 1 : m_subtitle_index); while(!m_stop) { int ch[8]; int chnum = 0; if(g_abort) goto do_exit; #if 0 while((ch[chnum] = getchar()) != EOF) chnum++; if (chnum > 1) ch[0] = ch[chnum - 1] | (ch[chnum - 2] << 8); switch(ch[0]) { case 'z': m_tv_show_info = !m_tv_show_info; vc_tv_show_info(m_tv_show_info); break; case '1': SetSpeed(m_av_clock->OMXPlaySpeed() - 1); break; case '2': SetSpeed(m_av_clock->OMXPlaySpeed() + 1); break; case 'j': if(m_has_audio) { int new_index = m_omx_reader.GetAudioIndex() - 1; if (new_index >= 0) m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, new_index); } break; case 'k': if(m_has_audio) m_omx_reader.SetActiveStream(OMXSTREAM_AUDIO, m_omx_reader.GetAudioIndex() + 1); break; case 'i': if(m_omx_reader.GetChapterCount() > 0) { m_omx_reader.SeekChapter(m_omx_reader.GetChapter() - 1, &startpts); FlushStreams(startpts); } else { m_incr = -600.0; } break; case 'o': if(m_omx_reader.GetChapterCount() > 0) { m_omx_reader.SeekChapter(m_omx_reader.GetChapter() + 1, &startpts); FlushStreams(startpts); } else { m_incr = 600.0; } break; case 'n': if(m_has_subtitle) { int new_index = m_subtitle_index-1; if(new_index >= 0) { m_subtitle_index = new_index; printf("Subtitle count : %d state %s : index %d\n", m_omx_reader.SubtitleStreamCount(), m_show_subtitle ? "on" : "off", (m_omx_reader.SubtitleStreamCount() > 0) ? m_subtitle_index + 1 : m_subtitle_index); m_omx_reader.SetActiveStream(OMXSTREAM_SUBTITLE, m_subtitle_index); m_player_subtitles->Flush(); } } break; case 'm': if(m_has_subtitle) { int new_index = m_subtitle_index+1; if(new_index < m_omx_reader.SubtitleStreamCount()) { m_subtitle_index = new_index; printf("Subtitle count : %d state %s : index %d\n", m_omx_reader.SubtitleStreamCount(), m_show_subtitle ? "on" : "off", (m_omx_reader.SubtitleStreamCount() > 0) ? m_subtitle_index + 1 : m_subtitle_index); m_omx_reader.SetActiveStream(OMXSTREAM_SUBTITLE, m_subtitle_index); m_player_subtitles->Flush(); } } break; case 's': if(m_has_subtitle) { if(m_show_subtitle) { m_omx_reader.SetActiveStream(OMXSTREAM_SUBTITLE, -1); m_player_subtitles->Flush(); m_show_subtitle = false; } else { m_omx_reader.SetActiveStream(OMXSTREAM_SUBTITLE, m_subtitle_index); m_show_subtitle = true; } printf("Subtitle count : %d state %s : index %d\n", m_omx_reader.SubtitleStreamCount(), m_show_subtitle ? "on" : "off", (m_omx_reader.SubtitleStreamCount() > 0) ? m_subtitle_index + 1 : m_subtitle_index); } break; case 'q': m_stop = true; goto do_exit; break; case 0x5b44: // key left if(m_omx_reader.CanSeek()) m_incr = -30.0; break; case 0x5b43: // key right if(m_omx_reader.CanSeek()) m_incr = 30.0; break; case 0x5b41: // key up if(m_omx_reader.CanSeek()) m_incr = 600.0; break; case 0x5b42: // key down if(m_omx_reader.CanSeek()) m_incr = -600.0; break; case ' ': case 'p': m_Pause = !m_Pause; if(m_Pause) { SetSpeed(OMX_PLAYSPEED_PAUSE); m_av_clock->OMXPause(); } else { SetSpeed(OMX_PLAYSPEED_NORMAL); m_av_clock->OMXResume(); } break; case '-': m_player_audio->SetCurrentVolume(m_player_audio->GetCurrentVolume() - 300); printf("Current Volume: %.2fdB\n", m_player_audio->GetCurrentVolume() / 100.0f); break; case '+': m_player_audio->SetCurrentVolume(m_player_audio->GetCurrentVolume() + 300); printf("Current Volume: %.2fdB\n", m_player_audio->GetCurrentVolume() / 100.0f); break; default: break; } #endif if(m_Pause) { OMXClock::OMXSleep(2); continue; } if(m_incr != 0 && !m_bMpeg) { int seek_flags = 0; double seek_pos = 0; double pts = 0; pts = m_av_clock->GetPTS(); seek_pos = (pts / DVD_TIME_BASE) + m_incr; seek_flags = m_incr < 0.0f ? AVSEEK_FLAG_BACKWARD : 0; seek_pos *= 1000.0f; m_incr = 0; if(m_omx_reader.SeekTime(seek_pos, seek_flags, &startpts)) FlushStreams(startpts); m_player_video->Close(); if(m_has_video && !m_player_video->Open(m_hints_video, m_av_clock, textureId, m_Deinterlace, m_bMpeg, m_hdmi_clock_sync, m_thread_player, m_display_aspect)) goto do_exit; } /* player got in an error state */ if(m_player_audio->Error()) { printf("audio player error. emergency exit!!!\n"); goto do_exit; } if(m_stats) { printf("V : %8.02f %8d %8d A : %8.02f %8.02f Cv : %8d Ca : %8d \r", m_av_clock->OMXMediaTime(), m_player_video->GetDecoderBufferSize(), m_player_video->GetDecoderFreeSpace(), m_player_audio->GetCurrentPTS() / DVD_TIME_BASE, m_player_audio->GetDelay(), m_player_video->GetCached(), m_player_audio->GetCached()); } if(m_omx_reader.IsEof() && !m_omx_pkt) { if (!m_player_audio->GetCached() && !m_player_video->GetCached()) break; // Abort audio buffering, now we're on our own if (m_buffer_empty) m_av_clock->OMXResume(); OMXClock::OMXSleep(10); continue; } /* when the audio buffer runs under 0.1 seconds we buffer up */ if(m_has_audio) { if(m_player_audio->GetDelay() < 0.1f && !m_buffer_empty) { if(!m_av_clock->OMXIsPaused()) { m_av_clock->OMXPause(); //printf("buffering start\n"); m_buffer_empty = true; clock_gettime(CLOCK_REALTIME, &starttime); } } if(m_player_audio->GetDelay() > (AUDIO_BUFFER_SECONDS * 0.75f) && m_buffer_empty) { if(m_av_clock->OMXIsPaused()) { m_av_clock->OMXResume(); //printf("buffering end\n"); m_buffer_empty = false; } } if(m_buffer_empty) { clock_gettime(CLOCK_REALTIME, &endtime); if((endtime.tv_sec - starttime.tv_sec) > 1) { m_buffer_empty = false; m_av_clock->OMXResume(); //printf("buffering timed out\n"); } } } if(!m_omx_pkt) m_omx_pkt = m_omx_reader.Read(); if(m_has_video && m_omx_pkt && m_omx_reader.IsActive(OMXSTREAM_VIDEO, m_omx_pkt->stream_index)) { if(m_player_video->AddPacket(m_omx_pkt)) m_omx_pkt = NULL; else OMXClock::OMXSleep(10); if(m_tv_show_info) { char response[80]; vc_gencmd(response, sizeof response, "render_bar 4 video_fifo %d %d %d %d", m_player_video->GetDecoderBufferSize()-m_player_video->GetDecoderFreeSpace(), 0 , 0, m_player_video->GetDecoderBufferSize()); vc_gencmd(response, sizeof response, "render_bar 5 audio_fifo %d %d %d %d", (int)(100.0*m_player_audio->GetDelay()), 0, 0, 100*AUDIO_BUFFER_SECONDS); } } else if(m_has_audio && m_omx_pkt && m_omx_pkt->codec_type == AVMEDIA_TYPE_AUDIO) { if(m_player_audio->AddPacket(m_omx_pkt)) m_omx_pkt = NULL; else OMXClock::OMXSleep(10); } else if(m_omx_pkt && m_omx_reader.IsActive(OMXSTREAM_SUBTITLE, m_omx_pkt->stream_index)) { if(m_omx_pkt->size && m_show_subtitle && (m_omx_pkt->hints.codec == CODEC_ID_TEXT || m_omx_pkt->hints.codec == CODEC_ID_SSA)) { if(m_player_subtitles->AddPacket(m_omx_pkt)) m_omx_pkt = NULL; else OMXClock::OMXSleep(10); } else { m_omx_reader.FreePacket(m_omx_pkt); m_omx_pkt = NULL; } } else { if(m_omx_pkt) { m_omx_reader.FreePacket(m_omx_pkt); m_omx_pkt = NULL; } } } do_exit: printf("\n"); if(!m_stop && !g_abort) { if(m_has_audio) m_player_audio->WaitCompletion(); else if(m_has_video) m_player_video->WaitCompletion(); } if(m_refresh) { m_BcmHost.vc_tv_hdmi_power_on_best(tv_state.width, tv_state.height, tv_state.frame_rate, HDMI_NONINTERLACED, (EDID_MODE_MATCH_FLAG_T)(HDMI_MODE_MATCH_FRAMERATE|HDMI_MODE_MATCH_RESOLUTION|HDMI_MODE_MATCH_SCANMODE)); } m_av_clock->OMXStop(); m_av_clock->OMXStateIdle(); m_player_subtitles->Close(); m_player_video->Close(); m_player_audio->Close(); if(m_omx_pkt) { m_omx_reader.FreePacket(m_omx_pkt); m_omx_pkt = NULL; } m_omx_reader.Close(); vc_tv_show_info(0); g_OMX.Deinitialize(); g_RBP.Deinitialize(); printf("have a nice day ;)\n"); return 1; }