[Live-devel] Problem Streaming MPEG4ES from buffer

Ross Finlayson finlayson at live555.com
Wed Jun 6 06:52:30 PDT 2007


>I use the following code to fill the buffer:
>
>enc_bytes = avcodec_encode_video(enc_codec_ctx, outbuf, fMaxSize, dec_frame);
>if(enc_bytes >= 0)
>                {                
>                    memcpy(fTo, outbuf, enc_bytes);
>                  
>                    if(enc_bytes > fMaxSize)

This is very bad.  You must never copy more than "fMaxSize" bytes to 
the destination pointed to by "fTo".  Therefore, you must check the 
data size against "fMaxSize" *before* you copy it.

I.e, you should instead do:

                    if(enc_bytes > fMaxSize)
                    {
                        fFrameSize = fMaxSize;
                        fNumTruncatedBytes = enc_bytes - fMaxSize;
                    }
                    else
                    {
                        fFrameSize = enc_bytes;
                        fNumTruncatedBytes = 0;
                    }
                    memcpy(fTo, outbuf, fFrameSize);

-- 

Ross Finlayson
Live Networks, Inc.
http://www.live555.com/


More information about the live-devel mailing list