1717
1818import static androidx .media3 .common .util .Util .getPcmFormat ;
1919import static com .google .common .truth .Truth .assertThat ;
20+ import static org .junit .Assert .assertThrows ;
2021
2122import androidx .media3 .common .C ;
2223import androidx .media3 .common .MediaItem ;
@@ -46,8 +47,7 @@ public class AudioGraphTest {
4647
4748 @ Test
4849 public void silentItem_outputsCorrectAmountOfBytes () throws Exception {
49- AudioGraph audioGraph =
50- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
50+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
5151
5252 GraphInput input = audioGraph .registerInput (FAKE_ITEM , getPcmFormat (SURROUND_50000 ));
5353 input .onMediaItemChanged (
@@ -63,9 +63,8 @@ public void silentItem_outputsCorrectAmountOfBytes() throws Exception {
6363 public void silentItem_withSampleRateChange_outputsCorrectAmountOfBytes () throws Exception {
6464 SonicAudioProcessor changeTo100000Hz = new SonicAudioProcessor ();
6565 changeTo100000Hz .setOutputSampleRateHz (100_000 );
66- AudioGraph audioGraph =
67- new AudioGraph (
68- new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of (changeTo100000Hz ));
66+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
67+ audioGraph .configure (ImmutableList .of (changeTo100000Hz ));
6968
7069 GraphInput input = audioGraph .registerInput (FAKE_ITEM , getPcmFormat (SURROUND_50000 ));
7170 input .onMediaItemChanged (
@@ -79,48 +78,23 @@ public void silentItem_withSampleRateChange_outputsCorrectAmountOfBytes() throws
7978
8079 @ Test
8180 public void getOutputAudioFormat_afterInitialization_isNotSet () {
82- AudioGraph audioGraph =
83- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
81+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
8482
8583 assertThat (audioGraph .getOutputAudioFormat ()).isEqualTo (AudioFormat .NOT_SET );
8684 }
8785
8886 @ Test
8987 public void getOutputAudioFormat_afterRegisterInput_matchesInputFormat () throws Exception {
90- AudioGraph audioGraph =
91- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
88+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
9289
9390 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (MONO_48000 ));
9491
9592 assertThat (audioGraph .getOutputAudioFormat ()).isEqualTo (MONO_48000 );
9693 }
9794
98- @ Test
99- public void getOutputAudioFormat_afterConfigure_matchesConfiguredFormat () throws Exception {
100- AudioGraph audioGraph =
101- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
102-
103- audioGraph .configure (/* mixerAudioFormat= */ SURROUND_50000 );
104-
105- assertThat (audioGraph .getOutputAudioFormat ()).isEqualTo (SURROUND_50000 );
106- }
107-
108- @ Test
109- public void registerInput_afterConfigure_doesNotChangeOutputFormat () throws Exception {
110- AudioGraph audioGraph =
111- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
112-
113- audioGraph .configure (/* mixerAudioFormat= */ STEREO_44100 );
114- audioGraph .registerInput (FAKE_ITEM , getPcmFormat (STEREO_48000 ));
115- audioGraph .registerInput (FAKE_ITEM , getPcmFormat (MONO_44100 ));
116-
117- assertThat (audioGraph .getOutputAudioFormat ()).isEqualTo (STEREO_44100 );
118- }
119-
12095 @ Test
12196 public void registerInput_afterRegisterInput_doesNotChangeOutputFormat () throws Exception {
122- AudioGraph audioGraph =
123- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
97+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
12498
12599 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (STEREO_48000 ));
126100 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (MONO_44100 ));
@@ -130,8 +104,7 @@ public void registerInput_afterRegisterInput_doesNotChangeOutputFormat() throws
130104
131105 @ Test
132106 public void registerInput_afterReset_changesOutputFormat () throws Exception {
133- AudioGraph audioGraph =
134- new AudioGraph (new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of ());
107+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
135108
136109 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (STEREO_48000 ));
137110 audioGraph .reset ();
@@ -140,26 +113,12 @@ public void registerInput_afterReset_changesOutputFormat() throws Exception {
140113 assertThat (audioGraph .getOutputAudioFormat ()).isEqualTo (MONO_44100 );
141114 }
142115
143- @ Test
144- public void configure_withAudioProcessor_affectsOutputFormat () throws Exception {
145- SonicAudioProcessor sonicAudioProcessor = new SonicAudioProcessor ();
146- sonicAudioProcessor .setOutputSampleRateHz (48_000 );
147- AudioGraph audioGraph =
148- new AudioGraph (
149- new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of (sonicAudioProcessor ));
150-
151- audioGraph .configure (/* mixerAudioFormat= */ SURROUND_50000 );
152-
153- assertThat (audioGraph .getOutputAudioFormat ().sampleRate ).isEqualTo (48_000 );
154- }
155-
156116 @ Test
157117 public void registerInput_withAudioProcessor_affectsOutputFormat () throws Exception {
158118 SonicAudioProcessor sonicAudioProcessor = new SonicAudioProcessor ();
159119 sonicAudioProcessor .setOutputSampleRateHz (48_000 );
160- AudioGraph audioGraph =
161- new AudioGraph (
162- new DefaultAudioMixer .Factory (), /* effects= */ ImmutableList .of (sonicAudioProcessor ));
120+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
121+ audioGraph .configure (ImmutableList .of (sonicAudioProcessor ));
163122
164123 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (SURROUND_50000 ));
165124
@@ -172,16 +131,39 @@ public void registerInput_withMultipleAudioProcessors_affectsOutputFormat() thro
172131 changeTo96000Hz .setOutputSampleRateHz (96_000 );
173132 SonicAudioProcessor changeTo48000Hz = new SonicAudioProcessor ();
174133 changeTo48000Hz .setOutputSampleRateHz (48_000 );
175- AudioGraph audioGraph =
176- new AudioGraph (
177- new DefaultAudioMixer .Factory (),
178- /* effects= */ ImmutableList .of (changeTo96000Hz , changeTo48000Hz ));
134+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
135+ audioGraph .configure (ImmutableList .of (changeTo96000Hz , changeTo48000Hz ));
179136
180137 audioGraph .registerInput (FAKE_ITEM , getPcmFormat (SURROUND_50000 ));
181138
182139 assertThat (audioGraph .getOutputAudioFormat ().sampleRate ).isEqualTo (48_000 );
183140 }
184141
142+ @ Test
143+ public void configure_changesOutputFormat () throws Exception {
144+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
145+ SonicAudioProcessor sonicAudioProcessor = new SonicAudioProcessor ();
146+ sonicAudioProcessor .setOutputSampleRateHz (48_000 );
147+ audioGraph .configure (ImmutableList .of (sonicAudioProcessor ));
148+
149+ audioGraph .registerInput (FAKE_ITEM , getPcmFormat (STEREO_44100 ));
150+
151+ assertThat (audioGraph .getOutputAudioFormat ().sampleRate ).isEqualTo (48_000 );
152+ }
153+
154+ @ Test
155+ public void configure_afterRegisterInput_throws () throws Exception {
156+ AudioGraph audioGraph = new AudioGraph (new DefaultAudioMixer .Factory ());
157+ SonicAudioProcessor sonicAudioProcessor = new SonicAudioProcessor ();
158+ sonicAudioProcessor .setOutputSampleRateHz (48_000 );
159+
160+ audioGraph .registerInput (FAKE_ITEM , getPcmFormat (STEREO_44100 ));
161+
162+ assertThrows (
163+ IllegalStateException .class ,
164+ () -> audioGraph .configure (ImmutableList .of (sonicAudioProcessor )));
165+ }
166+
185167 /** Drains the graph and returns the number of bytes output. */
186168 private static int drainAudioGraph (AudioGraph audioGraph ) throws ExportException {
187169 int bytesOutput = 0 ;
0 commit comments