2008-07-16 16:35:59 +08:00
|
|
|
//
|
2008-07-25 17:08:15 +08:00
|
|
|
// ZoneMinder RTP Source Class Implementation, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2008-07-16 16:35:59 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-07-16 16:35:59 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "zm_rtp_source.h"
|
|
|
|
|
|
|
|
#include "zm_time.h"
|
|
|
|
#include "zm_rtp_data.h"
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2014-01-02 00:19:42 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
|
|
|
|
2013-11-29 05:32:06 +08:00
|
|
|
RtpSource::RtpSource( int id, const std::string &localHost, int localPortBase, const std::string &remoteHost, int remotePortBase, uint32_t ssrc, uint16_t seq, uint32_t rtpClock, uint32_t rtpTime, _AVCODECID codecId ) :
|
2016-04-04 22:11:48 +08:00
|
|
|
mId( id ),
|
|
|
|
mSsrc( ssrc ),
|
|
|
|
mLocalHost( localHost ),
|
|
|
|
mRemoteHost( remoteHost ),
|
|
|
|
mRtpClock( rtpClock ),
|
|
|
|
mCodecId( codecId ),
|
|
|
|
mFrame( 65536 ),
|
|
|
|
mFrameCount( 0 ),
|
|
|
|
mFrameGood( true ),
|
|
|
|
mFrameReady( false ),
|
|
|
|
mFrameProcessed( false )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
char hostname[256] = "";
|
|
|
|
gethostname( hostname, sizeof(hostname) );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mCname = stringtf( "zm-%d@%s", mId, hostname );
|
|
|
|
Debug( 3, "RTP CName = %s", mCname.c_str() );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
init( seq );
|
|
|
|
mMaxSeq = seq - 1;
|
|
|
|
mProbation = MIN_SEQUENTIAL;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mLocalPortChans[0] = localPortBase;
|
|
|
|
mLocalPortChans[1] = localPortBase+1;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mRemotePortChans[0] = remotePortBase;
|
|
|
|
mRemotePortChans[1] = remotePortBase+1;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mRtpFactor = mRtpClock;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mBaseTimeReal = tvNow();
|
|
|
|
mBaseTimeNtp = tvZero();
|
|
|
|
mBaseTimeRtp = rtpTime;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mLastSrTimeReal = tvZero();
|
|
|
|
mLastSrTimeNtp = tvZero();
|
|
|
|
mLastSrTimeRtp = 0;
|
2017-05-20 21:03:04 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if(mCodecId != AV_CODEC_ID_H264 && mCodecId != AV_CODEC_ID_MPEG4)
|
|
|
|
Warning( "The device is using a codec that may not be supported. Do not be surprised if things don't work." );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 02:00:35 +08:00
|
|
|
void RtpSource::init( uint16_t seq )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 3, "Initialising sequence" );
|
|
|
|
mBaseSeq = seq;
|
|
|
|
mMaxSeq = seq;
|
|
|
|
mBadSeq = RTP_SEQ_MOD + 1; // so seq == mBadSeq is false
|
|
|
|
mCycles = 0;
|
|
|
|
mReceivedPackets = 0;
|
|
|
|
mReceivedPrior = 0;
|
|
|
|
mExpectedPrior = 0;
|
|
|
|
// other initialization
|
|
|
|
mJitter = 0;
|
|
|
|
mTransit = 0;
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 02:00:35 +08:00
|
|
|
bool RtpSource::updateSeq( uint16_t seq )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
uint16_t uDelta = seq - mMaxSeq;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Source is not valid until MIN_SEQUENTIAL packets with
|
|
|
|
// sequential sequence numbers have been received.
|
|
|
|
Debug( 5, "Seq: %d", seq );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( mProbation)
|
|
|
|
{
|
|
|
|
// packet is in sequence
|
|
|
|
if ( seq == mMaxSeq + 1)
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 3, "Sequence in probation %d, in sequence", mProbation );
|
|
|
|
mProbation--;
|
|
|
|
mMaxSeq = seq;
|
|
|
|
if ( mProbation == 0 )
|
|
|
|
{
|
|
|
|
init( seq );
|
|
|
|
mReceivedPackets++;
|
2008-07-16 16:35:59 +08:00
|
|
|
return( true );
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
else
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Warning( "Sequence in probation %d, out of sequence", mProbation );
|
|
|
|
mProbation = MIN_SEQUENTIAL - 1;
|
|
|
|
mMaxSeq = seq;
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
else if ( uDelta < MAX_DROPOUT )
|
|
|
|
{
|
|
|
|
if ( uDelta == 1 )
|
|
|
|
{
|
2017-05-20 21:03:04 +08:00
|
|
|
Debug( 4, "Packet in sequence, gap %d", uDelta );
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Warning( "Packet in sequence, gap %d", uDelta );
|
|
|
|
}
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// in order, with permissible gap
|
|
|
|
if ( seq < mMaxSeq )
|
|
|
|
{
|
|
|
|
// Sequence number wrapped - count another 64K cycle.
|
|
|
|
mCycles += RTP_SEQ_MOD;
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
mMaxSeq = seq;
|
|
|
|
}
|
|
|
|
else if ( uDelta <= RTP_SEQ_MOD - MAX_MISORDER )
|
|
|
|
{
|
|
|
|
Warning( "Packet out of sequence, gap %d", uDelta );
|
|
|
|
// the sequence number made a very large jump
|
|
|
|
if ( seq == mBadSeq )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 3, "Restarting sequence" );
|
|
|
|
// Two sequential packets -- assume that the other side
|
|
|
|
// restarted without telling us so just re-sync
|
|
|
|
// (i.e., pretend this was the first packet).
|
|
|
|
init( seq );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
mBadSeq = (seq + 1) & (RTP_SEQ_MOD-1);
|
|
|
|
return( false );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Warning( "Packet duplicate or reordered, gap %d", uDelta );
|
|
|
|
// duplicate or reordered packet
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
mReceivedPackets++;
|
|
|
|
return( uDelta==1?true:false );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RtpSource::updateJitter( const RtpDataHeader *header )
|
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( mRtpFactor > 0 )
|
|
|
|
{
|
|
|
|
Debug( 5, "Delta rtp = %.6f", tvDiffSec( mBaseTimeReal ) );
|
|
|
|
uint32_t localTimeRtp = mBaseTimeRtp + uint32_t( tvDiffSec( mBaseTimeReal ) * mRtpFactor );
|
|
|
|
Debug( 5, "Local RTP time = %x", localTimeRtp );
|
|
|
|
Debug( 5, "Packet RTP time = %x", ntohl(header->timestampN) );
|
|
|
|
uint32_t packetTransit = localTimeRtp - ntohl(header->timestampN);
|
|
|
|
Debug( 5, "Packet transit RTP time = %x", packetTransit );
|
|
|
|
|
|
|
|
if ( mTransit > 0 )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
// Jitter
|
|
|
|
int d = packetTransit - mTransit;
|
|
|
|
Debug( 5, "Jitter D = %d", d );
|
|
|
|
if ( d < 0 )
|
|
|
|
d = -d;
|
|
|
|
//mJitter += (1./16.) * ((double)d - mJitter);
|
|
|
|
mJitter += d - ((mJitter + 8) >> 4);
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
mTransit = packetTransit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mJitter = 0;
|
|
|
|
}
|
|
|
|
Debug( 5, "RTP Jitter: %d", mJitter );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
2010-07-05 02:00:35 +08:00
|
|
|
void RtpSource::updateRtcpData( uint32_t ntpTimeSecs, uint32_t ntpTimeFrac, uint32_t rtpTime )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
struct timeval ntpTime = tvMake( ntpTimeSecs, suseconds_t((USEC_PER_SEC*(ntpTimeFrac>>16))/(1<<16)) );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
|
2017-05-20 21:03:04 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( mBaseTimeNtp.tv_sec == 0 )
|
|
|
|
{
|
|
|
|
mBaseTimeReal = tvNow();
|
|
|
|
mBaseTimeNtp = ntpTime;
|
|
|
|
mBaseTimeRtp = rtpTime;
|
|
|
|
}
|
|
|
|
else if ( !mRtpClock )
|
|
|
|
{
|
|
|
|
Debug( 5, "lastSrNtpTime: %ld.%06ld, rtpTime: %x", mLastSrTimeNtp.tv_sec, mLastSrTimeNtp.tv_usec, rtpTime );
|
2010-07-05 02:00:35 +08:00
|
|
|
Debug( 5, "ntpTime: %ld.%06ld, rtpTime: %x", ntpTime.tv_sec, ntpTime.tv_usec, rtpTime );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
double diffNtpTime = tvDiffSec( mBaseTimeNtp, ntpTime );
|
|
|
|
uint32_t diffRtpTime = rtpTime - mBaseTimeRtp;
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
//Debug( 5, "Real-diff: %.6f", diffRealTime );
|
|
|
|
Debug( 5, "NTP-diff: %.6f", diffNtpTime );
|
|
|
|
Debug( 5, "RTP-diff: %d", diffRtpTime );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
mRtpFactor = (uint32_t)(diffRtpTime / diffNtpTime);
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 5, "RTPfactor: %d", mRtpFactor );
|
|
|
|
}
|
|
|
|
mLastSrTimeNtpSecs = ntpTimeSecs;
|
|
|
|
mLastSrTimeNtpFrac = ntpTimeFrac;
|
|
|
|
mLastSrTimeNtp = ntpTime;
|
|
|
|
mLastSrTimeRtp = rtpTime;
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void RtpSource::updateRtcpStats()
|
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
uint32_t extendedMax = mCycles + mMaxSeq;
|
|
|
|
mExpectedPackets = extendedMax - mBaseSeq + 1;
|
|
|
|
|
|
|
|
Debug( 5, "Expected packets = %d", mExpectedPackets );
|
|
|
|
|
|
|
|
// The number of packets lost is defined to be the number of packets
|
|
|
|
// expected less the number of packets actually received:
|
|
|
|
mLostPackets = mExpectedPackets - mReceivedPackets;
|
|
|
|
Debug( 5, "Lost packets = %d", mLostPackets );
|
|
|
|
|
|
|
|
uint32_t expectedInterval = mExpectedPackets - mExpectedPrior;
|
|
|
|
Debug( 5, "Expected interval = %d", expectedInterval );
|
|
|
|
mExpectedPrior = mExpectedPackets;
|
|
|
|
uint32_t receivedInterval = mReceivedPackets - mReceivedPrior;
|
|
|
|
Debug( 5, "Received interval = %d", receivedInterval );
|
|
|
|
mReceivedPrior = mReceivedPackets;
|
|
|
|
uint32_t lostInterval = expectedInterval - receivedInterval;
|
|
|
|
Debug( 5, "Lost interval = %d", lostInterval );
|
|
|
|
|
|
|
|
if ( expectedInterval == 0 || lostInterval <= 0 )
|
|
|
|
mLostFraction = 0;
|
|
|
|
else
|
|
|
|
mLostFraction = (lostInterval << 8) / expectedInterval;
|
|
|
|
Debug( 5, "Lost fraction = %d", mLostFraction );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RtpSource::handlePacket( const unsigned char *packet, size_t packetLen )
|
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
const RtpDataHeader *rtpHeader;
|
|
|
|
rtpHeader = (RtpDataHeader *)packet;
|
|
|
|
int rtpHeaderSize = 12 + rtpHeader->cc * 4;
|
|
|
|
// No need to check for nal type as non fragmented packets already have 001 start sequence appended
|
|
|
|
bool h264FragmentEnd = (mCodecId == AV_CODEC_ID_H264) && (packet[rtpHeaderSize+1] & 0x40);
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
// M stands for Marker, it is the 8th bit
|
|
|
|
// The interpretation of the marker is defined by a profile. It is intended
|
|
|
|
// to allow significant events such as frame boundaries to be marked in the
|
|
|
|
// packet stream. A profile may define additional marker bits or specify
|
|
|
|
// that there is no marker bit by changing the number of bits in the payload type field.
|
2016-04-04 22:11:48 +08:00
|
|
|
bool thisM = rtpHeader->m || h264FragmentEnd;
|
|
|
|
|
|
|
|
if ( updateSeq( ntohs(rtpHeader->seqN) ) )
|
|
|
|
{
|
|
|
|
Hexdump( 4, packet+rtpHeaderSize, 16 );
|
|
|
|
|
|
|
|
if ( mFrameGood )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
int extraHeader = 0;
|
2017-05-20 21:03:04 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if( mCodecId == AV_CODEC_ID_H264 )
|
|
|
|
{
|
|
|
|
int nalType = (packet[rtpHeaderSize] & 0x1f);
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
Debug( 3, "Have H264 frame: nal type is %d", nalType );
|
2017-05-20 21:03:04 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
switch (nalType)
|
2013-11-29 05:32:06 +08:00
|
|
|
{
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
case 24: // STAP-A
|
2017-05-20 21:03:04 +08:00
|
|
|
{
|
|
|
|
extraHeader = 2;
|
|
|
|
break;
|
|
|
|
}
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
case 25: // STAP-B
|
|
|
|
case 26: // MTAP-16
|
|
|
|
case 27: // MTAP-24
|
2017-05-20 21:03:04 +08:00
|
|
|
{
|
|
|
|
extraHeader = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// FU-A and FU-B
|
2016-04-04 22:11:48 +08:00
|
|
|
case 28: case 29:
|
2013-11-29 05:32:06 +08:00
|
|
|
{
|
2017-05-20 21:03:04 +08:00
|
|
|
// Is this NAL the first NAL in fragmentation sequence
|
|
|
|
if ( packet[rtpHeaderSize+1] & 0x80 )
|
|
|
|
{
|
|
|
|
// Now we will form new header of frame
|
|
|
|
mFrame.append( "\x0\x0\x1\x0", 4 );
|
|
|
|
// Reconstruct NAL header from FU headers
|
|
|
|
*(mFrame+3) = (packet[rtpHeaderSize+1] & 0x1f) |
|
|
|
|
(packet[rtpHeaderSize] & 0xe0);
|
|
|
|
}
|
|
|
|
|
|
|
|
extraHeader = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
Debug(3, "Unhandled nalType %d", nalType );
|
2013-11-29 05:32:06 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-20 21:03:04 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
// Append NAL frame start code
|
|
|
|
if ( !mFrame.size() )
|
|
|
|
mFrame.append( "\x0\x0\x1", 3 );
|
|
|
|
}
|
|
|
|
mFrame.append( packet+rtpHeaderSize+extraHeader, packetLen-rtpHeaderSize-extraHeader );
|
2017-05-20 21:03:04 +08:00
|
|
|
} else {
|
|
|
|
Debug( 3, "NOT H264 frame: type is %d", mCodecId );
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2013-11-30 00:15:56 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
Hexdump( 4, mFrame.head(), 16 );
|
2008-07-16 16:35:59 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( thisM )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( mFrameGood )
|
|
|
|
{
|
2017-05-20 21:03:04 +08:00
|
|
|
Debug( 3, "Got new frame %d, %d bytes", mFrameCount, mFrame.size() );
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
mFrameProcessed.setValueImmediate( false );
|
|
|
|
mFrameReady.updateValueSignal( true );
|
|
|
|
if ( !mFrameProcessed.getValueImmediate() )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2017-05-20 21:03:04 +08:00
|
|
|
// What is the point of this for loop? Is it just me, or will it call getUpdatedValue once or twice? Could it not be better written as
|
|
|
|
// if ( ! mFrameProcessed.getUpdatedValue( 1 ) && mFrameProcessed.getUpdatedValue( 1 ) ) return false;
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
for ( int count = 0; !mFrameProcessed.getUpdatedValue( 1 ); count++ )
|
|
|
|
if( count > 1 )
|
|
|
|
return( false );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
mFrameCount++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Warning( "Discarding incomplete frame %d, %d bytes", mFrameCount, mFrame.size() );
|
|
|
|
}
|
|
|
|
mFrame.clear();
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( mFrame.size() )
|
2008-07-16 16:35:59 +08:00
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Warning( "Discarding partial frame %d, %d bytes", mFrameCount, mFrame.size() );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2013-09-27 19:08:11 +08:00
|
|
|
else
|
2016-04-04 22:11:48 +08:00
|
|
|
{
|
|
|
|
Warning( "Discarding frame %d", mFrameCount );
|
|
|
|
}
|
|
|
|
mFrameGood = false;
|
|
|
|
mFrame.clear();
|
|
|
|
}
|
|
|
|
if ( thisM )
|
|
|
|
{
|
|
|
|
mFrameGood = true;
|
|
|
|
prevM = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prevM = false;
|
|
|
|
|
|
|
|
updateJitter( rtpHeader );
|
|
|
|
|
|
|
|
return( true );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RtpSource::getFrame( Buffer &buffer )
|
|
|
|
{
|
2016-04-04 22:11:48 +08:00
|
|
|
Debug( 3, "Getting frame" );
|
|
|
|
if ( !mFrameReady.getValueImmediate() )
|
|
|
|
{
|
|
|
|
// Allow for a couple of spurious returns
|
|
|
|
for ( int count = 0; !mFrameReady.getUpdatedValue( 1 ); count++ )
|
|
|
|
if ( count > 1 )
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
buffer = mFrame;
|
|
|
|
mFrameReady.setValueImmediate( false );
|
|
|
|
mFrameProcessed.updateValueSignal( true );
|
2017-05-20 21:03:04 +08:00
|
|
|
Debug( 4, "Copied %d bytes", buffer.size() );
|
2016-04-04 22:11:48 +08:00
|
|
|
return( true );
|
2008-07-16 16:35:59 +08:00
|
|
|
}
|
2013-11-29 05:32:06 +08:00
|
|
|
|
2014-01-02 00:19:42 +08:00
|
|
|
#endif // HAVE_LIBAVCODEC
|