diff mbox series

[FFmpeg-devel,2/8] avformat/mpegts: simplify nb_packets code

Message ID 20201218232208.14207-2-michael@niedermayer.cc
State Accepted
Commit c0e660ba14161f1d58dab2e59c603a08aff9e8c8
Headers show
Series [FFmpeg-devel,1/8] avformat/mpegts: Increase pcr_incr width to 64bit | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer Dec. 18, 2020, 11:22 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/mpegts.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Marton Balint Dec. 20, 2020, 10:30 p.m. UTC | #1
On Sat, 19 Dec 2020, Michael Niedermayer wrote:

> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
> libavformat/mpegts.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> index 1122455f66..cc292ab929 100644
> --- a/libavformat/mpegts.c
> +++ b/libavformat/mpegts.c
> @@ -3090,7 +3090,6 @@ static int mpegts_read_header(AVFormatContext *s)
>         AVStream *st;
>         int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
>         int64_t pcrs[2], pcr_h;
> -        int packet_count[2];
>         uint8_t packet[TS_PACKET_SIZE];
>         const uint8_t *data;
> 
> @@ -3116,7 +3115,6 @@ static int mpegts_read_header(AVFormatContext *s)
>                 parse_pcr(&pcr_h, &pcr_l, data) == 0) {
>                 finished_reading_packet(s, ts->raw_packet_size);
>                 pcr_pid = pid;
> -                packet_count[nb_pcrs] = nb_packets;
>                 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
>                 nb_pcrs++;
>                 if (nb_pcrs >= 2) {
> @@ -3126,7 +3124,6 @@ static int mpegts_read_header(AVFormatContext *s)
>                     } else {
>                         av_log(ts->stream, AV_LOG_WARNING, "invalid pcr pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]);
>                         pcrs[0] = pcrs[1];
> -                        packet_count[0] = packet_count[1];
>                         nb_pcrs--;
>                     }
>                 }
> @@ -3138,8 +3135,8 @@ static int mpegts_read_header(AVFormatContext *s)
>
>         /* NOTE1: the bitrate is computed without the FEC */
>         /* NOTE2: it is only the bitrate of the start of the stream */
> -        ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
> -        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * packet_count[0];
> +        ts->pcr_incr = pcrs[1] - pcrs[0];
> +        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * (nb_packets - 1);
>         s->bit_rate  = TS_PACKET_SIZE * 8 * 27000000LL / ts->pcr_incr;
>         st->codecpar->bit_rate = s->bit_rate;
>         st->start_time      = ts->cur_pcr;

LGTM for this and the preivous as well.

(BTW did anybody hear of anyone ever using the mpegts raw demuxer?)

Thanks,
Marton
Michael Niedermayer Dec. 21, 2020, 9:56 p.m. UTC | #2
On Sun, Dec 20, 2020 at 11:30:05PM +0100, Marton Balint wrote:
> 
> 
> On Sat, 19 Dec 2020, Michael Niedermayer wrote:
> 
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> > libavformat/mpegts.c | 7 ++-----
> > 1 file changed, 2 insertions(+), 5 deletions(-)
> > 
> > diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
> > index 1122455f66..cc292ab929 100644
> > --- a/libavformat/mpegts.c
> > +++ b/libavformat/mpegts.c
> > @@ -3090,7 +3090,6 @@ static int mpegts_read_header(AVFormatContext *s)
> >         AVStream *st;
> >         int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
> >         int64_t pcrs[2], pcr_h;
> > -        int packet_count[2];
> >         uint8_t packet[TS_PACKET_SIZE];
> >         const uint8_t *data;
> > 
> > @@ -3116,7 +3115,6 @@ static int mpegts_read_header(AVFormatContext *s)
> >                 parse_pcr(&pcr_h, &pcr_l, data) == 0) {
> >                 finished_reading_packet(s, ts->raw_packet_size);
> >                 pcr_pid = pid;
> > -                packet_count[nb_pcrs] = nb_packets;
> >                 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
> >                 nb_pcrs++;
> >                 if (nb_pcrs >= 2) {
> > @@ -3126,7 +3124,6 @@ static int mpegts_read_header(AVFormatContext *s)
> >                     } else {
> >                         av_log(ts->stream, AV_LOG_WARNING, "invalid pcr pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]);
> >                         pcrs[0] = pcrs[1];
> > -                        packet_count[0] = packet_count[1];
> >                         nb_pcrs--;
> >                     }
> >                 }
> > @@ -3138,8 +3135,8 @@ static int mpegts_read_header(AVFormatContext *s)
> > 
> >         /* NOTE1: the bitrate is computed without the FEC */
> >         /* NOTE2: it is only the bitrate of the start of the stream */
> > -        ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
> > -        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * packet_count[0];
> > +        ts->pcr_incr = pcrs[1] - pcrs[0];
> > +        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * (nb_packets - 1);
> >         s->bit_rate  = TS_PACKET_SIZE * 8 * 27000000LL / ts->pcr_incr;
> >         st->codecpar->bit_rate = s->bit_rate;
> >         st->start_time      = ts->cur_pcr;
> 
> LGTM for this and the preivous as well.

will apply


> 
> (BTW did anybody hear of anyone ever using the mpegts raw demuxer?)

it seems its not tested by fate

[...]
diff mbox series

Patch

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 1122455f66..cc292ab929 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -3090,7 +3090,6 @@  static int mpegts_read_header(AVFormatContext *s)
         AVStream *st;
         int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l;
         int64_t pcrs[2], pcr_h;
-        int packet_count[2];
         uint8_t packet[TS_PACKET_SIZE];
         const uint8_t *data;
 
@@ -3116,7 +3115,6 @@  static int mpegts_read_header(AVFormatContext *s)
                 parse_pcr(&pcr_h, &pcr_l, data) == 0) {
                 finished_reading_packet(s, ts->raw_packet_size);
                 pcr_pid = pid;
-                packet_count[nb_pcrs] = nb_packets;
                 pcrs[nb_pcrs] = pcr_h * 300 + pcr_l;
                 nb_pcrs++;
                 if (nb_pcrs >= 2) {
@@ -3126,7 +3124,6 @@  static int mpegts_read_header(AVFormatContext *s)
                     } else {
                         av_log(ts->stream, AV_LOG_WARNING, "invalid pcr pair %"PRId64" >= %"PRId64"\n", pcrs[0], pcrs[1]);
                         pcrs[0] = pcrs[1];
-                        packet_count[0] = packet_count[1];
                         nb_pcrs--;
                     }
                 }
@@ -3138,8 +3135,8 @@  static int mpegts_read_header(AVFormatContext *s)
 
         /* NOTE1: the bitrate is computed without the FEC */
         /* NOTE2: it is only the bitrate of the start of the stream */
-        ts->pcr_incr = (pcrs[1] - pcrs[0]) / (packet_count[1] - packet_count[0]);
-        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * packet_count[0];
+        ts->pcr_incr = pcrs[1] - pcrs[0];
+        ts->cur_pcr  = pcrs[0] - ts->pcr_incr * (nb_packets - 1);
         s->bit_rate  = TS_PACKET_SIZE * 8 * 27000000LL / ts->pcr_incr;
         st->codecpar->bit_rate = s->bit_rate;
         st->start_time      = ts->cur_pcr;