parent
a3eabe9c72
commit
1f3b3d1203
|
@ -532,7 +532,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
|
||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
AVPacket* queuedpacket;
|
AVPacket* queuedpacket;
|
||||||
uint8_t* directbuffer;
|
uint8_t* directbuffer;
|
||||||
zm_packetqueue packetqueue("testqueue");
|
zm_packetqueue packetqueue;
|
||||||
|
|
||||||
/* Request a writeable buffer of the target image */
|
/* Request a writeable buffer of the target image */
|
||||||
directbuffer = image.WriteBuffer(width, height, colours, subpixelorder);
|
directbuffer = image.WriteBuffer(width, height, colours, subpixelorder);
|
||||||
|
|
|
@ -22,25 +22,11 @@
|
||||||
#define VIDEO_QUEUESIZE 200
|
#define VIDEO_QUEUESIZE 200
|
||||||
#define AUDIO_QUEUESIZE 50
|
#define AUDIO_QUEUESIZE 50
|
||||||
|
|
||||||
using namespace boost::interprocess;
|
using namespace std;
|
||||||
|
|
||||||
zm_packetqueue::zm_packetqueue(const std::string &name)
|
zm_packetqueue::zm_packetqueue()
|
||||||
: m_name(name),
|
: MaxVideoQueueSize(VIDEO_QUEUESIZE)
|
||||||
msm(open_or_create, m_name.c_str(), 65536),
|
, MaxAudioQueueSize(AUDIO_QUEUESIZE) {
|
||||||
alloc(msm.get_segment_manager()) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
//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
|
|
||||||
ptr = msm.find_or_construct<AVPacket>(m_name.c_str())(alloc);
|
|
||||||
} catch (...) {
|
|
||||||
shared_memory_object::remove("MySharedMemory");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
shared_memory_object::remove("MySharedMemory");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zm_packetqueue::~zm_packetqueue() {
|
zm_packetqueue::~zm_packetqueue() {
|
||||||
|
@ -55,7 +41,7 @@ bool zm_packetqueue::queueAudioPacket(AVPacket* packet)
|
||||||
return queuePacket(AudioQueue, packet);
|
return queuePacket(AudioQueue, packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zm_packetqueue::queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet) {
|
bool zm_packetqueue::queuePacket(queue<AVPacket>& pktQueue, AVPacket* packet){
|
||||||
|
|
||||||
AVPacket input_ref = { 0 };
|
AVPacket input_ref = { 0 };
|
||||||
if (av_packet_ref(&input_ref, packet) < 0){
|
if (av_packet_ref(&input_ref, packet) < 0){
|
||||||
|
@ -66,7 +52,7 @@ bool zm_packetqueue::queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packe
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool zm_packetqueue::popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet)
|
bool zm_packetqueue::popPacket(queue<AVPacket>& pktQueue, AVPacket* packet)
|
||||||
{
|
{
|
||||||
if (pktQueue.empty())
|
if (pktQueue.empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define ZM_PACKETQUEUE_H
|
#define ZM_PACKETQUEUE_H
|
||||||
|
|
||||||
#include <boost/interprocess/managed_shared_memory.hpp>
|
#include <boost/interprocess/managed_shared_memory.hpp>
|
||||||
#include <boost/interprocess/containers/deque.hpp>
|
#include <boost/interprocess/containers/map.hpp>
|
||||||
#include <boost/interprocess/allocators/allocator.hpp>
|
#include <boost/interprocess/allocators/allocator.hpp>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
@ -29,31 +29,26 @@ extern "C" {
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef queue<AVPacket, deque<AVPacket, QueueShmemAllocator> > QueueType;
|
||||||
|
|
||||||
class zm_packetqueue {
|
class zm_packetqueue {
|
||||||
public:
|
public:
|
||||||
zm_packetqueue(const std::string &name);
|
zm_packetqueue();
|
||||||
virtual ~zm_packetqueue();
|
zm_packetqueue(const zm_packetqueue& orig);
|
||||||
bool queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
virtual ~zm_packetqueue();
|
||||||
bool queueVideoPacket(AVPacket* packet);
|
bool queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||||
bool queueAudioPacket(AVPacket* packet);
|
bool queueVideoPacket(AVPacket* packet);
|
||||||
bool popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
bool queueAudioPacket(AVPacket* packet);
|
||||||
bool popVideoPacket(AVPacket* packet);
|
bool popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
|
||||||
bool popAudioPacket(AVPacket* packet);
|
bool popVideoPacket(AVPacket* packet);
|
||||||
void clearQueues();
|
bool popAudioPacket(AVPacket* packet);
|
||||||
void clearQueue(std::queue<AVPacket>& pktQueue);
|
void clearQueues();
|
||||||
|
void clearQueue(std::queue<AVPacket>& pktQueue);
|
||||||
private:
|
private:
|
||||||
typedef boost::interprocess::allocator <AVPacket,
|
int MaxVideoQueueSize;
|
||||||
boost::interprocess::managed_shared_memory::segment_manager>
|
int MaxAudioQueueSize;
|
||||||
QueueShmemAllocator;
|
std::queue<AVPacket> VideoQueue;
|
||||||
typedef std::queue<AVPacket, std::deque<AVPacket, QueueShmemAllocator> >
|
std::queue<AVPacket> AudioQueue;
|
||||||
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