<?php
   require_once 'video_streamer_base.php';

   class VideoStreamerChunkedBasic extends VideoStreamerBase {
      protected $_chunk_size = 0;

      public function __construct($video_path, $require_cookie, $chunk_size) {
         parent::__construct($video_path, $require_cookie);
         $this->_chunk_size = $chunk_size;
      }

      protected function setResponseHeaders() {
         header("HTTP/1.1 200 OK");
         header("Content-Type: video/mp4");
         header("Accept-Ranges: none");
         header("Transfer-Encoding: chunked");
      }

      protected function doVideoStream() {
         set_time_limit(0);
         while (!feof($this->_video_stream)) {
            $data = fread($this->_video_stream, $this->_chunk_size);
            // Apparently PHP automatically takes care of formatting the chunks
            // (calculate chunk size and insert line breaks), so all we need to
            // do is put the chunk data to system buffer and flush it?
            echo $data;
            flush();
         }
      }
   }
?>