@@ -258,9 +258,11 @@ class FrameCryptor {
258
258
}));
259
259
try {
260
260
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 ()}' );
263
263
if (lastError != CryptorError .kInternalError) {
264
+ logger.info (
265
+ 'cryptorState changed from $lastError to kInternalError because ${e .toString ()}, ${s .toString ()}' );
264
266
lastError = CryptorError .kInternalError;
265
267
postMessage ({
266
268
'type' : 'cryptorState' ,
@@ -327,6 +329,7 @@ class FrameCryptor {
327
329
328
330
if (secretKey == null ) {
329
331
if (lastError != CryptorError .kMissingKey) {
332
+ logger.info ('cryptorState changed from $lastError to kMissingKey' );
330
333
lastError = CryptorError .kMissingKey;
331
334
postMessage ({
332
335
'type' : 'cryptorState' ,
@@ -377,6 +380,7 @@ class FrameCryptor {
377
380
controller.enqueue (frame);
378
381
379
382
if (lastError != CryptorError .kOk) {
383
+ logger.info ('cryptorState changed from $lastError to kOk' );
380
384
lastError = CryptorError .kOk;
381
385
postMessage ({
382
386
'type' : 'cryptorState' ,
@@ -391,9 +395,11 @@ class FrameCryptor {
391
395
392
396
logger.finer (
393
397
'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 ()}' );
396
400
if (lastError != CryptorError .kEncryptError) {
401
+ logger.info (
402
+ 'cryptorState changed from $lastError to kEncryptError because ${e .toString ()}, ${s .toString ()}' );
397
403
lastError = CryptorError .kEncryptError;
398
404
postMessage ({
399
405
'type' : 'cryptorState' ,
@@ -460,14 +466,21 @@ class FrameCryptor {
460
466
var headerLength =
461
467
kind == 'video' ? getUnencryptedBytes (frame, codec) : 1 ;
462
468
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 );
463
476
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
+ }
471
484
472
485
/// missingKey flow:
473
486
/// tries to decrypt once, fails, tries to ratchet once and decrypt again,
@@ -477,6 +490,7 @@ class FrameCryptor {
477
490
/// to throw missingkeys faster lower your failureTolerance
478
491
if (initialKeySet == null || ! keyHandler.hasValidKey) {
479
492
if (lastError != CryptorError .kMissingKey) {
493
+ logger.info ('cryptorState changed from $lastError to kMissingKey' );
480
494
lastError = CryptorError .kMissingKey;
481
495
postMessage ({
482
496
'type' : 'cryptorState' ,
@@ -526,6 +540,7 @@ class FrameCryptor {
526
540
logger.finer (
527
541
'ratchetKey: lastError != CryptorError.kKeyRatcheted, reset state to kKeyRatcheted' );
528
542
543
+ logger.info ('cryptorState changed from $lastError to kKeyRatcheted' );
529
544
lastError = CryptorError .kKeyRatcheted;
530
545
postMessage ({
531
546
'type' : 'cryptorState' ,
@@ -584,6 +599,7 @@ class FrameCryptor {
584
599
controller.enqueue (frame);
585
600
586
601
if (lastError != CryptorError .kOk) {
602
+ logger.info ('cryptorState changed from $lastError to kOk' );
587
603
lastError = CryptorError .kOk;
588
604
postMessage ({
589
605
'type' : 'cryptorState' ,
@@ -598,8 +614,11 @@ class FrameCryptor {
598
614
599
615
logger.finer (
600
616
'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 ()}' );
602
619
if (lastError != CryptorError .kDecryptError) {
620
+ logger.info (
621
+ 'cryptorState changed from $lastError to kDecryptError ${e .toString ()}, ${s .toString ()}' );
603
622
lastError = CryptorError .kDecryptError;
604
623
postMessage ({
605
624
'type' : 'cryptorState' ,
0 commit comments