HRESULT TestPattern::CreateFrame(IDeckLinkVideoFrame** frame, void (*fillFunc)(IDeckLinkVideoFrame*)) { HRESULT result; int bytesPerPixel = GetBytesPerPixel(m_config->m_pixelFormat); IDeckLinkMutableVideoFrame* newFrame = NULL; IDeckLinkMutableVideoFrame* referenceFrame = NULL; IDeckLinkVideoConversion* frameConverter = NULL; *frame = NULL; result = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * bytesPerPixel, m_config->m_pixelFormat, bmdFrameFlagDefault, &newFrame); if (result != S_OK) { fprintf(stderr, "Failed to create video frame\n"); goto bail; } if (m_config->m_pixelFormat == bmdFormat8BitYUV) { fillFunc(newFrame); } else { // Create a black frame in 8 bit YUV and convert to desired format result = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 2, bmdFormat8BitYUV, bmdFrameFlagDefault, &referenceFrame); if (result != S_OK) { fprintf(stderr, "Failed to create reference video frame\n"); goto bail; } fillFunc(referenceFrame); frameConverter = CreateVideoConversionInstance(); result = frameConverter->ConvertFrame(referenceFrame, newFrame); if (result != S_OK) { fprintf(stderr, "Failed to convert frame\n"); goto bail; } } *frame = newFrame; newFrame = NULL; bail: if (referenceFrame != NULL) referenceFrame->Release(); if (frameConverter != NULL) frameConverter->Release(); if (newFrame != NULL) newFrame->Release(); return result; }
SignalGenerator3DVideoFrame* CSignalGeneratorDlg::CreateBlackFrame () { IDeckLinkMutableVideoFrame* referenceBlack = NULL; IDeckLinkMutableVideoFrame* scheduleBlack = NULL; HRESULT hr; BMDPixelFormat pixelFormat; int bytesPerPixel; IDeckLinkVideoConversion* frameConverter = NULL; SignalGenerator3DVideoFrame* ret = NULL; pixelFormat = (BMDPixelFormat)m_pixelFormatCombo.GetItemData(m_pixelFormatCombo.GetCurSel()); bytesPerPixel = GetBytesPerPixel(pixelFormat); hr = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*bytesPerPixel, pixelFormat, bmdFrameFlagDefault, &scheduleBlack); if (hr != S_OK) goto bail; if (pixelFormat == bmdFormat8BitYUV) { FillBlack(scheduleBlack); } else { hr = m_deckLinkOutput->CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth*2, bmdFormat8BitYUV, bmdFrameFlagDefault, &referenceBlack); if (hr != S_OK) goto bail; FillBlack(referenceBlack); hr = CoCreateInstance(CLSID_CDeckLinkVideoConversion, NULL, CLSCTX_ALL, IID_IDeckLinkVideoConversion, (void**)&frameConverter); if (hr != S_OK) goto bail; hr = frameConverter->ConvertFrame(referenceBlack, scheduleBlack); if (hr != S_OK) goto bail; } ret = new SignalGenerator3DVideoFrame(scheduleBlack); bail: if (referenceBlack) referenceBlack->Release(); if (scheduleBlack) scheduleBlack->Release(); if (frameConverter) frameConverter->Release(); return ret; }
void BMDOutputDelegate::ScheduleNextFrame(bool preroll) { if(!preroll) { // If not prerolling, make sure that playback is still active if (m_running == false) return; } if(m_frameSet) { //qDebug() << "m_frameSet: not setting"; return; } m_frameSet = true; QTime t; t.start(); // if ((m_totalFramesScheduled % m_framesPerSecond) == 0) // { // // On each second, schedule a frame of black // if (m_deckLinkOutput->ScheduleVideoFrame(m_videoFrameBlack, (m_totalFramesScheduled * m_frameDuration), m_frameDuration, m_frameTimescale) != S_OK) // return; // } //qDebug() << "BMDOutputDelegate::ScheduleNextFrame: [3] Frame Repaint: "<<t.restart()<<" ms"; if(!m_image.isNull()) { void *frameBytes; m_rgbFrame->GetBytes(&frameBytes); int maxBytes = m_frameWidth * m_frameHeight * 4; memcpy(frameBytes, (const uchar*)m_image.bits(), m_image.byteCount() > maxBytes ? maxBytes : m_image.byteCount()); //qDebug() << "BMDOutputDelegate::ScheduleNextFrame: [4] Load BMD Frame with RGB: "<<t.restart()<<" ms"; // Pixel conversions // Source frame Target frame // bmdFormat8BitRGBA bmdFormat8BitYUV // bmdFormat8BitARGB // bmdFormat8BitBGRA bmdFormat8BitYUV // bmdFormat8BitARGB bmdFormat8BitYUV if(m_deckLinkConverter) { m_deckLinkConverter->ConvertFrame(m_rgbFrame, m_yuvFrame); //qDebug() << "BMDOutputDelegate::ScheduleNextFrame: [5] RGB->YUV: "<<t.restart()<<" ms"; if (m_deckLinkOutput->ScheduleVideoFrame(m_yuvFrame, (m_totalFramesScheduled * m_frameDuration), m_frameDuration, m_frameTimescale) != S_OK) return; //qDebug() << "BMDOutputDelegate::ScheduleNextFrame: [6] ScheduleVideoFrame(): "<<t.restart()<<" ms"; } else { qDebug() << "BMDOutputDelegate::ScheduleNextFrame: No m_deckLinkConverter available, unable to convert frame."; } } m_totalFramesScheduled += 1; }