[FFmpeg-cvslog] Merge commit '90ed6c5cf7f236bc9efb47c97b40358c666d1386'

Derek Buitenhuis git at videolan.org
Tue Apr 26 15:27:44 CEST 2016


ffmpeg | branch: master | Derek Buitenhuis <derek.buitenhuis at gmail.com> | Tue Apr 26 14:09:52 2016 +0100| [79aafd43fd255fc04e4f4db4c45d6d1f5a9b9fff] | committer: Derek Buitenhuis

Merge commit '90ed6c5cf7f236bc9efb47c97b40358c666d1386'

* commit '90ed6c5cf7f236bc9efb47c97b40358c666d1386':
  h2645_parse: compute the actual data length, without trailing paddding

Merged-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=79aafd43fd255fc04e4f4db4c45d6d1f5a9b9fff
---

 libavcodec/h2645_parse.c |   39 ++++++++++++++++++++++++++++++++++++---
 libavcodec/h2645_parse.h |    6 ++++++
 2 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/libavcodec/h2645_parse.c b/libavcodec/h2645_parse.c
index 6e24ea3..d9721a2 100644
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@ -22,14 +22,13 @@
 
 #include "config.h"
 
+#include "libavutil/intmath.h"
 #include "libavutil/intreadwrite.h"
 #include "libavutil/mem.h"
 
 #include "hevc.h"
 #include "h2645_parse.h"
 
-/* FIXME: This is adapted from ff_h264_decode_nal, avoiding duplication
- * between these functions would be nice. */
 int ff_h2645_extract_rbsp(const uint8_t *src, int length,
                           H2645NAL *nal)
 {
@@ -178,6 +177,31 @@ static const char *nal_unit_name(int nal_type)
     }
 }
 
+static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
+{
+    int size = nal->size;
+    int v;
+
+    while (skip_trailing_zeros && size > 0 && nal->data[size - 1] == 0)
+        size--;
+
+    if (!size)
+        return 0;
+
+    v = nal->data[size - 1];
+
+    if (size > INT_MAX / 8)
+        return AVERROR(ERANGE);
+    size *= 8;
+
+    /* remove the stop bit and following trailing zeros,
+     * or nothing for damaged bitstreams */
+    if (v)
+        size -= ff_ctz(v) + 1;
+
+    return size;
+}
+
 /**
  * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
  * 0 if the unit should be skipped, 1 otherwise
@@ -231,6 +255,7 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
     while (length >= 4) {
         H2645NAL *nal;
         int extract_length = 0;
+        int skip_trailing_zeros = 1;
 
         if (is_nalff) {
             int i;
@@ -292,7 +317,15 @@ int ff_h2645_packet_split(H2645Packet *pkt, const uint8_t *buf, int length,
 
         pkt->nb_nals++;
 
-        ret = init_get_bits8(&nal->gb, nal->data, nal->size);
+        /* see commit 3566042a0 */
+        if (consumed < length - 3 &&
+            buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&
+            buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)
+            skip_trailing_zeros = 0;
+
+        nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
+
+        ret = init_get_bits8(&nal->gb, nal->data, nal->size_bits);
         if (ret < 0)
             return ret;
 
diff --git a/libavcodec/h2645_parse.h b/libavcodec/h2645_parse.h
index ce889db..3619192 100644
--- a/libavcodec/h2645_parse.h
+++ b/libavcodec/h2645_parse.h
@@ -33,6 +33,12 @@ typedef struct H2645NAL {
     int size;
     const uint8_t *data;
 
+    /**
+     * Size, in bits, of just the data, excluding the stop bit and any trailing
+     * padding. I.e. what HEVC calls SODB.
+     */
+    int size_bits;
+
     int raw_size;
     const uint8_t *raw_data;
 


======================================================================

diff --cc libavcodec/h2645_parse.c
index 6e24ea3,defe001..d9721a2
--- a/libavcodec/h2645_parse.c
+++ b/libavcodec/h2645_parse.c
@@@ -25,11 -26,8 +26,9 @@@
  #include "libavutil/intreadwrite.h"
  #include "libavutil/mem.h"
  
 +#include "hevc.h"
  #include "h2645_parse.h"
  
- /* FIXME: This is adapted from ff_h264_decode_nal, avoiding duplication
-  * between these functions would be nice. */
  int ff_h2645_extract_rbsp(const uint8_t *src, int length,
                            H2645NAL *nal)
  {
@@@ -146,38 -127,31 +145,63 @@@ nsc
      return si;
  }
  
 +static const char *nal_unit_name(int nal_type)
 +{
 +    switch(nal_type) {
 +    case NAL_TRAIL_N    : return "TRAIL_N";
 +    case NAL_TRAIL_R    : return "TRAIL_R";
 +    case NAL_TSA_N      : return "TSA_N";
 +    case NAL_TSA_R      : return "TSA_R";
 +    case NAL_STSA_N     : return "STSA_N";
 +    case NAL_STSA_R     : return "STSA_R";
 +    case NAL_RADL_N     : return "RADL_N";
 +    case NAL_RADL_R     : return "RADL_R";
 +    case NAL_RASL_N     : return "RASL_N";
 +    case NAL_RASL_R     : return "RASL_R";
 +    case NAL_BLA_W_LP   : return "BLA_W_LP";
 +    case NAL_BLA_W_RADL : return "BLA_W_RADL";
 +    case NAL_BLA_N_LP   : return "BLA_N_LP";
 +    case NAL_IDR_W_RADL : return "IDR_W_RADL";
 +    case NAL_IDR_N_LP   : return "IDR_N_LP";
 +    case NAL_CRA_NUT    : return "CRA_NUT";
 +    case NAL_VPS        : return "VPS";
 +    case NAL_SPS        : return "SPS";
 +    case NAL_PPS        : return "PPS";
 +    case NAL_AUD        : return "AUD";
 +    case NAL_EOS_NUT    : return "EOS_NUT";
 +    case NAL_EOB_NUT    : return "EOB_NUT";
 +    case NAL_FD_NUT     : return "FD_NUT";
 +    case NAL_SEI_PREFIX : return "SEI_PREFIX";
 +    case NAL_SEI_SUFFIX : return "SEI_SUFFIX";
 +    default : return "?";
 +    }
 +}
 +
+ static int get_bit_length(H2645NAL *nal, int skip_trailing_zeros)
+ {
+     int size = nal->size;
+     int v;
+ 
+     while (skip_trailing_zeros && size > 0 && nal->data[size - 1] == 0)
+         size--;
+ 
+     if (!size)
+         return 0;
+ 
+     v = nal->data[size - 1];
+ 
+     if (size > INT_MAX / 8)
+         return AVERROR(ERANGE);
+     size *= 8;
+ 
+     /* remove the stop bit and following trailing zeros,
+      * or nothing for damaged bitstreams */
+     if (v)
 -        size -= av_ctz(v) + 1;
++        size -= ff_ctz(v) + 1;
+ 
+     return size;
+ }
+ 
  /**
   * @return AVERROR_INVALIDDATA if the packet is not a valid NAL unit,
   * 0 if the unit should be skipped, 1 otherwise
@@@ -290,9 -249,15 +315,17 @@@ int ff_h2645_packet_split(H2645Packet *
          if (consumed < 0)
              return consumed;
  
 +        pkt->nb_nals++;
 +
-         ret = init_get_bits8(&nal->gb, nal->data, nal->size);
+         /* see commit 3566042a0 */
+         if (consumed < length - 3 &&
+             buf[consumed]     == 0x00 && buf[consumed + 1] == 0x00 &&
+             buf[consumed + 2] == 0x01 && buf[consumed + 3] == 0xE0)
+             skip_trailing_zeros = 0;
+ 
+         nal->size_bits = get_bit_length(nal, skip_trailing_zeros);
+ 
 -        ret = init_get_bits(&nal->gb, nal->data, nal->size_bits);
++        ret = init_get_bits8(&nal->gb, nal->data, nal->size_bits);
          if (ret < 0)
              return ret;
  



More information about the ffmpeg-cvslog mailing list