version: '3.8'

services:
  # NGINX RTMP server for streaming
  nginx-rtmp:
    build:
      context: .
      dockerfile: nginxconf/Dockerfile
    container_name: iptvsim-nginx
    ports:
      - "1935:1935"  # RTMP port - for publishing streams
      - "80:8080"  # HTTP port - for HLS/DASH playback and stats
    volumes:
      - ./nginxconf/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginxconf/stat.xsl:/etc/nginx/stat.xsl:ro
      - ./nginxconf/index.html:/usr/share/nginx/html/index.html
    networks:
      - iptvsim-network
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/stat"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Go application for streaming control
  byschiitv:
    build:
      context: ./byschiitv
      dockerfile: Dockerfile
    container_name: iptvsim-app
    ports:
      - "8080:8080"  # API port - for queue management
    volumes:
      - "${HOST_MEDIA_PATH:-./byschiitv/media}:/media:ro"
    networks:
      - iptvsim-network
    depends_on:
      - nginx-rtmp
    environment:
      - GIN_MODE=release
    restart: unless-stopped
    group_add:
      - video
    privileged: true          # keep on while you debug; you can tighten later
    devices:
      - "/dev/video10:/dev/video10"   # stateful decoder (m2m)
      - "/dev/video11:/dev/video11"   # stateful encoder (m2m)
      - "/dev/video12:/dev/video12"   # codec-isp helper
      - "/dev/dri:/dev/dri"           # DRM / PRIME for zero-copy paths
networks:
  iptvsim-network:
    driver: bridge
