Skip to content

Commit c9fc8ee

Browse files
wmdebritoWagner Brito
authored andcommitted
[mpegts] Enlarge H.264 SPS/PPS raw_data buffers to 256 bytes
The per-NAL raw_data buffers used to build the codec extra data were only 64 bytes. Some SPS with full VUI/HRD parameters can exceed that (e.g. Wowza-originated HLS), so the SPS was silently dropped (raw_data_size reset to 0) and the H.264 extra data ended up empty. Kodi then rejects the video stream with "Codec id 27 require extradata" and disables it, leaving an audio-only stream that immediately hits EOF. Increase the SPS/PPS raw_data buffers to 256 bytes so that for some large SPS extra data is built correctly.
1 parent 4532955 commit c9fc8ee

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

lib/mpegts/mpegts/ES_h264.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,30 @@ void ES_h264::Parse(STREAM_PKT* pkt)
158158
{
159159
if (m_streamData.sps[0].raw_data_size)
160160
{
161-
uint8_t *ed(stream_info.extra_data);
162-
stream_info.extra_data_size = 4 + m_streamData.sps[0].raw_data_size;
163-
ed[0] = ed[1] = ed[2] = 0, ed[3] = 1, ed += 4;
164-
memcpy(ed, m_streamData.sps[0].raw_data, m_streamData.sps[0].raw_data_size), ed += m_streamData.sps[0].raw_data_size;
161+
uint8_t* ed = stream_info.extra_data;
162+
const uint8_t* edEnd = stream_info.extra_data + sizeof(stream_info.extra_data);
163+
stream_info.extra_data_size = 0;
164+
165+
// Append a parameter set NAL (SPS/PPS) as Annex B, bounded by the
166+
// destination buffer to avoid overflowing stream_info.extra_data
167+
auto appendNal = [&](const uint8_t* src, size_t n) -> bool {
168+
if (ed + 4 + n > edEnd)
169+
{
170+
DBG(DEMUX_DBG_INFO, "H.264: stream_info.extra_data too small! %u\n",
171+
static_cast<unsigned int>(stream_info.extra_data_size + 4 + n));
172+
return false;
173+
}
174+
ed[0] = ed[1] = ed[2] = 0, ed[3] = 1, ed += 4;
175+
memcpy(ed, src, n), ed += n;
176+
stream_info.extra_data_size += 4 + n;
177+
return true;
178+
};
179+
180+
appendNal(m_streamData.sps[0].raw_data, m_streamData.sps[0].raw_data_size);
165181
for (int i = 0; i < 256; ++i)
166182
{
167183
if (m_streamData.pps[i].raw_data_size)
168-
{
169-
ed[0] = ed[1] = ed[2] = 0, ed[3] = 1, ed += 4;
170-
memcpy(ed, m_streamData.pps[i].raw_data, m_streamData.pps[i].raw_data_size), ed += m_streamData.pps[i].raw_data_size;
171-
stream_info.extra_data_size += 4 + m_streamData.pps[i].raw_data_size;
172-
}
184+
appendNal(m_streamData.pps[i].raw_data, m_streamData.pps[i].raw_data_size);
173185
}
174186
}
175187
else

lib/mpegts/mpegts/ES_h264.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ namespace TSDemux
2828
int log2_max_pic_order_cnt_lsb;
2929
int delta_pic_order_always_zero_flag;
3030
int raw_data_size;
31-
uint8_t raw_data[64];
31+
uint8_t raw_data[256];
3232
} sps[256];
3333

3434
struct PPS
3535
{
3636
uint8_t sps;
3737
uint8_t pic_order_present_flag;
3838
uint16_t raw_data_size;
39-
uint8_t raw_data[64];
39+
uint8_t raw_data[256];
4040
} pps[256];
4141

4242
struct VCL_NAL

lib/mpegts/mpegts/elementaryStream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace TSDemux
6161
int bit_rate;
6262
int bits_per_sample;
6363
bool interlaced;
64-
uint8_t extra_data[512];
64+
uint8_t extra_data[1024];
6565
int extra_data_size;
6666
};
6767

0 commit comments

Comments
 (0)