WIP packetqueue shared memory
parent
f3ca10aac6
commit
8aa1cb6bf6
|
@ -488,7 +488,7 @@ int FfmpegCamera::CaptureAndRecord(Image &image, bool recording, char* event_fil
|
|||
AVPacket packet;
|
||||
AVPacket* queuedpacket;
|
||||
uint8_t* directbuffer;
|
||||
zm_packetqueue packetqueue;
|
||||
zm_packetqueue packetqueue("testqueue");
|
||||
|
||||
/* Request a writeable buffer of the target image */
|
||||
directbuffer = image.WriteBuffer(width, height, colours, subpixelorder);
|
||||
|
|
|
@ -22,11 +22,45 @@
|
|||
#define VIDEO_QUEUESIZE 200
|
||||
#define AUDIO_QUEUESIZE 50
|
||||
|
||||
using namespace std;
|
||||
using namespace boost::interprocess;
|
||||
|
||||
zm_packetqueue::zm_packetqueue()
|
||||
: MaxVideoQueueSize(VIDEO_QUEUESIZE)
|
||||
, MaxAudioQueueSize(AUDIO_QUEUESIZE){
|
||||
zm_packetqueue::zm_packetqueue(const std::string &name)
|
||||
: m_name(name),
|
||||
msm(open_or_create, m_name.c_str(), 65536),
|
||||
alloc(msm.get_segment_manager()) {
|
||||
|
||||
try {
|
||||
|
||||
//Alias an STL compatible allocator of for the map.
|
||||
//This allocator will allow to place containers
|
||||
//in managed shared memory segments
|
||||
|
||||
|
||||
//Alias a map of ints that uses the previous STL-like allocator.
|
||||
//Note that the third parameter argument is the ordering function
|
||||
//of the map, just like with std::map, used to compare the keys.
|
||||
//typedef map<KeyType, MappedType, std::less<KeyType>, ShmemAllocator> MyMap;
|
||||
|
||||
//Initialize the shared memory STL-compatible allocator
|
||||
QueueShmemAllocator alloc_inst (segment.get_segment_manager());
|
||||
|
||||
//Construct a shared memory map.
|
||||
//Note that the first parameter is the comparison function,
|
||||
//and the second one the allocator.
|
||||
//This the same signature as std::map's constructor taking an allocator
|
||||
// MyMap *mymap =
|
||||
// segment.construct<MyMap>("MyMap") //object name
|
||||
// (std::less<int>() //first ctor parameter
|
||||
// ,alloc_inst); //second ctor parameter
|
||||
//
|
||||
// //Insert data in the map
|
||||
// for(int i = 0; i < 100; ++i){
|
||||
// mymap->insert(std::pair<const int, float>(i, (float)i));
|
||||
} catch (...) {
|
||||
shared_memory_object::remove("MySharedMemory");
|
||||
throw;
|
||||
}
|
||||
shared_memory_object::remove("MySharedMemory");
|
||||
}
|
||||
|
||||
zm_packetqueue::zm_packetqueue(const zm_packetqueue& orig) {
|
||||
|
@ -44,7 +78,7 @@ bool zm_packetqueue::queueAudioPacket(AVPacket* packet)
|
|||
return queuePacket(AudioQueue, packet);
|
||||
}
|
||||
|
||||
bool zm_packetqueue::queuePacket(queue<AVPacket>& pktQueue, AVPacket* packet){
|
||||
bool zm_packetqueue::queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet) {
|
||||
|
||||
AVPacket input_ref = { 0 };
|
||||
if (av_packet_ref(&input_ref, packet) < 0){
|
||||
|
@ -55,7 +89,7 @@ bool zm_packetqueue::queuePacket(queue<AVPacket>& pktQueue, AVPacket* packet){
|
|||
return true;
|
||||
}
|
||||
|
||||
bool zm_packetqueue::popPacket(queue<AVPacket>& pktQueue, AVPacket* packet)
|
||||
bool zm_packetqueue::popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet)
|
||||
{
|
||||
if (pktQueue.empty())
|
||||
{
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#define ZM_PACKETQUEUE_H
|
||||
|
||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||
#include <boost/interprocess/containers/map.hpp>
|
||||
#include <boost/interprocess/containers/deque.hpp>
|
||||
#include <boost/interprocess/allocators/allocator.hpp>
|
||||
#include <queue>
|
||||
|
||||
|
@ -29,26 +29,31 @@ extern "C" {
|
|||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
typedef queue<AVPacket, deque<AVPacket, QueueShmemAllocator> > QueueType;
|
||||
|
||||
class zm_packetqueue {
|
||||
public:
|
||||
zm_packetqueue();
|
||||
zm_packetqueue(const zm_packetqueue& orig);
|
||||
virtual ~zm_packetqueue();
|
||||
bool queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||
bool queueVideoPacket(AVPacket* packet);
|
||||
bool queueAudioPacket(AVPacket* packet);
|
||||
bool popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||
bool popVideoPacket(AVPacket* packet);
|
||||
bool popAudioPacket(AVPacket* packet);
|
||||
void clearQueues();
|
||||
void clearQueue(std::queue<AVPacket>& pktQueue);
|
||||
zm_packetqueue(const std::string &name);
|
||||
virtual ~zm_packetqueue();
|
||||
bool queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||
bool queueVideoPacket(AVPacket* packet);
|
||||
bool queueAudioPacket(AVPacket* packet);
|
||||
bool popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||
bool popVideoPacket(AVPacket* packet);
|
||||
bool popAudioPacket(AVPacket* packet);
|
||||
void clearQueues();
|
||||
void clearQueue(std::queue<AVPacket>& pktQueue);
|
||||
private:
|
||||
int MaxVideoQueueSize;
|
||||
int MaxAudioQueueSize;
|
||||
std::queue<AVPacket> VideoQueue;
|
||||
std::queue<AVPacket> AudioQueue;
|
||||
typedef boost::interprocess::allocator <AVPacket,
|
||||
boost::interprocess::managed_shared_memory::segment_manager>
|
||||
QueueShmemAllocator;
|
||||
typedef std::queue<AVPacket, std::deque<AVPacket, QueueShmemAllocator> >
|
||||
QueueType;
|
||||
std::string m_name;
|
||||
boost::interprocess::managed_shared_memory msm;
|
||||
QueueShmemAllocator alloc;
|
||||
int MaxVideoQueueSize;
|
||||
int MaxAudioQueueSize;
|
||||
std::queue<AVPacket> VideoQueue;
|
||||
std::queue<AVPacket> AudioQueue;
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue