From 439190526bf83be031b72c1fac3709f6160b06eb Mon Sep 17 00:00:00 2001 From: Ruwen Hahn Date: Tue, 28 Nov 2023 15:36:14 +0100 Subject: [PATCH] obs-outputs: Add `video_id_t` value for 0 This will be initialized to 0 in various cases, so let's make that a valid enum value (even if it's not valid in rtmp?) --- plugins/obs-outputs/flv-mux.c | 4 ++++ plugins/obs-outputs/flv-mux.h | 1 + plugins/obs-outputs/flv-output.c | 11 +++++++++++ plugins/obs-outputs/rtmp-stream.c | 11 +++++++++++ 4 files changed, 27 insertions(+) diff --git a/plugins/obs-outputs/flv-mux.c b/plugins/obs-outputs/flv-mux.c index 97b4eec9c08d23..cc77162c7107c1 100644 --- a/plugins/obs-outputs/flv-mux.c +++ b/plugins/obs-outputs/flv-mux.c @@ -66,6 +66,10 @@ enum datatype_t { static void s_w4cc(struct serializer *s, enum video_id_t id) { switch (id) { + case CODEC_NONE: + assert(0 && "Tried to serialize CODEC_NONE"); + break; + case CODEC_AV1: s_w8(s, 'a'); s_w8(s, 'v'); diff --git a/plugins/obs-outputs/flv-mux.h b/plugins/obs-outputs/flv-mux.h index 032cc8876f1877..abebda6b1a0089 100644 --- a/plugins/obs-outputs/flv-mux.h +++ b/plugins/obs-outputs/flv-mux.h @@ -22,6 +22,7 @@ #define MILLISECOND_DEN 1000 enum video_id_t { + CODEC_NONE = 0, // not valid in rtmp CODEC_H264 = 1, // legacy & Y2023 spec CODEC_AV1, // Y2023 spec CODEC_HEVC, diff --git a/plugins/obs-outputs/flv-output.c b/plugins/obs-outputs/flv-output.c index ea3e590f9c8fc5..fb0237fdd623b5 100644 --- a/plugins/obs-outputs/flv-output.c +++ b/plugins/obs-outputs/flv-output.c @@ -271,6 +271,12 @@ static bool write_video_header(struct flv_output *stream, size_t idx) return false; switch (stream->video_codec[idx]) { + case CODEC_NONE: + do_log(LOG_ERROR, + "Codec not initialized for track %zu while sending header", + idx); + return false; + case CODEC_H264: packet.size = obs_parse_avc_header(&packet.data, header, size); // Always send H264 on track 0 as old style for compat @@ -534,6 +540,11 @@ static void flv_output_data(void *data, struct encoder_packet *packet) } switch (stream->video_codec[packet->track_idx]) { + case CODEC_NONE: + do_log(LOG_ERROR, "Codec not initialized for track %zu", + packet->track_idx); + goto unlock; + case CODEC_H264: obs_parse_avc_packet(&parsed_packet, packet); break; diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c index 5c6a13a7d07768..e88eab647c7a31 100644 --- a/plugins/obs-outputs/rtmp-stream.c +++ b/plugins/obs-outputs/rtmp-stream.c @@ -815,6 +815,12 @@ static bool send_video_header(struct rtmp_stream *stream, size_t idx) return false; switch (stream->video_codec[idx]) { + case CODEC_NONE: + do_log(LOG_ERROR, + "Codec not initialized for track %zu while sending header", + idx); + return false; + case CODEC_H264: packet.size = obs_parse_avc_header(&packet.data, header, size); // Always send H264 on track 0 as old style for compat @@ -1742,6 +1748,11 @@ static void rtmp_stream_data(void *data, struct encoder_packet *packet) } switch (stream->video_codec[packet->track_idx]) { + case CODEC_NONE: + do_log(LOG_ERROR, "Codec not initialized for track %zu", + packet->track_idx); + return; + case CODEC_H264: obs_parse_avc_packet(&new_packet, packet); break;