Changeset 727


Ignore:
Timestamp:
01/19/12 14:38:18 (4 months ago)
Author:
shiretu
Message:

-- fixed issues with multi-NAL RTSP streams

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/1.0/sources/thelib/include/protocols/rtmp/streaming/outnetrtmp4tsstream.h

    r668 r727  
    3636        IOBuffer _videoBuffer; 
    3737        bool _inboundStreamIsRTP; 
     38        double _lastVideoTimestamp; 
     39        bool _isKeyFrame; 
    3840public: 
    3941        OutNetRTMP4TSStream(BaseProtocol *pProtocol, StreamsManager *pStreamsManager, 
  • branches/1.0/sources/thelib/src/protocols/rtmp/streaming/outnetrtmp4tsstream.cpp

    r725 r727  
    5050 
    5151        _inboundStreamIsRTP = false; 
     52        _lastVideoTimestamp = -1; 
     53        _isKeyFrame = false; 
    5254} 
    5355 
     
    210212                default: 
    211213                { 
     214                        //1. Create timestamp reference 
     215                        if (_lastVideoTimestamp < 0) 
     216                                _lastVideoTimestamp = absoluteTimestamp; 
     217 
     218                        //2. Send over the accumulated stuff if this is a new packet from a 
     219                        //brand new sequence of packets 
     220                        if (_lastVideoTimestamp != absoluteTimestamp) { 
     221                                if (!BaseOutNetRTMPStream::FeedData( 
     222                                                GETIBPOINTER(_videoBuffer), //pData 
     223                                                GETAVAILABLEBYTESCOUNT(_videoBuffer), //dataLength 
     224                                                0, //processedLength 
     225                                                GETAVAILABLEBYTESCOUNT(_videoBuffer), //totalLength 
     226                                                _lastVideoTimestamp, //absoluteTimestamp 
     227                                                false //isAudio 
     228                                                )) { 
     229                                        FATAL("Unable to send video"); 
     230                                        return false; 
     231                                } 
     232                                _videoBuffer.IgnoreAll(); 
     233                                _isKeyFrame = false; 
     234                        } 
     235                        _lastVideoTimestamp = absoluteTimestamp; 
     236 
    212237                        uint8_t *pTemp = NULL; 
    213238 
     
    233258 
    234259                                //setup the frame type 
    235                                 if (NALU_TYPE(pData[0]) == NALU_TYPE_IDR) { 
    236                                         //FINEST("HERE"); 
     260                                _isKeyFrame |= (nalType == NALU_TYPE_IDR); 
     261                                if (_isKeyFrame) { 
    237262                                        GETIBPOINTER(_videoBuffer)[0] = 0x17; 
    238263                                } else { 
    239                                         //FINEST("HERE"); 
    240264                                        GETIBPOINTER(_videoBuffer)[0] = 0x27; 
    241265                                } 
    242266                        } 
    243267 
    244                         //break if this is not a M bit on a RTSP 
    245                         if (_inboundStreamIsRTP) { 
    246                                 if ((*(pData - 1)) == 0) { 
    247                                         //check the size of _videoBuffer and watch out for HUGE frames 
    248                                         if (GETAVAILABLEBYTESCOUNT(_videoBuffer) >= 4 * 1024 * 1024) { 
    249                                                 WARN("Big video frame. Discard it"); 
    250                                                 _videoBuffer.IgnoreAll(); 
    251                                         } 
    252                                         return true; 
    253                                 } 
    254                         } 
    255  
    256                         if (GETAVAILABLEBYTESCOUNT(_videoBuffer) > 5) { 
    257                                 //checkData(_videoBuffer); 
    258  
    259                                 //send the data 
    260                                 if (!BaseOutNetRTMPStream::FeedData( 
    261                                                 GETIBPOINTER(_videoBuffer), //pData 
    262                                                 GETAVAILABLEBYTESCOUNT(_videoBuffer), //dataLength 
    263                                                 0, //processedLength 
    264                                                 GETAVAILABLEBYTESCOUNT(_videoBuffer), //totalLength 
    265                                                 absoluteTimestamp, //absoluteTimestamp 
    266                                                 false //isAudio 
    267                                                 )) { 
    268                                         FATAL("Unable to send video"); 
    269                                         return false; 
    270                                 } 
    271                         } 
    272  
    273                         //cleanup 
    274                         _videoBuffer.IgnoreAll(); 
     268                        //6. make sure the packet doesn't grow too big 
     269                        if (GETAVAILABLEBYTESCOUNT(_videoBuffer) >= 4 * 1024 * 1024) { 
     270                                WARN("Big video frame. Discard it"); 
     271                                _videoBuffer.IgnoreAll(); 
     272                                _isKeyFrame = false; 
     273                                _lastVideoTimestamp = -1; 
     274                        } 
    275275 
    276276                        //done 
  • branches/1.0/sources/thelib/src/protocols/rtp/streaming/innetrtpstream.cpp

    r725 r727  
    312312                _videoPacketsCount++; 
    313313                _videoBytesCount += dataLength; 
    314                 *(pData - 1) = GET_RTP_M(rtpHeader); 
    315314                return FeedData(pData, dataLength, 0, dataLength, ts, false); 
    316315        } else if (naluType == NALU_TYPE_FUA) { 
     
    325324                        } 
    326325                        pData[1] = (pData[0]&0xe0) | (pData[1]&0x1f); 
    327                         _currentNalu.ReadFromByte(0); 
    328326                        _currentNalu.ReadFromBuffer(pData + 1, dataLength - 1); 
    329327                        return true; 
     
    335333                                _videoPacketsCount++; 
    336334                                _videoBytesCount += GETAVAILABLEBYTESCOUNT(_currentNalu); 
    337                                 GETIBPOINTER(_currentNalu)[0] = GET_RTP_M(rtpHeader); 
    338                                 if (!FeedData(GETIBPOINTER(_currentNalu) + 1, 
    339                                                 GETAVAILABLEBYTESCOUNT(_currentNalu) - 1, 0, 
    340                                                 GETAVAILABLEBYTESCOUNT(_currentNalu) - 1, 
     335                                if (!FeedData(GETIBPOINTER(_currentNalu), 
     336                                                GETAVAILABLEBYTESCOUNT(_currentNalu), 
     337                                                0, 
     338                                                GETAVAILABLEBYTESCOUNT(_currentNalu), 
    341339                                                ts, 
    342340                                                false)) { 
     
    361359                        _videoPacketsCount++; 
    362360                        _videoBytesCount += length; 
    363                         if (index + length >= dataLength) { 
    364                                 *(pData + index - 1) = 1; 
    365                         } else { 
    366                                 *(pData + index - 1) = 0; 
    367                         } 
    368361                        if (!FeedData(pData + index, 
    369362                                        length, 0, 
  • trunk/sources/thelib/include/protocols/rtmp/streaming/outnetrtmp4tsstream.h

    r722 r727  
    3636        IOBuffer _videoBuffer; 
    3737        bool _inboundStreamIsRTP; 
     38        double _lastVideoTimestamp; 
     39        bool _isKeyFrame; 
    3840public: 
    3941        OutNetRTMP4TSStream(BaseRTMPProtocol *pProtocol, StreamsManager *pStreamsManager, 
  • trunk/sources/thelib/src/protocols/rtmp/streaming/outnetrtmp4tsstream.cpp

    r725 r727  
    5050 
    5151        _inboundStreamIsRTP = false; 
     52        _lastVideoTimestamp = -1; 
     53        _isKeyFrame = false; 
    5254} 
    5355 
     
    210212                default: 
    211213                { 
     214                        //1. Create timestamp reference 
     215                        if (_lastVideoTimestamp < 0) 
     216                                _lastVideoTimestamp = absoluteTimestamp; 
     217 
     218                        //2. Send over the accumulated stuff if this is a new packet from a 
     219                        //brand new sequence of packets 
     220                        if (_lastVideoTimestamp != absoluteTimestamp) { 
     221                                if (!BaseOutNetRTMPStream::FeedData( 
     222                                                GETIBPOINTER(_videoBuffer), //pData 
     223                                                GETAVAILABLEBYTESCOUNT(_videoBuffer), //dataLength 
     224                                                0, //processedLength 
     225                                                GETAVAILABLEBYTESCOUNT(_videoBuffer), //totalLength 
     226                                                _lastVideoTimestamp, //absoluteTimestamp 
     227                                                false //isAudio 
     228                                                )) { 
     229                                        FATAL("Unable to send video"); 
     230                                        return false; 
     231                                } 
     232                                _videoBuffer.IgnoreAll(); 
     233                                _isKeyFrame = false; 
     234                        } 
     235                        _lastVideoTimestamp = absoluteTimestamp; 
     236 
    212237                        uint8_t *pTemp = NULL; 
    213238 
     
    233258 
    234259                                //setup the frame type 
    235                                 if (NALU_TYPE(pData[0]) == NALU_TYPE_IDR) { 
    236                                         //FINEST("HERE"); 
     260                                _isKeyFrame |= (nalType == NALU_TYPE_IDR); 
     261                                if (_isKeyFrame) { 
    237262                                        GETIBPOINTER(_videoBuffer)[0] = 0x17; 
    238263                                } else { 
    239                                         //FINEST("HERE"); 
    240264                                        GETIBPOINTER(_videoBuffer)[0] = 0x27; 
    241265                                } 
    242266                        } 
    243267 
    244                         //break if this is not a M bit on a RTSP 
    245                         if (_inboundStreamIsRTP) { 
    246                                 if ((*(pData - 1)) == 0) { 
    247                                         //check the size of _videoBuffer and watch out for HUGE frames 
    248                                         if (GETAVAILABLEBYTESCOUNT(_videoBuffer) >= 4 * 1024 * 1024) { 
    249                                                 WARN("Big video frame. Discard it"); 
    250                                                 _videoBuffer.IgnoreAll(); 
    251                                         } 
    252                                         return true; 
    253                                 } 
    254                         } 
    255  
    256                         if (GETAVAILABLEBYTESCOUNT(_videoBuffer) > 5) { 
    257                                 //checkData(_videoBuffer); 
    258  
    259                                 //send the data 
    260                                 if (!BaseOutNetRTMPStream::FeedData( 
    261                                                 GETIBPOINTER(_videoBuffer), //pData 
    262                                                 GETAVAILABLEBYTESCOUNT(_videoBuffer), //dataLength 
    263                                                 0, //processedLength 
    264                                                 GETAVAILABLEBYTESCOUNT(_videoBuffer), //totalLength 
    265                                                 absoluteTimestamp, //absoluteTimestamp 
    266                                                 false //isAudio 
    267                                                 )) { 
    268                                         FATAL("Unable to send video"); 
    269                                         return false; 
    270                                 } 
    271                         } 
    272  
    273                         //cleanup 
    274                         _videoBuffer.IgnoreAll(); 
     268                        //6. make sure the packet doesn't grow too big 
     269                        if (GETAVAILABLEBYTESCOUNT(_videoBuffer) >= 4 * 1024 * 1024) { 
     270                                WARN("Big video frame. Discard it"); 
     271                                _videoBuffer.IgnoreAll(); 
     272                                _isKeyFrame = false; 
     273                                _lastVideoTimestamp = -1; 
     274                        } 
    275275 
    276276                        //done 
  • trunk/sources/thelib/src/protocols/rtp/streaming/innetrtpstream.cpp

    r725 r727  
    312312                _videoPacketsCount++; 
    313313                _videoBytesCount += dataLength; 
    314                 *(pData - 1) = GET_RTP_M(rtpHeader); 
    315314                return FeedData(pData, dataLength, 0, dataLength, ts, false); 
    316315        } else if (naluType == NALU_TYPE_FUA) { 
     
    325324                        } 
    326325                        pData[1] = (pData[0]&0xe0) | (pData[1]&0x1f); 
    327                         _currentNalu.ReadFromByte(0); 
    328326                        _currentNalu.ReadFromBuffer(pData + 1, dataLength - 1); 
    329327                        return true; 
     
    335333                                _videoPacketsCount++; 
    336334                                _videoBytesCount += GETAVAILABLEBYTESCOUNT(_currentNalu); 
    337                                 GETIBPOINTER(_currentNalu)[0] = GET_RTP_M(rtpHeader); 
    338                                 if (!FeedData(GETIBPOINTER(_currentNalu) + 1, 
    339                                                 GETAVAILABLEBYTESCOUNT(_currentNalu) - 1, 0, 
    340                                                 GETAVAILABLEBYTESCOUNT(_currentNalu) - 1, 
     335                                if (!FeedData(GETIBPOINTER(_currentNalu), 
     336                                                GETAVAILABLEBYTESCOUNT(_currentNalu), 
     337                                                0, 
     338                                                GETAVAILABLEBYTESCOUNT(_currentNalu), 
    341339                                                ts, 
    342340                                                false)) { 
     
    361359                        _videoPacketsCount++; 
    362360                        _videoBytesCount += length; 
    363                         if (index + length >= dataLength) { 
    364                                 *(pData + index - 1) = 1; 
    365                         } else { 
    366                                 *(pData + index - 1) = 0; 
    367                         } 
    368361                        if (!FeedData(pData + index, 
    369362                                        length, 0, 
Note: See TracChangeset for help on using the changeset viewer.