Move and extend frame decode failure logging

Move logging of decode failure from VCMGenericDecoder to VideoReceiveStream2 where remote SSRC is always known. Log frame details such as size and resolution which help to identify this frame in bitstream dump.

Bug: b/309132190
Change-Id: Ibe50799e448ffdc19f9857cc1625cfde0d7aa7a1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/328821
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Commit-Queue: Sergey Silkin <ssilkin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41276}
diff --git a/modules/video_coding/generic_decoder.cc b/modules/video_coding/generic_decoder.cc
index fc356e7..00585ab 100644
--- a/modules/video_coding/generic_decoder.cc
+++ b/modules/video_coding/generic_decoder.cc
@@ -329,18 +329,7 @@
     }
     _callback->OnDecoderInfoChanged(std::move(decoder_info));
   }
-  if (ret < WEBRTC_VIDEO_CODEC_OK) {
-    const absl::optional<uint32_t> ssrc =
-        !frame_info.packet_infos.empty()
-            ? absl::make_optional(frame_info.packet_infos[0].ssrc())
-            : absl::nullopt;
-    RTC_LOG(LS_WARNING) << "Failed to decode frame with timestamp "
-                        << frame.RtpTimestamp() << ", ssrc "
-                        << (ssrc ? rtc::ToString(*ssrc) : "<not set>")
-                        << ", error code: " << ret;
-    _callback->ClearTimestampMap();
-  } else if (ret == WEBRTC_VIDEO_CODEC_NO_OUTPUT) {
-    // No output.
+  if (ret < WEBRTC_VIDEO_CODEC_OK || ret == WEBRTC_VIDEO_CODEC_NO_OUTPUT) {
     _callback->ClearTimestampMap();
   }
   return ret;
diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc
index 2696647..af25c36 100644
--- a/video/video_receive_stream2.cc
+++ b/video/video_receive_stream2.cc
@@ -904,6 +904,22 @@
   }
 
   int decode_result = video_receiver_.Decode(frame_ptr);
+  if (decode_result < WEBRTC_VIDEO_CODEC_OK) {
+    // Asynchronous decoders may delay error reporting, potentially resulting in
+    // error reports reflecting issues that occurred several frames back.
+    RTC_LOG(LS_WARNING)
+        << "Failed to decode frame. Return code: " << decode_result
+        << ", SSRC: " << remote_ssrc()
+        << ", frame RTP timestamp: " << frame_ptr->RtpTimestamp()
+        << ", type: " << VideoFrameTypeToString(frame_ptr->FrameType())
+        << ", size: " << frame_ptr->size()
+        << ", width: " << frame_ptr->_encodedWidth
+        << ", height: " << frame_ptr->_encodedHeight
+        << ", spatial idx: " << frame_ptr->SpatialIndex().value_or(-1)
+        << ", temporal idx: " << frame_ptr->TemporalIndex().value_or(-1)
+        << ", id: " << frame_ptr->Id();
+  }
+
   if (encoded_frame_output_enabled) {
     absl::optional<RecordableEncodedFrame::EncodedResolution>
         pending_resolution;