diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 19df58227..edbbd636e 100755 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -486,6 +486,7 @@ int FfmpegCamera::CaptureAndRecord(Image &image, bool recording, char* event_fil } AVPacket packet; + AVPacket* queuedpacket; uint8_t* directbuffer; 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); wasRecording = true; 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) { Info("Deleting videoStore instance"); diff --git a/src/zm_packetqueue.cpp b/src/zm_packetqueue.cpp index ec37e7139..574f30a5e 100644 --- a/src/zm_packetqueue.cpp +++ b/src/zm_packetqueue.cpp @@ -24,7 +24,9 @@ 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) { @@ -34,59 +36,59 @@ zm_packetqueue::~zm_packetqueue() { } bool zm_packetqueue::queueVideoPacket(AVPacket* packet){ - return queuePacket(m_VideoQueue, packet); + return queuePacket(VideoQueue, packet); } bool zm_packetqueue::queueAudioPacket(AVPacket* packet) { - return queuePacket(m_AudioQueue, packet); + return queuePacket(AudioQueue, packet); } -bool zm_packetqueue::queuePacket(queue& packetQueue, AVPacket* packet){ +bool zm_packetqueue::queuePacket(queue& pktQueue, AVPacket* packet){ AVPacket input_ref = { 0 }; if (av_packet_ref(&input_ref, packet) < 0){ return false; } - packetQueue.push(*packet); + pktQueue.push(*packet); return true; } -bool zm_packetqueue::popPacket(queue& packetQueue, AVPacket* packet) +bool zm_packetqueue::popPacket(queue& pktQueue, AVPacket* packet) { - if (packetQueue.empty()) + if (pktQueue.empty()) { return false; } - *packet = packetQueue.front(); - packetQueue.pop(); + *packet = pktQueue.front(); + pktQueue.pop(); return true; } -void zm_packetqueue::clearQueue(std::queue& packetQueue) +void zm_packetqueue::clearQueue(std::queue& pktQueue) { - while(!packetQueue.empty()) + while(!pktQueue.empty()) { - packetQueue.pop(); + pktQueue.pop(); } } void zm_packetqueue::clearQueues() { - clearQueue(m_VideoQueue); - clearQueue(m_AudioQueue); + clearQueue(VideoQueue); + clearQueue(AudioQueue); } bool zm_packetqueue::popAudioPacket(AVPacket* packet) { - return popPacket(m_AudioQueue, packet); + return popPacket(AudioQueue, packet); } bool zm_packetqueue::popVideoPacket(AVPacket* packet) { - return popPacket(m_VideoQueue, packet); + return popPacket(VideoQueue, packet); } diff --git a/src/zm_packetqueue.h b/src/zm_packetqueue.h index 17fe0e9e5..135c7bf2f 100644 --- a/src/zm_packetqueue.h +++ b/src/zm_packetqueue.h @@ -31,19 +31,19 @@ public: zm_packetqueue(); zm_packetqueue(const zm_packetqueue& orig); virtual ~zm_packetqueue(); - bool queuePacket(std::queue& packetQueue, AVPacket* packet); + bool queuePacket(std::queue& pktQueue, AVPacket* packet); bool queueVideoPacket(AVPacket* packet); bool queueAudioPacket(AVPacket* packet); - bool popPacket(std::queue& packetQueue, AVPacket* packet); + bool popPacket(std::queue& pktQueue, AVPacket* packet); bool popVideoPacket(AVPacket* packet); bool popAudioPacket(AVPacket* packet); void clearQueues(); - void clearQueue(std::queue& packetQueue); + void clearQueue(std::queue& pktQueue); private: - int m_MaxVideoQueueSize; - int m_MaxAudioQueueSize; - std::queue m_VideoQueue; - std::queue m_AudioQueue; + int MaxVideoQueueSize; + int MaxAudioQueueSize; + std::queue VideoQueue; + std::queue AudioQueue; };