From 64caf0401dab65b4311a814ee85b17df6f90d4fc 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 e544da85fd5caf..7a2f140848cd5b 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 8a801bdb0a8e02..97a1b3d13bfd72 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 H.264 on track 0 as old style for compatibility. @@ -541,6 +547,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 40e3cbbb4d8253..8903406ffda9b5 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 H.264 on track 0 as old style for compatibility. @@ -1747,6 +1753,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;