Skip to content

[mpegts] Enlarge H.264 SPS/PPS raw_data buffers to 256 bytes#2086

Merged
CastagnaIT merged 1 commit into
xbmc:Piersfrom
wmdebrito:fix/mpegts-h264-sps-extradata-increase-buffer
Jul 1, 2026
Merged

[mpegts] Enlarge H.264 SPS/PPS raw_data buffers to 256 bytes#2086
CastagnaIT merged 1 commit into
xbmc:Piersfrom
wmdebrito:fix/mpegts-h264-sps-extradata-increase-buffer

Conversation

@wmdebrito

@wmdebrito wmdebrito commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

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.

Also extra_data was increase from 512 to 1024 to accommodate rare situations.
NAL buffers are now 256 bytes each, so a single legitimate SPS+PPS can be up to 4+255+4+255 = 518 bytes. With only 512, the guard I added would correctly refuse to overflow — but it would then drop a valid PPS, silently reintroducing a decode failure. 1024 ensures the destination can hold whatever the 256-byte NAL buffers can legitimately produce. The guard prevents the crash; the 1024 prevents truncation.

Motivation and context

Fix some streams that are not playing due to small buffer size.

How has this been tested?

Tested on Kodi 21 with a custom IA build. The falling stream was now able to be played. No regression on other streams

Screenshots (if appropriate):

Stream: https://streamtv.novotempo.com/CDN-TV-PT/smil:tvnovotempo.smil/playlist.m3u8
12:07:59.315 CDVDDemuxClient::RequestStream(): added/updated stream 1001 with codec_id 27
12:07:59.315 CDVDDemuxClient::RequestStream(): added/updated stream 1002 with codec_id 86018
12:07:59.316 Opening stream: 1001 source: 256
12:07:59.932 [WHITELIST] Searching the whitelist for: width: 1280, height: 720, fps: 29.970, 3D: false
12:07:59.979 error: OpenStream: Codec id 27 require extradata.
12:07:59.979 warning: OpenStream - Unsupported stream 1001. Stream disabled.
12:07:59.979 Opening stream: 1002 source: 256
12:08:00.004 CDVDAudioCodecFFmpeg::Open() Successful opened audio decoder aac
12:08:00.034 Process - eof reading from demuxer

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • None of the above (please explain below)

Checklist:

  • I have read the Contributing document
  • My code follows the Code Guidelines of this project
  • My change requires a change to the Wiki documentation
  • I have updated the documentation accordingly

@kodiai

kodiai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Decision: APPROVE

Issues: none

Evidence:

  • Review prompt covered 1 changed file.
Review Details
  • Review plan: ready hash=10a45c29a9f3 route=tiny-diff task=review.small-diff files=1 lines=4(local-diff) budget=na/753s gates=3/3 publish=canonical-visible-surface graph=skipped candidates=preferred doctrine=disabled/0/0/0 reasons=disabled

  • Review reducer: ready input=2 kept=2 suppressed=0 rewritten=0 deprioritized=0 lowConfidence=0 auditEvents=0 severityDemoted=0 graphValidated=0 graphUncertain=0 doctrine=disabled/0/0/0 reasons=disabled

  • Review candidates: shadow recorded=2 rejected=0 errors=0 artifact=present repo=xbmc-inputstream.adaptive pr=2086 key=kodiai-review-output:v1:inst-109141824:xbmc-inputstream.adaptive:pr-2086:action- delivery=b9e697d0-740d-11f1-9146-de0c4dc9e010

  • Review candidate publication: mode=blocked approved=2 rewritten=0 publishable=0 nonPublishable=2 fixBlocked=2 published=0 directFallback=0 reasons=fix-eligibility-blocked movedToDetails=0 detailsOmitted=0 buckets=blocked:2:fix-eligibility-blocked+missing-replacement

  • M072 candidate publication bridge: status=denied; bridgeVersion=candidate-publication-bridge.v1; bridgeId=candidate-publication-record:0748298f8284ca7c50fa78dbfe07e103; recordKey=candidate-publication-record:0748298f8284ca7c50fa78dbfe07e103; correlationKey=candidate-publication-bridge:40cd795b8da5266805fff00ae29dbab8; source=review-handler-publication; candidateRef=candidate-publication-summary-e63c7f55; verification=none; counts=candidateCount:0,evidenceCount:0,verifiedCount:0,partiallyVerifiedCount:0,unverifiedCount:0,disprovenCount:0,publicationEligibleCount:0,malformedRecordCount:0,unsafeInputFieldCount:0; reasons=no-evidence,publication-ineligible; malformed=none; presence=deliveryId:y,reviewOutputKey:y,upstreamCorrelationKey:y,policyCorrelationKey:y; handoffOwner=available; redaction=privateOnly:y,rawPayloads:n,publicationFields:n,evidencePayloads:n,githubCommentBody:n,reducerRawPayload:n,discardedRawPayload:n,discardedPublicationFields:n,discardedEvidencePayloads:n

  • Review finding lifecycle: status=normalized; counts=input:2,recorded:2,rejected:0,unsafeInputFields:0; correlation=repo:y,pull:y,reviewOutputKey:y,deliveryId:y,commit:y; statuses=detected:2,open:2,suggested:0,validated:0,revalidated:0,resolved:0,blocked:0,degraded:0; severity=critical:1,major:0,medium:1,minor:0; actionability=actionable:0,needs-human-review:2,needs-reproduction:0,blocked:0,not-actionable:0; reasons=automatic-detected,automatic-open,automatic-review; rejected=none; redaction=privateOnly:y,rawPrompts:n,rawModelOutput:n,candidateBodies:n,toolPayloads:n,secretLike:n,diffs:n,unboundedArrays:n,unsafeFields:0

  • Review validation truth: status=normalized; counts=detected:2,suggested:0,validated:0,revalidated:0,resolved:0,blocked:0,degraded:0,open:2,uncertain:0,inputFindings:2,unsafeInputFields:0; evidence=fresh:0,stale:0,missingValidation:2,missingRevalidation:2; reasons=validation-missing:2; refs=rfl-0423d736430a2516:open:validation-missing:fix:n:validation:n:revalidation:n,rfl-e34a53a997c12a61:open:validation-missing:fix:n:validation:n:revalidation:n; correlation=reviewOutputKey:y,deliveryId:y; redaction=privateOnly:y,rawPrompts:n,rawModelOutput:n,candidateBodies:n,replacementText:n,toolPayloads:n,secretLike:n,diffs:n,unboundedArrays:n,unsafeFields:0

  • Files reviewed: 1

  • Findings: 0 critical, 0 major, 0 medium, 0 minor

  • Lines changed: +2 -2

  • Profile: strict (auto, lines changed: 4)

  • Contributor experience: coarse-fallback (using coarse fallback signals only)

  • Shadow specialist: lane=docs-config-truth status=skipped reason=no-operator-truth-paths candidateCount=0 decisionCount=0 decisionCounts=candidate:0,duplicate:0,disagreement:0,dismissed:0,unclassifiable:0 duplicateCount=0 disagreementCount=0 dismissedCount=0 unclassifiableCount=0 truncatedCandidateCount=0 metricAvailability=token:n,cost:n,latency:n visiblePublicationDenied=true approvalPublicationDenied=true privateOnly=true shadowOnly=true redacted=raw:n,publication:n,approval:n,unsafe:0 correlationKey=060de31255849133 deliveryId=b9e697d0-740d-11f1-9146-de0c4dc… reviewOutputKey=kodiai-review-output:v1:inst-10…

  • Review completed: 2026-06-29T23:01:47.648Z

  • Total wall-clock: 5m 34s

  • Phase timings:

    • queue wait: 0ms
    • workspace preparation: 769ms
    • retrieval/context assembly: 3.9s
    • executor handoff: 46s
    • remote runtime: 4m 38s
    • publication: 2.5s
  • Tokens: 126 in / 12,250 out | 0.4014

  • Keyword parsing: No keywords detected

  • Budget behavior: complete (within-budget).

  • Prompt budget: 6 sections, 0 trimmed, 0 bypassed, 0 trimmed tokens.

  • Cache behavior: 2 observations, 1 hits, 1 misses, 0 degraded, 0 bypassed.

  • Continuation behavior: 0 observations, 0 compacted, 0 fallback, 0 degraded, 0 bypassed.

@wmdebrito wmdebrito marked this pull request as draft June 30, 2026 00:01
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.
@wmdebrito wmdebrito force-pushed the fix/mpegts-h264-sps-extradata-increase-buffer branch from 9ae1d8e to c9fc8ee Compare June 30, 2026 02:30
@wmdebrito wmdebrito marked this pull request as ready for review June 30, 2026 03:14
Comment on lines +64 to 65
uint8_t extra_data[1024];
int extra_data_size;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a better change should be replace both with a std::vector<uint8_t>
so that the size is not hardcoded but dynamic, you will solve the problem at the root
but its fine anyway if you want to keep it like this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a good idea, I will create it in another PR to test it better.

@CastagnaIT CastagnaIT added Type: Fix non-breaking change which fixes an issue v22 Piers labels Jun 30, 2026

@CastagnaIT CastagnaIT left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the fix, please backport

@CastagnaIT CastagnaIT merged commit e711237 into xbmc:Piers Jul 1, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport: Done Type: Fix non-breaking change which fixes an issue v22 Piers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants