Repository navigation
Setting audioOn before the audio threads start - #104
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR Summary by QodoStart audio threads only after setting their run flag
AI Description
Merge Risk
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
Audio can stop right after it starts, with no error. The capture thread (
aud_thread, from each HAL) and the encoding thread (aenc_thread()) both loop onwhile (keepRunning && audioOn).media_audio_enable()setsaudioOn = 1only after it has created both threads. If a new thread runs before the creating thread reaches that line, it seesaudioOn == 0and returns at once.It depends on the scheduler which thread runs first, so it may never show on one system and always show on another. On a Fullhan FH8856V200 board, it never showed with the vendor kernel (4.9). With a newer kernel (Linux 6.18), the audio threads ended right after start every time.
Why
audioOnis the threads' run condition, so it has to be set before they start. It is set at the end ofmedia_audio_enable(), after bothpthread_create()calls.What this changes
src/media.c,media_audio_enable():audioOn = 1moves to before the twopthread_create()calls.pthread_create()has to undo it.audioOngoes back to 0. If the capture thread was already running, it is joined. The attribute object is released before the error return. OtherwiseaudioOnwould stay 1 after a failure: a latermedia_audio_enable()would return at once, andmedia_audio_disable()would join a thread that never existed.How it was checked
./build.sh fhan-v2, no new warnings../test.sh -apasses.Effect on other platforms
Shared code, every target with audio. Every HAL's capture thread loops on
audioOnthe same way: HiSilicon, Ingenic, Anyka, Fullhan and the others. Where the race never showed, nothing changes.🤖 Generated with Claude Code