{"record":{"id":"79d0d789d5ccfa6f","repo":"DrKLO/Telegram","slug":"opus-repacketizer-out-failed-s-n","errorCode":null,"errorMessage":"opus_repacketizer_out() failed: %s\\n","messagePattern":"opus_repacketizer_out\\(\\) failed: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"TMessagesProj/jni/opus/src/repacketizer_demo.c","lineNumber":179,"sourceCode":"         if (err>0) {\n            unsigned char int_field[4];\n            int_to_char(err, int_field);\n            if(fwrite(int_field, 1, 4, fout)!=4){\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            int_to_char(rng[nb_packets-1], int_field);\n            if (fwrite(int_field, 1, 4, fout)!=4) {\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            if (fwrite(output_packet, 1, err, fout)!=(unsigned)err) {\n               fprintf(stderr, \"Error writing.\\n\");\n               return EXIT_FAILURE;\n            }\n            /*fprintf(stderr, \"out len = %d\\n\", err);*/\n         } else {\n            fprintf(stderr, \"opus_repacketizer_out() failed: %s\\n\", opus_strerror(err));\n         }\n      } else {\n         int nb_frames = opus_repacketizer_get_nb_frames(rp);\n         for (i=0;i<nb_frames;i++)\n         {\n            err = opus_repacketizer_out_range(rp, i, i+1, output_packet, MAX_PACKETOUT);\n            if (err>0) {\n               unsigned char int_field[4];\n               int_to_char(err, int_field);\n               if (fwrite(int_field, 1, 4, fout)!=4) {\n                  fprintf(stderr, \"Error writing.\\n\");\n                  return EXIT_FAILURE;\n               }\n               if (i==nb_frames-1)\n                  int_to_char(rng[nb_packets-1], int_field);\n               else\n                  int_to_char(0, int_field);\n               if (fwrite(int_field, 1, 4, fout)!=4) {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/jni/opus/src/repacketizer_demo.c#L161-L197","documentation":"In the merge (non-split) code path, opus_repacketizer_out() returned a value of 0 or negative, indicating failure. This function assembles all buffered packets into a single output packet; a return of 0 means the repacketizer is empty, and a negative value is an error code (decoded by opus_strerror). Common causes: the repacketizer buffer is empty because opus_repacketizer_cat failed for all packets, or the merged output exceeds MAX_PACKETOUT. Note that this branch does not exit — it only prints the error and continues the main loop.","triggerScenarios":"All opus_repacketizer_cat calls failed in the inner loop, leaving the repacketizer empty; the merged packet would exceed the output buffer (MAX_PACKETOUT=32000 bytes); the packets contain incompatible frame configurations that the repacketizer cannot combine. The `else` branch at line 178 handles this without exiting, so the loop continues to the next batch.","commonSituations":"Merging packets that individually are valid but together exceed the maximum packet size; repacketizer_cat silently broke the loop before any packet was added; testing edge cases with maximum-size packets.","solutions":["Reduce the -merge count to produce smaller combined packets.","Check the opus_strerror output for the specific error code (OPUS_BUFFER_TOO_SMALL, OPUS_INVALID_PACKET).","Ensure the input packets are from a compatible encoder configuration.","Inspect whether any opus_repacketizer_cat errors preceded this failure (error 229)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Check repacketizer state before calling opus_repacketizer_out\nint nb_frames = opus_repacketizer_get_nb_frames(rp);\nif (nb_frames == 0) {\n    fprintf(stderr, \"Repacketizer is empty, skipping output.\\n\");\n    continue;\n}\nint out_len = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);\nif (out_len <= 0) {\n    fprintf(stderr, \"out failed: %s\\n\", opus_strerror(out_len));\n    continue;\n}","typeGuard":null,"tryCatchPattern":"int out_len = opus_repacketizer_out(rp, output_packet, MAX_PACKETOUT);\nif (out_len <= 0) {\n    fprintf(stderr, \"opus_repacketizer_out() failed: %s\\n\", opus_strerror(out_len));\n    // continue to next batch rather than abort\n    continue;\n}","preventionTips":["Check opus_repacketizer_get_nb_frames(rp) > 0 before calling opus_repacketizer_out.","Reduce merge count if the combined packet may exceed MAX_PACKETOUT (32000 bytes).","Log the error code from opus_strerror to distinguish buffer-too-small from invalid-state."],"tags":["opus","library-api","repacketizer","packet-validation","buffer-size"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}