Coverage Report

Created: 2025-10-12 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/hxxx_nal.h
Line
Count
Source
1
/*****************************************************************************
2
 * hxxx_nal.h: Common helpers for AVC/HEVC NALU
3
 *****************************************************************************
4
 * Copyright (C) 2014-2015 VLC authors and VideoLAN
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#ifndef HXXX_NAL_H
21
#define HXXX_NAL_H
22
23
#include <stdbit.h>
24
25
#include <vlc_common.h>
26
#include <vlc_es.h>
27
#include "startcode_helper.h"
28
29
static const uint8_t  annexb_startcode4[] = { 0x00, 0x00, 0x00, 0x01 };
30
55.2k
#define annexb_startcode3 (&annexb_startcode4[1])
31
32
/* strips any AnnexB startcode [0] 0 0 1 */
33
static inline bool hxxx_strip_AnnexB_startcode( const uint8_t **pp_data, size_t *pi_data )
34
2.33M
{
35
2.33M
    unsigned bitflow = 0;
36
2.33M
    const uint8_t *p_data = *pp_data;
37
2.33M
    size_t i_data = *pi_data;
38
39
9.33M
    while( i_data && p_data[0] <= 1 )
40
9.33M
    {
41
9.33M
        bitflow = (bitflow << 1) | (!p_data[0]);
42
9.33M
        p_data++;
43
9.33M
        i_data--;
44
9.33M
        if( !(bitflow & 0x01) )
45
2.33M
        {
46
2.33M
            if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */
47
2.33M
            {
48
2.33M
                *pi_data = i_data;
49
2.33M
                *pp_data = p_data;
50
2.33M
                return true;
51
2.33M
            }
52
0
            return false;
53
2.33M
        }
54
9.33M
    }
55
0
    return false;
56
2.33M
}
h264.c:hxxx_strip_AnnexB_startcode
Line
Count
Source
34
727k
{
35
727k
    unsigned bitflow = 0;
36
727k
    const uint8_t *p_data = *pp_data;
37
727k
    size_t i_data = *pi_data;
38
39
2.90M
    while( i_data && p_data[0] <= 1 )
40
2.90M
    {
41
2.90M
        bitflow = (bitflow << 1) | (!p_data[0]);
42
2.90M
        p_data++;
43
2.90M
        i_data--;
44
2.90M
        if( !(bitflow & 0x01) )
45
727k
        {
46
727k
            if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */
47
727k
            {
48
727k
                *pi_data = i_data;
49
727k
                *pp_data = p_data;
50
727k
                return true;
51
727k
            }
52
0
            return false;
53
727k
        }
54
2.90M
    }
55
0
    return false;
56
727k
}
hxxx_sei.c:hxxx_strip_AnnexB_startcode
Line
Count
Source
34
230k
{
35
230k
    unsigned bitflow = 0;
36
230k
    const uint8_t *p_data = *pp_data;
37
230k
    size_t i_data = *pi_data;
38
39
922k
    while( i_data && p_data[0] <= 1 )
40
922k
    {
41
922k
        bitflow = (bitflow << 1) | (!p_data[0]);
42
922k
        p_data++;
43
922k
        i_data--;
44
922k
        if( !(bitflow & 0x01) )
45
230k
        {
46
230k
            if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */
47
230k
            {
48
230k
                *pi_data = i_data;
49
230k
                *pp_data = p_data;
50
230k
                return true;
51
230k
            }
52
0
            return false;
53
230k
        }
54
922k
    }
55
0
    return false;
56
230k
}
Unexecuted instantiation: h264_nal.c:hxxx_strip_AnnexB_startcode
Unexecuted instantiation: h264_slice.c:hxxx_strip_AnnexB_startcode
hevc.c:hxxx_strip_AnnexB_startcode
Line
Count
Source
34
1.37M
{
35
1.37M
    unsigned bitflow = 0;
36
1.37M
    const uint8_t *p_data = *pp_data;
37
1.37M
    size_t i_data = *pi_data;
38
39
5.50M
    while( i_data && p_data[0] <= 1 )
40
5.50M
    {
41
5.50M
        bitflow = (bitflow << 1) | (!p_data[0]);
42
5.50M
        p_data++;
43
5.50M
        i_data--;
44
5.50M
        if( !(bitflow & 0x01) )
45
1.37M
        {
46
1.37M
            if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */
47
1.37M
            {
48
1.37M
                *pi_data = i_data;
49
1.37M
                *pp_data = p_data;
50
1.37M
                return true;
51
1.37M
            }
52
0
            return false;
53
1.37M
        }
54
5.50M
    }
55
0
    return false;
56
1.37M
}
Unexecuted instantiation: hevc_nal.c:hxxx_strip_AnnexB_startcode
Unexecuted instantiation: vc1.c:hxxx_strip_AnnexB_startcode
57
58
/* Declarations */
59
60
typedef struct
61
{
62
    const uint8_t *p_head;
63
    const uint8_t *p_tail;
64
    uint8_t i_nal_length_size;
65
} hxxx_iterator_ctx_t;
66
67
static inline void hxxx_iterator_init( hxxx_iterator_ctx_t *p_ctx, const uint8_t *p_data, size_t i_data,
68
                                       uint8_t i_nal_length_size )
