dragonflight/services/capture/patch_decklink.py

52 lines
2 KiB
Python
Raw Normal View History

import re
dec_path = '/ffmpeg/libavdevice/decklink_dec.cpp'
with open(dec_path) as f:
content = f.read()
# Fix 1: IDeckLinkMemoryAllocator -> IDeckLinkMemoryAllocator_v14_2_1
# SDK 16 removed the unversioned alias
for old, new in [
(': public IDeckLinkMemoryAllocator\n', ': public IDeckLinkMemoryAllocator_v14_2_1\n'),
('IDeckLinkMemoryAllocator *', 'IDeckLinkMemoryAllocator_v14_2_1 *'),
('IDeckLinkMemoryAllocator*', 'IDeckLinkMemoryAllocator_v14_2_1*'),
]:
content = content.replace(old, new)
print('Fix 1: IDeckLinkMemoryAllocator renamed')
# Fix 2: SetVideoInputFrameMemoryAllocator removed from IDeckLinkInput in SDK 16
content = re.sub(
r'ret = \(ctx->dli->SetVideoInputFrameMemoryAllocator\(allocator\)[^;]*;',
'ret = 0; /* SDK16: SetVideoInputFrameMemoryAllocator removed */',
content
)
print('Fix 2: SetVideoInputFrameMemoryAllocator patched')
# Fix 3: IDeckLinkVideoFrame::GetBytes removed in SDK 16 - moved to IDeckLinkVideoBuffer
# Replace: videoFrame->GetBytes(&frameBytes);
# With: { IDeckLinkVideoBuffer *vbuf = nullptr; videoFrame->QueryInterface(IID_IDeckLinkVideoBuffer, (void**)&vbuf); if (vbuf) { vbuf->GetBytes(&frameBytes); vbuf->Release(); } }
getbytes_replacement = (
'{ IDeckLinkVideoBuffer *_vbuf = nullptr; '
'videoFrame->QueryInterface(IID_IDeckLinkVideoBuffer, (void**)&_vbuf); '
'if (_vbuf) { _vbuf->GetBytes(&frameBytes); _vbuf->Release(); } }'
)
content = content.replace(
'videoFrame->GetBytes(&frameBytes);',
getbytes_replacement + ';'
)
print('Fix 3: videoFrame->GetBytes replaced with QueryInterface(IDeckLinkVideoBuffer)')
# Fix 4: Add include for versioned allocator header
if 'DeckLinkAPIMemoryAllocator_v14_2_1.h' not in content:
content = content.replace(
'#include "decklink_common.h"',
'#include "decklink_common.h"\n#include "DeckLinkAPIMemoryAllocator_v14_2_1.h"'
)
print('Fix 4: DeckLinkAPIMemoryAllocator_v14_2_1.h include added')
with open(dec_path, 'w') as f:
f.write(content)
print('All patches applied successfully')