Commit 6ce1dd73 authored by kinaba@chromium.org's avatar kinaba@chromium.org

Files.app: mpeg metadata parser must not be stateful.

The previous code writes the parsed metadata to |metadata| dictionary
remembered in |this.rootParser_|, but this is wrong.

The parser class is shared among multiple parses, so to correctly
distinguish concurrent parsing activity, it cannot store states
in the member fields.

BUG=172989

Review URL: https://codereview.chromium.org/391313003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283545 0039d316-1c4b-4281-b951-d872f2087c98
parent 393561d2
...@@ -149,10 +149,10 @@ MpegParser.createRootParser = function(metadata) { ...@@ -149,10 +149,10 @@ MpegParser.createRootParser = function(metadata) {
* @param {function} onError Error callback. * @param {function} onError Error callback.
*/ */
MpegParser.prototype.parse = function(file, metadata, callback, onError) { MpegParser.prototype.parse = function(file, metadata, callback, onError) {
this.rootParser_ = MpegParser.createRootParser(metadata); var rootParser = MpegParser.createRootParser(metadata);
// Kick off the processing by reading the first atom's header. // Kick off the processing by reading the first atom's header.
this.requestRead(file, 0, MpegParser.HEADER_SIZE, null, this.requestRead(rootParser, file, 0, MpegParser.HEADER_SIZE, null,
onError, callback.bind(null, metadata)); onError, callback.bind(null, metadata));
}; };
...@@ -231,6 +231,7 @@ MpegParser.prototype.parseMpegAtomsInRange = function( ...@@ -231,6 +231,7 @@ MpegParser.prototype.parseMpegAtomsInRange = function(
}; };
/** /**
* @param {Object} rootParser Parser definition.
* @param {File} file File. * @param {File} file File.
* @param {number} filePos Start position in the file. * @param {number} filePos Start position in the file.
* @param {number} size Atom size. * @param {number} size Atom size.
...@@ -239,13 +240,14 @@ MpegParser.prototype.parseMpegAtomsInRange = function( ...@@ -239,13 +240,14 @@ MpegParser.prototype.parseMpegAtomsInRange = function(
* @param {function} onSuccess Success callback. * @param {function} onSuccess Success callback.
*/ */
MpegParser.prototype.requestRead = function( MpegParser.prototype.requestRead = function(
file, filePos, size, name, onError, onSuccess) { rootParser, file, filePos, size, name, onError, onSuccess) {
var self = this; var self = this;
var reader = new FileReader(); var reader = new FileReader();
reader.onerror = onError; reader.onerror = onError;
reader.onload = function(event) { reader.onload = function(event) {
self.processTopLevelAtom( self.processTopLevelAtom(
reader.result, file, filePos, size, name, onError, onSuccess); reader.result, rootParser, file, filePos, size, name,
onError, onSuccess);
}; };
this.vlog('reading @' + filePos + ':' + size); this.vlog('reading @' + filePos + ':' + size);
reader.readAsArrayBuffer(file.slice(filePos, filePos + size)); reader.readAsArrayBuffer(file.slice(filePos, filePos + size));
...@@ -253,6 +255,7 @@ MpegParser.prototype.requestRead = function( ...@@ -253,6 +255,7 @@ MpegParser.prototype.requestRead = function(
/** /**
* @param {ArrayBuffer} buf Data buffer. * @param {ArrayBuffer} buf Data buffer.
* @param {Object} rootParser Parser definition.
* @param {File} file File. * @param {File} file File.
* @param {number} filePos Start position in the file. * @param {number} filePos Start position in the file.
* @param {number} size Atom size. * @param {number} size Atom size.
...@@ -261,7 +264,7 @@ MpegParser.prototype.requestRead = function( ...@@ -261,7 +264,7 @@ MpegParser.prototype.requestRead = function(
* @param {function} onSuccess Success callback. * @param {function} onSuccess Success callback.
*/ */
MpegParser.prototype.processTopLevelAtom = function( MpegParser.prototype.processTopLevelAtom = function(
buf, file, filePos, size, name, onError, onSuccess) { buf, rootParser, file, filePos, size, name, onError, onSuccess) {
try { try {
var br = new ByteReader(buf); var br = new ByteReader(buf);
...@@ -280,7 +283,7 @@ MpegParser.prototype.processTopLevelAtom = function( ...@@ -280,7 +283,7 @@ MpegParser.prototype.processTopLevelAtom = function(
// Process the top level atom. // Process the top level atom.
if (name) { // name is null only the first time. if (name) { // name is null only the first time.
this.applyParser( this.applyParser(
this.rootParser_[name], rootParser[name],
br, br,
{start: 0, end: atomEnd, name: name}, {start: 0, end: atomEnd, name: name},
filePos filePos
...@@ -298,12 +301,13 @@ MpegParser.prototype.processTopLevelAtom = function( ...@@ -298,12 +301,13 @@ MpegParser.prototype.processTopLevelAtom = function(
// If we do not have a parser for the next atom, skip the content and // If we do not have a parser for the next atom, skip the content and
// read only the header (the one after the next). // read only the header (the one after the next).
if (!this.rootParser_[nextName]) { if (!rootParser[nextName]) {
filePos += nextSize - MpegParser.HEADER_SIZE; filePos += nextSize - MpegParser.HEADER_SIZE;
nextSize = MpegParser.HEADER_SIZE; nextSize = MpegParser.HEADER_SIZE;
} }
this.requestRead(file, filePos, nextSize, nextName, onError, onSuccess); this.requestRead(rootParser, file, filePos, nextSize, nextName,
onError, onSuccess);
} else { } else {
// The previous read did not return the next atom header, EOF reached. // The previous read did not return the next atom header, EOF reached.
this.vlog('EOF @' + filePos); this.vlog('EOF @' + filePos);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment