HRESULT BMDOutputDelegate::ScheduledFrameCompleted (IDeckLinkVideoFrame* /*completedFrame*/, BMDOutputFrameCompletionResult /*result*/) { // When a video frame has been released by the API, schedule another video frame to be output m_frameSet = false; ScheduleNextFrame(false); return S_OK; }
HRESULT Player::ScheduledFrameCompleted(IDeckLinkVideoFrame *completedFrame, BMDOutputFrameCompletionResult result) { if (fill_me) ScheduleNextFrame(false); return S_OK; }
HRESULT TestPattern::ScheduledFrameCompleted(IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult result) { ++m_totalFramesCompleted; PrintStatusLine(); // When a video frame has been released by the API, schedule another video frame to be output ScheduleNextFrame(false); return S_OK; }
void BMDOutputDelegate::SetCurrentFrame(VideoFramePtr ptr) { m_frame = ptr; PrepareFrame(); if((++ m_frameReceivedCount % m_framesPerSecond) == 0) m_frameSet = false; ScheduleNextFrame(false); //if(m_totalFramesScheduled == 0) //ScheduleNextFrame(false); //qDebug() << "BMDOutputDelegate::SetCurrentFrame(): Got frame, size:"<<ptr->size(); /* // if(image.width() != FRAME_WIDTH || // image.height() != FRAME_HEIGHT) // { // image = image.scaled(FRAME_WIDTH,FRAME_HEIGHT,Qt::IgnoreAspectRatio); // } if(image.format() != V4L_QIMAGE_FORMAT) image = image.convertToFormat(V4L_QIMAGE_FORMAT); // QImage and V4L's def of RGB24 differ in that they have the R & B bytes swapped compared to each other // - so we swap them here to appear correct in output. if(V4L_NATIVE_FORMAT == VIDEO_PALETTE_RGB24 && V4L_QIMAGE_FORMAT == QImage::Format_RGB888) { uchar tmp; uchar *bits = image.scanLine(0); for(int i=0; i<image.byteCount(); i+=3) { tmp = bits[i]; bits[i] = bits[i+2]; bits[i+2] = tmp; } } if(write(m_BMDOutputDev, (const uchar*)image.bits(), image.byteCount()) != image.byteCount()) { qDebug() << "BMDOutput::readFrame(): Error writing to "<<m_bmdOutputName<<" (bytes written does not match bytes requested), V4L error: " << strerror(errno); } else { //qDebug() << "DVizSharedMemoryThread::readFrame(): Wrote "<<outImg.byteCount()<<" bytes to "<<V4L_OUTPUT; } */ }
void Player::StartRunning(int videomode) { IDeckLinkDisplayMode *videoDisplayMode = NULL; unsigned long audioSamplesPerFrame; // Get the display mode for 1080i 59.95 videoDisplayMode = GetDisplayModeByIndex(videomode); if (!videoDisplayMode) return; m_frameWidth = videoDisplayMode->GetWidth(); m_frameHeight = videoDisplayMode->GetHeight(); videoDisplayMode->GetFrameRate(&m_frameDuration, &m_frameTimescale); // Set the video output mode if (m_deckLinkOutput->EnableVideoOutput(videoDisplayMode->GetDisplayMode(), bmdVideoOutputFlagDefault) != S_OK) { fprintf(stderr, "Failed to enable video output\n"); return; } // Set the audio output mode if (m_deckLinkOutput->EnableAudioOutput(bmdAudioSampleRate48kHz, m_audioSampleDepth, audio_st->codec->channels, bmdAudioOutputStreamTimestamped) != S_OK) { fprintf(stderr, "Failed to enable audio output\n"); return; } for (unsigned i = 0; i < 10; 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"); return; } m_running = true; return; }
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(); }
HRESULT CSignalGeneratorDlg::ScheduledFrameCompleted (IDeckLinkVideoFrame* completedFrame, BMDOutputFrameCompletionResult result) { // When a video frame has been ScheduleNextFrame(false); return S_OK; }
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(); }
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(); }