Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Reduce memory consumption by using smaller video resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimir-kotikov committed Aug 8, 2016
1 parent 3cf975b commit 89a9c69
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/windows/BarcodeScannerProxy.js
Expand Up @@ -155,6 +155,7 @@ BarcodeReader.prototype.init = function (capture, width, height) {
this._width = width;
this._height = height;
this._zxingReader = new ZXing.BarcodeReader();
this._zxingReader.tryHarder = true;
};

/**
Expand Down Expand Up @@ -399,7 +400,7 @@ module.exports = {

focusControl.configure(focusConfig);

// Continuous focus should start only after preview has started. See 'Remarks' at
// Continuous focus should start only after preview has started. See 'Remarks' at
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.focuscontrol.configure.aspx
function waitForIsPlaying() {
var isPlaying = !capturePreview.paused && !capturePreview.ended && capturePreview.readyState > 2;
Expand Down Expand Up @@ -444,7 +445,7 @@ module.exports = {
.then(function () {

var controller = capture.videoDeviceController;
var deviceProps = controller.getAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.videoRecord);
var deviceProps = controller.getAvailableMediaStreamProperties(Windows.Media.Capture.MediaStreamType.videoPreview);

deviceProps = Array.prototype.slice.call(deviceProps);
deviceProps = deviceProps.filter(function (prop) {
Expand All @@ -455,8 +456,15 @@ module.exports = {
return propB.width - propA.width;
});

var maxResProps = deviceProps[0];
return controller.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.videoRecord, maxResProps)
var preferredProps = deviceProps.filter(function(prop){
// Filter out props where frame size is between 640*480 and 1280*720
return prop.width >= 640 && prop.height >= 480 && prop.width <= 1280 && prop.height <= 720;
});

// prefer video frame size between between 640*480 and 1280*720
// use maximum resolution otherwise
var maxResProps = preferredProps[0] || deviceProps[0];
return controller.setMediaStreamPropertiesAsync(Windows.Media.Capture.MediaStreamType.videoPreview, maxResProps)
.then(function () {
return {
capture: capture,
Expand Down

0 comments on commit 89a9c69

Please sign in to comment.