Packetqueue tweaks, need to move this stuff up to monitor to maintain a packet buffer

This commit is contained in:
Steve Gilvarry 2016-04-25 22:06:07 +10:00
parent 966fbb1a10
commit 7fcd12fab9
3 changed files with 33 additions and 23 deletions

View File

@ -486,6 +486,7 @@ int FfmpegCamera::CaptureAndRecord(Image &image, bool recording, char* event_fil
} }
AVPacket packet; AVPacket packet;
AVPacket* queuedpacket;
uint8_t* directbuffer; uint8_t* directbuffer;
zm_packetqueue packetqueue; zm_packetqueue packetqueue;
@ -546,6 +547,13 @@ int FfmpegCamera::CaptureAndRecord(Image &image, bool recording, char* event_fil
videoStore = new VideoStore((const char *) event_file, "mp4", mFormatContext->streams[mVideoStreamId], mAudioStreamId == -1 ? NULL : mFormatContext->streams[mAudioStreamId], startTime); videoStore = new VideoStore((const char *) event_file, "mp4", mFormatContext->streams[mVideoStreamId], mAudioStreamId == -1 ? NULL : mFormatContext->streams[mAudioStreamId], startTime);
wasRecording = true; wasRecording = true;
strcpy(oldDirectory, event_file); strcpy(oldDirectory, event_file);
while(packetqueue.popVideoPacket(queuedpacket)){
int ret = videoStore->writeVideoFramePacket(&packet, mFormatContext->streams[mVideoStreamId]); //, &lastKeyframePkt);
if (ret < 0) {//Less than zero and we skipped a frame
av_free_packet(&packet);
return 0;
}
}
} else if (!recording && wasRecording && videoStore) { } else if (!recording && wasRecording && videoStore) {
Info("Deleting videoStore instance"); Info("Deleting videoStore instance");

View File

@ -24,7 +24,9 @@
using namespace std; using namespace std;
zm_packetqueue::zm_packetqueue() { zm_packetqueue::zm_packetqueue()
: MaxVideoQueueSize(VIDEO_QUEUESIZE)
, MaxAudioQueueSize(AUDIO_QUEUESIZE){
} }
zm_packetqueue::zm_packetqueue(const zm_packetqueue& orig) { zm_packetqueue::zm_packetqueue(const zm_packetqueue& orig) {
@ -34,59 +36,59 @@ zm_packetqueue::~zm_packetqueue() {
} }
bool zm_packetqueue::queueVideoPacket(AVPacket* packet){ bool zm_packetqueue::queueVideoPacket(AVPacket* packet){
return queuePacket(m_VideoQueue, packet); return queuePacket(VideoQueue, packet);
} }
bool zm_packetqueue::queueAudioPacket(AVPacket* packet) bool zm_packetqueue::queueAudioPacket(AVPacket* packet)
{ {
return queuePacket(m_AudioQueue, packet); return queuePacket(AudioQueue, packet);
} }
bool zm_packetqueue::queuePacket(queue<AVPacket>& packetQueue, 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){
return false; return false;
} }
packetQueue.push(*packet); pktQueue.push(*packet);
return true; return true;
} }
bool zm_packetqueue::popPacket(queue<AVPacket>& packetQueue, AVPacket* packet) bool zm_packetqueue::popPacket(queue<AVPacket>& pktQueue, AVPacket* packet)
{ {
if (packetQueue.empty()) if (pktQueue.empty())
{ {
return false; return false;
} }
*packet = packetQueue.front(); *packet = pktQueue.front();
packetQueue.pop(); pktQueue.pop();
return true; return true;
} }
void zm_packetqueue::clearQueue(std::queue<AVPacket>& packetQueue) void zm_packetqueue::clearQueue(std::queue<AVPacket>& pktQueue)
{ {
while(!packetQueue.empty()) while(!pktQueue.empty())
{ {
packetQueue.pop(); pktQueue.pop();
} }
} }
void zm_packetqueue::clearQueues() void zm_packetqueue::clearQueues()
{ {
clearQueue(m_VideoQueue); clearQueue(VideoQueue);
clearQueue(m_AudioQueue); clearQueue(AudioQueue);
} }
bool zm_packetqueue::popAudioPacket(AVPacket* packet) bool zm_packetqueue::popAudioPacket(AVPacket* packet)
{ {
return popPacket(m_AudioQueue, packet); return popPacket(AudioQueue, packet);
} }
bool zm_packetqueue::popVideoPacket(AVPacket* packet) bool zm_packetqueue::popVideoPacket(AVPacket* packet)
{ {
return popPacket(m_VideoQueue, packet); return popPacket(VideoQueue, packet);
} }

View File

@ -31,19 +31,19 @@ public:
zm_packetqueue(); zm_packetqueue();
zm_packetqueue(const zm_packetqueue& orig); zm_packetqueue(const zm_packetqueue& orig);
virtual ~zm_packetqueue(); virtual ~zm_packetqueue();
bool queuePacket(std::queue<AVPacket>& packetQueue, AVPacket* packet); bool queuePacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
bool queueVideoPacket(AVPacket* packet); bool queueVideoPacket(AVPacket* packet);
bool queueAudioPacket(AVPacket* packet); bool queueAudioPacket(AVPacket* packet);
bool popPacket(std::queue<AVPacket>& packetQueue, AVPacket* packet); bool popPacket(std::queue<AVPacket>& pktQueue, AVPacket* packet);
bool popVideoPacket(AVPacket* packet); bool popVideoPacket(AVPacket* packet);
bool popAudioPacket(AVPacket* packet); bool popAudioPacket(AVPacket* packet);
void clearQueues(); void clearQueues();
void clearQueue(std::queue<AVPacket>& packetQueue); void clearQueue(std::queue<AVPacket>& pktQueue);
private: private:
int m_MaxVideoQueueSize; int MaxVideoQueueSize;
int m_MaxAudioQueueSize; int MaxAudioQueueSize;
std::queue<AVPacket> m_VideoQueue; std::queue<AVPacket> VideoQueue;
std::queue<AVPacket> m_AudioQueue; std::queue<AVPacket> AudioQueue;
}; };