#!/bin/bash
set -e
cd "$(dirname "$0")"

echo "=== Checking prerequisites ==="

if [ ! -f sdk/DeckLinkAPI.h ]; then
  echo "ERROR: sdk/DeckLinkAPI.h not found."
  echo ""
  echo "Please download the Blackmagic DeckLink SDK 16.x from:"
  echo "  https://www.blackmagicdesign.com/developer/product/capture"
  echo ""
  echo "Then extract the Linux/include/ folder contents into:"
  echo "  $(pwd)/sdk/"
  echo ""
  echo "Required files: DeckLinkAPI.h DeckLinkAPIVersion.h DeckLinkAPIDispatch.cpp"
  echo "                LinuxCOM.h DeckLinkAPIModes.h DeckLinkAPITypes.h"
  exit 1
fi

echo "SDK headers found:"
ls sdk/*.h sdk/*.cpp 2>/dev/null

echo ""
echo "=== Building capture container with DeckLink FFmpeg ==="
docker compose -f ../../docker-compose.yml build capture

echo ""
echo "=== Verifying DeckLink support in built image ==="
docker run --rm wild-dragon-capture ffmpeg -f decklink -list_devices true -i dummy 2>&1 | head -20
