{"record":{"id":"68986c376fc469fd","repo":"DrKLO/Telegram","slug":"opus-custom-decode-failed-s-n","errorCode":null,"errorMessage":"opus_custom_decode() failed: %s\\n","messagePattern":"opus_custom_decode\\(\\) failed: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"TMessagesProj/jni/opus/celt/opus_custom_demo.c","lineNumber":172,"sourceCode":"            }\n            data[i/8] ^= 1<<(7-(i%8));\n         }\n      }\n      if (errors == 1)\n         data[eid/8] ^= 1<<(7-(eid%8));\n      else if (errors%2 == 1)\n         data[rand()%8] ^= 1<<rand()%8;\n#endif\n\n#if 1 /* Set to zero to use the encoder's output instead */\n      /* This is to simulate packet loss */\n      if (argc==9 && rand()%1000<atoi(argv[argc-3]))\n      /*if (errors && (errors%2==0))*/\n         ret = opus_custom_decode(dec, NULL, len, out, frame_size);\n      else\n         ret = opus_custom_decode(dec, data, len, out, frame_size);\n      if (ret < 0)\n         fprintf(stderr, \"opus_custom_decode() failed: %s\\n\", opus_strerror(ret));\n#else\n      for (i=0;i<ret*channels;i++)\n         out[i] = in[i];\n#endif\n#if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH)\n      for (i=0;i<ret*channels;i++)\n      {\n         rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]);\n         /*out[i] -= in[i];*/\n      }\n#endif\n      count++;\n      fwrite(out+skip*channels, sizeof(short), (ret-skip)*channels, fout);\n      skip = 0;\n   }\n   PRINT_MIPS(stderr);\n\n   opus_custom_encoder_destroy(enc);","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/celt/opus_custom_demo.c#L154-L190","documentation":"opus_custom_decode(dec, data, len, out, frame_size) returned ret < 0 during the decode loop. The message prints opus_strerror(ret). This is a warning only — execution continues, so 'out' may contain stale/uninitialized samples that get written to the output and feed the RESYNTH RMSD calculation. The decode can also be called with NULL data to simulate packet loss.","triggerScenarios":"ret is a negative OPUS_* code. Causes: len is 0 or negative (especially if the encode step failed but the loop continued), corrupted packet data (the optional bit-error simulation), or frame_size mismatch with the decoder. The packet-loss branch passes NULL as the data pointer, which the decoder handles as concealment — but a bad len there still errors.","commonSituations":"Encode failure (error 211) left len <= 0 and the loop did not skip, so decode gets an invalid length; bit-error simulation enabled (#if block) corrupting bytes; frame_size inconsistent between encode and decode; very aggressive packet-loss rate producing many concealment calls.","solutions":["Ensure len is > 0 (encode succeeded) before decoding; skip the iteration otherwise.","On ret < 0, skip writing 'out' to the output file and exclude this frame from the RMSD count.","If using the bit-error simulation, keep corruption within tolerable limits or expect decode errors.","Match frame_size exactly between encode and decode calls."],"exampleFix":"// before\nret = opus_custom_decode(dec, data, len, out, frame_size);\nif (ret < 0)\n    fprintf(stderr, \"opus_custom_decode() failed: %s\\n\", opus_strerror(ret));\n\n// after: guard the len, and skip write/RMSD on failure\nif (len <= 0) { /* nothing to decode this frame */ continue; }\nret = opus_custom_decode(dec, data, len, out, frame_size);\nif (ret < 0) { fprintf(stderr, \"opus_custom_decode() failed: %s\\n\", opus_strerror(ret)); continue; }","handlingStrategy":"validation","validationCode":"// Only decode when encode produced a valid length; skip on failure.\nif (len <= 0) { continue; }\nret = opus_custom_decode(dec, data, len, out, frame_size);\nif (ret < 0) { fprintf(stderr, \"opus_custom_decode() failed: %s\\n\", opus_strerror(ret)); continue; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard decode on len > 0 so a prior encode failure doesn't propagate.","Skip writing 'out' and exclude the frame from RMSD when decode fails.","Keep frame_size identical between encode and decode."],"tags":["opus","decoder","decode-loop","error-handling","packet-loss","audio","c"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}