#ifndef _MEDIA_HELPER_H_
|
#define _MEDIA_HELPER_H_
|
|
#include <stdint.h>
|
#include <sys/time.h>
|
#include <algorithm>
|
|
#define MH_SUBSAMPLE1(v, a) ((((v) + (a) - 1)) / (a))
|
#define MH_SUBSAMPLE2(v, a, s) (v < 0) ? (-((-v + a) >> s)) : ((v + a) >> s)
|
|
#define MH_F_Z 0.00000001f //0.000000001f
|
#define MH_F_LT(x1, x2) (x1 < x2) //#todo
|
#define MH_F_GT(x1, x2) (x1 > x2)
|
#define MH_F_LTEQ(x1, x2) (x1 <= x2)
|
#define MH_F_GTEQ(x1, x2) (x1 >= x2)
|
#define MH_F_ZEQ(x) (x + MH_F_Z > 0.0f && x - MH_F_Z < 0.0f)
|
|
inline void microseconds_to_timeval(uint64_t v1, timeval& v2)
|
{
|
v2.tv_sec = v1 / 1000 / 1000;
|
v2.tv_usec = v1 % 1000;
|
}
|
|
inline timeval microseconds_to_timeval(uint64_t v1)
|
{
|
timeval v2;
|
v2.tv_sec = v1 / 1000 / 1000;
|
v2.tv_usec = v1 % 1000;
|
return v2;
|
}
|
|
inline uint64_t timeval_to_microseconds(const timeval& v2)
|
{
|
return (v2.tv_sec * 1000 * 1000 + v2.tv_usec);
|
}
|
|
template<typename TPoolPtr, typename TPoolElem>
|
struct PoolElemLocker
|
{
|
TPoolPtr pool;
|
TPoolElem elem;
|
PoolElemLocker(TPoolPtr _pool, TPoolElem _elem) : pool(_pool), elem(_elem)
|
{
|
|
}
|
~PoolElemLocker()
|
{
|
pool->release(elem);
|
pool->notify_free();
|
}
|
};
|
|
template<typename TArrayPtr>
|
struct ArrayDeleter
|
{
|
TArrayPtr array;
|
ArrayDeleter(TArrayPtr _array) : array(_array)
|
{
|
|
}
|
~ArrayDeleter()
|
{
|
delete[] array;
|
}
|
};
|
|
template<typename T>
|
struct ScopeLocker;
|
|
template<>
|
struct ScopeLocker<pthread_mutex_t>
|
{
|
pthread_mutex_t* mut;
|
ScopeLocker(pthread_mutex_t* _mut) : mut(_mut) { if (mut) pthread_mutex_lock(mut); }
|
~ScopeLocker(){ if (mut) pthread_mutex_unlock(mut); }
|
};
|
|
uint8_t* base64_decode(char const* in, size_t inSize, size_t& resultSize, bool trimTrailingZeros = true);
|
char* base64_encode(char const* orig, size_t origLength);
|
|
class SPropRecord;
|
SPropRecord* parseSPropParameterSets(char const* sPropParameterSetsStr, int& numSPropRecords);
|
|
template <typename T>
|
T clamp(const T& n, const T& n1, const T& n2)
|
{
|
if (n1 < n2)
|
{
|
if (n < n1) return n1;
|
else if(n > n2) return n2;
|
else return n;
|
}
|
else
|
{
|
if (n < n2) return n1;
|
else if(n > n1) return n2;
|
else return n;
|
}
|
return n;
|
}
|
|
#endif
|