Coverage Report

Created: 2026-08-14 07:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/hxxx_ep3b.h
Line
Count
Source
1
/*****************************************************************************
2
 * hxxx_ep3b.h
3
 *****************************************************************************
4
 * Copyright (C) 2014-2015 VLC authors and VideoLAN
5
 *                    2018 VideoLabs
6
 *
7
 * This program is free software; you can redistribute it and/or modify it
8
 * under the terms of the GNU Lesser General Public License as published by
9
 * the Free Software Foundation; either version 2.1 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public License
18
 * along with this program; if not, write to the Free Software Foundation,
19
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20
 *****************************************************************************/
21
#include <vlc_bits.h>
22
23
static inline const uint8_t *hxxx_ep3b_to_rbsp( const uint8_t *p, const uint8_t *end, unsigned *pi_prev, size_t i_count )
24
37.4M
{
25
84.7M
    for( size_t i=0; i<i_count; i++ )
26
51.5M
    {
27
51.5M
        if( ++p >= end )
28
4.22M
            return p;
29
30
47.2M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
47.2M
        if( *p == 0x03 &&
33
258k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
245k
        {
35
245k
            if( (*pi_prev & 0x06) == 0x06 )
36
54.6k
            {
37
54.6k
                ++p;
38
54.6k
                *pi_prev = !*p;
39
54.6k
            }
40
245k
        }
41
47.2M
    }
42
33.1M
    return p;
43
37.4M
}
hxxx_sei.c:hxxx_ep3b_to_rbsp
Line
Count
Source
24
4.24M
{
25
20.5M
    for( size_t i=0; i<i_count; i++ )
26
16.4M
    {
27
16.4M
        if( ++p >= end )
28
149k
            return p;
29
30
16.3M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
16.3M
        if( *p == 0x03 &&
33
58.7k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
56.6k
        {
35
56.6k
            if( (*pi_prev & 0x06) == 0x06 )
36
15.5k
            {
37
15.5k
                ++p;
38
15.5k
                *pi_prev = !*p;
39
15.5k
            }
40
56.6k
        }
41
16.3M
    }
42
4.09M
    return p;
43
4.24M
}
h264_nal.c:hxxx_ep3b_to_rbsp
Line
Count
Source
24
4.15M
{
25
8.86M
    for( size_t i=0; i<i_count; i++ )
26
4.81M
    {
27
4.81M
        if( ++p >= end )
28
106k
            return p;
29
30
4.70M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
4.70M
        if( *p == 0x03 &&
33
22.9k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
20.2k
        {
35
20.2k
            if( (*pi_prev & 0x06) == 0x06 )
36
1.22k
            {
37
1.22k
                ++p;
38
1.22k
                *pi_prev = !*p;
39
1.22k
            }
40
20.2k
        }
41
4.70M
    }
42
4.04M
    return p;
43
4.15M
}
h264_slice.c:hxxx_ep3b_to_rbsp
Line
Count
Source
24
3.27M
{
25
6.54M
    for( size_t i=0; i<i_count; i++ )
26
3.36M
    {
27
3.36M
        if( ++p >= end )
28
96.5k
            return p;
29
30
3.27M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
3.27M
        if( *p == 0x03 &&
33
7.26k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
6.76k
        {
35
6.76k
            if( (*pi_prev & 0x06) == 0x06 )
36
1.89k
            {
37
1.89k
                ++p;
38
1.89k
                *pi_prev = !*p;
39
1.89k
            }
40
6.76k
        }
41
3.27M
    }
42
3.17M
    return p;
43
3.27M
}
hevc_nal.c:hxxx_ep3b_to_rbsp
Line
Count
Source
24
24.0M
{
25
45.2M
    for( size_t i=0; i<i_count; i++ )
26
25.1M
    {
27
25.1M
        if( ++p >= end )
28
3.86M
            return p;
29
30
21.2M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
21.2M
        if( *p == 0x03 &&
33
157k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
149k
        {
35
149k
            if( (*pi_prev & 0x06) == 0x06 )
36
35.1k
            {
37
35.1k
                ++p;
38
35.1k
                *pi_prev = !*p;
39
35.1k
            }
40
149k
        }
41
21.2M
    }
42
20.1M
    return p;
43
24.0M
}
vc1.c:hxxx_ep3b_to_rbsp
Line
Count
Source
24
1.72M
{
25
3.43M
    for( size_t i=0; i<i_count; i++ )
26
1.72M
    {
27
1.72M
        if( ++p >= end )
28
12.9k
            return p;
29
30
1.71M
        *pi_prev = (*pi_prev << 1) | (!*p);
31
32
1.71M
        if( *p == 0x03 &&
33
12.1k
           ( p + 1 ) != end ) /* Never escape sequence if no next byte */
34
12.1k
        {
35
12.1k
            if( (*pi_prev & 0x06) == 0x06 )
36
870
            {
37
870
                ++p;
38
870
                *pi_prev = !*p;
39
870
            }
40
12.1k
        }
41
1.71M
    }
42
1.71M
    return p;
43
1.72M
}
44
45
#if 0
46
/* Discards emulation prevention three bytes */
47
static inline uint8_t * hxxx_ep3b_to_rbsp(const uint8_t *p_src, size_t i_src, size_t *pi_ret)
48
{
49
    uint8_t *p_dst;
50
    if(!p_src || !(p_dst = malloc(i_src)))
51
        return NULL;
52
53
    size_t j = 0;
54
    for (size_t i = 0; i < i_src; i++) {
55
        if (i < i_src - 3 &&
56
            p_src[i] == 0 && p_src[i+1] == 0 && p_src[i+2] == 3) {
57
            p_dst[j++] = 0;
58
            p_dst[j++] = 0;
59
            i += 2;
60
            continue;
61
        }
62
        p_dst[j++] = p_src[i];
63
    }
64
    *pi_ret = j;
65
    return p_dst;
66
}
67
#endif
68
69
/* vlc_bits's bs_t forward callback for stripping emulation prevention three bytes */
70
struct hxxx_bsfw_ep3b_ctx_s
71
{
72
    unsigned i_prev;
73
    size_t i_bytepos;
74
};
75
76
static void hxxx_bsfw_ep3b_ctx_init( struct hxxx_bsfw_ep3b_ctx_s *ctx )
77
5.35M
{
78
5.35M
    ctx->i_prev = 0;
79
5.35M
    ctx->i_bytepos = 0;
80
5.35M
}
hxxx_sei.c:hxxx_bsfw_ep3b_ctx_init
Line
Count
Source
77
155k
{
78
155k
    ctx->i_prev = 0;
79
155k
    ctx->i_bytepos = 0;
80
155k
}
h264_nal.c:hxxx_bsfw_ep3b_ctx_init
Line
Count
Source
77
333k
{
78
333k
    ctx->i_prev = 0;
79
333k
    ctx->i_bytepos = 0;
80
333k
}
h264_slice.c:hxxx_bsfw_ep3b_ctx_init
Line
Count
Source
77
435k
{
78
435k
    ctx->i_prev = 0;
79
435k
    ctx->i_bytepos = 0;
80
435k
}
hevc_nal.c:hxxx_bsfw_ep3b_ctx_init
Line
Count
Source
77
4.34M
{
78
4.34M
    ctx->i_prev = 0;
79
4.34M
    ctx->i_bytepos = 0;
80
4.34M
}
vc1.c:hxxx_bsfw_ep3b_ctx_init
Line
Count
Source
77
87.4k
{
78
87.4k
    ctx->i_prev = 0;
79
87.4k
    ctx->i_bytepos = 0;
80
87.4k
}
81
82
static size_t hxxx_bsfw_byte_forward_ep3b( bs_t *s, size_t i_count )
83
49.1M
{
84
49.1M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
49.1M
    if( s->p == NULL )
86
5.35M
    {
87
5.35M
        s->p = s->p_start;
88
5.35M
        ctx->i_bytepos = 1;
89
5.35M
        return 1;
90
5.35M
    }
91
92
43.7M
    if( s->p >= s->p_end )
93
6.37M
        return 0;
94
95
37.4M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
37.4M
    ctx->i_bytepos += i_count;
97
37.4M
    return i_count;
98
43.7M
}
hxxx_sei.c:hxxx_bsfw_byte_forward_ep3b
Line
Count
Source
83
4.61M
{
84
4.61M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
4.61M
    if( s->p == NULL )
86
155k
    {
87
155k
        s->p = s->p_start;
88
155k
        ctx->i_bytepos = 1;
89
155k
        return 1;
90
155k
    }
91
92
4.46M
    if( s->p >= s->p_end )
93
215k
        return 0;
94
95
4.24M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
4.24M
    ctx->i_bytepos += i_count;
97
4.24M
    return i_count;
98
4.46M
}
h264_nal.c:hxxx_bsfw_byte_forward_ep3b
Line
Count
Source
83
4.89M
{
84
4.89M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
4.89M
    if( s->p == NULL )
86
333k
    {
87
333k
        s->p = s->p_start;
88
333k
        ctx->i_bytepos = 1;
89
333k
        return 1;
90
333k
    }
91
92
4.55M
    if( s->p >= s->p_end )
93
404k
        return 0;
94
95
4.15M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
4.15M
    ctx->i_bytepos += i_count;
97
4.15M
    return i_count;
98
4.55M
}
h264_slice.c:hxxx_bsfw_byte_forward_ep3b
Line
Count
Source
83
3.96M
{
84
3.96M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
3.96M
    if( s->p == NULL )
86
435k
    {
87
435k
        s->p = s->p_start;
88
435k
        ctx->i_bytepos = 1;
89
435k
        return 1;
90
435k
    }
91
92
3.53M
    if( s->p >= s->p_end )
93
260k
        return 0;
94
95
3.27M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
3.27M
    ctx->i_bytepos += i_count;
97
3.27M
    return i_count;
98
3.53M
}
hevc_nal.c:hxxx_bsfw_byte_forward_ep3b
Line
Count
Source
83
33.8M
{
84
33.8M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
33.8M
    if( s->p == NULL )
86
4.34M
    {
87
4.34M
        s->p = s->p_start;
88
4.34M
        ctx->i_bytepos = 1;
89
4.34M
        return 1;
90
4.34M
    }
91
92
29.4M
    if( s->p >= s->p_end )
93
5.43M
        return 0;
94
95
24.0M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
24.0M
    ctx->i_bytepos += i_count;
97
24.0M
    return i_count;
98
29.4M
}
vc1.c:hxxx_bsfw_byte_forward_ep3b
Line
Count
Source
83
1.86M
{
84
1.86M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
85
1.86M
    if( s->p == NULL )
86
87.4k
    {
87
87.4k
        s->p = s->p_start;
88
87.4k
        ctx->i_bytepos = 1;
89
87.4k
        return 1;
90
87.4k
    }
91
92
1.78M
    if( s->p >= s->p_end )
93
57.9k
        return 0;
94
95
1.72M
    s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count );
96
1.72M
    ctx->i_bytepos += i_count;
97
1.72M
    return i_count;
98
1.78M
}
99
100
static size_t hxxx_bsfw_byte_pos_ep3b( const bs_t *s )
101
1.88M
{
102
1.88M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
103
1.88M
    return ctx->i_bytepos;
104
1.88M
}
hxxx_sei.c:hxxx_bsfw_byte_pos_ep3b
Line
Count
Source
101
1.88M
{
102
1.88M
    struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv;
103
1.88M
    return ctx->i_bytepos;
104
1.88M
}
Unexecuted instantiation: h264_nal.c:hxxx_bsfw_byte_pos_ep3b
Unexecuted instantiation: h264_slice.c:hxxx_bsfw_byte_pos_ep3b
Unexecuted instantiation: hevc_nal.c:hxxx_bsfw_byte_pos_ep3b
Unexecuted instantiation: vc1.c:hxxx_bsfw_byte_pos_ep3b
105
106
static const bs_byte_callbacks_t hxxx_bsfw_ep3b_callbacks =
107
{
108
    hxxx_bsfw_byte_forward_ep3b,
109
    hxxx_bsfw_byte_pos_ep3b,
110
};