私はosxで開発しています。
nsimage オブジェクトからオフスクリーンでレンダリングされたピクセル データへのポインターを設定しようとしています。これは私のコードです:
- (id)initWithFrame:(NSImage*)image
{
if (self = [super init])
{
// set size
NSRect rect = NSMakeRect(0, 0, [image size].width, [image size].height);
// set image
frameImageRef = [image CGImageForProposedRect:NULL context:NULL hints:NULL];
frameContextRef = CreateARGBBitmapContext(frameImageRef);
CGContextDrawImage(frameContextRef, rect, frameImageRef);
}
return self;
}
- (int) getBytesPerRow
{
return (int)CGImageGetBytesPerRow(frameImageRef);
}
次のコードを使用して、デッキリンク フレームへのポインターを設定します。
- (void*) renderToDeckLink;
{
return CGBitmapContextGetData (frameContextRef);
}
すべてのオブジェクトが正常に初期化されています。エラーはありません。画像がメモリにレンダリングされているように見えます。
これは、decklink デバイスで再生するためのdecklink フレームを作成するコードです。
- (void) createVideoFrame:(NSImage*)image
{
// clear previous videoframe
if (videoFrame != NULL)
{
videoFrame->Release();
}
この投稿の上部にあるコードは、renderFrame クラスにあります。
// create renderFrame object
renderFrame *frame = [[renderFrame alloc] initWithFrame:image];
// get displaymode
IDeckLinkDisplayMode* decklinkdisplaymode = (IDeckLinkDisplayMode*)CurrentRes;
// create new videoframe on output
if (deckLinkOutput->CreateVideoFrame((int)decklinkdisplaymode->GetWidth(), (int)decklinkdisplaymode->GetHeight(), [frame getBytesPerRow], bmdFormat8BitARGB, bmdFrameFlagDefault, &videoFrame) != S_OK)
{
NSLog(@"error");
// failed to create new video frame on output
}
次のコード行は、pixeldata ポインターを videoframe オブジェクトに渡す場所です。
// fill frame with buffer
videoFrame->GetBytes((void**)[frame renderToDeckLink]);
// schedule frame
[self scheduleVideoFrame];
// release pixeldata
[frame releaseData];
}
すべてがコンパイルされています。Pixeldata がオフスクリーンでレンダリングされています。フレームは正しくスケジュールされ、decklink デバイスで再生されます。しかし、私が得るのは黒い画面だけです。おそらく、ピクセルデータへのポインタに何か問題があるのでしょうか? 障害がどこにあるのかわかりません。
どんな助けでも大歓迎です!
Thx トーマス