15 #ifndef SHAKA_EMBEDDED_UTILS_H_ 16 #define SHAKA_EMBEDDED_UTILS_H_ 23 #include <type_traits> 75 return x == other.
x && y == other.
y && w == other.
w && h == other.
h;
78 return !(*
this == other);
83 std::ostream& operator<<(std::ostream& os, const ShakaRect<T>& rect) {
84 return os <<
"{x=" << rect.x <<
",y=" << rect.y <<
",w=" << rect.w <<
",h=" 100 using enable_if_num =
101 typename std::enable_if<std::is_arithmetic<U>::value>
::type;
103 static T gcd(T a, T b) {
114 static void reduce(T* num, T* den) {
115 T a = gcd(*num, *den);
126 Rational(T num1, T num2, T den1, T den2) {
127 if (num1 == 0 || num2 == 0 || den1 == 0 || den2 == 0) {
128 numerator = denominator = 0;
132 reduce(&num1, &den1);
133 reduce(&num1, &den2);
134 reduce(&num2, &den1);
135 reduce(&num2, &den2);
139 assert(std::numeric_limits<T>::max() / num1 >= num2);
140 assert(std::numeric_limits<T>::max() / den1 >= den2);
144 numerator = num1 * num2;
145 denominator = den1 * den2;
146 assert(gcd(numerator, denominator) == 1);
154 return numerator / denominator;
157 return {denominator, numerator};
160 operator bool()
const {
161 return numerator != 0 && denominator != 0;
163 operator double()
const {
164 return static_cast<double>(numerator) / denominator;
167 template <
typename U>
172 template <
typename U>
174 return !(*
this == other);
177 template <
typename U>
182 template <
typename U,
typename = enable_if_num<U>>
184 return {numerator, other, denominator, 1};
187 template <
typename U>
192 template <
typename U,
typename = enable_if_num<U>>
194 return {numerator, 1, denominator, other};
200 static_assert(std::is_pod<
Rational<int>>::value,
"Rational should be POD");
202 template <
typename T>
203 std::ostream& operator<<(std::ostream& os, const Rational<T>& bar) {
204 return os << bar.numerator <<
"/" << bar.denominator;
208 template <
typename T,
typename U,
typename =
209 typename std::enable_if<std::is_arithmetic<T>::value>
::type>
216 template <
typename T,
typename U,
typename =
217 typename std::enable_if<std::is_arithmetic<T>::value>
::type>
254 std::string ret = key_system;
255 std::string::size_type pos = 0;
256 while ((pos = ret.find(
'.', pos)) != std::string::npos) {
257 ret.insert(pos,
"\\");
285 const std::string& property) {
293 #endif // SHAKA_EMBEDDED_UTILS_H_
Rational< common< U > > operator/(U other) const
bool operator==(const Rational< U > &other) const
Rational< common< U > > operator*(const Rational< U > &other) const
bool operator==(const ShakaRect &other) const
std::string LicenseServerConfig(const std::string &key_system)
std::shared_ptr< shaka::media::DecodedFrame > frame
bool operator!=(const ShakaRect &other) const
Rational< T > inverse() const
bool operator!=(const Rational< U > &other) const
Rational< common< U > > operator*(U other) const
Rational< typename std::common_type< T, U >::type > operator/(T a, const Rational< U > &b)
void FitVideoToRegion(ShakaRect< uint32_t > frame, ShakaRect< uint32_t > bounds, Rational< uint32_t > sample_aspect_ratio, VideoFillMode mode, ShakaRect< uint32_t > *src, ShakaRect< uint32_t > *dest)
Rational< typename std::common_type< T, U >::type > operator*(T a, const Rational< U > &b)
std::string EscapeKeySystem(const std::string &key_system)
std::string AdvancedDrmConfig(const std::string &key_system, const std::string &property)
Rational< common< U > > operator/(const Rational< U > &other) const