[Opalvoip-svn] SF.net SVN: opalvoip:[32288] opal/branches/v3_14/plugins/video
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2014-07-03 04:47:55
|
Revision: 32288 http://sourceforge.net/p/opalvoip/code/32288 Author: rjongbloed Date: 2014-07-03 04:47:51 +0000 (Thu, 03 Jul 2014) Log Message: ----------- Fixed (maybe) bizarre crash (sometimes, some systems) of FFMPEG when closing codec. Make sure is only closed if we opened it, don't rely on values inside the AVCodecContext, they are too mysterious. Fixed packetisation of H.263/H.263+, was not allowing for the in RTP payload headers when fragmenting frame, so many where not packetised. Modified Paths: -------------- opal/branches/v3_14/plugins/video/H.263-1998/h263-1998.cxx opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.cxx opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.h opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.cxx opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.h opal/branches/v3_14/plugins/video/common/ffmpeg.cxx opal/branches/v3_14/plugins/video/common/ffmpeg.h Modified: opal/branches/v3_14/plugins/video/H.263-1998/h263-1998.cxx =================================================================== --- opal/branches/v3_14/plugins/video/H.263-1998/h263-1998.cxx 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/H.263-1998/h263-1998.cxx 2014-07-03 04:47:51 UTC (rev 32288) @@ -499,14 +499,8 @@ ClampResolution(); - if (!m_fullFrame->SetResolution(m_width, m_height)) { - PTRACE(1, m_prefix, "Unable to allocate memory for packet buffer"); - return false; - } - SetResolution(m_width, m_height); SetEncoderOptions(m_frameTime, m_maxBitRate, m_maxRTPSize, m_tsto, m_keyFramePeriod); - m_fullFrame->SetMaxPayloadSize(m_context->rtp_payload_size); PTRACE(4, m_prefix, "Packetization is " << m_fullFrame->GetName()); #define CODEC_TRACER_FLAG(tracer, flag) \ @@ -581,8 +575,6 @@ m_context->rtp_mode = 1; #endif - m_context->rtp_payload_size = PluginCodec_RTP_MaxPayloadSize; - #ifdef CODEC_FLAG_H263P_UMV m_context->flags &= ~CODEC_FLAG_H263P_UMV; #endif Modified: opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.cxx =================================================================== --- opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.cxx 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.cxx 2014-07-03 04:47:51 UTC (rev 32288) @@ -171,6 +171,12 @@ } +void RFC2190Packetizer::SetMaxPayloadSize(size_t size) +{ + m_maxPayloadSize = size - 8; // Allow for Mode B header +} + + bool RFC2190Packetizer::Reset(size_t len) { // make sure data is at least long enough to contain PSC, TR & minimum PTYPE, PQUANT and CPM @@ -363,7 +369,7 @@ { // sometimes, FFmpeg encodes the same frame multiple times // we need to detect this in order to avoid duplicating the encoded data - if ((data == m_buffer) && (fragments.size() != 0)) { + if (data == m_buffer) { m_currentMB = 0; m_currentBytes = 0; fragments.resize(0); Modified: opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.h =================================================================== --- opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.h 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/H.263-1998/rfc2190.h 2014-07-03 04:47:51 UTC (rev 32288) @@ -46,6 +46,7 @@ public: RFC2190Packetizer(); + virtual void SetMaxPayloadSize(size_t size); virtual bool Reset(size_t len = 0); virtual bool SetResolution(unsigned width, unsigned height); Modified: opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.cxx =================================================================== --- opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.cxx 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.cxx 2014-07-03 04:47:51 UTC (rev 32288) @@ -316,6 +316,12 @@ } +void RFC2429Frame::SetMaxPayloadSize(size_t size) +{ + m_maxPayloadSize = size - 2; // Allow for header +} + + bool RFC2429Frame::Reset(size_t len) { m_packetizationOffset = 0; Modified: opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.h =================================================================== --- opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.h 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/H.263-1998/rfc2429.h 2014-07-03 04:47:51 UTC (rev 32288) @@ -70,6 +70,7 @@ virtual const char * GetName() const { return "RFC2429"; } + virtual void SetMaxPayloadSize(size_t size); virtual bool Reset(size_t len = 0); virtual bool GetPacket(PluginCodec_RTP & frame, unsigned int & flags); Modified: opal/branches/v3_14/plugins/video/common/ffmpeg.cxx =================================================================== --- opal/branches/v3_14/plugins/video/common/ffmpeg.cxx 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/common/ffmpeg.cxx 2014-07-03 04:47:51 UTC (rev 32288) @@ -105,6 +105,7 @@ , m_alignedInputYUV(NULL) , m_alignedInputSize(0) , m_fullFrame(fullFrame) + , m_open(false) , m_errorCount(0) , m_hadMissingPacket(false) { @@ -186,7 +187,7 @@ bool FFMPEGCodec::InitEncoder(AVCodecID codecId) { - PTRACE(5, m_prefix, "Opening encoder"); + PTRACE(5, m_prefix, "Initialising encoder"); m_codec = avcodec_find_encoder(codecId); if (m_codec == NULL) { @@ -256,25 +257,29 @@ #endif if (result < 0) { - PTRACE(1, m_prefix, "Failed to open codec"); + PTRACE(1, m_prefix, "Failed to open codec \"" << m_codec->long_name << '"'); return false; } - PTRACE(4, m_prefix, "Codec opened"); + PTRACE(4, m_prefix, "Codec opened \"" << m_codec->long_name << '"'); + m_open = true; return true; } void FFMPEGCodec::CloseCodec() { - if (m_context != NULL && m_context->codec != NULL) + if (m_open) { + PTRACE(4, m_prefix, "Closing codec \"" << m_codec->long_name << '"'); avcodec_close(m_context); + m_open = false; + } } bool FFMPEGCodec::SetResolution(unsigned width, unsigned height) { - bool wasOpen = m_context->codec != NULL; + bool wasOpen = m_open; if (wasOpen) { PTRACE(3, m_prefix, "Resolution has changed - reopening codec"); CloseCodec(); @@ -358,7 +363,12 @@ m_context->lmin = m_context->qmin * FF_QP2LAMBDA; m_context->lmax = m_context->qmax * FF_QP2LAMBDA; - m_context->rtp_payload_size = maxRTPSize; + if (m_fullFrame == NULL) + m_context->rtp_payload_size = maxRTPSize; + else { + m_fullFrame->SetMaxPayloadSize(maxRTPSize); + m_context->rtp_payload_size = m_fullFrame->GetMaxPayloadSize(); // Might be adjusted to smaller value + } m_context->qmax = tsto; if (m_context->qmax <= m_context->qmin) @@ -378,7 +388,6 @@ PTRACE(5, m_prefix, "qmin set to " << m_context->qmin); PTRACE(5, m_prefix, "qmax set to " << m_context->qmax); PTRACE(5, m_prefix, "payload size set to " << m_context->rtp_payload_size); - } @@ -608,6 +617,12 @@ } +void FFMPEGCodec::EncodedFrame::SetMaxPayloadSize(size_t size) +{ + m_maxPayloadSize = size; +} + + bool FFMPEGCodec::EncodedFrame::SetResolution(unsigned width, unsigned height) { return SetMaxSize(width*height*2); @@ -656,7 +671,7 @@ void FFMPEGCodec::ErrorCallback(unsigned level, const char * msg) { - PTRACE(level, m_prefix, "FFMPEG: " << msg); + PTRACE(level, m_prefix, "FFMPEG(" << level << "): " << msg); if (level < 2) ++m_errorCount; Modified: opal/branches/v3_14/plugins/video/common/ffmpeg.h =================================================================== --- opal/branches/v3_14/plugins/video/common/ffmpeg.h 2014-07-02 23:36:27 UTC (rev 32287) +++ opal/branches/v3_14/plugins/video/common/ffmpeg.h 2014-07-03 04:47:51 UTC (rev 32288) @@ -96,8 +96,9 @@ uint8_t * GetBuffer() const { return m_buffer; } size_t GetMaxSize() const { return m_maxSize; } size_t GetLength() const { return m_length; } - void SetMaxPayloadSize(size_t size) { m_maxPayloadSize = size; } + size_t GetMaxPayloadSize() const { return m_maxPayloadSize; } + virtual void SetMaxPayloadSize(size_t size); virtual bool SetResolution(unsigned width, unsigned height); virtual bool SetMaxSize(size_t newSize); virtual bool Reset(size_t len = 0); @@ -122,6 +123,7 @@ uint8_t * m_alignedInputYUV; size_t m_alignedInputSize; EncodedFrame * m_fullFrame; + bool m_open; int m_errorCount; bool m_hadMissingPacket; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |