]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/h264.c
mpegvideo_enc: separate declarations and statements
[ffmpeg] / libavcodec / h264.c
index 5d4ce90cae923674efdf3bde0616564597a038e9..a9a10513e39e4ba7ea7e94876673a21645a77802 100644 (file)
@@ -137,10 +137,7 @@ int ff_h264_check_intra_pred_mode(H264Context *h, int mode){
     return mode;
 }
 
-const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,
-                                  int *dst_length, int *consumed, int length,
-                                  int nalsize_known)
-{
+const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){
     int i, si, di;
     uint8_t *dst;
     int bufidx;
@@ -151,9 +148,6 @@ const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src,
 
     src++; length--;
 
-    if (nalsize_known) {
-        i = length;
-    } else
 #if HAVE_FAST_UNALIGNED
 # if HAVE_FAST_64BIT
 #   define RS 7
@@ -3765,7 +3759,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
         int consumed;
         int dst_length;
         int bit_length;
-        const uint8_t *ptr;
+        uint8_t *ptr;
         int i, nalsize = 0;
         int err;
 
@@ -3795,8 +3789,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
 
         hx = h->thread_context[context_count];
 
-        ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed,
-                                next_avc - buf_index, !!nalsize);
+        ptr= ff_h264_decode_nal(hx, buf + buf_index, &dst_length, &consumed, next_avc - buf_index);
         if (ptr==NULL || dst_length < 0){
             return -1;
         }
@@ -3816,6 +3809,9 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
         }
 
         if (h->is_avc && (nalsize != consumed) && nalsize){
+            // set trailing bits in the last partial byte to zero
+            if (bit_length & 7)
+                ptr[bit_length >> 3] = ptr[bit_length >> 3] & (0xff << 8 - (bit_length & 7));
             av_log(h->s.avctx, AV_LOG_DEBUG, "AVC: Consumed only %d bytes instead of %d\n", consumed, nalsize);
         }