/*
 * (C) 2006-2023 see Authors.txt
 *
 * This file is part of MPC-BE.
 *
 * MPC-BE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * MPC-BE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#pragma once

static const WCHAR* MPEG2_Profile[] =
{
	L"4:2:2",
	L"High Profile",
	L"Spatially Scalable Profile",
	L"SNR Scalable Profile",
	L"Main Profile",
	L"Simple Profile",
	L"6",
	L"7",
};

static const WCHAR* MPEG2_Level[] =
{
	L"0",
	L"1",
	L"Main Level",
	L"3",
	L"High Level",
	L"High Level",
	L"High1440 Level",
	L"5",
	L"Main Level",
	L"6",
	L"Low Level",
	L"7",
	L"8",
	L"9",
	L"10",
	L"11",
};

//
template <typename T>
static T* GetFormatHelper(const CMediaType* _pFormat)
{
	ASSERT(_pFormat->cbFormat >= sizeof(T));
	return reinterpret_cast <T*>(_pFormat->pbFormat);
}

static int GetHighestBitSet32(unsigned long _Value)
{
	unsigned long Ret;
	unsigned char bNonZero = _BitScanReverse(&Ret, _Value);
	if (bNonZero) {
		return Ret;
	} else {
		return -1;
	}
}

static CString FormatBitrate(const DWORD _Bitrate)
{
	CString Temp;
	if (_Bitrate > 20000000) { // More than 2 mbit
		Temp.Format(L"%u mbit/s", _Bitrate / 1000000);
	} else {
		Temp.Format(L"%u kbit/s", _Bitrate / 1000);
	}

	return Temp;
}

static CString FormatString(const wchar_t *pszFormat, ...)
{
	CString Temp;
	ATLASSERT(AtlIsValidString(pszFormat));

	va_list argList;
	va_start(argList, pszFormat);
	Temp.FormatV(pszFormat, argList);
	va_end(argList);

	return Temp;
}

CString GetMediaTypeDesc(std::vector<CMediaType>& mts, LPCWSTR pName, CBaseFilter* pFilter);
CString GetMediaTypeDesc(const CMediaType* pmt, LPCWSTR pName);
