diff mbox

[FFmpeg-devel,1/3] cbs_h264: Actually decompose end-of-sequence NAL units

Message ID 20181016210128.7652-1-sw@jkqxz.net
State Accepted
Commit 3143fe34f622ae61ca75a65feba3a8f1a497567e
Headers show

Commit Message

Mark Thompson Oct. 16, 2018, 9:01 p.m. UTC
64c50c0e978cd556dc2da238dfe0bb367e7c1ab9 declared support for decomposing
them but omitted to implement it; this adds an implementation.

Also do the same for end-of-stream NAL units, since they are equivalent.
---
For an example of both, see the end of Sharp_MP_PAFF_1r2.jvt (also tested as part of fate-cbs-h264).


 libavcodec/cbs_h2645.c                | 32 ++++++++++++++++++++++++++-
 libavcodec/cbs_h264_syntax_template.c | 18 +++++++++++++++
 2 files changed, 49 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 4b31601c0f..a1b92c87ce 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -872,7 +872,21 @@  static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
         break;
 
     case H264_NAL_END_SEQUENCE:
-        return 0;
+    case H264_NAL_END_STREAM:
+        {
+            err = ff_cbs_alloc_unit_content(ctx, unit,
+                                            sizeof(H264RawNALUnitHeader),
+                                            NULL);
+            if (err < 0)
+                return err;
+
+            err = (unit->type == H264_NAL_END_SEQUENCE ?
+                   cbs_h264_read_end_of_sequence :
+                   cbs_h264_read_end_of_stream)(ctx, &gbc, unit->content);
+            if (err < 0)
+                return err;
+        }
+        break;
 
     default:
         return AVERROR(ENOSYS);
@@ -1147,6 +1161,22 @@  static int cbs_h264_write_nal_unit(CodedBitstreamContext *ctx,
         }
         break;
 
+    case H264_NAL_END_SEQUENCE:
+        {
+            err = cbs_h264_write_end_of_sequence(ctx, pbc, unit->content);
+            if (err < 0)
+                return err;
+        }
+        break;
+
+    case H264_NAL_END_STREAM:
+        {
+            err = cbs_h264_write_end_of_stream(ctx, pbc, unit->content);
+            if (err < 0)
+                return err;
+        }
+        break;
+
     default:
         av_log(ctx->log_ctx, AV_LOG_ERROR, "Write unimplemented for "
                "NAL unit type %"PRIu32".\n", unit->type);
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index 1c8d7d5eae..1a9fb9cfeb 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -1375,3 +1375,21 @@  static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
 
     return 0;
 }
+
+static int FUNC(end_of_sequence)(CodedBitstreamContext *ctx, RWContext *rw,
+                                 H264RawNALUnitHeader *current)
+{
+    HEADER("End of Sequence");
+
+    return FUNC(nal_unit_header)(ctx, rw, current,
+                                 1 << H264_NAL_END_SEQUENCE);
+}
+
+static int FUNC(end_of_stream)(CodedBitstreamContext *ctx, RWContext *rw,
+                               H264RawNALUnitHeader *current)
+{
+    HEADER("End of Stream");
+
+    return FUNC(nal_unit_header)(ctx, rw, current,
+                                 1 << H264_NAL_END_STREAM);
+}