Playback system
Kodi's playback system turns a media item into an active player and gives the rest of the application one common way to start, inspect, control, and finish playback. It separates player choice from player behavior so built-in, external, remote, and game players can follow the same application flow while keeping their playback work in their own engines. See Playback engines for the concrete engines.
Playback architecture
The playback architecture has three main roles. CApplicationPlayer owns the active player from the application's view. IPlayer defines the common contract for player setup, media access, controls, stream changes, rendering, and session state. CPlayerCoreFactory maps a player name to a configured player and chooses that name for a media item. These roles keep user actions and application state independent of the selected engine.
References: xbmc/…/ApplicationPlayer.h• L34-71, xbmc/…/IPlayer.h• L30-47, xbmc/…/IPlayer.h• L88-107, xbmc/…/IPlayer.h• L232-310, xbmc/…/PlayerCoreFactory.h• L28-53
The active player reports its media traits and supported controls. Kodi uses this information to classify the session as audio, video, game, radio, or live playback and to show only controls that the player can support. The contract also reports streaming, rendering, visible overlay, game-agent, and disc state when those concepts apply. References: xbmc/…/IPlayer.h• L99-125, xbmc/…/IPlayer.h• L192-208, xbmc/…/IPlayer.h• L216-262, xbmc/…/IPlayer.h• L268-310, xbmc/…/ApplicationPlayer.cpp• L225-303
Video decode sessions
A video decode session is a short-lived path for opening a media item, finding its first usable video stream, and decoding a picture at a requested time. Kodi uses the same path for thumbnail extraction, stream detail inspection, and content-geometry measurement, so these consumers share one view of which video stream and picture formats are usable. References: xbmc/…/VideoDecodeSession.h• L24-49, xbmc/…/VideoDecodeSession.cpp• L24-81, xbmc/…/DVDFileInfo.cpp• L209-245, xbmc/…/DVDFileInfo.cpp• L359-392, xbmc/…/VideoFileGeometry.cpp• L217-263, xbmc/…/TestContentGeometrySampler.cpp• L73-117
The session ignores attached pictures and keeps the first real video stream as the decode target. It seeks to the requested time and accepts the first decoded picture that is not marked as dropped. A bounded number of codec requests prevents a filter that holds a frame back from keeping metadata or thumbnail work active forever. References: xbmc/…/VideoDecodeSession.cpp• L46-79, xbmc/…/VideoDecodeSession.cpp• L84-130
Video decoding
Video decoding turns demuxed packets into timed pictures that the player can queue and the renderer can display. The common codec boundary lets Kodi use software or hardware decoding while keeping picture timing, frame status, color data, HDR data, and stream-specific metadata available to later playback stages. References: xbmc/…/DVDVideoCodec.h• L44-80, xbmc/…/DVDVideoCodec.h• L125-180, xbmc/…/DVDVideoCodecFFmpeg.cpp• L591-678, xbmc/…/DVDVideoCodecFFmpeg.cpp• L681-947
The FFmpeg video path selects a hardware decoder when the process reports a usable format and falls back to software decoding when that path fails. It can also apply the requested deinterlacing, scaling, or rotation before it returns a picture. Decoder controls allow the player to drain, drop, reset, or reopen the path as playback speed and hardware state change. References: xbmc/…/DVDVideoCodecFFmpeg.cpp• L253-312, xbmc/…/DVDVideoCodecFFmpeg.cpp• L505-559, xbmc/…/DVDVideoCodecFFmpeg.cpp• L978-1018, xbmc/…/DVDVideoCodecFFmpeg.cpp• L1505-1536
Browser video decoding
The WASM video path uses the browser's WebCodecs service for supported video streams. It builds the browser codec description from the stream hints, sends encoded packets through a bounded asynchronous bridge, and returns timed frames to Kodi with their display and color data. H.264, HEVC, VP8, VP9, and AV1 are supported when the browser accepts the matching configuration. References: xbmc/…/DVDVideoCodecWebCodecs.cpp• L274-305, xbmc/…/DVDVideoCodecWebCodecsBitstream.cpp• L410-452, xbmc/…/CMakeLists.txt• L40-46
The bridge keeps browser decoder work on the browser main thread while Kodi waits on shared state for configuration, output frames, copies, and errors. A frame can stay in the browser and move into a WebGL texture, or it can be copied into Kodi memory when direct texture import is not available. Repeated decoder failure first causes decoder recovery at the next key frame and then falls back to FFmpeg. References: xbmc/…/DVDVideoCodecWebCodecsBridge.h• L11-23, xbmc/…/DVDVideoCodecWebCodecs.cpp• L307-364, xbmc/…/DVDVideoCodecWebCodecs.cpp• L430-481, xbmc/…/DVDVideoCodecWebCodecs.cpp• L1003-1055, xbmc/…/webcodecs_bridge.js• L469-735
WebCodecs needs a key frame that can be decoded without earlier packets. Kodi checks the encoded bitstream instead of relying only on the demuxer's key-frame flag, and it resets the browser decoder after seek or flush before it accepts the next key frame. References: xbmc/…/DVDVideoCodecWebCodecsBitstream.cpp• L230-407, xbmc/…/DVDVideoCodecWebCodecsBitstream.cpp• L480-505, xbmc/…/DVDVideoCodecWebCodecs.cpp• L484-503, xbmc/…/webcodecs_bridge.js• L643-681
The following diagram shows how the WASM browser path turns encoded packets into pictures for Kodi.
flowchart LR
Packet[Demuxed video packet] --> Config[Build browser codec configuration]
Config --> Decoder[Browser VideoDecoder]
Packet --> Key[Classify usable key frame]
Key --> Decoder
Decoder --> Shared[Shared frame state]
Shared --> Texture[Import VideoFrame as WebGL texture]
Shared --> Copy[Copy frame into Kodi memory]
Texture --> Picture[Timed Kodi picture]
Copy --> Picture
Decoder --> Failure{Decoder keeps failing?}
Failure -->|Yes| Recover[Reset at next key frame]
Recover --> Decoder
Recover -->|Recovery limit reached| FFmpeg[FFmpeg fallback]
CProcessInfo is the shared capability and status boundary between decoding, rendering, and the playback state cache. On Windows, CProcessInfoWin10 advertises the formats that the renderer can accept and requests Dolby Vision metadata only when the user setting and system effect support both allow it. On WASM, CProcessInfoWasm registers the browser process control and supplies the platform's fallback deinterlace method.
References: xbmc/…/ProcessInfo.h• L34-67, xbmc/…/ProcessInfo.h• L93-100, xbmc/…/ProcessInfoWin10.cpp• L31-57, xbmc/…/ProcessInfoWasm.h• L13-20, xbmc/…/ProcessInfoWasm.cpp• L11-24
Content geometry measurement
Content geometry measurement samples decoded pictures to find the visible picture rectangle inside coded video. Kodi uses it for files that can be opened without a full player, while it refuses unsuitable remote streams and reports no result when decoding is not reliable. References: xbmc/…/VideoFileGeometry.h• L26-54, xbmc/…/VideoFileGeometry.cpp• L202-215, xbmc/…/VideoFileGeometry.cpp• L217-307
The measurement keeps the coded picture size separate from the detected content rectangle. It also respects color range and stereoscopic layout from both decoded pictures and stream hints, so a side-by-side source is measured as one view rather than as one wide picture. The sampler can add more points when the first result is uncertain and can discard a cancelled or unreadable scan. References: xbmc/…/VideoFileGeometry.cpp• L40-135, xbmc/…/VideoFileGeometry.cpp• L154-199, xbmc/…/VideoFileGeometry.cpp• L263-307, xbmc/…/TestContentGeometrySampler.cpp• L103-178
Video frame rendering
Video frame rendering turns decoded pictures into display output while adapting to the pixel format and features of the graphics device. Windows renderers can use decoder textures directly when supported or use a compatible copy path, then apply color conversion, output precision, HDR handling, and display geometry before the frame reaches the display. References: xbmc/…/RendererBase.cpp• L218-252, xbmc/…/RendererBase.cpp• L265-342, xbmc/…/RendererShaders.cpp• L82-129, xbmc/…/RendererShaders.cpp• L146-247
The WASM WebCodecs renderer uses one texture for each queued picture and imports browser frames in render order. The browser provides the frame's RGB texture, while Kodi keeps display geometry, aspect handling, rotation, opacity, and the selected nearest or linear filter. This path does not offer Kodi tone mapping because the browser performs the color conversion before Kodi sees the frame. References: xbmc/…/RendererWebCodecs.h• L16-20, xbmc/…/RendererWebCodecs.cpp• L33-87, xbmc/…/RendererWebCodecs.cpp• L160-187, xbmc/…/RendererWebCodecs.cpp• L210-255, xbmc/…/CMakeLists.txt• L51-54
High-quality scaling is an optional display step. Kodi enables it only when the selected method and device support it, and its automatic choice favors suitable low-resolution upscaling within the configured frame-rate limit. Orientation disables this path. If the preferred scaler cannot be built, the renderer tries a simpler path and then returns to normal output rather than using an incomplete effect. References: xbmc/…/RendererHQ.h• L12-37, xbmc/…/RendererHQ.cpp• L24-47, xbmc/…/RendererHQ.cpp• L55-149
The renderer can reuse a completed scaled picture when the output target and stereo position still match. It must discard that cached result when the output changes or when a stereo mode cannot safely use the cache. This keeps scaling work separate from the final copy into the active display target. References: xbmc/…/RendererHQ.cpp• L151-229, xbmc/…/RendererHQ.h• L29-37
HDR output
HDR output follows the source picture's color and light metadata. The Windows renderer can switch between SDR, HDR10, HLG, and Dolby Vision output, and it restores the display state when playback ends. Dolby Vision output requires an allowed display mode, a supported display, and a frame with Dolby Vision metadata. References: xbmc/…/RendererBase.cpp• L31-50, xbmc/…/RendererBase.cpp• L166-198, xbmc/…/RendererBase.cpp• L645-793
On Windows Store systems, the shader renderer can send a Dolby Vision picture and its reference processing unit (RPU) metadata through the system Dolby Vision effect. The effect converts the decoder's video into display-referred RGB and uses the display color range when HDR output is active. If the effect cannot open or process a frame, the renderer disables that path and returns to its normal video conversion path. References: xbmc/…/DolbyVisionEffect.h• L26-59, xbmc/…/DolbyVisionEffect.cpp• L218-284, xbmc/…/DolbyVisionEffect.cpp• L334-445, xbmc/…/RendererShaders.cpp• L117-125, xbmc/…/RendererShaders.cpp• L265-369
The following diagram shows how decoded video becomes display output.
flowchart LR
Picture[Decoded picture] --> Format{Device supports format?}
Format -->|Yes| Native[Use compatible picture path]
Format -->|No| Copy[Copy to supported format]
Native --> Color[Convert color and apply display settings]
Copy --> Color
Color --> HDR{HDR or Dolby Vision path?}
HDR -->|Yes| HDRProcess[Apply display HDR processing]
HDR -->|No| SDR[Keep standard output]
HDRProcess --> Scale{High-quality scaling usable?}
SDR --> Scale
Scale -->|Yes| HQ[Scale and reuse valid cache]
Scale -->|No| Basic[Normal output path]
HQ --> Display[Display target]
Basic --> Display
Player selection
Player selection maps a media item to one or more suitable player names. The factory loads built-in choices and selection rules from system configuration, then applies the user's profile configuration. The first matching player becomes the default unless the caller names a player or the item needs a special choice. References: xbmc/…/PlayerCoreFactory.cpp• L41-71, xbmc/…/PlayerCoreFactory.cpp• L298-308, xbmc/…/PlayerCoreFactory.cpp• L340-463
Rules can use the item's media kind and source. They can also use its protocol, file type, MIME type, path, disc form, or known stream facts such as codec, size, aspect, channel count, and HDR type. A nested rule adds a more specific choice after its parent rule matches. A stream-detail rule cannot match until the item has those details. References: xbmc/…/PlayerSelectionRule.cpp• L35-89, xbmc/…/PlayerSelectionRule.cpp• L114-207
The factory keeps default choices for video, music, and games. It also accepts configured external players and discovered remote players. Game items select RetroPlayer, while audio and video items use compatible default aliases and player types. Input-stream items can change the default alias.
References: xbmc/…/PlayerCoreFactory.cpp• L103-197, xbmc/…/PlayerCoreFactory.cpp• L465-501, xbmc/…/PlayerCoreConfig.cpp• L46-89
When playback starts, the application resolves the requested name or the selected default. It passes start position, restore state, fullscreen permission, and initial stream preferences as player options. It keeps the current player when that player can open the next item in place. It closes and replaces the player when the player kind changes or the media needs a new session. A queued replacement opens after the current player closes. References: xbmc/…/IPlayer.h• L30-47, xbmc/…/ApplicationPlayer.cpp• L39-74, xbmc/…/ApplicationPlayer.cpp• L86-167
The following diagram shows how Kodi moves an item from selection to an active playback session.
flowchart TD
Item[Media item] --> Request[Open playback request]
Request --> Choice{Player name supplied?}
Choice -->|Yes| Named[Use requested player]
Choice -->|No| Rules[Apply player rules and defaults]
Rules --> Selected[Select first suitable player]
Named --> Session[Reuse or replace active player]
Selected --> Session
Session --> Create[Create and initialize player]
Create --> Open[Open media with player options]
Open --> Active[Active playback session]
Active --> Next[Open queued next item]
Playback control
CApplicationPlayer presents one control surface over the active player. It forwards pause, speed, tempo, frame advance, seek, chapter, bookmark, volume, mute, and delay changes. It also exposes current time, duration, percentage, cache status, menu state, and playback capabilities. The same abstraction can expose player actions, render features, and disc controls when the active player supports them.
References: xbmc/…/ApplicationPlayer.h• L79-178, xbmc/…/ApplicationPlayer.cpp• L305-379, xbmc/…/ApplicationPlayer.cpp• L417-599, xbmc/…/IPlayer.h• L97-214, xbmc/…/IPlayer.h• L232-310
The same surface provides stream access for audio, video, and subtitles. Kodi can list streams with user-facing details, select a stream, add external subtitles, and enable or disable subtitle display. The application checks player capabilities before it offers a stream control because engines do not support the same changes. References: xbmc/…/IPlayer.h• L51-69, xbmc/…/IPlayer.h• L119-150, xbmc/…/VideoStreamSelectHelper.cpp• L181-245, xbmc/…/VideoStreamSelectHelper.cpp• L248-325
User actions reach the application player through CPlayerController. The controller turns those actions into stream choices, subtitle visibility, audio and subtitle delay, and other playback changes. The active player applies the changes to its engine and reports the new state through the common interface.
References: xbmc/…/PlayerController.cpp• L60-179, xbmc/…/PlayerController.cpp• L187-290, xbmc/…/ApplicationPlayer.cpp• L646-750
Disc and menu playback
Disc playback adds navigation state to the normal stream flow. The Blu-ray input path can open a physical disc, a disc image, or a selected playlist, then reports title, playlist, chapter, menu, still-frame, stream, and overlay events to the video player. This lets the common player surface control both ordinary media time and disc-specific actions. References: xbmc/…/DVDInputStreamBluray.h• L53-158, xbmc/…/DVDInputStreamBluray.cpp• L139-217, xbmc/…/DVDInputStreamBluray.cpp• L471-671
The input path keeps the selected playlist and clip state available for stream labels and resume state. A playlist can omit streams that still exist in its clip, so language information can come from either the active playlist or the clip metadata. The player also uses the first presented audio or presentation-graphic stream as the disc default. References: xbmc/…/DVDInputStreamBluray.cpp• L456-468, xbmc/…/DVDInputStreamBluray.cpp• L1119-1197, xbmc/…/DVDInputStreamBluray.cpp• L1408-1453
Audio and video settings
CVideoSettings is the shared set of per-playback choices for video display and audio or subtitle timing. It includes view and render choices, image changes, selected streams, volume amplification, subtitle state, and audio or subtitle delay. The application player passes these choices to the active player instead of applying engine-specific settings itself.
References: xbmc/…/VideoSettings.h• L199-240, xbmc/…/IPlayer.h• L263-265, xbmc/…/ApplicationPlayer.cpp• L1026-1043
Video settings follow a load-use-store cycle. Kodi loads saved settings for the item or uses global defaults when playback starts. The GUI and controller then change the active settings. When playback closes, non-default settings are saved for the item and default settings remove the item-specific record. References: xbmc/…/ApplicationPlayerCallback.cpp• L509-545, xbmc/…/PlayerController.cpp• L187-268
The active player also declares its audio and subtitle capabilities. These declarations let settings and stream dialogs hide controls that the player cannot honor. References: xbmc/…/IPlayer.h• L51-69, xbmc/…/IPlayer.h• L216-229, xbmc/…/GUIDialogAudioSettings.cpp• L247-320
Music playback
PAPlayer provides the music path through the common player contract. It turns a music item into a decoded audio stream, prepares that stream in the Audio Engine, and exposes time, seek, pause, speed, cache, and audio-stream state to the application.
References: xbmc/…/PAPlayer.cpp• L205-255, xbmc/…/PAPlayer.cpp• L336-376, xbmc/…/PAPlayer.cpp• L479-543, xbmc/…/PAPlayer.cpp• L974-1162
Music playback can prepare the next item before the current item ends. Crossfade settings control the handoff, while consecutive album tracks can use a gapless transition. A cue-sheet item can also change the active part without opening a new source. Queue callbacks ask the application for the next item and keep the playlist moving when a stream finishes or cannot open. References: xbmc/…/PAPlayer.cpp• L257-315, xbmc/…/PAPlayer.cpp• L371-461, xbmc/…/PAPlayer.cpp• L620-875
Subtitle and overlay rendering
Subtitle rendering turns timed subtitle events into visible overlays that follow the current video frame, display geometry, stereo mode, and subtitle settings. The overlay renderer prepares text output before the GUI walk, caches that output for the render pass, and marks the GUI dirty when subtitle pixels change or an image subtitle appears or disappears. References: xbmc/…/OverlayRenderer.h• L104-127, xbmc/…/OverlayRenderer.cpp• L470-621, xbmc/…/OverlayRenderer.cpp• L623-695
The GLES overlay path also keeps HDR overlay color and alpha behavior consistent with the display path. HDR palettes are adapted for the target color space, limited-range output is applied where the direct overlay path needs it, and premultiplied-alpha overlays tell the GUI shader which blend model to use. These rules prevent transparent pixels and HDR subtitle colors from changing the surrounding video. References: xbmc/…/OverlayRendererGLES.cpp• L141-199, xbmc/…/OverlayRendererGLES.cpp• L464-519
The libass subtitle service supports both native ASS/SSA tracks and adapted tracks created from other subtitle formats. It applies Kodi's style and position choices when the style object changes, then renders the track at the current presentation time. The same dirty-update path keeps the debug OSD active even though that overlay is not added for every video frame. References: xbmc/…/DVDSubtitlesLibass.h• L30-109, xbmc/…/DVDSubtitlesLibass.cpp• L327-407, xbmc/…/DebugRenderer.cpp• L30-54, xbmc/…/DebugRenderer.cpp• L109-123
Game playback
Game playback uses the same IPlayer boundary as audio and video playback while the game client owns game-specific work. CRetroPlayer resolves the game client and any selected save state, then creates the session services for input, streams, rendering, and timing. It opens either a game file or a standalone client session and reports successful start through the common player callback path.
References: xbmc/…/RetroPlayer.cpp• L77-240, xbmc/…/RetroPlayer.h• L37-89
Game input follows playback speed. Active playback polls input and permits rumble, while pause stops polling and disables rumble. Closing first quiesces playback and may create an automatic save state, then stops input services, unloads the client, and restores Kodi's graphics state. References: xbmc/…/RetroPlayerInput.cpp• L41-83, xbmc/…/RetroPlayer.cpp• L243-305
Game video can arrive as software frames or as frames drawn by the client into a shared graphics context. The render manager prefers pools with a visible renderer, copies submitted frames when zero-copy use is not possible, preserves a paused software frame, and captures completed hardware frames into separate display buffers. Hardware context cleanup waits for nested client calls to finish. References: xbmc/…/RPRenderManager.cpp• L153-216, xbmc/…/RPRenderManager.cpp• L219-324, xbmc/…/RPRenderManager.cpp• L331-421, xbmc/…/RPRenderManager.cpp• L504-568
The game renderer applies display geometry, scaling, rotation, and optional shader presets to the selected frame. A preset is usable only when its passes and textures can be built. Failed presets are remembered so a bad asset does not repeatedly disrupt frame output. References: xbmc/…/RPBaseRenderer.cpp• L41-77, xbmc/…/RPBaseRenderer.cpp• L120-168, xbmc/…/ShaderPreset.cpp• L42-76, xbmc/…/ShaderPreset.cpp• L89-160
Software-rendered save states can include a captured video preview. Hardware-rendered save states contain game state without readable pixels. Savestate capture serializes the game while holding the client's snapshot lock and records extra metadata only after serialization succeeds. References: xbmc/…/RPRenderManager.cpp• L910-953, xbmc/…/RPRenderManager.cpp• L1176-1379, xbmc/…/SavestateDatabase.cpp• L49-117, xbmc/…/TestSavestateCapture.cpp• L53-108
The following diagram shows how a game frame reaches Kodi's display path.
flowchart LR
Client[Game client] -->|software pixels| Pool[Compatible buffer pool]
Client -->|hardware framebuffer| Context[Shared graphics context]
Context --> Capture[Capture completed frame]
Pool --> Renderer[Selected game renderer]
Capture --> Renderer
Renderer --> GUI[Kodi GUI and display]
Audio output configuration
The audio output layer turns the active stream format into a device configuration. ActiveAE keeps stream buffering, timing, resampling, and sink selection together, then reports the accepted sink format and delay back to the rest of playback. This keeps stream playback separate from the details of a host audio device.
References: xbmc/…/ActiveAE.cpp• L41-71, xbmc/…/ActiveAE.cpp• L151-289, xbmc/…/ActiveAE.cpp• L320-450
On ALSA, CAESinkALSA chooses a device, maps Kodi channel layouts to the device's supported layouts, configures sample rate and data format, and reports the format that the hardware accepted back to the audio engine. Windows audio sinks provide the same boundary for WASAPI and XAudio. They test endpoint capabilities before playback and retry transient device failures without treating a failed probe as a permanent capability.
References: xbmc/…/AESinkALSA.cpp• L188-241, xbmc/…/AESinkALSA.cpp• L395-473, xbmc/…/AESinkWASAPI.cpp• L335-625, xbmc/…/AESinkXAudio.cpp• L366-542
The browser WASM sink provides the same output boundary for Web Audio. It exposes one browser device, accepts planar PCM only, adapts the requested channel count to the browser's output limit, and reports worklet latency and underruns back to the audio engine. It does not provide encoded passthrough. References: xbmc/…/AESinkWasmAudioWorklet.h• L18-45, xbmc/…/AESinkWasmAudioWorklet.cpp• L36-78, xbmc/…/AESinkWasmAudioWorklet.cpp• L80-120, xbmc/…/AESinkWasmAudioWorklet.cpp• L164-213
Encoded audio formats need a matching output rate and channel map before they reach a passthrough sink. The bitstream packer provides those values for formats such as TrueHD, DTS-HD, E-AC-3, AC-3, and DTS. Decoded audio instead uses an exact or best supported channel map and falls back to a compatible format when needed. References: xbmc/…/AEBitstreamPacker.h• L20-32, xbmc/…/TestAEBitstreamPacker.cpp• L14-84, xbmc/…/AESinkALSA.cpp• L476-494, xbmc/…/AESinkWASAPI.cpp• L705-846
Stream state
Stream state is the shared view of playback progress and media status. CDataCacheCore carries current time, usable time bounds, percentage, speed, tempo, seek state, decoder facts, queue levels, chapters, bookmarks, and edit markers between player work and application or GUI reads. This matters for live and time-shifted media because the playable range can move instead of starting at zero and ending at a fixed duration.
References: xbmc/…/DataCacheCore.h• L32-55, xbmc/…/DataCacheCore.h• L146-225
The application reads time and percentage from this shared state while it forwards most controls to the active player. It resets the cache when it creates a new player and refreshes cached stream selections after a change. This gives the application a stable view even when the engine updates playback state on another execution path. References: xbmc/…/ApplicationPlayer.cpp• L66-74, xbmc/…/ApplicationPlayer.cpp• L381-427, xbmc/…/ApplicationPlayer.cpp• L469-505, xbmc/…/ApplicationPlayer.cpp• L680-749
Video playback keeps a player state that joins time bounds with menu state, chapters, bookmarks, cache status, and stream readiness. Separate current-stream records track the active audio, video, subtitle, teletext, radio-data, and audio-metadata paths. When a queued item reuses the player, Kodi clears stale audio and video presence before applying the new stream set. References: xbmc/…/VideoPlayer.h• L38-105, xbmc/…/VideoPlayer.h• L121-179, xbmc/…/VideoPlayer.cpp• L1044-1063, xbmc/…/VideoPlayer.cpp• L1065-1227
The video path keeps packet timing, stream identity, codec hints, and stream-change markers together as media moves from an input stream through a demuxer to the selected audio, video, and auxiliary stream players. A stream-change marker rebuilds the available choices and reopens suitable defaults, while packet timestamps and keyframe hints let the video path keep output near the playback clock. References: xbmc/…/DVDStreamInfo.h• L28-98, xbmc/…/DemuxPacket.h• L22-49, xbmc/…/VideoPlayer.cpp• L988-1041, xbmc/…/VideoPlayer.cpp• L1233-1308, xbmc/…/VideoPlayerVideo.cpp• L544-645
Video item inspection uses stream facts to prepare stream details, thumbnails, external subtitles, and HDR metadata for library and playback views. Kodi excludes attached pictures from the main video list, uses a bounded software decode for thumbnails and frame-derived HDR detail, and adds matching external subtitle files when the item is eligible for inspection. The same path reports no result for unsupported disc, remote, or otherwise unreadable sources. See Video library for how these details support library views. References: xbmc/…/DVDFileInfo.h• L24-43, xbmc/…/DVDFileInfo.cpp• L209-284, xbmc/…/DVDFileInfo.cpp• L290-339, xbmc/…/DVDFileInfo.cpp• L359-392, xbmc/…/DVDFileInfo.cpp• L396-522, xbmc/…/DVDFileInfo.cpp• L525-595
Radio data playback
Radio data playback is an auxiliary stream in a radio session. CVideoPlayer creates and opens a dedicated RDS processor when the input exposes radio data, while the processor turns station messages into current radio metadata and user-facing events.
References: xbmc/…/VideoPlayer.cpp• L728-742, xbmc/…/VideoPlayer.cpp• L1185-1196, xbmc/…/VideoPlayerRadioRDS.cpp• L435-472
The processor validates and decodes RDS messages on its own data path. It updates station text, programme type, radio text, artist and title data, traffic notices, language, and country information through the current radio and music tags. A stream reset flushes pending messages, rebuilds the session cache, attaches a new radio tag to the current channel, and notifies the GUI. Closing removes that tag from the channel. References: xbmc/…/VideoPlayerRadioRDS.cpp• L458-528, xbmc/…/VideoPlayerRadioRDS.cpp• L530-583, xbmc/…/VideoPlayerRadioRDS.cpp• L600-719
Country information is resolved from the RDS extended country code, the PI country code, and the table index. KODI::RDS::Country returns a territory when the standard defines a cell; reserved cells and names without a registered territory remain empty, while invalid code combinations are rejected. This keeps RDS data in the same territory form used by the rest of Kodi.
References: xbmc/…/RadioRDSCountries.h• L19-54, xbmc/…/RadioRDSCountries.cpp• L106-148, xbmc/…/VideoPlayerRadioRDS.cpp• L1400-1422, xbmc/…/VideoPlayerRadioRDS.cpp• L1436-1481
The following diagram shows how radio data moves from the playback stream to application metadata.
flowchart LR
Input[Radio input] --> RDS[RDS data stream]
RDS --> Decode[Validate and decode messages]
Decode --> Metadata[Radio and music metadata]
Decode --> Events[Traffic and GUI events]
Metadata --> GUI[GUI and PVR views]
Events --> GUI
Player callbacks
IPlayerCallback is the event path from a player back to the application. A player uses it to report start, end, stop, error, pause, resume, seek, speed, queue, audio-video change, and settings events. CApplicationPlayerCallback turns those events into GUI messages and related application work.
References: xbmc/…/IPlayerCallback.h• L18-37, xbmc/…/ApplicationPlayerCallback.h• L19-38
Playback callbacks connect engine events to downstream systems. Start and state changes notify the GUI and scripting layer. Errors notify the GUI and stop playback. Close events save resume state and play counts after the callback adjusts video stacks and disc paths. Video start can also pause low-priority jobs while playback begins. See Application runtime for the wider application event flow. References: xbmc/…/ApplicationPlayerCallback.cpp• L49-116, xbmc/…/ApplicationPlayerCallback.cpp• L352-410, xbmc/…/ApplicationPlayerCallback.cpp• L412-507
The callback path also handles media whose visible item differs from the engine's current part. For stacked files and disc menus, it converts relative progress into the full item's position before it saves a bookmark. Progress near the end counts as finished and clears the bookmark. References: xbmc/…/ApplicationPlayerCallback.cpp• L174-329, xbmc/…/ApplicationPlayerCallback.cpp• L352-410
The following diagram shows how a player event becomes application state and user-visible behavior.
sequenceDiagram
participant Engine as Active player
participant Callback as Application callback
participant App as Application services
participant GUI as GUI and scripts
participant Store as Video state store
Engine->>Callback: Playback event
Callback->>App: Update stream, stack, or job state
Callback->>GUI: Send playback message
Callback->>Store: Save or load item settings and resume state
GUI-->>App: User control or next-item request
App->>Engine: Apply playback command
Change checklist
When these files or sections are changed, remember to consider these:
- Keep player names, aliases, player types, and capability flags aligned between
PlayerCoreFactory,PlayerCoreConfig, and system/playercorefactory.xml. - When adding a callback event, update both the common callback contract and the application callback path so the GUI or state store receives it.
- When changing stream identifiers or stream capability rules, check the application proxy and the stream selection dialogs together.
- When changing time bounds or seek state, preserve the distinction between normal media time and the moving range used by live or time-shifted media.
- When changing resume or stack progress, keep relative player times separate from the absolute item or stack times saved to the database.
- When changing video setting fields, preserve the load and store behavior that distinguishes item-specific settings from global defaults.
- When changing music queue, crossfade, cue-sheet, or decoder startup behavior, keep queue callbacks, current-item identity, and resume offsets aligned.
- When changing audio format, channel-map, or passthrough rules, keep the Audio Engine format contract aligned with sink negotiation and bitstream output-rate rules.
- When changing sink selection or recovery, keep preferred-device matching, retry timing, accepted format reporting, and delay accounting aligned.
- When changing browser audio output, keep the advertised PCM layout, planar input contract, worklet sample rate, quantum-sized period, latency report, and underrun handling aligned.
- When changing Windows sink probing or fallback rules, keep device identity, default-format checks, returned capability lists, and temporary-device failure handling aligned between enumeration and initialization.
- When changing
IPlayercapabilities or startup options, update the application-facing control and session paths so unsupported controls are not exposed and restore state is not lost. - When changing shared video probing or picture decoding, keep thumbnail extraction, stream detail inspection, and picture-format checks on the same stream-selection and decode limits.
- When adding or changing the WASM WebCodecs path, keep browser codec strings, bitstream format flags, key-frame classification, shared-state layout, and C++/JavaScript enum values aligned.
- When changing browser frame ownership or render uploads, preserve the order between frame release, texture import, copy completion, and renderer buffer reuse.
- When changing WASM decoder recovery or fallback, keep key-frame restart, bounded in-flight work, process status, renderer buffer type, and FFmpeg fallback behavior aligned.
- When changing file inspection, preserve attached-picture exclusion, extraction eligibility, external subtitle discovery, and frame-based HDR detail fallback as one contract.
- When changing renderer format support or color conversion, keep hardware-frame use, copy fallback, source color primaries, output precision, and supported texture views aligned.
- When changing decoder output metadata or pixel formats, keep codec picture fields, process capabilities, render-buffer state, and renderer input support aligned.
- When changing Dolby Vision handling, keep RPU extraction, Windows effect availability, display mode selection, output color state, and renderer fallback aligned.
- When changing high-quality scaling, preserve the orientation and stereo restrictions, cache invalidation rules, and fallback from advanced scaling to normal output.
- When changing stream-change handling or player reuse, clear stale audio and video presence before the next item's stream set is applied.
- When changing content geometry sampling, keep cancellation, stereo view selection, decoded pixel layout, and the no-reading result for unusable files consistent.
- When changing overlay preparation or dirty-state rules, keep subtitle and debug overlays updating even when the GUI walk skips unchanged controls. Preserve HDR range conversion and premultiplied-alpha state for GLES overlays.
- When changing RDS reset or stream close behavior, clear the session tag and detach it from the current PVR channel before the next radio session starts.
- When changing RDS country tables or territory handling, preserve the distinction between an invalid code combination, a reserved cell, and a valid withdrawn region code.
- When changing hardware game rendering, preserve the stable client framebuffer, completed-frame capture, context binding, and deferred cleanup contract.
- When changing game input or speed handling, keep polling and rumble state aligned with pause and resume transitions.
- When changing game open or close sequencing, preserve the opening guard, client unload order, automatic-save eligibility, and restoration of Kodi's graphics state.
- When changing render buffer types or pool order, keep software formats away from hardware-only pools and preserve a readable frame path for pause and save-state previews.
- When changing savestate capture, keep client-state serialization, snapshot locking, metadata capture, preview ownership, and failure cleanup in the same order.
- When changing shader preset handling, keep renderer compatibility, preset pass creation, texture creation, and failed-path handling aligned.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No player rule or default matches the item | The application cannot create a player and playback does not open | Keep at least one compatible default and validate configured player names against registered player types |
| A rule depends on stream details that are not available | The rule is skipped and another player may be selected | Ensure stream details are present before relying on codec, size, aspect, channel, or HDR matches |
| A player lacks a requested audio or subtitle capability | The related control cannot change the active stream or setting | Check the player capability list before exposing or sending the control |
| A player does not support a requested startup option | Playback starts at the wrong position, stream, or display mode | Map only supported CPlayerOptions values into the player open path |
| A queued music decoder cannot open or produce data | The item is skipped and the application is asked for another queue item | Keep decoder failure on the queue-error path and advance the playlist |
| A raw audio stream is changed before the previous raw stream drains | The next track can start with an invalid or truncated digital stream | Drain raw streams before preparing the next one |
| A requested audio format or channel map is not supported by the sink | Audio output falls back to another format or fails to initialize | Preserve sink negotiation and verify the accepted format and layout before playback continues |
| A preferred audio device is unavailable during a transient fault | Playback may fail even though the device can return later | Retry failed sink opens and keep preferred-device matching separate from permanent capability results |
| Passthrough opens with the wrong channel count or encoded format | The receiver may reject the stream or decode it incorrectly | Keep passthrough channel maps, AES format data, and bitstream output rates consistent |
| A browser sink receives raw audio or a channel count outside its output limit | The WASM audio session cannot initialize or cannot deliver the requested stream | Keep the sink PCM-only and resolve the channel layout from the browser's reported output limit |
| A Windows endpoint rejects the requested format or buffer setup | Audio initialization fails or playback uses a less suitable output format | Keep format fallback and device-period retry paths active; do not apply PCM fallback to raw passthrough |
| The browser does not support the requested WebCodecs configuration | The WASM decoder cannot open the video stream | Build the codec configuration from valid stream hints and allow the normal FFmpeg path to handle unsupported streams |
| WebCodecs receives a delta frame before a usable key frame | The browser decoder cannot start or cannot recover after a reset | Parse the packet for a self-contained key frame and hold deltas until one arrives |
| The browser frame ring or decoder work becomes full | New packets or output frames are delayed or dropped | Apply the in-flight limit, keep shared counters atomic, and let the video player retry when the decoder is busy |
| Browser texture import or frame copy fails | The current video frame cannot reach Kodi's renderer | Probe texture support, keep the copy path available, and fall back to FFmpeg after repeated decoder failure |
| A WebCodecs frame is released before its texture upload or copy completes | The renderer can display incomplete data or the copy can write to invalid memory | Keep frame ownership until the asynchronous operation settles and release through the buffer or copy completion path |
| A WebCodecs C++ and JavaScript layout or enum value changes on one side only | Frame metadata is read with the wrong format or at the wrong offset | Treat the bridge header, Embind values, JavaScript offsets, and static layout checks as one ABI |
| A player callback reports an error | The GUI receives an error and playback is stopped | Treat error as a terminal playback event and do not rely on a normal end event |
| A close callback receives zero progress after a failed start | Existing resume state is left unchanged | Do not save close state until the player reports meaningful progress |
| A stacked or disc item saves player-relative time as item time | Resume position and play count become wrong | Convert the bookmark through the stack or disc mapping before saving |
| A reused video player keeps the previous item's has-audio or has-video flag | Controls and downstream state describe a stream that is no longer active | Clear presence flags when the current stream identifiers are unset |
| A video item has no usable real video stream or decoding cannot produce a picture | Thumbnail extraction or frame-based stream details are unavailable | Require a real video stream and stop after the shared decode session's bounded search |
| A file is outside the supported extraction scope | Thumbnail or stream metadata work is skipped even though playback may still be possible | Keep disc, unsuitable remote, unresolved plugin, and unsupported PVR checks in CanExtract |
| A geometry scan uses a picture layout the detector cannot read | The scan reports no usable content rectangle | Accept only supported planar layouts and return no reading when the file cannot be opened or decoded |
| The device cannot use a decoded pixel format directly | The video renderer must copy the frame or cannot render it | Check texture support and keep a supported copy path for hardware and planar formats |
| Hardware video decoding cannot provide a usable frame | The codec requests a reopen or falls back to a software path | Keep hardware format checks, decoder failure handling, and software fallback connected |
| Dolby Vision RPU data is absent or the Windows effect is unavailable | The frame uses the normal HDR or SDR renderer path instead of Dolby Vision reshaping | Require both valid frame metadata and effect availability before enabling Dolby Vision output |
| The Dolby Vision effect fails during stream setup or frame processing | Kodi disables the effect for the stream and continues with normal video rendering | Keep effect failure on the renderer fallback path and do not leave Dolby Vision display mode enabled |
| A high-quality scaler cannot build its required shader resources | The renderer falls back to normal scaling and reports the unavailable effect | Try the simpler scaler, then disable HQ scaling rather than using partial resources |
| A cached scaled frame no longer matches the target or stereo position | The display can use an old size or eye placement | Recreate or invalidate the cache when target format, size, output, or stereo placement changes |
| An HDR GLES overlay uses the wrong range or alpha model | Transparent pixels can brighten the overlay area or subtitle colors can look wrong | Convert HDR overlay data for the target range and pass premultiplied-alpha state to the shader |
| An RDS code names no valid table cell | Radio country metadata is rejected and the affected RDS update is not applied | Validate the extended code, PI country code, and index through the shared country lookup |
| RDS state is not reset when the stream changes | Metadata from the previous station remains visible | Flush the RDS queue and clear the current radio tag at stream reset and close |
| Overlay changes do not mark the GUI dirty | Subtitles or debug text can remain stale until another GUI change | Mark dirty when timed text changes and when image overlays appear or disappear |
| A hardware game frame is sampled while the client draws into the same framebuffer | The displayed frame can be torn or incomplete | Capture the completed frame into a separate buffer before Kodi renders it |
| Hardware context cleanup runs during a client call | The game can lose its render target or Kodi can lose GUI graphics state | Defer destruction until nested client frames end, then restore Kodi's state |
| A hardware-rendered save state is treated as if it contains pixels | Thumbnail or preview loading fails because the state has no video frame | Treat hardware save states as game-state-only and do not require a video preview |
| Savestate serialization fails before metadata capture | The saved state can contain mismatched or stale metadata | Capture metadata only after successful serialization and release the snapshot buffer on failure |
| A shader preset cannot build all passes or textures | The renderer cannot apply the requested effect | Reject the preset and remember the failed path instead of rendering with partial resources |
Key files
| File | Why to read it |
|---|---|
| xbmc/…/ApplicationPlayer.h | Defines the application-facing playback surface and the active player lifecycle. |
| xbmc/…/ApplicationPlayer.cpp | Shows how Kodi selects, creates, replaces, controls, and queries the active player. |
| xbmc/…/IPlayer.h | Defines the common player contract, startup options, stream controls, capabilities, session state, rendering features, and disc state. |
| xbmc/…/IPlayerCallback.h | Defines the events that connect a player to the application. |
| xbmc/…/PlayerCoreFactory.cpp | Explains default player choice, rule processing, configuration loading, and remote player discovery. |
| xbmc/…/PlayerSelectionRule.cpp | Explains the media and stream facts that can affect player choice. |
| xbmc/…/ApplicationPlayerCallback.cpp | Shows how playback events update the GUI, saved settings, resume state, play counts, and stacks. |
| xbmc/…/DataCacheCore.h | Defines the shared time, cache, stream, and playback state used by the application. |
| xbmc/…/VideoSettings.h | Defines the settings shared by the GUI and the active player. |
| xbmc/…/VideoPlayer.h | Defines video playback state, current stream state, and the stream selection boundary. |
| xbmc/…/VideoPlayer.cpp | Shows how input and demux streams become selected audio, video, subtitle, and auxiliary streams. |
| xbmc/…/DVDFileInfo.h | Defines the eligibility and public operations for media inspection and thumbnail extraction. |
| xbmc/…/DVDFileInfo.cpp | Shows how stream details, HDR details, thumbnails, and external subtitles are prepared for media items. |
| xbmc/…/DVDVideoCodec.h | Defines the codec boundary and the picture metadata passed from decoding to rendering. |
| xbmc/…/DVDVideoCodecFFmpeg.cpp | Shows hardware and software decoder choice, frame production, decoder controls, and HDR or Dolby Vision metadata transfer. |
| xbmc/…/DVDVideoCodecWebCodecs.cpp | Shows the WASM browser decoder lifecycle, shared frame flow, recovery, and FFmpeg fallback. |
| xbmc/…/DVDVideoCodecWebCodecsBitstream.cpp | Shows browser codec descriptions, stream format handling, and key-frame classification. |
| xbmc/…/DVDVideoCodecWebCodecsBridge.h | Defines the C++ and JavaScript bridge contract for browser decoder state and frames. |
| xbmc/…/webcodecs_bridge.js | Shows browser decoder setup, asynchronous frame ownership, texture import, copying, and error state. |
| xbmc/…/ProcessInfo.h | Defines shared decoder, renderer capability, and playback status information. |
| xbmc/…/ProcessInfoWin10.cpp | Shows Windows render format support and the conditions for requesting Dolby Vision metadata. |
| xbmc/…/ProcessInfoWasm.cpp | Registers the WASM process control and its fallback deinterlace method. |
| xbmc/…/RendererBase.h | Defines the Windows render buffer, HDR state, and common renderer boundary. |
| xbmc/…/RendererDXVA.cpp | Shows hardware video output selection and display conversion support. |
| xbmc/…/RendererShaders.cpp | Shows how Windows video formats, color conversion, hardware textures, and output precision are selected. |
| xbmc/…/DolbyVisionEffect.cpp | Shows how Windows Store playback reshapes Dolby Vision frames into display output. |
| xbmc/…/RendererHQ.cpp | Shows how high-quality scaling is selected, built, cached, and bypassed when it is not usable. |
| xbmc/…/RendererHQ.h | Defines the high-quality scaling state and output cache. |
| xbmc/…/RendererWebCodecs.cpp | Shows browser frame import, texture lifetime, filtering, and display through GLES. |
| xbmc/…/OverlayRendererGLES.cpp | Shows GLES overlay color-range, HDR palette, and premultiplied-alpha handling. |
| xbmc/…/VideoPlayerRadioRDS.cpp | Shows how RDS data becomes radio metadata, traffic events, language, and territory state. |
| xbmc/…/RenderManager.cpp | Defines the video render and capture boundary used by video playback. |
| xbmc/…/ActiveAE.cpp | Shows how audio streams become buffered, timed, resampled, and connected to an output sink. |
| xbmc/…/AESinkALSA.cpp | Shows ALSA format negotiation, device discovery, delivery, delay, and recovery. |
| xbmc/…/AESinkWASAPI.cpp | Shows Windows exclusive-output negotiation, passthrough support, buffer setup, and endpoint recovery. |
| xbmc/…/AESinkXAudio.cpp | Shows XAudio device probing, capability caching, format fallback, and queued audio delivery. |
| xbmc/…/AESinkWasmAudioWorklet.cpp | Shows browser PCM output, channel adaptation, worklet latency, and underrun reporting. |
| xbmc/…/RetroPlayer.cpp | Shows how a game session opens, controls speed, saves state, restores graphics state, and closes. |
| xbmc/…/RetroPlayerInput.cpp | Shows how game input polling and rumble follow playback speed. |
| xbmc/…/RPRenderManager.cpp | Shows how software and hardware game frames move to Kodi's renderers and save-state previews. |
| xbmc/…/RPBaseRenderer.cpp | Shows game-frame geometry, renderer compatibility, and shader preset use. |
| xbmc/…/ShaderPreset.cpp | Shows how game shader presets are loaded, updated, and rejected when resources fail. |
| xbmc/…/SavestateDatabase.cpp | Shows savestate serialization, storage, loading, filtering, and preview metadata. |
| xbmc/…/PlaybackTestEnvironment.h | Defines the isolated game playback services used by playback tests. |
| xbmc/…/TestSavestateCapture.cpp | Protects snapshot locking, serialization failure cleanup, and metadata ordering. |
| xbmc/…/TestVideoPlayer.cpp | Exercises the video player lifecycle and stream-control behavior. |
playback-engines.md | Provides the child-level view of the concrete playback engines. |