69
0
{
70
0
    p_ctx->p_head = p_data;
71
0
    p_ctx->p_tail = p_data + i_data;
72
0
    if( stdc_has_single_bit(i_nal_length_size) && i_nal_length_size <= 4 )
73
0
        p_ctx->i_nal_length_size = i_nal_length_size;
74
0
    else
75
0
        p_ctx->i_nal_length_size = 0;
76
0
}
Unexecuted instantiation: h264.c:hxxx_iterator_init
Unexecuted instantiation: hxxx_sei.c:hxxx_iterator_init
Unexecuted instantiation: h264_nal.c:hxxx_iterator_init
Unexecuted instantiation: h264_slice.c:hxxx_iterator_init
Unexecuted instantiation: hevc.c:hxxx_iterator_init
Unexecuted instantiation: hevc_nal.c:hxxx_iterator_init
Unexecuted instantiation: vc1.c:hxxx_iterator_init
77
78
static inline bool hxxx_iterate_next( hxxx_iterator_ctx_t *p_ctx, const uint8_t **pp_start, size_t *pi_size )
79
0
{
80
0
    if( p_ctx->i_nal_length_size == 0 )
81
0
        return false;
82
0
83
0
    if( p_ctx->p_tail - p_ctx->p_head < p_ctx->i_nal_length_size )
84
0
        return false;
85
0
86
0
    uint32_t i_nal_size = 0;
87
0
    for( uint8_t i=0; i < p_ctx->i_nal_length_size ; i++ )
88
0
        i_nal_size = (i_nal_size << 8) | *p_ctx->p_head++;
89
0
90
0
    if( i_nal_size > (size_t)(p_ctx->p_tail - p_ctx->p_head) )
91
0
        return false;
92
0
93
0
    *pp_start = p_ctx->p_head;
94
0
    *pi_size = i_nal_size;
95
0
    p_ctx->p_head += i_nal_size;
96
0
97
0
    return true;
98
0
}
Unexecuted instantiation: h264.c:hxxx_iterate_next
Unexecuted instantiation: hxxx_sei.c:hxxx_iterate_next
Unexecuted instantiation: h264_nal.c:hxxx_iterate_next
Unexecuted instantiation: h264_slice.c:hxxx_iterate_next
Unexecuted instantiation: hevc.c:hxxx_iterate_next
Unexecuted instantiation: hevc_nal.c:hxxx_iterate_next
Unexecuted instantiation: vc1.c:hxxx_iterate_next
99
100
static inline bool hxxx_annexb_iterate_next( hxxx_iterator_ctx_t *p_ctx, const uint8_t **pp_start, size_t *pi_size )
101
0
{
102
0
    if( !p_ctx->p_head )
103
0
        return false;
104
105
0
    p_ctx->p_head = startcode_FindAnnexB( p_ctx->p_head, p_ctx->p_tail );
106
0
    if( !p_ctx->p_head )
107
0
        return false;
108
109
0
    const uint8_t *p_end = startcode_FindAnnexB( p_ctx->p_head + 3, p_ctx->p_tail );
110
0
    if( !p_end )
111
0
        p_end = p_ctx->p_tail;
112
113
    /* fix 3 to 4 startcode offset and strip any trailing zeros */
114
0
    while( p_end > p_ctx->p_head && p_end[-1] == 0 )
115
0
        p_end--;
116
117
0
    *pp_start = p_ctx->p_head;
118
0
    *pi_size = p_end - p_ctx->p_head;
119
0
    p_ctx->p_head = p_end;
120
121
0
    return hxxx_strip_AnnexB_startcode( pp_start, pi_size );
122
0
}
Unexecuted instantiation: h264.c:hxxx_annexb_iterate_next
Unexecuted instantiation: hxxx_sei.c:hxxx_annexb_iterate_next
Unexecuted instantiation: h264_nal.c:hxxx_annexb_iterate_next
Unexecuted instantiation: h264_slice.c:hxxx_annexb_iterate_next
Unexecuted instantiation: hevc.c:hxxx_annexb_iterate_next
Unexecuted instantiation: hevc_nal.c:hxxx_annexb_iterate_next
Unexecuted instantiation: vc1.c:hxxx_annexb_iterate_next
123
124
/* Takes any AnnexB NAL buffer and converts it to prefixed size (AVC/HEVC) */
125
block_t *hxxx_AnnexB_to_xVC( block_t *p_block, uint8_t i_nal_length_size );
126
127
#endif // HXXX_NAL_H