diff mbox series

[FFmpeg-devel,v3,2/6] avformat/mpegtsenc: refact mpegts_check_bitstream to loop up table

Message ID TYSPR06MB64338E8E2E351A8D6F761FFAAA782@TYSPR06MB6433.apcprd06.prod.outlook.com
State Superseded
Headers show
Series Add mp4 and ts support for vvc | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Nuo Mi Jan. 27, 2024, 4:15 a.m. UTC
---
 libavformat/mpegtsenc.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

Comments

Andreas Rheinhardt Jan. 27, 2024, 2:45 p.m. UTC | #1
Nuo Mi:
> ---
>  libavformat/mpegtsenc.c | 33 ++++++++++++++++++---------------
>  1 file changed, 18 insertions(+), 15 deletions(-)
> 
> diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> index 84edd418f0..418fa08ad5 100644
> --- a/libavformat/mpegtsenc.c
> +++ b/libavformat/mpegtsenc.c
> @@ -2257,23 +2257,26 @@ static void mpegts_deinit(AVFormatContext *s)
>  static int mpegts_check_bitstream(AVFormatContext *s, AVStream *st,
>                                    const AVPacket *pkt)
>  {
> -    int ret = 1;
> +    struct Entry {
> +        enum AVCodecID id;
> +        const char *bsf_name;

No relocations please.

> +        uint8_t m;
> +        uint8_t v;

m? (Mask?) v? (Version?) Don't be so cryptic.

> +    } list[] = {
> +        { AV_CODEC_ID_H264, "h264_mp4toannexb", 0xff, 0x01 },
> +        { AV_CODEC_ID_HEVC, "hevc_mp4toannexb", 0xff, 0x01 },
> +    };
>  
> -    if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
> -        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> -                             (AV_RB24(pkt->data) != 0x000001 ||
> -                              (st->codecpar->extradata_size > 0 &&
> -                               st->codecpar->extradata[0] == 1)))
> -            ret = ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
> -    } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) {
> -        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> -                             (AV_RB24(pkt->data) != 0x000001 ||
> -                              (st->codecpar->extradata_size > 0 &&
> -                               st->codecpar->extradata[0] == 1)))
> -            ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
> +    for (int i = 0; i < FF_ARRAY_ELEMS(list); i++) {
> +        struct Entry *e = list + i;
> +        if (e->id == st->codecpar->codec_id &&
> +                pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> +                (AV_RB24(pkt->data) != 0x000001 ||
> +                    (st->codecpar->extradata_size > 0 &&
> +                        (st->codecpar->extradata[0] & e->m == e->v))))
> +            return ff_stream_add_bitstream_filter(st, e->bsf_name, NULL);
>      }
> -
> -    return ret;
> +    return 1;
>  }
>  
>  #define OFFSET(x) offsetof(MpegTSWrite, x)
Nuo Mi Jan. 27, 2024, 3:54 p.m. UTC | #2
Hi Andreas,
thank you for the review

On Sat, Jan 27, 2024 at 10:44 PM Andreas Rheinhardt <
andreas.rheinhardt@outlook.com> wrote:

> Nuo Mi:
> > ---
> >  libavformat/mpegtsenc.c | 33 ++++++++++++++++++---------------
> >  1 file changed, 18 insertions(+), 15 deletions(-)
> >
> > diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
> > index 84edd418f0..418fa08ad5 100644
> > --- a/libavformat/mpegtsenc.c
> > +++ b/libavformat/mpegtsenc.c
> > @@ -2257,23 +2257,26 @@ static void mpegts_deinit(AVFormatContext *s)
> >  static int mpegts_check_bitstream(AVFormatContext *s, AVStream *st,
> >                                    const AVPacket *pkt)
> >  {
> > -    int ret = 1;
> > +    struct Entry {
> > +        enum AVCodecID id;
> > +        const char *bsf_name;
>
> No relocations please.
>
 Could you give me more clues about this?

>
> > +        uint8_t m;
> > +        uint8_t v;
>
> m? (Mask?) v? (Version?) Don't be so cryptic.
>
m is a mask.

for h264, hevc, v is the version
for vvc, v is reserved 5 bits (11111).
I will change v to value.


> > +    } list[] = {
> > +        { AV_CODEC_ID_H264, "h264_mp4toannexb", 0xff, 0x01 },
> > +        { AV_CODEC_ID_HEVC, "hevc_mp4toannexb", 0xff, 0x01 },
> > +    };
> >
> > -    if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
> > -        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> > -                             (AV_RB24(pkt->data) != 0x000001 ||
> > -                              (st->codecpar->extradata_size > 0 &&
> > -                               st->codecpar->extradata[0] == 1)))
> > -            ret = ff_stream_add_bitstream_filter(st,
> "h264_mp4toannexb", NULL);
> > -    } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) {
> > -        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> > -                             (AV_RB24(pkt->data) != 0x000001 ||
> > -                              (st->codecpar->extradata_size > 0 &&
> > -                               st->codecpar->extradata[0] == 1)))
> > -            ret = ff_stream_add_bitstream_filter(st,
> "hevc_mp4toannexb", NULL);
> > +    for (int i = 0; i < FF_ARRAY_ELEMS(list); i++) {
> > +        struct Entry *e = list + i;
> > +        if (e->id == st->codecpar->codec_id &&
> > +                pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
> > +                (AV_RB24(pkt->data) != 0x000001 ||
> > +                    (st->codecpar->extradata_size > 0 &&
> > +                        (st->codecpar->extradata[0] & e->m == e->v))))
> > +            return ff_stream_add_bitstream_filter(st, e->bsf_name,
> NULL);
> >      }
> > -
> > -    return ret;
> > +    return 1;
> >  }
> >
> >  #define OFFSET(x) offsetof(MpegTSWrite, x)
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>
diff mbox series

Patch

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 84edd418f0..418fa08ad5 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -2257,23 +2257,26 @@  static void mpegts_deinit(AVFormatContext *s)
 static int mpegts_check_bitstream(AVFormatContext *s, AVStream *st,
                                   const AVPacket *pkt)
 {
-    int ret = 1;
+    struct Entry {
+        enum AVCodecID id;
+        const char *bsf_name;
+        uint8_t m;
+        uint8_t v;
+    } list[] = {
+        { AV_CODEC_ID_H264, "h264_mp4toannexb", 0xff, 0x01 },
+        { AV_CODEC_ID_HEVC, "hevc_mp4toannexb", 0xff, 0x01 },
+    };
 
-    if (st->codecpar->codec_id == AV_CODEC_ID_H264) {
-        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
-                             (AV_RB24(pkt->data) != 0x000001 ||
-                              (st->codecpar->extradata_size > 0 &&
-                               st->codecpar->extradata[0] == 1)))
-            ret = ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
-    } else if (st->codecpar->codec_id == AV_CODEC_ID_HEVC) {
-        if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
-                             (AV_RB24(pkt->data) != 0x000001 ||
-                              (st->codecpar->extradata_size > 0 &&
-                               st->codecpar->extradata[0] == 1)))
-            ret = ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
+    for (int i = 0; i < FF_ARRAY_ELEMS(list); i++) {
+        struct Entry *e = list + i;
+        if (e->id == st->codecpar->codec_id &&
+                pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
+                (AV_RB24(pkt->data) != 0x000001 ||
+                    (st->codecpar->extradata_size > 0 &&
+                        (st->codecpar->extradata[0] & e->m == e->v))))
+            return ff_stream_add_bitstream_filter(st, e->bsf_name, NULL);
     }
-
-    return ret;
+    return 1;
 }
 
 #define OFFSET(x) offsetof(MpegTSWrite, x)