Coverage Report

Created: 2025-07-23 08:18

/src/x265/source/encoder/sei.cpp
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
* Copyright (C) 2013-2020 MulticoreWare, Inc
3
*
4
* Authors: Steve Borho <steve@borho.org>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 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 General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
19
*
20
* This program is also available under a commercial proprietary license.
21
* For more information, contact us at license @ x265.com.
22
*****************************************************************************/
23
24
#include "common.h"
25
#include "bitstream.h"
26
#include "slice.h"
27
#include "sei.h"
28
29
using namespace X265_NS;
30
31
/* x265's identifying GUID */
32
const uint8_t SEIuserDataUnregistered::m_uuid_iso_iec_11578[16] = {
33
    0x2C, 0xA2, 0xDE, 0x09, 0xB5, 0x17, 0x47, 0xDB,
34
    0xBB, 0x55, 0xA4, 0xFE, 0x7F, 0xC2, 0xFC, 0x4E
35
};
36
37
/* marshal a single SEI message sei, storing the marshalled representation
38
* in bitstream bs */
39
void SEI::writeSEImessages(Bitstream& bs, const SPS& sps, NalUnitType nalUnitType, NALList& list, int isNested, int layer)
40
0
{
41
0
    if (!isNested)
42
0
        bs.resetBits();
43
44
0
    BitCounter counter;
45
0
    m_bitIf = &counter;
46
0
    writeSEI(sps);
47
    /* count the size of the payload and return the size in bits */
48
0
    X265_CHECK(0 == (counter.getNumberOfWrittenBits() & 7), "payload unaligned\n");
49
0
    uint32_t payloadData = counter.getNumberOfWrittenBits() >> 3;
50
51
    // set bitstream
52
0
    m_bitIf = &bs;
53
54
0
    uint32_t payloadType = m_payloadType;
55
0
    for (; payloadType >= 0xff; payloadType -= 0xff)
56
0
        WRITE_CODE(0xff, 8, "payload_type");
57
0
    WRITE_CODE(payloadType, 8, "payload_type");
58
59
0
    uint32_t payloadSize = payloadData;
60
0
    for (; payloadSize >= 0xff; payloadSize -= 0xff)
61
0
        WRITE_CODE(0xff, 8, "payload_size");
62
0
    WRITE_CODE(payloadSize, 8, "payload_size");
63
64
    // virtual writeSEI method, write to bs 
65
0
    writeSEI(sps);
66
67
0
    if (!isNested)
68
0
    {
69
0
        if (nalUnitType != NAL_UNIT_UNSPECIFIED)
70
0
            bs.writeByteAlignment();
71
0
        list.serialize(nalUnitType, bs, layer, (1 + (nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N)));
72
0
    }
73
0
}
74
75
void SEI::writeByteAlign()
76
0
{
77
    // TODO: expose bs.writeByteAlignment() as virtual function
78
0
    if (m_bitIf->getNumberOfWrittenBits() % 8 != 0)
79
0
    {
80
0
        WRITE_FLAG(1, "bit_equal_to_one");
81
0
        while (m_bitIf->getNumberOfWrittenBits() % 8 != 0)
82
0
        {
83
0
            WRITE_FLAG(0, "bit_equal_to_zero");
84
0
        }
85
0
    }
86
0
}
87
88
void SEI::setSize(uint32_t size)
89
0
{
90
0
    m_payloadSize = size;
91
0
}
92
93
/* charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" */
94
95
char* SEI::base64Decode(char encodedString[], int base64EncodeLength, char* decodedString)
96
0
{
97
0
    int i, j, k = 0;
98
    // stores the bitstream
99
0
    int bitstream = 0;
100
    // countBits stores the current number of bits in bitstream
101
0
    int countBits = 0;
102
103
0
    for (i = 0; i < base64EncodeLength; i += 4)
104
0
    {
105
0
        bitstream = 0;
106
0
        countBits = 0;
107
108
0
        for (j = 0; j < 4; j++)
109
0
        {
110
0
            if (encodedString[i + j] != '=')
111
0
            {
112
0
                int value = 0;
113
0
                if (encodedString[i + j] >= 'A' && encodedString[i + j] <= 'Z')
114
0
                    value = encodedString[i + j] - 'A';
115
0
                else if (encodedString[i + j] >= 'a' && encodedString[i + j] <= 'z')
116
0
                    value = encodedString[i + j] - 'a' + 26;
117
0
                else if (encodedString[i + j] >= '0' && encodedString[i + j] <= '9')
118
0
                    value = encodedString[i + j] - '0' + 52;
119
0
                else if (encodedString[i + j] == '+')
120
0
                    value = 62;
121
0
                else if (encodedString[i + j] == '/')
122
0
                    value = 63;
123
0
                else
124
0
                    value = 0;
125
126
0
                bitstream = (bitstream << 6) | value;
127
0
                countBits += 6;
128
0
            }
129
0
        }
130
131
0
        while (countBits >= 8)
132
0
        {
133
0
            countBits -= 8;
134
0
            decodedString[k++] = (bitstream >> countBits) & 0xFF;
135
0
        }
136
0
    }
137
138
0
    if (k < base64EncodeLength)
139
0
    {
140
0
        decodedString[k] = '\0';
141
0
    }
142
143
0
    return decodedString;
144
0
}
145