Re: [libav-devel] [PATCH 06/15] lavc: Add coded bitstream read/write support for H.265

2017-07-24 Thread Anton Khirnov
Quoting Mark Thompson (2017-06-24 01:39:12)
> ---
>  libavcodec/cbs.c |1 +
>  libavcodec/cbs_h2645.c   |  410 +++-
>  libavcodec/cbs_h265.h|  544 
>  libavcodec/cbs_h265_syntax.c | 1482 
> ++
>  libavcodec/cbs_internal.h|1 +
>  5 files changed, 2435 insertions(+), 3 deletions(-)
>  create mode 100644 libavcodec/cbs_h265.h
>  create mode 100644 libavcodec/cbs_h265_syntax.c
> 

Looks okish from a quick look

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 06/15] lavc: Add coded bitstream read/write support for H.265

2017-06-23 Thread Mark Thompson
---
 libavcodec/cbs.c |1 +
 libavcodec/cbs_h2645.c   |  410 +++-
 libavcodec/cbs_h265.h|  544 
 libavcodec/cbs_h265_syntax.c | 1482 ++
 libavcodec/cbs_internal.h|1 +
 5 files changed, 2435 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/cbs_h265.h
 create mode 100644 libavcodec/cbs_h265_syntax.c

diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c
index 2619b38dd..6030cfd48 100644
--- a/libavcodec/cbs.c
+++ b/libavcodec/cbs.c
@@ -28,6 +28,7 @@
 
 static const CodedBitstreamType *cbs_type_table[] = {
 _cbs_type_h264,
+_cbs_type_h265,
 };
 
 int ff_cbs_init(CodedBitstreamContext *ctx,
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index ca8d83e9f..190a5a898 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -23,9 +23,11 @@
 #include "cbs.h"
 #include "cbs_internal.h"
 #include "cbs_h264.h"
+#include "cbs_h265.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
+#include "hevc.h"
 
 
 #define HEADER(name) do { \
@@ -40,6 +42,7 @@
 
 #define FUNC_NAME(rw, codec, name) cbs_ ## codec ## _ ## rw ## _ ## name
 #define FUNC_H264(rw, name) FUNC_NAME(rw, h264, name)
+#define FUNC_H265(rw, name) FUNC_NAME(rw, h265, name)
 
 
 #define READ
@@ -102,6 +105,10 @@ static int cbs_h2645_read_more_rbsp_data(BitstreamContext 
*bc)
 #include "cbs_h264_syntax.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax.c"
+#undef FUNC
+
 #undef READ
 #undef READWRITE
 #undef RWContext
@@ -171,6 +178,10 @@ static int cbs_h2645_read_more_rbsp_data(BitstreamContext 
*bc)
 #include "cbs_h264_syntax.c"
 #undef FUNC
 
+#define FUNC(name) FUNC_H265(READWRITE, name)
+#include "cbs_h265_syntax.c"
+#undef FUNC
+
 #undef WRITE
 #undef READWRITE
 #undef RWContext
@@ -231,6 +242,40 @@ static void cbs_h264_free_nal_unit(CodedBitstreamUnit 
*unit)
 av_freep(>content);
 }
 
+static void cbs_h265_free_nal_unit(CodedBitstreamUnit *unit)
+{
+switch (unit->type) {
+case HEVC_NAL_VPS:
+av_freep(&((H265RawVPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_SPS:
+av_freep(&((H265RawSPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_PPS:
+av_freep(&((H265RawPPS*)unit->content)->extension_data.data);
+break;
+case HEVC_NAL_TRAIL_N:
+case HEVC_NAL_TRAIL_R:
+case HEVC_NAL_TSA_N:
+case HEVC_NAL_TSA_R:
+case HEVC_NAL_STSA_N:
+case HEVC_NAL_STSA_R:
+case HEVC_NAL_RADL_N:
+case HEVC_NAL_RADL_R:
+case HEVC_NAL_RASL_N:
+case HEVC_NAL_RASL_R:
+case HEVC_NAL_BLA_W_LP:
+case HEVC_NAL_BLA_W_RADL:
+case HEVC_NAL_BLA_N_LP:
+case HEVC_NAL_IDR_W_RADL:
+case HEVC_NAL_IDR_N_LP:
+case HEVC_NAL_CRA_NUT:
+av_freep(&((H265RawSlice*)unit->content)->data);
+break;
+}
+av_freep(>content);
+}
+
 static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx,
CodedBitstreamFragment *frag,
const H2645Packet *packet)
@@ -345,6 +390,58 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext 
*ctx,
"header.\n", bytestream2_get_bytes_left());
 }
 
+} else if (header && frag->data[0] && codec_id == AV_CODEC_ID_HEVC) {
+// HVCC header.
+size_t size, start, end;
+int i, j, nb_arrays, nal_unit_type, nb_nals, version;
+
+priv->mp4 = 1;
+
+bytestream2_init(, frag->data, frag->data_size);
+
+if (bytestream2_get_bytes_left() < 23)
+return AVERROR_INVALIDDATA;
+
+version = bytestream2_get_byte();
+if (version != 1) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid HVCC header: "
+   "first byte %u.", version);
+return AVERROR_INVALIDDATA;
+}
+
+bytestream2_skip(, 20);
+priv->nal_length_size = (bytestream2_get_byte() & 3) + 1;
+
+nb_arrays = bytestream2_get_byte();
+for (i = 0; i < nb_arrays; i++) {
+nal_unit_type = bytestream2_get_byte() & 0x3f;
+nb_nals = bytestream2_get_be16();
+
+start = bytestream2_tell();
+for (j = 0; j < nb_nals; j++) {
+if (bytestream2_get_bytes_left() < 2)
+return AVERROR_INVALIDDATA;
+size = bytestream2_get_be16();
+if (bytestream2_get_bytes_left() < size)
+return AVERROR_INVALIDDATA;
+bytestream2_skip(, size);
+}
+end = bytestream2_tell();
+
+err = ff_h2645_packet_split(>read_packet,
+frag->data + start, end - start,
+ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC);
+if (err < 0) {
+av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split "
+