@@ -258,9 +258,11 @@ class FrameCryptor {
258258 }));
259259 try {
260260 readable.pipeThrough (transformer).pipeTo (writable);
261- } catch (e) {
262- logger.warning ('e ${e .toString ()}' );
261+ } catch (e, s ) {
262+ logger.warning ('kInternalError: e ${e . toString ()} s ${ s .toString ()}' );
263263 if (lastError != CryptorError .kInternalError) {
264+ logger.info (
265+ 'cryptorState changed from $lastError to kInternalError because ${e .toString ()}, ${s .toString ()}' );
264266 lastError = CryptorError .kInternalError;
265267 postMessage ({
266268 'type' : 'cryptorState' ,
@@ -327,6 +329,7 @@ class FrameCryptor {
327329
328330 if (secretKey == null ) {
329331 if (lastError != CryptorError .kMissingKey) {
332+ logger.info ('cryptorState changed from $lastError to kMissingKey' );
330333 lastError = CryptorError .kMissingKey;
331334 postMessage ({
332335 'type' : 'cryptorState' ,
@@ -377,6 +380,7 @@ class FrameCryptor {
377380 controller.enqueue (frame);
378381
379382 if (lastError != CryptorError .kOk) {
383+ logger.info ('cryptorState changed from $lastError to kOk' );
380384 lastError = CryptorError .kOk;
381385 postMessage ({
382386 'type' : 'cryptorState' ,
@@ -391,9 +395,11 @@ class FrameCryptor {
391395
392396 logger.finer (
393397 'encrypto kind $kind ,codec $codec headerLength: $headerLength , timestamp: ${frame .timestamp }, ssrc: ${metaData .synchronizationSource }, data length: ${buffer .length }, encrypted length: ${finalBuffer .toBytes ().length }, iv $iv ' );
394- } catch (e) {
395- logger.warning ('encrypt : e ${e .toString ()}' );
398+ } catch (e, s ) {
399+ logger.warning ('kEncryptError : e ${e . toString ()}, s: ${ s .toString ()}' );
396400 if (lastError != CryptorError .kEncryptError) {
401+ logger.info (
402+ 'cryptorState changed from $lastError to kEncryptError because ${e .toString ()}, ${s .toString ()}' );
397403 lastError = CryptorError .kEncryptError;
398404 postMessage ({
399405 'type' : 'cryptorState' ,
@@ -460,14 +466,21 @@ class FrameCryptor {
460466 var headerLength =
461467 kind == 'video' ? getUnencryptedBytes (frame, codec) : 1 ;
462468 var metaData = frame.getMetadata ();
469+ Uint8List frameTrailer, iv;
470+ int ivLength, keyIndex;
471+ try {
472+ frameTrailer = buffer.sublist (buffer.length - 2 );
473+ ivLength = frameTrailer[0 ];
474+ keyIndex = frameTrailer[1 ];
475+ iv = buffer.sublist (buffer.length - ivLength - 2 , buffer.length - 2 );
463476
464- var frameTrailer = buffer. sublist (buffer.length - 2 );
465- var ivLength = frameTrailer[ 0 ] ;
466- var keyIndex = frameTrailer[ 1 ];
467- var iv = buffer. sublist (buffer.length - ivLength - 2 , buffer.length - 2 );
468-
469- initialKeySet = keyHandler. getKeySet (keyIndex) ;
470- initialKeyIndex = keyIndex;
477+ initialKeySet = keyHandler. getKeySet (keyIndex );
478+ initialKeyIndex = keyIndex ;
479+ } catch (e) {
480+ logger. finest (
481+ 'getting frameTrailer or iv failed, ignoring frame completely' );
482+ return ;
483+ }
471484
472485 /// missingKey flow:
473486 /// tries to decrypt once, fails, tries to ratchet once and decrypt again,
@@ -477,6 +490,7 @@ class FrameCryptor {
477490 /// to throw missingkeys faster lower your failureTolerance
478491 if (initialKeySet == null || ! keyHandler.hasValidKey) {
479492 if (lastError != CryptorError .kMissingKey) {
493+ logger.info ('cryptorState changed from $lastError to kMissingKey' );
480494 lastError = CryptorError .kMissingKey;
481495 postMessage ({
482496 'type' : 'cryptorState' ,
@@ -526,6 +540,7 @@ class FrameCryptor {
526540 logger.finer (
527541 'ratchetKey: lastError != CryptorError.kKeyRatcheted, reset state to kKeyRatcheted' );
528542
543+ logger.info ('cryptorState changed from $lastError to kKeyRatcheted' );
529544 lastError = CryptorError .kKeyRatcheted;
530545 postMessage ({
531546 'type' : 'cryptorState' ,
@@ -584,6 +599,7 @@ class FrameCryptor {
584599 controller.enqueue (frame);
585600
586601 if (lastError != CryptorError .kOk) {
602+ logger.info ('cryptorState changed from $lastError to kOk' );
587603 lastError = CryptorError .kOk;
588604 postMessage ({
589605 'type' : 'cryptorState' ,
@@ -598,8 +614,11 @@ class FrameCryptor {
598614
599615 logger.finer (
600616 'decrypto kind $kind ,codec $codec headerLength: $headerLength , timestamp: ${frame .timestamp }, ssrc: ${metaData .synchronizationSource }, data length: ${buffer .length }, decrypted length: ${finalBuffer .toBytes ().length }, keyindex $keyIndex iv $iv ' );
601- } catch (e) {
617+ } catch (e, s) {
618+ logger.warning ('kDecryptError ${e .toString ()}, s: ${s .toString ()}' );
602619 if (lastError != CryptorError .kDecryptError) {
620+ logger.info (
621+ 'cryptorState changed from $lastError to kDecryptError ${e .toString ()}, ${s .toString ()}' );
603622 lastError = CryptorError .kDecryptError;
604623 postMessage ({
605624 'type' : 'cryptorState' ,
0 commit comments