Skip to content

Support for Audio AC-4 samples with variable frame sizes #8222

@HESA-GrahamClift

Description

@HESA-GrahamClift

[REQUIRED] Use case description

In the case where audio and video is delivered over MPEG DASH, it can be beneficial for the audio and video segments to have equal duration (improves channel change time for instance). If the audio is not PCM, for instance AC-4, and when the frame rate of the audio is not an integer multiple of the frame rate of the video (eg 48000Hz, 59.94fps), then the AC-4 sample frame count will not be constant.
In DefaultAudioSink, handleBuffer method, there is an assumption that the framesPerEncodedSample needs to be read just once at the beginning. In variable frames per sample cases this can deliver incorrect result to framesToDuration(getWrittenframes()), and in some cases a drift can be seen in the currentPosition when the erroneous result is less than the current position reported from native calls to the decoder.

Proposed solution

Remove the test in handleBuffer for getting the framesPerEncodedSample for the first sample only. Instead, extract the count for every sample.

if (!configuration.isInputPcm /*&& framesPerEncodedSample == 0*/) {
    // If this is the first encoded sample, calculate the sample size in frames.
    framesPerEncodedSample = getFramesPerEncodedSample(configuration.outputEncoding, buffer);
    if (framesPerEncodedSample == 0) {
         // We still don't know the number of frames per sample, so drop the buffer.
         // For TrueHD this can occur after some seek operations, as not every sample starts with
         // a syncframe header. If we chunked samples together so the extracted samples always
         // started with a syncframe header, the chunks would be too large.
         return true;
     }
 }

Alternatives considered

None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions