Skip to content

start_threshold compared in bytes but populated in frames (auto-start path) #128

Description

@victorzappi

session_obj.c compares stream_config.start_threshold against a byte counter, but the tinyalsa plugin populates that field from ALSA sw_params, where start_threshold is defined in frames. No unit conversion occurs between the two.

Call chain

  1. The plugin's sw_params op receives the raw ALSA structure — include/tinyalsa/plugin.h:
int (*sw_params) (struct pcm_plugin *plugin, struct snd_pcm_sw_params *params);
  1. In the ALSA ABI the field is frames, per its own comment — sound/asound.h:
snd_pcm_uframes_t start_threshold;  /* min hw_avail frames for automatic start */

(snd_pcm_uframes_t is unsigned long.)

  1. plugins/tinyalsa/src/agm_pcm_plugin.c:518 copies it with a plain cast — no unit conversion, plus a 64-to-32-bit narrowing:
session_config->start_threshold = (uint32_t)sparams->start_threshold;
  1. service/inc/public/agm/agm_api.h:402 documents the destination field as bytes:
uint32_t start_threshold;  /**< start_threshold: number of buffers * buffer size */
  1. Nothing converts it downstream — service/src/session_obj.c:2297 and :2845 are plain struct assignments:
sess_obj->stream_config = *stream_config;
  1. service/src/session_obj.c:2533-2536 compares it to an accumulated byte count:
if (sess_obj->stream_config.start_threshold > 0 &&
    sess_obj->state == SESSION_PREPARED) {
    sess_obj->bytes_written += *count;
    if (sess_obj->bytes_written >= sess_obj->stream_config.start_threshold) {
  1. count is bytes, per the public API contract — agm_api.h:1000:
 * \param[in] count: actual number of bytes in the buffer.

Consequence

A client setting start_threshold through tinyalsa sw_params gets a session that auto-starts after start_threshold / bytes_per_frame frames instead of start_threshold frames. At stereo 16-bit (4 bytes per frame) the effective prefill is one quarter of what was requested, shrinking the ring-buffer cushion and making underruns more likely under graph load.

Either agm_pcm_plugin.c:518 needs a frames-to-bytes conversion from the session media format, or session_obj.c should accumulate frames rather than bytes — depending on which unit the field is meant to carry.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions