1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.media.audiotestharness.server.javasound; 18 19 import javax.sound.sampled.Control; 20 import javax.sound.sampled.Line; 21 import javax.sound.sampled.LineListener; 22 import javax.sound.sampled.LineUnavailableException; 23 import javax.sound.sampled.Mixer; 24 import javax.sound.sampled.Mixer.Info; 25 import javax.sound.sampled.TargetDataLine; 26 27 /** 28 * Test implementation of the {@link Mixer} interface that scaffolds out enough functionality to be 29 * able to test the {@link JavaAudioSystemService}. 30 */ 31 public class TestMixer implements Mixer { 32 33 private final String mName; 34 private final int mTargetLineCount; 35 private final TargetDataLine mTargetDataLine; 36 private final TestInfo mTestInfo; 37 38 /** 39 * Constructor. 40 * 41 * @param name the name that should be provided in the {@link Mixer.Info} returned by the {@link 42 * #getMixerInfo()} method. 43 * @param targetLineCount the number of target lines this Mixer should expose, in general, this 44 * means that the returned arrays for any target line method are of this size. 45 */ TestMixer(String name, int targetLineCount, TargetDataLine targetDataLine)46 public TestMixer(String name, int targetLineCount, TargetDataLine targetDataLine) { 47 mName = name; 48 mTargetLineCount = targetLineCount; 49 mTargetDataLine = targetDataLine; 50 mTestInfo = new TestInfo(mName, null, null, null); 51 } 52 53 @Override getMixerInfo()54 public Info getMixerInfo() { 55 return mTestInfo; 56 } 57 58 @Override getSourceLineInfo()59 public Line.Info[] getSourceLineInfo() { 60 return new Line.Info[0]; 61 } 62 63 @Override getTargetLineInfo()64 public Line.Info[] getTargetLineInfo() { 65 return new Line.Info[mTargetLineCount]; 66 } 67 68 @Override getSourceLineInfo(Line.Info info)69 public Line.Info[] getSourceLineInfo(Line.Info info) { 70 return new Line.Info[0]; 71 } 72 73 @Override getTargetLineInfo(Line.Info info)74 public Line.Info[] getTargetLineInfo(Line.Info info) { 75 return new Line.Info[mTargetLineCount]; 76 } 77 78 @Override isLineSupported(Line.Info info)79 public boolean isLineSupported(Line.Info info) { 80 return false; 81 } 82 83 @Override getLine(Line.Info info)84 public Line getLine(Line.Info info) throws LineUnavailableException { 85 if (mTargetDataLine == null) { 86 throw new LineUnavailableException("Unavailable"); 87 } else { 88 return mTargetDataLine; 89 } 90 } 91 92 @Override getMaxLines(Line.Info info)93 public int getMaxLines(Line.Info info) { 94 return 0; 95 } 96 97 @Override getSourceLines()98 public Line[] getSourceLines() { 99 return new Line[0]; 100 } 101 102 @Override getTargetLines()103 public Line[] getTargetLines() { 104 return new Line[mTargetLineCount]; 105 } 106 107 @Override synchronize(Line[] lines, boolean maintainSync)108 public void synchronize(Line[] lines, boolean maintainSync) {} 109 110 @Override unsynchronize(Line[] lines)111 public void unsynchronize(Line[] lines) {} 112 113 @Override isSynchronizationSupported(Line[] lines, boolean maintainSync)114 public boolean isSynchronizationSupported(Line[] lines, boolean maintainSync) { 115 return false; 116 } 117 118 @Override getLineInfo()119 public Line.Info getLineInfo() { 120 return null; 121 } 122 123 @Override open()124 public void open() throws LineUnavailableException {} 125 126 @Override close()127 public void close() {} 128 129 @Override isOpen()130 public boolean isOpen() { 131 return false; 132 } 133 134 @Override getControls()135 public Control[] getControls() { 136 return new Control[0]; 137 } 138 139 @Override isControlSupported(Control.Type control)140 public boolean isControlSupported(Control.Type control) { 141 return false; 142 } 143 144 @Override getControl(Control.Type control)145 public Control getControl(Control.Type control) { 146 return null; 147 } 148 149 @Override addLineListener(LineListener listener)150 public void addLineListener(LineListener listener) {} 151 152 @Override removeLineListener(LineListener listener)153 public void removeLineListener(LineListener listener) {} 154 155 /** Test implementation of the Mixer.Info class for visibility here. */ 156 public static class TestInfo extends Info { 157 158 /** 159 * Constructs a mixer's info object, passing it the given textual information. 160 * 161 * @param name the name of the mixer 162 * @param vendor the company who manufactures or creates the hardware or software mixer 163 * @param description descriptive text about the mixer 164 * @param version version information for the mixer 165 */ TestInfo(String name, String vendor, String description, String version)166 protected TestInfo(String name, String vendor, String description, String version) { 167 super(name, vendor, description, version); 168 } 169 } 170 } 171