<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style>body { line-height: 1.5; }blockquote { margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em; }p { margin-top: 0px; margin-bottom: 0px; }body { font-size: 10.5pt; font-family: 'Segoe UI'; color: rgb(0, 0, 0); line-height: 1.5; }</style></head><body>
<div><span></span>hi Ross,</div><div><br></div><div>I made changes to send every NAL unit seperately, and made sure all start code were cut off. For the "key frame" (the <span style="font-size: 10.5pt; line-height: 1.5; background-color: window;">SC+SPS+SC+PPS+SC+Frame in one chunk of data), I seperated them and called memmove and afterGetting for each. See the code in grey below.</span></div>
<div><br></div><div><span style="font-family: ''; font-size: 10.5pt; line-height: 1.5; background-color: window;">void Gm813xSource::deliverFrame(void)</span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">{<br>    int ret;<br>    gm_enc_multi_bitstream_t bs;<br><br>    if (!isCurrentlyAwaitingData())<br>        return; // we're not ready for the data yet<br><br>    memset(&bs, 0, sizeof(bs));<br><br>    bs.bindfd = main_bindfd;//poll_fds[i].bindfd;<br>    bs.bs.bs_buf = frameBuf;  // set buffer point<br>    bs.bs.bs_buf_len = FRAME_BUF_SIZE;  // set buffer length<br>    bs.bs.mv_buf = 0;  // not to recevie MV data<br>    bs.bs.mv_buf_len = 0;  // not to recevie MV data<br><br>    if (bytesInBuf > 0) { // send leftover data<br>        if (bytesInBuf > fMaxSize) {<br>            fFrameSize = fMaxSize;<br>            fNumTruncatedBytes = bytesInBuf - fMaxSize;<br>            bytesInBuf = fNumTruncatedBytes;<br>            dataPtr += fFrameSize;<br>        } else {<br>            fFrameSize = bytesInBuf;<br>            bytesInBuf = 0;<br>        }<br>        memmove(fTo, dataPtr, fFrameSize);<br>        FramedSource::afterGetting(this);<br>    } else { // get a new frame and send<br>        if ((ret = gm_recv_multi_bitstreams(&bs, 1)) < 0) {<br>            printf("Error, gm_recv_multi_bitstreams return value %d\n", ret);<br>        } else {<br>            if ((bs.retval < 0) && bs.bindfd) {<br>                printf("Error to receive bitstream. ret=%d\n", bs.retval);<br>            } else if (bs.retval == GM_SUCCESS) {<br>                u_int8_t* newFrameDataStart = (u_int8_t*)bs.bs.bs_buf; //%%% TO BE WRITTEN %%%<br>                unsigned newFrameSize = bs.bs.bs_len; //%%% TO BE WRITTEN %%%<br><br>                if(newFrameDataStart[0] == 0x00 && newFrameDataStart[1] == 0x00<br>                        && newFrameDataStart[2] == 0x00 && newFrameDataStart[3] == 0x01) {<br>                    newFrameDataStart += 4;<br>                    newFrameSize -= 4;<br>                }<br><br><span style="background-color: rgb(192, 192, 192);">                if(1 == bs.bs.keyframe<br>                        && newFrameDataStart[10] == 0 && newFrameDataStart[11] == 0<br>                        && newFrameDataStart[12] == 0 && newFrameDataStart[13] == 1<br>                        && newFrameDataStart[18] == 0 && newFrameDataStart[19] == 0<br>                        && newFrameDataStart[20] == 0 && newFrameDataStart[21] == 1<br>                        ) {<br>                    fFrameSize = 10;<br>                    gettimeofday(&fPresentationTime, NULL);<br>                    memmove(fTo, newFrameDataStart, fFrameSize); // SPS<br>                    FramedSource::afterGetting(this);<br><br>                    gettimeofday(&fPresentationTime, NULL);<br>                    fFrameSize = 4;<br>                    memmove(fTo, newFrameDataStart+14, fFrameSize); // PPS<br>                    FramedSource::afterGetting(this);<br><br>                    newFrameDataStart += (10 + 4 + 4 + 4); // SPS + SC + PPS + SC<br>                    newFrameSize -= 22;<br>                }<br></span><br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">                bytesInBuf = newFrameSize;<br>                dataPtr = newFrameDataStart;<br><br>                // Deliver the data here:<br>                if (newFrameSize > fMaxSize) {<br>                    fFrameSize = fMaxSize;<br>                    fNumTruncatedBytes = newFrameSize - fMaxSize;<br>                } else {<br>                    fFrameSize = newFrameSize;<br>                }<br><br>                bytesInBuf -= fFrameSize;<br>                dataPtr += fFrameSize;<br><br>                //fFrameSize = fMaxSize;<br><br>                gettimeofday(&fPresentationTime, NULL); // If you have a more accurate time - e.g., from an encoder - then use that instead.<br><br>                // If the device is *not* a 'live source' (e.g., it comes instead from a file or buffer), then set "fDurationInMicroseconds" here.<br>                memmove(fTo, newFrameDataStart, fFrameSize);<br><br>                // After delivering the data, inform the reader that it is now available:<br>                FramedSource::afterGetting(this);<br>            }<br>        }<br>    }<br>}<br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">Now that I made this changes, the app crashed when I tried to open a session with the server. Since it crashed at inside the libliveMedia, I got some difficulties to debug it. Can you give me some pointers here? </span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">Belows is the backtrace of this crash.</span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">(gdb) bt<br>#0  0x76c43e9c in ?? () from /lib/libc.so.0<br>#1  0x76e7d950 in OutPacketBuffer::enqueue(unsigned char const*, unsigned int)<br>    () from /mnt/nfs/target/usr/lib/libliveMedia.so.57<br>#2  0x76e7d988 in OutPacketBuffer::enqueueWord(unsigned int) ()<br>   from /mnt/nfs/target/usr/lib/libliveMedia.so.57<br>#3  0x76e8c18c in MultiFramedRTPSink::buildAndSendPacket(unsigned char) ()<br>   from /mnt/nfs/target/usr/lib/libliveMedia.so.57<br>#4  0x76dfe938 in AlarmHandler::handleTimeout() ()<br>   from /mnt/nfs/target/usr/lib/libBasicUsageEnvironment.so.1<br>#5  0x76dfeefc in BasicTaskScheduler::SingleStep(unsigned int) ()<br>   from /mnt/nfs/target/usr/lib/libBasicUsageEnvironment.so.1<br>#6  0x76dfe224 in BasicTaskScheduler0::doEventLoop(char volatile*) ()<br>   from /mnt/nfs/target/usr/lib/libBasicUsageEnvironment.so.1<br>#7  0x0000bc44 in main (argc=1, argv=0x7efcfdc4) at ../rtspd_main.cpp:74</span></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><br></span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'="">Again, thanks for your patience.</span></div><div><span style="font-family: "" segoe="" ui'";="" font-size:="" 14px;="" color:="" rgb(0,="" 0,="" 0);="" background-color:="" rgba(0,="" font-weight:="" normal;="" font-style:="" normal;text-decoration:="" none;'=""><br></span></div><hr style="width: 210px; height: 1px;" color="#b5c4df" size="1" align="left">
<div><span><div style="margin: 10px;"><div style="line-height: normal;"><div style="margin: 7.5pt; position: static !important;"><div style="font-family: 'Segoe UI', Tahoma;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-family: å®‹ä½“;"><font size="2">Xin</font></p></div><div style="font-size: 14px; font-family: 'Segoe UI', Tahoma;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: å®‹ä½“;"><span lang="EN-US" style="font-size: 10pt; font-family: Verdana, sans-serif;">Mobile: +86 </span><span lang="EN-US" style="font-size: 10pt; font-family: Verdana, sans-serif;">186-1245-1524<o:p></o:p></span></p></div><div style="font-size: 14px;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt;"><span lang="EN-US" style="font-family: Verdana, sans-serif; font-size: 10pt;">Email: </span><span lang="EN-US" style="font-family: Verdana, sans-serif; font-size: 10pt;"><a href="mailto:xliu@vscenevideo.com" style="color: purple;">xliu@vscenevideo.com</a><o:p></o:p></span></p></div><div style="font-size: 14px;"><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt;"><span lang="EN-US" style="font-family: Verdana, sans-serif; font-size: 10pt;">QQ: </span><span lang="EN-US" style="font-family: Verdana, sans-serif; font-size: 10pt;">156678745</span></p></div></div></div></div></span></div>
<blockquote style="margin-top: 0px; margin-bottom: 0px; margin-left: 0.5em;"><div> </div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-SIZE: 12px;FONT-FAMILY:tahoma;COLOR:#000000; BACKGROUND: #efefef; PADDING-BOTTOM: 8px; PADDING-TOP: 8px"><div><b>From:</b> <a href="mailto:finlayson@live555.com">Ross Finlayson</a></div><div><b>Date:</b> 2017-01-13 23:52</div><div><b>To:</b> <a href="mailto:live-devel@ns.live555.com">LIVE555 Streaming Media - development & use</a></div><div><b>Subject:</b> Re: [Live-devel] how to make latency as low as possible</div></div></div><div><div>> For the start code, I have eleminated them all. My camera's working pattern is like this, when encoding key frame, it outputs SC+SPS+SC+PPS+SC+Frame, when encoding non-key frame, it outputs SC+Frame. So, after I eleminated the SC, what I sent to the sink object is SPS+PPS+FRAME for key frame, and FRAME alone for non-key frame.</div>
<div>> </div>
<div>> Did I missed something here?</div>
<div> </div>
<div>Yes, you missed the part where I said that:</div>
<div>     each â€˜frame’ that come from your input source must be a ***single*** H.264 NAL unit, and MUST NOT be prepended by a 0x00 0x00 0x00 0x01 â€˜start code’.</div>
<div> </div>
<div>So, you must deliver (without a prepended â€˜start code’ in each case):</div>
<div>     SPS, then</div>
<div>     PPS, then</div>
<div>     FRAME, etc.</div>
<div> </div>
<div>***provided that*** FRAME is a single NAL unit.  If, instead, FRAME consists of multiple â€˜slice’ NAL units (this is actually preferred for streaming, because it’s much more tolerant of network packet loss), then you must deliver each â€˜slice’ NAL unit individually (again, without a â€˜start code’).</div>
<div> </div>
<div>Also, when testing your server, I suggest first using â€œopenRTSP” <http://www.live555.com/openRTSP/> as a client, before using VLC.</div>
<div> </div>
<div> </div>
<div>Ross Finlayson</div>
<div>Live Networks, Inc.</div>
<div>http://www.live555.com/</div>
<div> </div>
<div> </div>
<div>_______________________________________________</div>
<div>live-devel mailing list</div>
<div>live-devel@lists.live555.com</div>
<div>http://lists.live555.com/mailman/listinfo/live-devel</div>
</div></blockquote>
</body></html>