Coverage Report

Created: 2025-07-18 08:04

/src/vlc/modules/codec/webvtt/helpers.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * helpers.h: WEBVTT helper
3
 *****************************************************************************
4
 * Copyright (C) 2020 VideoLabs, 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 WEBVTT_HELPERS_H
21
#define WEBVTT_HELPERS_H
22
23
#ifdef __cplusplus
24
extern "C" {
25
#endif /* __cplusplus */
26
27
struct webvtt_cueelements_s
28
{
29
    struct
30
    {
31
        const uint8_t *p_data;
32
        size_t i_data;
33
    } iden, sttg, payl;
34
};
35
36
static inline size_t
37
WEBVTT_Pack_CueElementsGetNewSize( const struct webvtt_cueelements_s *els )
38
0
{
39
0
    return 8 +
40
0
           (els->iden.i_data ? (els->iden.i_data + 8) : 0) +
41
0
           (els->sttg.i_data ? (els->sttg.i_data + 8) : 0) +
42
0
           els->payl.i_data + 8;
43
0
}
44
45
static inline void
46
WEBVTT_Pack_CueElements( const struct webvtt_cueelements_s *els,
47
                         uint8_t *p_dst )
48
0
{
49
0
    size_t i_total = WEBVTT_Pack_CueElementsGetNewSize( els );
50
    /* root container */
51
0
    SetDWBE( &p_dst[0], i_total );
52
0
    memcpy(  &p_dst[4], "vttc", 4 );
53
0
    p_dst += 8;
54
    /* id child */
55
0
    if( els->iden.i_data )
56
0
    {
57
0
        SetDWBE( &p_dst[0], 8 + els->iden.i_data );
58
0
        memcpy(  &p_dst[4], "iden", 4 );
59
0
        memcpy(  &p_dst[8], els->iden.p_data, els->iden.i_data );
60
0
        p_dst += 8 + els->iden.i_data;
61
0
    }
62
    /* cue settings child */
63
0
    if( els->sttg.i_data )
64
0
    {
65
0
        SetDWBE( &p_dst[0], 8 + els->sttg.i_data );
66
0
        memcpy(  &p_dst[4], "sttg", 4 );
67
0
        memcpy(  &p_dst[8], els->sttg.p_data, els->sttg.i_data );
68
0
        p_dst += 8 + els->sttg.i_data;
69
0
    }
70
    /* text */
71
0
    SetDWBE( &p_dst[0], 8 + els->payl.i_data );
72
0
    memcpy(  &p_dst[4], "payl", 4 );
73
0
    memcpy(  &p_dst[8], els->payl.p_data, els->payl.i_data );
74
0
}
75
76
#ifdef __cplusplus
77
}
78
#endif /* __cplusplus */
79
80
#endif