Glenn Kasten | 37784a5 | 2014-02-03 11:57:33 -0800 | [diff] [blame^] | 1 | page.title=Audio Debugging |
| 2 | @jd:body |
| 3 | |
| 4 | <div id="qv-wrapper"> |
| 5 | <div id="qv"> |
| 6 | <h2>In this document</h2> |
| 7 | <ol id="auto-toc"> |
| 8 | </ol> |
| 9 | </div> |
| 10 | </div> |
| 11 | |
| 12 | <p> |
| 13 | This article describes some tips and tricks for debugging Android audio. |
| 14 | </p> |
| 15 | |
| 16 | <h2 id="teeSink">Tee Sink</h2> |
| 17 | |
| 18 | <p> |
| 19 | The "tee sink" is |
| 20 | an AudioFlinger debugging feature, available in custom builds only, |
| 21 | for retaining a short fragment of recent audio for later analysis. |
| 22 | This permits comparison between what was actually played or recorded |
| 23 | vs. what was expected. |
| 24 | </p> |
| 25 | |
| 26 | <p> |
| 27 | For privacy the tee sink is disabled by default, at both compile-time and |
| 28 | run-time. To use the tee sink, you will need to enable it by re-compiling, |
| 29 | and also by setting a property. Be sure to disable this feature after you are |
| 30 | done debugging; the tee sink should not be left enabled in production builds. |
| 31 | </p> |
| 32 | |
| 33 | <p> |
| 34 | The instructions in the remainder of this section are for Android 4.4, |
| 35 | and may require changes for other versions. |
| 36 | </p> |
| 37 | |
| 38 | <h3>Compile-time setup</h3> |
| 39 | |
| 40 | <ol> |
| 41 | <li><code>cd frameworks/av/services/audioflinger</code></li> |
| 42 | <li>edit <code>Configuration.h</code></li> |
| 43 | <li>uncomment <code>#define TEE_SINK</code></li> |
| 44 | <li>re-build <code>libaudioflinger.so</code></li> |
| 45 | <li><code>adb root</code></li> |
| 46 | <li><code>adb remount</code></li> |
| 47 | <li>push or sync the new <code>libaudioflinger.so</code> to the device's <code>/system/lib</code></li> |
| 48 | </ol> |
| 49 | |
| 50 | <h3>Run-time setup</h3> |
| 51 | |
| 52 | <ol> |
| 53 | <li><code>adb shell getprop | grep ro.debuggable</code> |
| 54 | <br />Confirm that the output is: <code>[ro.debuggable]: [1]</code> |
| 55 | </li> |
| 56 | <li><code>adb shell</code></li> |
| 57 | <li><code>ls -ld /data/misc/media</code> |
| 58 | <br /> |
| 59 | <p> |
| 60 | Confirm that the output is: |
| 61 | </p> |
| 62 | <pre> |
| 63 | drwx------ media media ... media |
| 64 | </pre> |
| 65 | <br /> |
| 66 | <p> |
| 67 | If the directory does not exist, create it as follows: |
| 68 | </p> |
| 69 | <code> |
| 70 | mkdir /data/misc/media |
| 71 | chown media:media /data/misc/media |
| 72 | </code> |
| 73 | </li> |
| 74 | <li><code>echo af.tee=# > /data/local.prop</code> |
| 75 | <br />where the <code>af.tee</code> value is a number described below |
| 76 | </li> |
| 77 | <li><code>chmod 644 /data/local.prop</code></li> |
| 78 | <li><code>reboot</code></li> |
| 79 | </ol> |
| 80 | |
| 81 | <h4>Values for <code>af.tee</code> property</h4> |
| 82 | |
| 83 | <p> |
| 84 | The value of <code>af.tee</code> is a number between 0 and 7, expressing |
| 85 | the sum of several bits, one per feature. |
| 86 | See the code at <code>AudioFlinger::AudioFlinger()</code> in <code>AudioFlinger.cpp</code> |
| 87 | for an explanation of each bit, but briefly: |
| 88 | </p> |
| 89 | <ul> |
| 90 | <li>1 = input</li> |
| 91 | <li>2 = FastMixer output</li> |
| 92 | <li>4 = per-track AudioRecord and AudioTrack</li> |
| 93 | </ul> |
| 94 | |
| 95 | <p> |
| 96 | There is no bit for deep buffer or normal mixer yet, |
| 97 | but you can get similar results using "4." |
| 98 | </p> |
| 99 | |
| 100 | <h3>Test and acquire data</h3> |
| 101 | |
| 102 | <ol> |
| 103 | <li>Run your audio test</li> |
| 104 | <li><code>adb shell dumpsys media.audio_flinger</code></li> |
| 105 | <li>Look for a line in dumpsys output such as this:<br /> |
| 106 | <code>tee copied to /data/misc/media/20131010101147_2.wav</code> |
| 107 | <br />This is a PCM .wav file</br> |
| 108 | </li> |
| 109 | <li><code>adb pull</code> any <code>/data/misc/media/*.wav</code> files of interest; |
| 110 | note that track-specific dump filenames do not appear in the dumpsys output, |
| 111 | but are still saved to <code>/data/misc/media</code> upon track closure |
| 112 | </li> |
| 113 | <li>Review the dump files for privacy concerns before sharing with others</li> |
| 114 | </ol> |
| 115 | |
| 116 | <h4>Suggestions</h4> |
| 117 | |
| 118 | <p>Try these ideas for more useful results:</p> |
| 119 | |
| 120 | <ul> |
| 121 | <li>Disable touch sounds and key clicks</li> |
| 122 | <li>Maximize all volumes</li> |
| 123 | <li>Disable apps that make sound or record from microphone, |
| 124 | if they are not of interest to your test |
| 125 | </li> |
| 126 | <li>Track-specific dumps are only saved when the track is closed; |
| 127 | you may need to force close an app in order to dump its track-specific data |
| 128 | <li>Do the <code>dumpsys</code> immediately after test; |
| 129 | there is a limited amount of recording space available</li> |
| 130 | <li>To make sure you don't lose your dump files, |
| 131 | upload them to your host periodically. |
| 132 | Only a limited number of dump files are preserved; |
| 133 | older dumps are removed after that limit is reached.</li> |
| 134 | </ul> |
| 135 | |
| 136 | <h3>Restore</h3> |
| 137 | |
| 138 | <p> |
| 139 | As noted above, the tee sink feature should not be left enabled. |
| 140 | Restore your build and device as follows: |
| 141 | </p> |
| 142 | <ol> |
| 143 | <li>Revert the source code changes to <code>Configuration.h</code></li> |
| 144 | <li>Re-build <code>libaudioflinger.so</code></li> |
| 145 | <li>Push or sync the restored <code>libaudioflinger.so</code> |
| 146 | to the device's <code>/system/lib</code> |
| 147 | </li> |
| 148 | <li><code>adb shell</code></li> |
| 149 | <li><code>rm /data/local.prop</code></li> |
| 150 | <li><code>rm /data/misc/media/*.wav</code></li> |
| 151 | <li><code>reboot</code></li> |
| 152 | </ol> |
| 153 | |