Add snapcast state and refactor inter task communication#203
Conversation
|
I have merged these together and created a branch and PR here: @luar123 not sure how best to handle this with all the changes going on at the moment! |
|
@craigmillard86 Let's discuss your changes in luar123#1 until #204 and this PR are merged. |
|
There seems to be a problem When I set |
|
Yes, I wrote this in the first post:
I added a second notification to player task (index 1, 0 is already used) so this needs to be set to 2. We could also change it to mutex. |
|
Either sdkconfig.defaults should be adjusted or use mutex Ok sorry should have read your post more thoroughly. I see this is still open for discussion |
|
Added it to the sdkconfigs. Mutex is not working, because it can't be given from multiple tasks. |
|
While working on #217 I discovered a few deficiencies:
|
|
I like you pushing those features forward. Some input that came to my mind when I saw you'll refactor snapcast setting related data exchange / inter task communications.
|
|
Good idea, will have a look. |
|
Back-ported volume control, snapcast state instead of player state and i2s lock from BT PR #217 |
Currently we have:
I see two options to improve:
@CarlosDerSeher what do you think? |
|
All codecs are called within http_task context, so no mutex needed here. I'd opt for option 2, as I am almost certain that scSetings object could be reduced in size. I am not sure which variables are absolutely needed in player task. |
|
Had a quick look and I think this is much cleaner already |
|
Thanks. Please have a closer look when you have time. In the meantime I will use it as base for my other work. I removed everything that is not needed from snapcastSetting_t and renamed to playerSetting_t. Then I created a new snapcastSetting_t that is playerSetting_t+mute+volume, because those two are not needed in the player task. Please also have a closer look at the changes in main.c regarding snapcast state and sending commands to http_task. I decided to use a task notification with an enum as value to send the commands. This could be improved by setting individual bits for the commands or using a event group to avoid overwriting previous commands (for example restart requested from network interface change). |
|
@CarlosDerSeher do you think you could look into this soon? I can then maintain the a2dp sink component in my repo so you don't have to review it. |
|
I've actually thought about bringing in a collaborator. |
|
Yes sure, I don't have a ton of free time to look into other PRs myself, but could certainly help. You can find me on discord with the same name. |
CarlosDerSeher
left a comment
There was a problem hiding this comment.
After reviewing (but not testing) the changes I think this is mostly OK. See my comments.
| if (sc_state == STOPPED) { | ||
| xSemaphoreGive(snapcastStateMux); | ||
| command = STOP; | ||
| while(command != START) { |
There was a problem hiding this comment.
Is this save to do? Will turn false for sure some time?
There was a problem hiding this comment.
The idea is that after init sc_state=STOPPED so it will block until main calls sc_start_snapcast(). This sets command=START. After this sc_state will only be STOPPED if sc_stop_snapcast() is called. This allows the main app to stop and disconnect snapcast completely.
Thinking about it, I should probably modify the OTA component to make use of this.
There was a problem hiding this comment.
Added sc_stop_snapclient() before killing http_task for OTA, so the connection is terminated properly.
CarlosDerSeher
left a comment
There was a problem hiding this comment.
I like the renaming to snapclient
| // KillAllThreads(); | ||
| // dsp_i2s_task_deinit(); | ||
| sc_stop_snapclient(); | ||
| vTaskDelay(1000 / portTICK_PERIOD_MS); // give snapclient some time to stop before we kill the http task that might be using the player |
There was a problem hiding this comment.
I am pretty sure this is safe to do but isn't there a way to get state information with the new implementation? Just to be 100% sure we can kill the http task.
There was a problem hiding this comment.
also please ensure the usage of pdMS_TO_TICKS throughout
There was a problem hiding this comment.
Fixed both: ota will now wait for the snapclient state callback and only kills http_task if it times out. Also snapclient_stop stops the player task now so we don't have to wait for the queue to drain. Overall, way less delay than before.
Had to increase the ota task stack size slightly.
|
Alright I think this is ready? Increased OTA stack won't matter much as it is only active after snapclient is off. |
|
I think this is good to go |
|
Okcould you have a look at the commit message? It seems there are some unrelated ones there. Especially the one about partition size. |
|
Could you merge with squash and simply replace the description(commit messages) with: manually squashing is a bit annoying because I merged develop a few times. |
|
Thank you! |
…r), CarlosDerSeher#218, CarlosDerSeher#219 (TAS5825M), CarlosDerSeher#220 (MA12070P + CONFIG_I2S_SLOT_32BIT) Resolved by adopting upstream's snapclient_* naming throughout (reverting our branch's earlier snapcast_* rename) to minimise long-term drift, while keeping our network_state_cb registration in init for the unified-ethernet feature. Renamed sc_restart_snapcast -> sc_restart_snapclient call sites in eth_interface.c to match. Preserved local additions on top of upstream: - network_state_cb + sc_add_state_cb registration for ethernet integration - Runtime MAC read from netif (matches unified MAC on the wire) - Early bring-up of settings_manager_init / network_events_init / network_if_init - 2-second back-off after netconn_close on RESTART/STOP - RESTART/STOP check + 2s delay after process_data error - reset_connection_state() helper + hoisted statics so update_state / process_data state is cleared between snapclient connections (prevents stale "playing" state from previous connection surviving ~1s into the new one) Verified ethernet flow end-to-end via code-reviewer + Explore agents. Build: idf:v5.5.1 / esp32s3 OK (snapclient.bin 0x134bb0 bytes, 38% free). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This PR adds snapcast state + callbacks and refactors the inter task communication.
player_send_snapcast_settingI am unsure about the task notifications, had a race conditions when using them in the callbacks (that's why the main task callback uses a mutex). So maybe it would be better to use mutex or queues instead.Todo: Either change notifications or set configTASK_NOTIFICATION_ARRAY_ENTRIES=2 in sdkconfigs.@craigmillard86 Using this PR network_playback_stopped/network_playback_started from #201 could be replaced by a state callback.