diff mbox

[FFmpeg-devel] avcodec/h264_mp4toannexb_bsf: use enum constants for the NAL unit type values

Message ID 20180729212225.11964-1-jamrial@gmail.com
State Accepted
Commit a9a433564d73b9d961c3ca16dbc74d8e090dd3fb
Headers show

Commit Message

James Almer July 29, 2018, 9:22 p.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavcodec/h264_mp4toannexb_bsf.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

Comments

mypopy@gmail.com July 30, 2018, 12:24 a.m. UTC | #1
On Mon, Jul 30, 2018 at 5:22 AM James Almer <jamrial@gmail.com> wrote:
>
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavcodec/h264_mp4toannexb_bsf.c | 15 ++++++++-------
>  1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/h264_mp4toannexb_bsf.c
b/libavcodec/h264_mp4toannexb_bsf.c
> index 292d106433..794c82e650 100644
> --- a/libavcodec/h264_mp4toannexb_bsf.c
> +++ b/libavcodec/h264_mp4toannexb_bsf.c
> @@ -26,6 +26,7 @@
>
>  #include "avcodec.h"
>  #include "bsf.h"
> +#include "h264.h"
>
>  typedef struct H264BSFContext {
>      int32_t  sps_offset;
> @@ -209,9 +210,9 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx,
AVPacket *out)
>          if (nal_size > buf_end - buf || nal_size < 0)
>              goto fail;
>
> -        if (unit_type == 7)
> +        if (unit_type == H264_NAL_SPS)
>              s->idr_sps_seen = s->new_idr = 1;
> -        else if (unit_type == 8) {
> +        else if (unit_type == H264_NAL_PPS) {
>              s->idr_pps_seen = s->new_idr = 1;
>              /* if SPS has not been seen yet, prepend the AVCC one to PPS
*/
>              if (!s->idr_sps_seen) {
> @@ -232,18 +233,18 @@ static int h264_mp4toannexb_filter(AVBSFContext
*ctx, AVPacket *out)
>          /* if this is a new IDR picture following an IDR picture, reset
the idr flag.
>           * Just check first_mb_in_slice to be 0 as this is the simplest
solution.
>           * This could be checking idr_pic_id instead, but would
complexify the parsing. */
> -        if (!s->new_idr && unit_type == 5 && (buf[1] & 0x80))
> +        if (!s->new_idr && unit_type == H264_NAL_IDR_SLICE && (buf[1] &
0x80))
>              s->new_idr = 1;
>
>          /* prepend only to the first type 5 NAL unit of an IDR picture,
if no sps/pps are already present */
> -        if (s->new_idr && unit_type == 5 && !s->idr_sps_seen &&
!s->idr_pps_seen) {
> +        if (s->new_idr && unit_type == H264_NAL_IDR_SLICE &&
!s->idr_sps_seen && !s->idr_pps_seen) {
>              if ((ret=alloc_and_copy(out,
>                                 ctx->par_out->extradata,
ctx->par_out->extradata_size,
>                                 buf, nal_size, 1)) < 0)
>                  goto fail;
>              s->new_idr = 0;
>          /* if only SPS has been seen, also insert PPS */
> -        } else if (s->new_idr && unit_type == 5 && s->idr_sps_seen &&
!s->idr_pps_seen) {
> +        } else if (s->new_idr && unit_type == H264_NAL_IDR_SLICE &&
s->idr_sps_seen && !s->idr_pps_seen) {
>              if (s->pps_offset == -1) {
>                  av_log(ctx, AV_LOG_WARNING, "PPS not present in the
stream, nor in AVCC, stream may be unreadable\n");
>                  if ((ret = alloc_and_copy(out, NULL, 0, buf, nal_size,
0)) < 0)
> @@ -253,9 +254,9 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx,
AVPacket *out)
>                                          buf, nal_size, 1)) < 0)
>                  goto fail;
>          } else {
> -            if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size,
unit_type == 7 || unit_type == 8)) < 0)
> +            if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size,
unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS)) < 0)
>                  goto fail;
> -            if (!s->new_idr && unit_type == 1) {
> +            if (!s->new_idr && unit_type == H264_NAL_SLICE) {
>                  s->new_idr = 1;
>                  s->idr_sps_seen = 0;
>                  s->idr_pps_seen = 0;
> --
LGTM
James Almer July 30, 2018, 9:03 p.m. UTC | #2
On 7/29/2018 9:24 PM, mypopy@gmail.com wrote:
> LGTM

Pushed, thanks.
diff mbox

Patch

diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c
index 292d106433..794c82e650 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -26,6 +26,7 @@ 
 
 #include "avcodec.h"
 #include "bsf.h"
+#include "h264.h"
 
 typedef struct H264BSFContext {
     int32_t  sps_offset;
@@ -209,9 +210,9 @@  static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
         if (nal_size > buf_end - buf || nal_size < 0)
             goto fail;
 
-        if (unit_type == 7)
+        if (unit_type == H264_NAL_SPS)
             s->idr_sps_seen = s->new_idr = 1;
-        else if (unit_type == 8) {
+        else if (unit_type == H264_NAL_PPS) {
             s->idr_pps_seen = s->new_idr = 1;
             /* if SPS has not been seen yet, prepend the AVCC one to PPS */
             if (!s->idr_sps_seen) {
@@ -232,18 +233,18 @@  static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
         /* if this is a new IDR picture following an IDR picture, reset the idr flag.
          * Just check first_mb_in_slice to be 0 as this is the simplest solution.
          * This could be checking idr_pic_id instead, but would complexify the parsing. */
-        if (!s->new_idr && unit_type == 5 && (buf[1] & 0x80))
+        if (!s->new_idr && unit_type == H264_NAL_IDR_SLICE && (buf[1] & 0x80))
             s->new_idr = 1;
 
         /* prepend only to the first type 5 NAL unit of an IDR picture, if no sps/pps are already present */
-        if (s->new_idr && unit_type == 5 && !s->idr_sps_seen && !s->idr_pps_seen) {
+        if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && !s->idr_sps_seen && !s->idr_pps_seen) {
             if ((ret=alloc_and_copy(out,
                                ctx->par_out->extradata, ctx->par_out->extradata_size,
                                buf, nal_size, 1)) < 0)
                 goto fail;
             s->new_idr = 0;
         /* if only SPS has been seen, also insert PPS */
-        } else if (s->new_idr && unit_type == 5 && s->idr_sps_seen && !s->idr_pps_seen) {
+        } else if (s->new_idr && unit_type == H264_NAL_IDR_SLICE && s->idr_sps_seen && !s->idr_pps_seen) {
             if (s->pps_offset == -1) {
                 av_log(ctx, AV_LOG_WARNING, "PPS not present in the stream, nor in AVCC, stream may be unreadable\n");
                 if ((ret = alloc_and_copy(out, NULL, 0, buf, nal_size, 0)) < 0)
@@ -253,9 +254,9 @@  static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *out)
                                         buf, nal_size, 1)) < 0)
                 goto fail;
         } else {
-            if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size, unit_type == 7 || unit_type == 8)) < 0)
+            if ((ret=alloc_and_copy(out, NULL, 0, buf, nal_size, unit_type == H264_NAL_SPS || unit_type == H264_NAL_PPS)) < 0)
                 goto fail;
-            if (!s->new_idr && unit_type == 1) {
+            if (!s->new_idr && unit_type == H264_NAL_SLICE) {
                 s->new_idr = 1;
                 s->idr_sps_seen = 0;
                 s->idr_pps_seen = 0;