Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AsyncAudioDecoder.cpp

Issue 2685673005: Use TaskScheduler instead of WorkerPool in BackgroundTaskRunner.cpp (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, Google Inc. All rights reserved. 2 * Copyright (C) 2011, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 20 matching lines...) Expand all
31 #include "platform/CrossThreadFunctional.h" 31 #include "platform/CrossThreadFunctional.h"
32 #include "platform/audio/AudioBus.h" 32 #include "platform/audio/AudioBus.h"
33 #include "platform/audio/AudioFileReader.h" 33 #include "platform/audio/AudioFileReader.h"
34 #include "platform/threading/BackgroundTaskRunner.h" 34 #include "platform/threading/BackgroundTaskRunner.h"
35 #include "public/platform/Platform.h" 35 #include "public/platform/Platform.h"
36 #include "public/platform/WebTraceLocation.h" 36 #include "public/platform/WebTraceLocation.h"
37 #include "wtf/PtrUtil.h" 37 #include "wtf/PtrUtil.h"
38 38
39 namespace blink { 39 namespace blink {
40 40
41 // This threshold is determined by the assumption that the target audio
42 // file is compressed in AAC or MP3. The decoding time varies upon different
43 // audio file encoding types, but it is fair to assume the usage of compressed
44 // file.
45 static const unsigned kTaskSizeThresholdInByte = 512000;
46
47 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData, 41 void AsyncAudioDecoder::decodeAsync(DOMArrayBuffer* audioData,
48 float sampleRate, 42 float sampleRate,
49 AudioBufferCallback* successCallback, 43 AudioBufferCallback* successCallback,
50 AudioBufferCallback* errorCallback, 44 AudioBufferCallback* errorCallback,
51 ScriptPromiseResolver* resolver, 45 ScriptPromiseResolver* resolver,
52 BaseAudioContext* context) { 46 BaseAudioContext* context) {
53 DCHECK(isMainThread()); 47 DCHECK(isMainThread());
54 DCHECK(audioData); 48 DCHECK(audioData);
55 if (!audioData) 49 if (!audioData)
56 return; 50 return;
57 51
58 BackgroundTaskRunner::TaskSize taskSize =
59 audioData->byteLength() < kTaskSizeThresholdInByte
60 ? BackgroundTaskRunner::TaskSizeShortRunningTask
61 : BackgroundTaskRunner::TaskSizeLongRunningTask;
62 BackgroundTaskRunner::postOnBackgroundThread( 52 BackgroundTaskRunner::postOnBackgroundThread(
63 BLINK_FROM_HERE, 53 BLINK_FROM_HERE,
64 crossThreadBind(&AsyncAudioDecoder::decodeOnBackgroundThread, 54 crossThreadBind(&AsyncAudioDecoder::decodeOnBackgroundThread,
65 wrapCrossThreadPersistent(audioData), sampleRate, 55 wrapCrossThreadPersistent(audioData), sampleRate,
66 wrapCrossThreadPersistent(successCallback), 56 wrapCrossThreadPersistent(successCallback),
67 wrapCrossThreadPersistent(errorCallback), 57 wrapCrossThreadPersistent(errorCallback),
68 wrapCrossThreadPersistent(resolver), 58 wrapCrossThreadPersistent(resolver),
69 wrapCrossThreadPersistent(context)), 59 wrapCrossThreadPersistent(context)));
70 taskSize);
71 } 60 }
72 61
73 void AsyncAudioDecoder::decodeOnBackgroundThread( 62 void AsyncAudioDecoder::decodeOnBackgroundThread(
74 DOMArrayBuffer* audioData, 63 DOMArrayBuffer* audioData,
75 float sampleRate, 64 float sampleRate,
76 AudioBufferCallback* successCallback, 65 AudioBufferCallback* successCallback,
77 AudioBufferCallback* errorCallback, 66 AudioBufferCallback* errorCallback,
78 ScriptPromiseResolver* resolver, 67 ScriptPromiseResolver* resolver,
79 BaseAudioContext* context) { 68 BaseAudioContext* context) {
80 DCHECK(!isMainThread()); 69 DCHECK(!isMainThread());
(...skipping 29 matching lines...) Expand all
110 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus); 99 AudioBuffer* audioBuffer = AudioBuffer::createFromAudioBus(audioBus);
111 100
112 // If the context is available, let the context finish the notification. 101 // If the context is available, let the context finish the notification.
113 if (context) { 102 if (context) {
114 context->handleDecodeAudioData(audioBuffer, resolver, successCallback, 103 context->handleDecodeAudioData(audioBuffer, resolver, successCallback,
115 errorCallback); 104 errorCallback);
116 } 105 }
117 } 106 }
118 107
119 } // namespace blink 108 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698