31 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
33 if (typeof(
Cc) ==
"undefined")
34 this.
Cc = Components.classes;
35 if (typeof(
Ci) ==
"undefined")
36 this.
Ci = Components.interfaces;
41 var format = eventDetails.QueryInterface(
Ci.sbIMediaFormatAudio);
44 "Expected sample rate "+
test.expectedRate+
45 " differed from actual sample rate "+format.sampleRate);
48 "Expected channel count "+
test.expectedChannels+
49 " differed from actual channel count "+format.channels);
52 if (format.audioType ==
"audio/x-int")
53 actualFormat =
Ci.sbIMediacoreAudioProcessor.FORMAT_INT16;
55 actualFormat =
Ci.sbIMediacoreAudioProcessor.FORMAT_FLOAT;
58 test.expectedFormat == 0 || actualFormat ==
test.expectedFormat,
59 "Expected format "+
test.expectedFormat+
60 " differed from actual format "+actualFormat);
82 var startFailed =
false;
89 assertTrue(startFailed,
"Calling start() again did not fail");
111 description:
"simple unconstrained decode",
112 filename:
"simple.ogg",
115 constraintChannels: 0,
116 constraintBlockSize: 0,
117 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
121 expectedBlockSize: 0,
122 expectedFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
125 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
checkFormat },
126 {
expected:
"samples", sampleCount: 20480, action:
null, blockAction:
null },
127 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
131 description:
"constrained decode to mono",
132 filename:
"simple.ogg",
134 constraintRate: 22050,
135 constraintChannels: 1,
136 constraintBlockSize: 2048,
137 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_FLOAT,
141 expectedBlockSize: 2048,
142 expectedFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_FLOAT,
145 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
checkFormat },
147 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
151 description:
"unconstrained 5.1 channel vorbis",
152 filename:
"surround51.ogg",
155 constraintChannels: 0,
156 constraintBlockSize: 0,
157 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
163 expectedBlockSize: 0,
164 expectedFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
167 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
checkFormat },
168 {
expected:
"samples", sampleCount: 20480, action:
null, blockAction:
null },
169 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
173 description:
"pause/unpause testing",
174 filename:
"simple.ogg",
177 constraintChannels: 0,
178 constraintBlockSize: 1000,
179 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
183 expectedBlockSize: 1000,
184 expectedFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
187 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
checkFormat },
189 {
expected:
"samples", sampleCount: 10480, action:
null, blockAction:
null },
190 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
194 description:
"pause/unpause every block testing",
195 filename:
"simple.ogg",
198 constraintChannels: 0,
199 constraintBlockSize: 1000,
200 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
204 expectedBlockSize: 1000,
205 expectedFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
208 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
checkFormat },
210 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
214 description:
"multiple calls to start",
215 filename:
"simple.ogg",
218 constraintChannels: 0,
219 constraintBlockSize: 0,
220 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
223 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
startAgain },
224 {
expected:
"samples", sampleCount: 20480, action:
null, blockAction:
null },
225 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
229 description:
"stop in the middle",
230 filename:
"simple.ogg",
233 constraintChannels: 0,
234 constraintBlockSize: 1000,
235 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
238 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
startAgain },
243 description:
"video only file",
244 filename:
"video.ogg",
247 constraintChannels: 0,
248 constraintBlockSize: 0,
249 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
252 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_ERROR, action:
null },
256 description:
"file that doesn't exist",
257 filename:
"nothere.ogg",
260 constraintChannels: 0,
261 constraintBlockSize: 0,
262 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
265 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_ERROR, action:
null },
269 description:
"gap test (corrupt data in middle of file)",
270 filename:
"corrupt-in-middle.ogg",
273 constraintChannels: 0,
274 constraintBlockSize: 0,
275 constraintFormat:
Ci.sbIMediacoreAudioProcessor.FORMAT_ANY,
278 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_START, action:
null},
279 {
expected:
"samples", sampleCount: 21184, action:
null, blockAction:
null },
280 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_GAP, action:
null },
281 {
expected:
"samples", sampleCount: 19456, action:
null, blockAction:
null },
282 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_GAP, action:
null },
283 {
expected:
"samples", sampleCount: 39232, action:
null, blockAction:
null },
284 {
expected:
"event", eventType:
Ci.sbIMediacoreAudioProcessorListener.EVENT_EOS, action:
null }
292 var processor =
Cc[
"@songbirdnest.com/Songbird/Mediacore/GStreamer/AudioProcessor;1"]
293 .createInstance(
Ci.sbIMediacoreAudioProcessor);
294 assertTrue(processor,
"failed to create processor");
301 onIntegerAudioDecoded :
function(timestamp, numSamples, sampleData) {
302 this.onAudio(timestamp, numSamples);
305 onFloatAudioDecoded :
function(timestamp, numSamples, sampleData) {
306 this.onAudio(timestamp, numSamples);
309 onAudio :
function(timestamp, numSamples) {
310 assertTrue(this.seqIdx <
test.sequence.length,
"Audio after end!");
311 var expectingSamples =
test.sequence[this.seqIdx].expected ==
"samples";
313 "Got audio samples when not expecting any");
315 numSamples <=
test.constraintBlockSize,
316 "Received incorrect block size");
318 var numSamplesExpected =
test.sequence[this.seqIdx].sampleCount;
320 this.samplesCounted += numSamples;
322 assertTrue(this.samplesCounted <= numSamplesExpected,
323 "Received more samples than expected");
325 if (
test.sequence[
this.seqIdx].blockAction !=
null)
327 test.sequence[this.seqIdx].blockAction(
this, processor,
test,
null);
330 if (this.samplesCounted == numSamplesExpected) {
331 this.samplesCounted = 0;
332 this.nextAction(
null);
336 onEvent :
function(eventType, details) {
337 assertTrue(this.seqIdx <
test.sequence.length,
"Event after end!");
338 var expectingEvent =
test.sequence[this.seqIdx].expected ==
"event";
340 "Got event of type "+eventType+
" when not expecting an event");
342 var expectedEventType =
test.sequence[this.seqIdx].eventType;
345 this.nextAction(details);
348 nextAction:
function(
data) {
350 var continueToNextSequence =
true;
351 if (
test.sequence[
this.seqIdx].action !=
null)
352 continueToNextSequence =
test.sequence[this.seqIdx].action(
355 if (continueToNextSequence)
359 nextSequence:
function() {
362 if (this.seqIdx ==
test.sequence.length) {
370 QueryInterface: XPCOMUtils.generateQI([
Ci.sbIMediacoreAudioProcessorListener])
373 processor.init(listener);
375 processor.constraintSampleRate =
test.constraintRate;
376 processor.constraintChannelCount =
test.constraintChannels;
377 processor.constraintBlockSize =
test.constraintBlockSize;
378 processor.constraintAudioFormat =
test.constraintFormat;
380 var
ioService =
Cc[
"@mozilla.org/network/io-service;1"]
381 .getService(
Ci.nsIIOService);
384 var
file = TEST_FILES.clone();
385 file.append(
test.filename);
387 var fileURI = ioService.newFileURI(file,
false);
388 var mediaItem = library.createMediaItem(fileURI);
389 processor.start(mediaItem);
401 log(
"Checking testcase [" + testcase.description +
"]");
function runTest()
Advanced DataRemote unit tests.
function newAppRelativeFile(path)
function pauseMomentarily(listener, processor, test, unused)
sbOSDControlService prototype QueryInterface
function assertTrue(aTest, aMessage)
function assertEqual(aExpected, aActual, aMessage)
function startAgain(listener, processor, test, eventDetails)
function checkFormat(listener, processor, test, eventDetails)
function stopProcessing(listener, processor, test, eventDetails)
function pauseTest(listener, processor, test, eventDetails)
function createLibrary(databaseGuid, databaseLocation)
function runAudioProcessingTest(library, test)
function doTimeout(delay, func)