void CSignalGeneratorDlg::OnBnClickedOk() { if (m_running == false) StartRunning(); else StopRunning(); }
bool HandleMessage( UINT msg, WPARAM wParam, LPARAM lParam ) { if( msg == WM_USER ) { m_iResult = WSAGETASYNCERROR( lParam ); StopRunning(); return true; } if( msg == WM_USER+1 ) { m_iResult = 0; StopRunning(); return true; } return false; }
BMDOutputDelegate::BMDOutputDelegate(IDeckLink* link) : m_deckLink(link) , m_deckLinkConverter(0) , m_rgbFrame(0) , m_yuvFrame(0) , m_running(false) , m_frameSet(false) , m_frameReceivedCount(0) { // Obtain the audio/video output interface (IDeckLinkOutput) if (m_deckLink->QueryInterface(IID_IDeckLinkOutput, (void**)&m_deckLinkOutput) != S_OK) goto bail; #ifdef Q_OS_WIN if(CoCreateInstance(CLSID_CDeckLinkVideoConversion, NULL, CLSCTX_ALL,IID_IDeckLinkVideoConversion, (void**)&m_deckLinkConverter) != S_OK) #else if(!(m_deckLinkConverter = CreateVideoConversionInstance())) #endif { qDebug() << "BMDCaptureDelegate: Cannot create an instance of IID_IDeckLinkVideoConversion, therefore cannot convert YUV->RGB, therefore we will not emit proper RGB frames now."; m_deckLinkConverter = NULL; goto bail; } // Provide this class as a delegate to the audio and video output interfaces m_deckLinkOutput->SetScheduledFrameCompletionCallback(this); // Start. StartRunning(); return; bail: if (m_running == true) { StopRunning(); } else { // Release any resources that were partially allocated if (m_deckLinkOutput != NULL) { m_deckLinkOutput->Release(); m_deckLinkOutput = NULL; } // if (m_deckLink != NULL) { m_deckLink->Release(); m_deckLink = NULL; } } return ; };
void CSignalGeneratorDlg::OnClose() { if (m_running) StopRunning(); if (m_deckLinkOutput) { m_deckLinkOutput->SetScheduledFrameCompletionCallback(NULL); m_deckLinkOutput->SetAudioCallback(NULL); } CDialog::OnClose(); }
CSignalGeneratorDlg::~CSignalGeneratorDlg() { if (m_running) StopRunning(); if (m_deckLinkOutput) { m_deckLinkOutput->Release(); m_deckLinkOutput = NULL; } if (m_deckLink) { m_deckLink->Release(); m_deckLink = NULL; } }
bool Player::Init(int videomode, int connection, int camera) { // Initialize the DeckLink API IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance(); HRESULT result; int i = 0; if (!deckLinkIterator) { fprintf(stderr, "This application requires the DeckLink drivers installed.\n"); goto bail; } m_audioSampleDepth = av_get_exact_bits_per_sample(audio_st->codec->codec_id); switch (audio_st->codec->channels) { case 2: case 8: case 16: break; default: fprintf(stderr, "%d channels not supported, please use 2, 8 or 16\n", audio_st->codec->channels); goto bail; } switch (m_audioSampleDepth) { case 16: case 32: break; default: fprintf(stderr, "%dbit audio not supported use 16bit or 32bit\n", m_audioSampleDepth); } do result = deckLinkIterator->Next(&m_deckLink); while (i++ < camera); if (result != S_OK) { fprintf(stderr, "No DeckLink PCI cards found\n"); goto bail; } // Obtain the audio/video output interface (IDeckLinkOutput) if (m_deckLink->QueryInterface(IID_IDeckLinkOutput, (void **)&m_deckLinkOutput) != S_OK) goto bail; result = m_deckLink->QueryInterface(IID_IDeckLinkConfiguration, (void **)&deckLinkConfiguration); if (result != S_OK) { fprintf( stderr, "Could not obtain the IDeckLinkConfiguration interface - result = %08x\n", result); goto bail; } //XXX make it generic switch (connection) { case 1: DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionComposite); DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionAnalog); break; case 2: DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionComponent); DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionAnalog); break; case 3: DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionHDMI); DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionEmbedded); break; case 4: DECKLINK_SET_VIDEO_CONNECTION(bmdVideoConnectionSDI); DECKLINK_SET_AUDIO_CONNECTION(bmdAudioConnectionEmbedded); break; default: // do not change it break; } // Provide this class as a delegate to the audio and video output interfaces m_deckLinkOutput->SetScheduledFrameCompletionCallback(this); m_deckLinkOutput->SetAudioCallback(this); avframe = avcodec_alloc_frame(); packet_queue_init(&audioqueue); packet_queue_init(&videoqueue); packet_queue_init(&dataqueue); pthread_t th; pthread_create(&th, NULL, fill_queues, NULL); usleep(buffer); // You can add the microseconds you need for pre-buffering before start playing // Start playing StartRunning(videomode); pthread_mutex_lock(&sleepMutex); pthread_cond_wait(&sleepCond, &sleepMutex); pthread_mutex_unlock(&sleepMutex); fill_me = 0; fprintf(stderr, "Exiting, cleaning up\n"); packet_queue_end(&audioqueue); packet_queue_end(&videoqueue); bail: if (m_running == true) { StopRunning(); } else { // Release any resources that were partially allocated if (m_deckLinkOutput != NULL) { m_deckLinkOutput->Release(); m_deckLinkOutput = NULL; } // if (m_deckLink != NULL) { m_deckLink->Release(); m_deckLink = NULL; } } if (deckLinkIterator != NULL) deckLinkIterator->Release(); return true; }
static void intHandler( int sig_num ) { sig_num = sig_num; StopRunning(); }
nsresult nsMsgOfflineManager::AdvanceToNextState(nsresult exitStatus) { // NS_BINDING_ABORTED is used for the user pressing stop, which // should cause us to abort the offline process. Other errors // should allow us to continue. if (exitStatus == NS_BINDING_ABORTED) { return StopRunning(exitStatus); } if (m_curOperation == eGoingOnline) { switch (m_curState) { case eNoState: m_curState = eSendingUnsent; if (m_sendUnsentMessages) { SendUnsentMessages(); } else AdvanceToNextState(NS_OK); break; case eSendingUnsent: m_curState = eSynchronizingOfflineImapChanges; if (m_playbackOfflineImapOps) return SynchronizeOfflineImapChanges(); else AdvanceToNextState(NS_OK); // recurse to next state. break; case eSynchronizingOfflineImapChanges: m_curState = eDone; return StopRunning(exitStatus); default: NS_ASSERTION(false, "unhandled current state when going online"); } } else if (m_curOperation == eDownloadingForOffline) { switch (m_curState) { case eNoState: m_curState = eDownloadingNews; if (m_downloadNews) DownloadOfflineNewsgroups(); else AdvanceToNextState(NS_OK); break; case eSendingUnsent: if (m_goOfflineWhenDone) { SetOnlineState(false); } break; case eDownloadingNews: m_curState = eDownloadingMail; if (m_downloadMail) DownloadMail(); else AdvanceToNextState(NS_OK); break; case eDownloadingMail: m_curState = eSendingUnsent; if (m_sendUnsentMessages) SendUnsentMessages(); else AdvanceToNextState(NS_OK); break; default: NS_ASSERTION(false, "unhandled current state when downloading for offline"); } } return NS_OK; }
void BMDOutputDelegate::StartRunning () { IDeckLinkDisplayMode* videoDisplayMode = NULL; // Get the display mode for 1080i 59.95 - mode 6 // Changed to NTSC 23.98 - JB 20110215 videoDisplayMode = GetDisplayModeByIndex(1); if (!videoDisplayMode) return; m_frameWidth = videoDisplayMode->GetWidth(); m_frameHeight = videoDisplayMode->GetHeight(); videoDisplayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale); // Calculate the number of frames per second, rounded up to the nearest integer. For example, for NTSC (29.97 FPS), framesPerSecond == 30. m_framesPerSecond = (unsigned long)((m_frameTimescale + (m_frameDuration-1)) / m_frameDuration); QImage image(m_frameWidth,m_frameHeight, QImage::Format_ARGB32); image.fill(Qt::green); //m_frame = VideoFramePtr(new VideoFrame(image, 1000/30)); HRESULT res; // Set the video output mode if (m_deckLinkOutput->EnableVideoOutput(videoDisplayMode->GetDisplayMode(), bmdVideoOutputFlagDefault) != S_OK) { //fprintf(stderr, "Failed to enable video output\n"); qDebug() << "BMDOutputDelegate::StartRunning(): Failed to EnableVideoOutput()"; goto bail; } res = m_deckLinkOutput->CreateVideoFrame( m_frameWidth, m_frameHeight, m_frameWidth * 4, bmdFormat8BitBGRA, bmdFrameFlagDefault, &m_rgbFrame); if(res != S_OK) { qDebug() << "BMDOutputDelegate::StartRunning: Error creating RGB frame, res:"<<res; goto bail; } res = m_deckLinkOutput->CreateVideoFrame( m_frameWidth, m_frameHeight, m_frameWidth * 2, bmdFormat8BitYUV, bmdFrameFlagDefault, &m_yuvFrame); if(res != S_OK) { qDebug() << "BMDOutputDelegate::StartRunning: Error creating YUV frame, res:"<<res; goto bail; } // // Generate a frame of black // if (m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &m_videoFrameBlack) != S_OK) // { // fprintf(stderr, "Failed to create video frame\n"); // goto bail; // } // FillBlack(m_videoFrameBlack); // // // Generate a frame of colour bars // if (m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &m_videoFrameBars) != S_OK) // { // fprintf(stderr, "Failed to create video frame\n"); // goto bail; // } // FillColourBars(m_videoFrameBars); // Begin video preroll by scheduling a second of frames in hardware m_totalFramesScheduled = 0; for (unsigned i = 0; i < m_framesPerSecond; i++) { PrepareFrame(); ScheduleNextFrame(true); } // Args: startTime, timeScale, playback speed (1.0 = normal) m_deckLinkOutput->StartScheduledPlayback(0, 100, 1.0); m_running = true; return; bail: // *** Error-handling code. Cleanup any resources that were allocated. *** // StopRunning(); }
void CSignalGeneratorDlg::StartRunning () { IDeckLinkDisplayMode* videoDisplayMode = NULL; BMDVideoOutputFlags videoOutputFlags = bmdVideoOutputFlagDefault; int curSelection; CString videoFormatName; curSelection = m_videoFormatCombo.GetCurSel(); m_videoFormatCombo.GetLBText(curSelection, videoFormatName); if (videoFormatName.Find(_T(" 3D"), 0) != -1) videoOutputFlags = bmdVideoOutputDualStream3D; // Determine the audio and video properties for the output stream m_outputSignal = (OutputSignal)m_outputSignalCombo.GetCurSel(); m_audioChannelCount = m_audioChannelCombo.GetItemData(m_audioChannelCombo.GetCurSel()); m_audioSampleDepth = (BMDAudioSampleType)m_audioSampleDepthCombo.GetItemData(m_audioSampleDepthCombo.GetCurSel()); m_audioSampleRate = bmdAudioSampleRate48kHz; // // - Extract the IDeckLinkDisplayMode from the display mode popup menu (stashed in the item's tag) videoDisplayMode = (IDeckLinkDisplayMode*)m_videoFormatCombo.GetItemDataPtr(m_videoFormatCombo.GetCurSel()); m_frameWidth = videoDisplayMode->GetWidth(); m_frameHeight = videoDisplayMode->GetHeight(); videoDisplayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale); // Calculate the number of frames per second, rounded up to the nearest integer. For example, for NTSC (29.97 FPS), framesPerSecond == 30. m_framesPerSecond = (unsigned long)((m_frameTimescale + (m_frameDuration-1)) / m_frameDuration); // Set the video output mode if (m_deckLinkOutput->EnableVideoOutput(videoDisplayMode->GetDisplayMode(), videoOutputFlags) != S_OK) goto bail; // Set the audio output mode if (m_deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, m_audioSampleDepth, m_audioChannelCount, bmdAudioOutputStreamTimestamped) != S_OK) goto bail; // Generate one second of audio tone m_audioSamplesPerFrame = (unsigned long)((m_audioSampleRate * m_frameDuration) / m_frameTimescale); m_audioBufferSampleLength = (unsigned long)((m_framesPerSecond * m_audioSampleRate * m_frameDuration) / m_frameTimescale); m_audioBuffer = HeapAlloc(GetProcessHeap(), 0, (m_audioBufferSampleLength * m_audioChannelCount * (m_audioSampleDepth / 8))); if (m_audioBuffer == NULL) goto bail; FillSine(m_audioBuffer, m_audioBufferSampleLength, m_audioChannelCount, m_audioSampleDepth); // Generate a frame of black m_videoFrameBlack = CreateBlackFrame(); if (! m_videoFrameBlack) goto bail; // Generate a frame of colour bars m_videoFrameBars = CreateBarsFrame(); if (! m_videoFrameBars) goto bail; // Begin video preroll by scheduling a second of frames in hardware m_totalFramesScheduled = 0; for (unsigned i = 0; i < m_framesPerSecond; i++) ScheduleNextFrame(true); // Begin audio preroll. This will begin calling our audio callback, which will start the DeckLink output stream. m_totalAudioSecondsScheduled = 0; if (m_deckLinkOutput->BeginAudioPreroll() != S_OK) goto bail; // Success; update the UI m_running = true; m_startButton.SetWindowText(_T("Stop")); // Disable the user interface while running (prevent the user from making changes to the output signal) EnableInterface(FALSE); return; bail: // *** Error-handling code. Cleanup any resources that were allocated. *** // StopRunning(); }
bool TestPattern::Init() { HRESULT result; int idx; bool success = false; IDeckLinkIterator* deckLinkIterator = NULL; IDeckLinkDisplayModeIterator* displayModeIterator = NULL; char* displayModeName = NULL; // Get the DeckLink device deckLinkIterator = CreateDeckLinkIteratorInstance(); if (!deckLinkIterator) { fprintf(stderr, "This application requires the DeckLink drivers installed.\n"); goto bail; } idx = m_config->m_deckLinkIndex; while ((result = deckLinkIterator->Next(&m_deckLink)) == S_OK) { if (idx == 0) break; --idx; m_deckLink->Release(); } if (result != S_OK || m_deckLink == NULL) { fprintf(stderr, "Unable to get DeckLink device %u\n", m_config->m_deckLinkIndex); goto bail; } // Get the output (display) interface of the DeckLink device if (m_deckLink->QueryInterface(IID_IDeckLinkOutput, (void**)&m_deckLinkOutput) != S_OK) goto bail; // Get the display mode idx = m_config->m_displayModeIndex; result = m_deckLinkOutput->GetDisplayModeIterator(&displayModeIterator); if (result != S_OK) goto bail; while ((result = displayModeIterator->Next(&m_displayMode)) == S_OK) { if (idx == 0) break; --idx; m_displayMode->Release(); } if (result != S_OK || m_displayMode == NULL) { fprintf(stderr, "Unable to get display mode %d\n", m_config->m_displayModeIndex); goto bail; } // Get display mode name result = m_displayMode->GetName((const char**)&displayModeName); if (result != S_OK) { displayModeName = (char *)malloc(32); snprintf(displayModeName, 32, "[index %d]", m_config->m_displayModeIndex); } // Check for 3D support on display mode if ((m_config->m_outputFlags & bmdVideoOutputDualStream3D) && !(m_displayMode->GetFlags() & bmdDisplayModeSupports3D)) { fprintf(stderr, "The display mode %s is not supported with 3D\n", displayModeName); goto bail; } m_config->DisplayConfiguration(); // Provide this class as a delegate to the audio and video output interfaces m_deckLinkOutput->SetScheduledFrameCompletionCallback(this); m_deckLinkOutput->SetAudioCallback(this); success = true; // Start. while (!do_exit) { StartRunning(); fprintf(stderr, "Starting playback\n"); pthread_mutex_lock(&sleepMutex); pthread_cond_wait(&sleepCond, &sleepMutex); pthread_mutex_unlock(&sleepMutex); fprintf(stderr, "Stopping playback\n"); StopRunning(); } printf("\n"); m_running = false; bail: if (displayModeName != NULL) free(displayModeName); if (m_displayMode != NULL) m_displayMode->Release(); if (displayModeIterator != NULL) displayModeIterator->Release(); if (m_deckLinkOutput != NULL) m_deckLinkOutput->Release(); if (m_deckLink != NULL) m_deckLink->Release(); if (deckLinkIterator != NULL) deckLinkIterator->Release(); return success; }
void TestPattern::StartRunning() { HRESULT result; unsigned long audioSamplesPerFrame; IDeckLinkVideoFrame* rightFrame; VideoFrame3D* frame3D; m_frameWidth = m_displayMode->GetWidth(); m_frameHeight = m_displayMode->GetHeight(); m_displayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale); // Calculate the number of frames per second, rounded up to the nearest integer. For example, for NTSC (29.97 FPS), framesPerSecond == 30. m_framesPerSecond = (unsigned long)((m_frameTimescale + (m_frameDuration-1)) / m_frameDuration); // Set the video output mode result = m_deckLinkOutput->EnableVideoOutput(m_displayMode->GetDisplayMode(), m_config->m_outputFlags); if (result != S_OK) { fprintf(stderr, "Failed to enable video output. Is another application using the card?\n"); goto bail; } // Set the audio output mode result = m_deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, m_config->m_audioSampleDepth, m_config->m_audioChannels, bmdAudioOutputStreamContinuous); if (result != S_OK) { fprintf(stderr, "Failed to enable audio output\n"); goto bail; } // Generate one second of audio m_audioBufferSampleLength = (unsigned long)((m_framesPerSecond * m_audioSampleRate * m_frameDuration) / m_frameTimescale); m_audioBuffer = valloc(m_audioBufferSampleLength * m_config->m_audioChannels * (m_config->m_audioSampleDepth / 8)); if (m_audioBuffer == NULL) { fprintf(stderr, "Failed to allocate audio buffer memory\n"); goto bail; } // Zero the buffer (interpreted as audio silence) memset(m_audioBuffer, 0x0, (m_audioBufferSampleLength * m_config->m_audioChannels * m_config->m_audioSampleDepth / 8)); audioSamplesPerFrame = (unsigned long)((m_audioSampleRate * m_frameDuration) / m_frameTimescale); if (m_outputSignal == kOutputSignalPip) FillSine(m_audioBuffer, audioSamplesPerFrame, m_config->m_audioChannels, m_config->m_audioSampleDepth); else FillSine((void*)((unsigned long)m_audioBuffer + (audioSamplesPerFrame * m_config->m_audioChannels * m_config->m_audioSampleDepth / 8)), (m_audioBufferSampleLength - audioSamplesPerFrame), m_config->m_audioChannels, m_config->m_audioSampleDepth); // Generate a frame of black if (CreateFrame(&m_videoFrameBlack, FillBlack) != S_OK) goto bail; if (m_config->m_outputFlags & bmdVideoOutputDualStream3D) { frame3D = new VideoFrame3D(m_videoFrameBlack); m_videoFrameBlack->Release(); m_videoFrameBlack = frame3D; frame3D = NULL; } // Generate a frame of colour bars if (CreateFrame(&m_videoFrameBars, FillForwardColourBars) != S_OK) goto bail; if (m_config->m_outputFlags & bmdVideoOutputDualStream3D) { if (CreateFrame(&rightFrame, FillReverseColourBars) != S_OK) goto bail; frame3D = new VideoFrame3D(m_videoFrameBars, rightFrame); m_videoFrameBars->Release(); rightFrame->Release(); m_videoFrameBars = frame3D; frame3D = NULL; } // Begin video preroll by scheduling a second of frames in hardware m_totalFramesScheduled = 0; m_totalFramesDropped = 0; m_totalFramesCompleted = 0; for (unsigned i = 0; i < m_framesPerSecond; i++) ScheduleNextFrame(true); // Begin audio preroll. This will begin calling our audio callback, which will start the DeckLink output stream. m_audioBufferOffset = 0; if (m_deckLinkOutput->BeginAudioPreroll() != S_OK) { fprintf(stderr, "Failed to begin audio preroll\n"); goto bail; } m_running = true; return; bail: // *** Error-handling code. Cleanup any resources that were allocated. *** // StopRunning(); }