void emAvFileModel::SetPlayState(PlayStateType playState) { if (GetFileState()!=FS_LOADED) return; if (PlayState==playState) return; PlayState=playState; Signal(PlayStateSignal); if (PlayState==PS_STOPPED) { RemoveFromActiveList(); CloseStream(); PlayPos=0; Signal(PlayPosSignal); Image.Empty(); Signal(ImageSignal); } else { AddToActiveList(); if (GetStreamState()!=STREAM_OPENING && GetStreamState()!=STREAM_OPENED) { if (!WarningText.IsEmpty() || !ErrorText.IsEmpty()) { WarningText.Empty(); ErrorText.Empty(); Signal(InfoSignal); } OpenStream("auto","emAv",GetFilePath()); SetProperty("audio_volume",emString::Format("%d",AudioVolume)); SetProperty("audio_mute",AudioMute?"on":"off"); if (AudioVisu>=0 && AudioVisu<AudioVisus.GetCount()) { SetProperty("audio_visu",AudioVisus[AudioVisu].Get()); } SetProperty("pos",emString::Format("%d",PlayPos)); #if 0 // ??? This did not function. if (AudioChannel>=0 && AudioChannel<AudioChannels.GetCount()) { SetProperty("audio_channel",AudioChannels[AudioChannel].Get()); } if (SpuChannel>=0 && SpuChannel<SpuChannels.GetCount()) { SetProperty("spu_channel",SpuChannels[SpuChannel].Get()); } #endif } SetProperty( "state", PlayState==PS_PAUSED ? "paused" : PlayState==PS_SLOW ? "slow" : PlayState==PS_FAST ? "fast" : "normal" ); } SaveFileState(); }
bool emAvFileModel::TryContinueLoading() throw(emString) { switch (GetStreamState()) { case STREAM_CLOSED: OpenStream("none","none",GetFilePath()); return false; case STREAM_OPENED: CloseStream(); PlayPos=0; AudioVolume=100; AudioMute=false; LoadAudioVolume(); LoadAudioVisu(); LoadFileState(); return true; case STREAM_ERRORED: throw emString(GetStreamErrorText()); default: emSleepMS(10); return false; } }
/** * The main entry point for the application. */ int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, gWindowTitle, sizeof(gWindowTitle)); LoadString(hInstance, IDC_STREAMING, gWindowClass, sizeof(gWindowClass)); // Register the window class RegisterWindowClass(hInstance); // Perform application initialization: if ( !InitInstance(hInstance, nCmdShow) ) { return FALSE; } // Set the view to the default position ResetView(); // Cache the last mouse position GetCursorPos(&gLastMousePos); // Initialize the Twitch SDK InitializeStreaming("<username>", "<password>", "<clientId>", "<clientSecret>", GetIntelDllPath()); // Main message loop MSG msg; while (true) { // Check to see if any messages are waiting in the queue while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { // Process window messages TranslateMessage(&msg); DispatchMessage(&msg); // Received a quit message if (msg.message == WM_QUIT) { break; } } // Received a quit message so exit the app if (msg.message == WM_QUIT) { break; } if (gReinitializeRequired) { gReinitializeRequired = false; InitializeRendering(); } // Draw the scene RenderScene(); UpdateWaveMesh(); // Process user input independent of the event queue if (gFocused) { HandleInput(); } // Record the frame time unsigned __int64 curTime = GetSystemTimeMs(); // Begin streaming when ready if (gStreamingDesired && !IsStreaming() && IsReadyToStream()) { StartStreaming(gBroadcastWidth, gBroadcastHeight, gBroadcastFramesPerSecond); gLastCaptureTime = 0; } // If you send frames too quickly to the SDK (based on the broadcast FPS you configured) it will not be able // to make use of them all. In that case, it will simply release buffers without using them which means the // game wasted time doing the capture. To mitigate this, the app should pace the captures to the broadcast FPS. unsigned __int64 captureDelta = curTime - gLastCaptureTime; bool isTimeForNextCapture = (captureDelta / 1000.0) >= (1.0 / gBroadcastFramesPerSecond); // streaming is in progress so try and capture a frame if (IsStreaming() && !gPaused && isTimeForNextCapture) { // capture a snapshot of the back buffer unsigned char* pBgraFrame = nullptr; int width = 0; int height = 0; bool gotFrame = false; switch (gCaptureMethod) { case CaptureMethod::Slow: gotFrame = CaptureFrame_Slow(gBroadcastWidth, gBroadcastHeight, pBgraFrame); break; case CaptureMethod::Fast: gotFrame = CaptureFrame_Fast(gBroadcastWidth, gBroadcastHeight, pBgraFrame, width, height); break; } // send a frame to the stream if (gotFrame) { SubmitFrame(pBgraFrame); } } // The SDK may generate events that need to be handled by the main thread so we should handle them FlushStreamingEvents(); unsigned __int64 timePerFrame = curTime - gLastFrameTime; unsigned int fps = 0; if (timePerFrame > 0) { fps = static_cast<int>(1000 / timePerFrame); } gLastFrameTime = curTime; // Update the window title to show the state #undef STREAM_STATE #define STREAM_STATE(__state__) #__state__, char buffer[128]; const char* streamStates[] = { STREAM_STATE_LIST }; #undef STREAM_STATE sprintf_s(buffer, sizeof(buffer), "Twitch Direct3D Streaming Sample - %s - %s FPS=%d", GetUsername().c_str(), streamStates[GetStreamState()], fps); SetWindowTextA(gWindowHandle, buffer); } // Shutdown the Twitch SDK StopStreaming(); ShutdownStreaming(); // Cleanup the rendering method switch (gCaptureMethod) { case CaptureMethod::Slow: DeinitRendering_Slow(); break; case CaptureMethod::Fast: DeinitRendering_Fast(); break; } // Shutdown the app gGraphicsDevice->Release(); gDirect3D->Release(); // Cleanup the mesh DestroyWaveMesh(); return (int)msg.wParam; }
void emAvFileModel::PropertyChanged(const emString & name, const emString & value) { PlayStateType ps; double d; bool b; int i; if (name=="type") { b=(value=="video"); if (Video!=b) { Video=b; Signal(InfoSignal); } } else if (name=="length") { i=atoi(value); if (i<0) i=0; if (PlayLength!=i) { PlayLength=i; Signal(InfoSignal); if (PlayPos>PlayLength) { PlayPos=PlayLength; Signal(PlayPosSignal); } } } else if (name=="aspect") { i=atoi(value); if (i>0) { d=65536.0/i; if (Tallness!=d) { Tallness=d; Signal(ImageSignal); } } } else if (name=="info") { if (InfoText!=value) { InfoText=value; Signal(InfoSignal); } } else if (name=="warning") { if (WarningText!=value) { WarningText=value; Signal(InfoSignal); } } else if (name=="audio_visus") { if (UpdateStringArray(AudioVisus,value)) { Signal(InfoSignal); if (AudioVisu>=AudioVisus.GetCount()) { AudioVisu=0; Signal(AdjustmentSignal); } } } else if (name=="audio_channels") { if (UpdateStringArray(AudioChannels,value)) { Signal(InfoSignal); if (AudioChannel>=AudioChannels.GetCount()) { AudioChannel=0; Signal(AdjustmentSignal); } } } else if (name=="spu_channels") { if (UpdateStringArray(SpuChannels,value)) { Signal(InfoSignal); if (SpuChannel>=SpuChannels.GetCount()) { SpuChannel=0; Signal(AdjustmentSignal); } } } else if (name=="state") { if (value=="paused") ps=PS_PAUSED; else if (value=="normal") ps=PS_NORMAL; else if (value=="fast") ps=PS_FAST; else if (value=="slow") ps=PS_SLOW; else ps=PS_STOPPED; if (PlayState!=ps) { PlayState=ps; Signal(PlayStateSignal); if (ps==PS_STOPPED) RemoveFromActiveList(); else AddToActiveList(); if (PlayState==PS_STOPPED && GetFileState()==FS_LOADED) { CloseStream(); PlayPos=0; Signal(PlayPosSignal); Image.Empty(); Signal(ImageSignal); } } } else if (name=="pos") { i=atoi(value); if (i<0) i=0; if (i>PlayLength) i=PlayLength; if (PlayPos!=i) { PlayPos=i; Signal(PlayPosSignal); if (GetStreamState()==STREAM_OPENED) SaveFileState(); } } else if (name=="audio_volume") { i=atoi(value); if (i<0) i=0; if (i>100) i=100; if (AudioVolume!=i) { AudioVolume=i; Signal(AdjustmentSignal); } } else if (name=="audio_mute") { b=(value=="on"); if (AudioMute!=b) { AudioMute=b; Signal(AdjustmentSignal); } } else if (name=="audio_visu") { for (i=AudioVisus.GetCount()-1; i>=0; i--) { if (AudioVisus[i]==value) break; } if (i>=0 && AudioVisu!=i) { AudioVisu=i; Signal(AdjustmentSignal); } } else if (name=="audio_channel") { for (i=AudioChannels.GetCount()-1; i>=0; i--) { if (AudioChannels[i]==value) break; } if (i>=0 && AudioChannel!=i) { AudioChannel=i; Signal(AdjustmentSignal); } } else if (name=="spu_channel") { for (i=SpuChannels.GetCount()-1; i>=0; i--) { if (SpuChannels[i]==value) break; } if (i>=0 && SpuChannel!=i) { SpuChannel=i; Signal(AdjustmentSignal); } } else { emDLog( "emAvFileModel::PropertyChanged: Unsupported property name \"%s\".", name.Get() ); } }