整理代码

This commit is contained in:
蒲爽 2026-09-28 21:33:04 +08:00
commit c7b4e178ec
364 changed files with 59691 additions and 0 deletions

View file

@ -0,0 +1,132 @@
#ifndef D93EB1DD_2BCB_47B7_9361_91841576013D
#define D93EB1DD_2BCB_47B7_9361_91841576013D
/*
*******************************************************************************
* INCLUDE
*******************************************************************************
*/
#include "MediaType.h"
#include <Poco/Notification.h>
#include <Poco/NotificationQueue.h>
#include <Poco/SharedPtr.h>
#include <vector>
#include <iostream>
namespace Video
{
namespace Core
{
/*
*******************************************************************************
* CLASS DECLARE
*******************************************************************************
*/
template <class T> class Notification: public Poco::Notification
{
public:
Notification(typename T::Ptr pObject): _pObject(pObject)
{
}
public:
typename T::Ptr get()
{
return _pObject;
}
private:
typename T::Ptr _pObject;
};
enum class QueueStatus
{
UNKNOWN = -1,
NORMAL,
OVERHALF,
FULL,
};
template <class T> class NotificationQueue
{
public:
using Ptr = Poco::SharedPtr<NotificationQueue<T>>;
public:
NotificationQueue(const std::string& name, MediaType type, int limit = 300);
public:
MediaType type() const;
void enqueue(typename T::Ptr pObject, bool force = true);
typename T::Ptr dequeue(long timeout);
void clear();
QueueStatus status();
int size();
private:
Poco::NotificationQueue _queue;
std::string _name;
MediaType _type;
int _limit;
};
template <class T>
inline NotificationQueue<T>::NotificationQueue(const std::string& name, MediaType type, int limit)
: _name(name), _type(type), _limit(limit)
{
}
template <class T> inline MediaType NotificationQueue<T>::type() const
{
return _type;
}
template <class T> inline void NotificationQueue<T>::enqueue(typename T::Ptr pObject, bool force)
{
if (_queue.size() >= _limit)
{
if (!force)
throw std::overflow_error("Queue overflow!");
std::cout << "NotificationQueue(" + _name + "[" << (type() == MediaType::VIDEO ? "Video" : "Audio")
<< "]): OVERFLOW!" << std::endl;
_queue.dequeueNotification()->release();
}
_queue.enqueueNotification(new Notification<T>(pObject));
}
template <class T> inline typename T::Ptr NotificationQueue<T>::dequeue(long timeout)
{
Poco::Notification::Ptr p = _queue.waitDequeueNotification(timeout);
if (!p)
throw Poco::TimeoutException("Dequeue timeout: " + std::string(type() == MediaType::VIDEO ? "Video" : "Audio"));
return p.cast<Notification<T>>()->get();
}
template <class T> inline void NotificationQueue<T>::clear()
{
_queue.clear();
}
template <class T> inline QueueStatus NotificationQueue<T>::status()
{
QueueStatus s = QueueStatus::NORMAL;
const auto size = _queue.size();
if (size >= _limit)
s = QueueStatus::FULL;
else if (size >= (_limit >> 1))
s = QueueStatus::OVERHALF;
return s;
}
template <class T> inline int NotificationQueue<T>::size()
{
return _queue.size();
}
}
}
#endif