zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.

Home Page:https://zxing-js.github.io/library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BrowserMultiFormatReader.reader.reset() never called, leaving video resources to consume lots of power.

kodecharlie opened this issue · comments

The problem is that an invocation of BrowserMultiFormatReader.reset()
never results in a call to BrowserMultiFormatReader.reader.reset().

Here's the current snapshot of BrowserMultiFormatReader:

export class BrowserMultiFormatReader extends BrowserCodeReader {

  protected readonly reader: MultiFormatReader;

  public constructor(
    hints: Map<DecodeHintType, any> = null,
    timeBetweenScansMillis: number = 500
  ) {
    const reader = new MultiFormatReader();
    reader.setHints(hints);
    super(reader, timeBetweenScansMillis);
  }

  /**
   * Overwrite decodeBitmap to call decodeWithState, which will pay
   * attention to the hints set in the constructor function
   */
  public decodeBitmap(binaryBitmap: BinaryBitmap): Result {
    return this.reader.decodeWithState(binaryBitmap);
  }
}

To resolve, I propose overriding BrowserCodeReader.reset()inside BrowserMultiFormatReader like this:

// Overrides BrowserCodeReader
public reset(): void {
  super.reset();
  if (this.reader != null) {
    this.reader.reset();
  }
}

That way, we deactivate any state within the superclass as well as turning off resources allocated by
the masked instance of MultiFormatReader.

Stale issue message