19
19
import static androidx .media3 .exoplayer .video .VideoSink .RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED ;
20
20
import static com .google .common .truth .Truth .assertThat ;
21
21
import static org .junit .Assert .assertThrows ;
22
- import static org .mockito .ArgumentMatchers .any ;
23
22
import static org .mockito .ArgumentMatchers .anyInt ;
24
23
import static org .mockito .ArgumentMatchers .anyLong ;
25
24
import static org .mockito .ArgumentMatchers .eq ;
28
27
import static org .mockito .Mockito .when ;
29
28
30
29
import android .content .Context ;
30
+ import androidx .media3 .common .C ;
31
31
import androidx .media3 .common .ColorInfo ;
32
32
import androidx .media3 .common .DebugViewProvider ;
33
33
import androidx .media3 .common .Effect ;
@@ -100,11 +100,100 @@ public void onInputStreamChanged_setsVideoSinkVideoEffects() throws VideoSink.Vi
100
100
startPositionUs ,
101
101
RELEASE_FIRST_FRAME_WHEN_PREVIOUS_STREAM_PROCESSED ,
102
102
ImmutableList .of ());
103
- testVideoGraphFactory .verifyRegisteredEffectsMatches (/* invocationTimes= */ 3 );
103
+ testVideoGraphFactory .verifyRegisterInputStream (/* invocationTimes= */ 3 );
104
104
assertThat (testVideoGraphFactory .getCapturedEffects ())
105
105
.isEqualTo (ImmutableList .of (firstEffects , secondEffects , ImmutableList .of ()));
106
106
}
107
107
108
+ @ Test
109
+ public void onInputStreamChanged_withNoToneMapping_initializesGraphWithInputColorInfo ()
110
+ throws VideoSink .VideoSinkException {
111
+ TestVideoGraphFactory testVideoGraphFactory = new TestVideoGraphFactory ();
112
+ PlaybackVideoGraphWrapper playbackVideoGraphWrapper =
113
+ createPlaybackVideoGraphWrapper (testVideoGraphFactory );
114
+ ColorInfo hlgColorInfo =
115
+ new ColorInfo .Builder ()
116
+ .setColorRange (C .COLOR_RANGE_FULL )
117
+ .setColorSpace (C .COLOR_SPACE_BT2020 )
118
+ .setColorTransfer (C .COLOR_TRANSFER_HLG )
119
+ .build ();
120
+ Format inputFormat = new Format .Builder ().setColorInfo (hlgColorInfo ).build ();
121
+ long startPositionUs = 0 ;
122
+ VideoSink sink = playbackVideoGraphWrapper .getSink (/* inputIndex= */ 0 );
123
+
124
+ sink .initialize (inputFormat );
125
+ sink .onInputStreamChanged (
126
+ VideoSink .INPUT_TYPE_SURFACE ,
127
+ inputFormat ,
128
+ startPositionUs ,
129
+ RELEASE_FIRST_FRAME_IMMEDIATELY ,
130
+ /* videoEffects= */ ImmutableList .of ());
131
+
132
+ testVideoGraphFactory .verifyRegisterInputStream (/* invocationTimes= */ 1 );
133
+ assertThat (testVideoGraphFactory .getCapturedFormats ()).containsExactly (inputFormat );
134
+ }
135
+
136
+ @ Test
137
+ public void onInputStreamChanged_withInputSdrToneMapped_initializesGraphWithBt709Input ()
138
+ throws VideoSink .VideoSinkException {
139
+ TestVideoGraphFactory testVideoGraphFactory = new TestVideoGraphFactory ();
140
+ PlaybackVideoGraphWrapper playbackVideoGraphWrapper =
141
+ createPlaybackVideoGraphWrapper (testVideoGraphFactory );
142
+ ColorInfo hlgColorInfo =
143
+ new ColorInfo .Builder ()
144
+ .setColorRange (C .COLOR_RANGE_FULL )
145
+ .setColorSpace (C .COLOR_SPACE_BT2020 )
146
+ .setColorTransfer (C .COLOR_TRANSFER_HLG )
147
+ .build ();
148
+ Format inputFormat = new Format .Builder ().setColorInfo (hlgColorInfo ).build ();
149
+ long startPositionUs = 0 ;
150
+ VideoSink sink = playbackVideoGraphWrapper .getSink (/* inputIndex= */ 0 );
151
+
152
+ playbackVideoGraphWrapper .setIsInputSdrToneMapped (true );
153
+ sink .initialize (inputFormat );
154
+ sink .onInputStreamChanged (
155
+ VideoSink .INPUT_TYPE_SURFACE ,
156
+ inputFormat ,
157
+ startPositionUs ,
158
+ RELEASE_FIRST_FRAME_IMMEDIATELY ,
159
+ /* videoEffects= */ ImmutableList .of ());
160
+
161
+ testVideoGraphFactory .verifyRegisterInputStream (/* invocationTimes= */ 1 );
162
+ Format bt709ColorInfoInputFormat =
163
+ inputFormat .buildUpon ().setColorInfo (ColorInfo .SDR_BT709_LIMITED ).build ();
164
+ assertThat (testVideoGraphFactory .getCapturedFormats ())
165
+ .containsExactly (bt709ColorInfoInputFormat );
166
+ }
167
+
168
+ @ Test
169
+ public void onInputStreamChanged_withOpenGlToneMapping_initializesGraphWithInputColorInfo ()
170
+ throws VideoSink .VideoSinkException {
171
+ TestVideoGraphFactory testVideoGraphFactory = new TestVideoGraphFactory ();
172
+ PlaybackVideoGraphWrapper playbackVideoGraphWrapper =
173
+ createPlaybackVideoGraphWrapper (testVideoGraphFactory );
174
+ ColorInfo hlgColorInfo =
175
+ new ColorInfo .Builder ()
176
+ .setColorRange (C .COLOR_RANGE_FULL )
177
+ .setColorSpace (C .COLOR_SPACE_BT2020 )
178
+ .setColorTransfer (C .COLOR_TRANSFER_HLG )
179
+ .build ();
180
+ Format inputFormat = new Format .Builder ().setColorInfo (hlgColorInfo ).build ();
181
+ long startPositionUs = 0 ;
182
+ VideoSink sink = playbackVideoGraphWrapper .getSink (/* inputIndex= */ 0 );
183
+
184
+ playbackVideoGraphWrapper .setRequestOpenGlToneMapping (true );
185
+ sink .initialize (inputFormat );
186
+ sink .onInputStreamChanged (
187
+ VideoSink .INPUT_TYPE_SURFACE ,
188
+ inputFormat ,
189
+ startPositionUs ,
190
+ RELEASE_FIRST_FRAME_IMMEDIATELY ,
191
+ /* videoEffects= */ ImmutableList .of ());
192
+
193
+ testVideoGraphFactory .verifyRegisterInputStream (/* invocationTimes= */ 1 );
194
+ assertThat (testVideoGraphFactory .getCapturedFormats ()).containsExactly (inputFormat );
195
+ }
196
+
108
197
private static PlaybackVideoGraphWrapper createPlaybackVideoGraphWrapper (
109
198
VideoGraph .Factory videoGraphFactory ) {
110
199
Context context = ApplicationProvider .getApplicationContext ();
@@ -150,6 +239,8 @@ private static class TestVideoGraphFactory implements VideoGraph.Factory {
150
239
@ SuppressWarnings ("unchecked" )
151
240
private final ArgumentCaptor <List <Effect >> effectsCaptor = ArgumentCaptor .forClass (List .class );
152
241
242
+ private final ArgumentCaptor <Format > formatCaptor = ArgumentCaptor .forClass (Format .class );
243
+
153
244
@ Override
154
245
public VideoGraph create (
155
246
Context context ,
@@ -171,18 +262,22 @@ public boolean supportsMultipleInputs() {
171
262
return false ;
172
263
}
173
264
174
- public void verifyRegisteredEffectsMatches (int invocationTimes ) {
265
+ public void verifyRegisterInputStream (int invocationTimes ) {
175
266
verify (videoGraph , times (invocationTimes ))
176
267
.registerInputStream (
177
268
/* inputIndex= */ anyInt (),
178
269
/* inputType= */ eq (VideoSink .INPUT_TYPE_SURFACE ),
179
- /* format= */ any (),
270
+ formatCaptor . capture (),
180
271
effectsCaptor .capture (),
181
272
/* offsetToAddUs= */ anyLong ());
182
273
}
183
274
184
275
public List <List <Effect >> getCapturedEffects () {
185
276
return effectsCaptor .getAllValues ();
186
277
}
278
+
279
+ public List <Format > getCapturedFormats () {
280
+ return formatCaptor .getAllValues ();
281
+ }
187
282
}
188
283
}
0 commit comments