Update go2rtc_stream.c#425
Open
rivandraa wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors go2rtc stream registration to add a single combined FFmpeg producer source (audio + optional H.264 transcode) and dynamically selects the audio codec (AAC for main streams, Opus for “_sub” streams), simplifying the prior separate audio/H.264 fallback sources.
Changes:
- Replace separate audio-only and H.264-fallback sources with a single combined FFmpeg source string.
- Select audio codec based on whether the stream is a sub-stream (“_sub” → opus, otherwise aac).
- Adjust registration/logging and manage the combined source string lifetime via
strdup()/free().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+224
to
228
| const char *audio_codec = (strstr(encoded_stream_id, "_sub") != NULL) ? "opus" : "aac"; | ||
|
|
||
| bool is_h264 = (codec != NULL && strcasestr(codec, "h264") != NULL); | ||
|
|
||
| if (!is_h264) { |
|
|
||
| const char *audio_codec = (strstr(encoded_stream_id, "_sub") != NULL) ? "opus" : "aac"; | ||
|
|
||
| bool is_h264 = (codec != NULL && strcasestr(codec, "h264") != NULL); |
Comment on lines
+248
to
+250
| result = (num_sources > 1) | ||
| ? go2rtc_api_add_stream_multi(encoded_stream_id, sources, num_sources) | ||
| : go2rtc_api_add_stream(encoded_stream_id, modified_url); |
| combined_idx = num_sources; | ||
| num_sources++; | ||
| log_info("Stream %s: Combined producer added (audio=%s, h264_detected=%s)", | ||
| encoded_stream_id, audio_codec, is_h264 ? "yes" : "no"); |
Comment on lines
+249
to
+250
| ? go2rtc_api_add_stream_multi(encoded_stream_id, sources, num_sources) | ||
| : go2rtc_api_add_stream(encoded_stream_id, modified_url); |
| char combined_buf[URL_BUFFER_SIZE]; | ||
| int combined_idx = -1; | ||
|
|
||
| const char *audio_codec = (strstr(encoded_stream_id, "_sub") != NULL) ? "opus" : "aac"; |
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.
Refactored stream registration logic to combine audio and video into a single source (combined_buf) instead of handling them separately.
Added support for dynamic audio codec selection: automatically using opus for streams with the _sub suffix, and aac for main streams.
Simplified H.264 fallback handling:
Introduced use of strdup() to safely store the combined buffer in the sources array, followed by free() after registration to prevent memory leaks.
Enhanced logging to provide clearer information, including the chosen audio codec and whether H.264 was detected.
Expanded the sources array capacity from 3 to 4 elements to accommodate the new combined source entry.
Important: For audio playback in live view to function properly, FFmpeg must be installed on the system.