Skip to content

Update go2rtc_stream.c#425

Open
rivandraa wants to merge 1 commit into
opensensor:mainfrom
rivandraa:patch-1
Open

Update go2rtc_stream.c#425
rivandraa wants to merge 1 commit into
opensensor:mainfrom
rivandraa:patch-1

Conversation

@rivandraa
Copy link
Copy Markdown
Contributor

  • 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:

    • If the codec is not H.264 → create a source with video=h264 plus the selected audio codec.
    • If the codec is already H.264 → only append the audio codec.
  • 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants