Coverage Report

Created: 2026-12-01 08:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/access/dtv/en50221_capmt.h
Line
Count
Source
1
/*****************************************************************************
2
 * en50221_capmt.h:
3
 *****************************************************************************
4
 * Copyright (C) 2016 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
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA    02111, USA.
19
 *****************************************************************************/
20
#ifndef EN50221_CAPMT_H
21
#define EN50221_CAPMT_H
22
23
typedef struct
24
{
25
    uint8_t  i_stream_type;
26
    uint16_t i_es_pid;
27
    size_t   i_descriptors;
28
    uint8_t *p_descriptors;
29
} en50221_capmt_es_info_t;
30
31
typedef struct en50221_capmt_info_s
32
{
33
    uint8_t  i_version;
34
    uint16_t i_program_number;
35
    size_t   i_program_descriptors;
36
    uint8_t *p_program_descriptors;
37
    size_t   i_es_count;
38
    en50221_capmt_es_info_t *p_es;
39
} en50221_capmt_info_t;
40
41
static inline void en50221_capmt_CADescriptorAppend( uint8_t **p_desc, size_t *pi_desc,
42
                                                     const uint8_t *p_data, uint8_t i_data )
43
68
{
44
68
    uint8_t *p_realloc = realloc( *p_desc, *pi_desc + i_data + 2 );
45
68
    if( likely(p_realloc) )
46
68
    {
47
68
        *p_desc = p_realloc;
48
68
        p_realloc[*pi_desc] = 0x09;
49
68
        p_realloc[*pi_desc + 1] = i_data;
50
68
        memcpy( &p_realloc[*pi_desc + 2], p_data, i_data );
51
68
        *pi_desc = *pi_desc + i_data + 2;
52
68
    }
53
68
}
54
55
static inline en50221_capmt_es_info_t *en50221_capmt_EsAdd( en50221_capmt_info_t *p_en,
56
                                                            uint8_t i_stream_type,
57
                                                            uint16_t i_es_pid )
58
132k
{
59
132k
    en50221_capmt_es_info_t *p_realloc = realloc( p_en->p_es, sizeof(en50221_capmt_es_info_t) *
60
132k
                                                              (p_en->i_es_count + 1) );
61
132k
    if( likely(p_realloc) )
62
132k
    {
63
132k
        p_en->p_es = p_realloc;
64
132k
        en50221_capmt_es_info_t *p_es = &p_en->p_es[ p_en->i_es_count++ ];
65
132k
        p_es->i_es_pid = i_es_pid;
66
132k
        p_es->i_stream_type = i_stream_type;
67
132k
        p_es->i_descriptors = 0;
68
132k
        p_es->p_descriptors = NULL;
69
132k
        return p_es;
70
132k
    }
71
0
    return NULL;
72
132k
}
73
74
static inline void en50221_capmt_AddESCADescriptor( en50221_capmt_es_info_t *p_es,
75
                                                    const uint8_t *p_data, uint8_t i_data )
76
0
{
77
0
    en50221_capmt_CADescriptorAppend( &p_es->p_descriptors, &p_es->i_descriptors,
78
0
                                       p_data, i_data );
79
0
}
80
81
static inline void en50221_capmt_AddCADescriptor( en50221_capmt_info_t *p_en,
82
                                                  const uint8_t *p_data, uint8_t i_data )
83
68
{
84
68
    en50221_capmt_CADescriptorAppend( &p_en->p_program_descriptors,
85
68
                                      &p_en->i_program_descriptors,
86
68
                                       p_data, i_data );
87
68
}
88
89
static inline void en50221_capmt_Delete( en50221_capmt_info_t *p_en )
90
45.0k
{
91
45.0k
    free( p_en->p_program_descriptors );
92
177k
    for( size_t i=0; i<p_en->i_es_count; i++ )
93
132k
        free( p_en->p_es[i].p_descriptors );
94
45.0k
    free( p_en->p_es );
95
45.0k
    free( p_en );
96
45.0k
}
97
98
static inline en50221_capmt_info_t * en50221_capmt_New( uint8_t i_version, uint16_t i_program )
99
45.0k
{
100
45.0k
    en50221_capmt_info_t *p_en = malloc( sizeof(*p_en) );
101
45.0k
    if( likely(p_en) )
102
45.0k
    {
103
45.0k
        p_en->i_version = i_version;
104
45.0k
        p_en->i_program_number = i_program;
105
45.0k
        p_en->i_program_descriptors = 0;
106
45.0k
        p_en->p_program_descriptors = NULL;
107
45.0k
        p_en->i_es_count = 0;
108
45.0k
        p_en->p_es = NULL;
109
45.0k
    }
110
45.0k
    return p_en;
111
45.0k
}
112
113
static inline en50221_capmt_info_t * en50221_capmt_Duplicate( const en50221_capmt_info_t *p_src )
114
0
{
115
0
    en50221_capmt_info_t *p_en = en50221_capmt_New( p_src->i_version, p_src->i_program_number );
116
0
    if( !p_en )
117
0
        return NULL;
118
0
    p_en->p_program_descriptors = calloc( p_src->i_program_descriptors, sizeof(uint8_t) );
119
0
    if( !p_en->p_program_descriptors )
120
0
        goto error;
121
0
    memcpy( p_en->p_program_descriptors, p_src->p_program_descriptors, p_src->i_program_descriptors );
122
0
    p_en->i_program_descriptors = p_src->i_program_descriptors;
123
0
124
0
    p_en->p_es = calloc( p_src->i_es_count, sizeof(en50221_capmt_es_info_t) );
125
0
    if( !p_en->p_es )
126
0
        goto error;
127
0
    memcpy( p_en->p_es, p_src->p_es, p_src->i_es_count );
128
0
    p_en->i_es_count = p_src->i_es_count;
129
0
130
0
    for( size_t i=0; i<p_en->i_es_count; i++ )
131
0
    {
132
0
        p_en->p_es[i].p_descriptors = malloc( p_src->p_es[i].i_descriptors );
133
0
        if( !p_en->p_es[i].p_descriptors )
134
0
        {
135
0
            p_en->p_es[i].i_descriptors = 0;
136
0
            continue;
137
0
        }
138
0
        memcpy( p_en->p_es[i].p_descriptors, p_src->p_es[i].p_descriptors, p_src->p_es[i].i_descriptors );
139
0
        p_en->p_es[i].i_descriptors = p_src->p_es[i].i_descriptors;
140
0
    }
141
0
142
0
    return p_en;
143
0
144
0
error:
145
0
    en50221_capmt_Delete( p_en );
146
0
    return NULL;
147
0
}
148
149
#endif