<?php
/**
 * Muxer engine resolver functions.
 *
 * @package The Studio Player
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! function_exists( 'thespl_get_muxer_engine_class' ) ) {
	/**
	 * Get the active muxer engine class name.
	 *
	 * @return string
	 */
	function thespl_get_muxer_engine_class() {
		$class_name = 'THESPL_Muxer_Engine';

		if ( defined( 'THESPL_HAS_PRO_ASSETS' ) && THESPL_HAS_PRO_ASSETS && class_exists( 'THESPL_Muxer_Engine_Pro' ) ) {
			$class_name = 'THESPL_Muxer_Engine_Pro';
		}

		return is_string( $class_name ) && '' !== $class_name ? $class_name : 'THESPL_Muxer_Engine';
	}
}

if ( ! function_exists( 'thespl_get_muxer_engine' ) ) {
	/**
	 * Get the active muxer engine instance.
	 *
	 * @return THESPL_Muxer_Engine
	 */
	function thespl_get_muxer_engine() {
		static $instance       = null;
		static $instance_class = '';

		$class_name = thespl_get_muxer_engine_class();
		if ( null !== $instance && $instance_class === $class_name ) {
			return $instance;
		}

		if ( ! class_exists( $class_name ) ) {
			$class_name = 'THESPL_Muxer_Engine';
		}

		$instance       = new $class_name();
		$instance_class = $class_name;

		return $instance;
	}
}
