On 2011-12-19 17:29:42 +0100, Jindřich Makovička wrote:
> On Mon, Dec 19, 2011 at 16:20, Janne Grunau <[email protected]> wrote:
> > On 2011-12-17 14:42:10 +0100, Luca Barbato wrote:
> >> Do not assume the audio packets being always smaller than
> >> DEFAULT_PES_PAYLOAD_SIZE.
> >>
> >> -    if (ts_st->payload_size + size > DEFAULT_PES_PAYLOAD_SIZE) {
> >> +    if (ts_st->payload_size > DEFAULT_PES_PAYLOAD_SIZE) {
> >
> > that's wrong, ts_st->payload is only DEFAULT_PES_PAYLOAD_SIZE large,
> > then this if condition is true, we've already written behind the buffer
> 
> I think the attached version should work better.

yes, thanks

> -- 
> Jindřich Makovička

> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index 57cfe45..a80b24a 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -999,18 +999,27 @@ static int mpegts_write_packet(AVFormatContext *s, 
> AVPacket *pkt)
>          }
>      }
>  
> +    // write a pes packet at least big DEFAULT_PES_PAYLOAD_SIZE
> +    // for video and subtitle, write a single pes packet
>      if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
> -        // for video and subtitle, write a single pes packet

the first comment is misleading and there is no need to move the second
line.

>          mpegts_write_pes(s, st, buf, size, pts, dts, pkt->flags & 
> AV_PKT_FLAG_KEY);
>          av_free(data);
>          return 0;
>      }
>  
>      if (ts_st->payload_size + size > DEFAULT_PES_PAYLOAD_SIZE) {
> -        mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
> -                         ts_st->payload_pts, ts_st->payload_dts,
> -                         ts_st->payload_flags & AV_PKT_FLAG_KEY);
> -        ts_st->payload_size = 0;
> +        if (ts_st->payload_size) {
> +            mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size,
> +                             ts_st->payload_pts, ts_st->payload_dts,
> +                             ts_st->payload_flags & AV_PKT_FLAG_KEY);
> +            ts_st->payload_size = 0;
> +        }
> +        if (size > DEFAULT_PES_PAYLOAD_SIZE) {
> +            mpegts_write_pes(s, st, buf, size, pts, dts,
> +                             pkt->flags & AV_PKT_FLAG_KEY);
> +            av_free(data);
> +            return 0;
> +        }
>      }

ok

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to