#!/usr/bin/env python3
"""Simple HTTP server for the H.265 SPS-replacement POC.

Serves poc.hevc / poc.mp4 / poc.html on http://localhost:8080/.
Use on a machine with VAAPI / D3D11 / V4L2 HEVC hardware decode.
"""
import http.server, socketserver, os

PORT = 8080
os.chdir(os.path.dirname(os.path.abspath(__file__)))

class H(http.server.SimpleHTTPRequestHandler):
    extensions_map = {
        **http.server.SimpleHTTPRequestHandler.extensions_map,
        '.hevc': 'video/hevc',
        '.mp4':  'video/mp4',
        '.html': 'text/html',
    }
    def end_headers(self):
        self.send_header('Cross-Origin-Opener-Policy', 'same-origin')
        self.send_header('Access-Control-Allow-Origin', '*')
        super().end_headers()

with socketserver.TCPServer(("", PORT), H) as httpd:
    print(f"serving on http://localhost:{PORT}/poc.html")
    httpd.serve_forever()
