MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / UpdatePlayer

Function UpdatePlayer

Source/Engine/Video/Android/VideoBackendAndroid.cpp:245–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243 }
244
245 void UpdatePlayer(int32 index)
246 {
247 PROFILE_CPU();
248 auto& player = *Players[index];
249 ZoneText(player.DebugUrl, player.DebugUrlLen);
250 auto& playerAndroid = player.GetBackendState<VideoPlayerAndroid>();
251
252 // Skip paused player
253 if (!playerAndroid.Playing || (playerAndroid.InputEnded && playerAndroid.OutputEnded))
254 return;
255 media_status_t status;
256 ssize_t bufferIndex;
257
258 // Get current sample info
259 int64_t presentationTimeUs = AMediaExtractor_getSampleTime(playerAndroid.Extractor);
260 int trackIndex = AMediaExtractor_getSampleTrackIndex(playerAndroid.Extractor);
261 if (trackIndex < 0)
262 {
263#if VIDEO_API_ANDROID_DEBUG
264 LOG(Info, "[VideoBackendAndroid] Samples track ended");
265#endif
266 if (playerAndroid.Loop)
267 {
268 // Loop
269 status = AMediaExtractor_seekTo(playerAndroid.Extractor, 0, AMEDIAEXTRACTOR_SEEK_CLOSEST_SYNC);
270 if (status != AMEDIA_OK)
271 {
272 VIDEO_API_ANDROID_ERROR(AMediaExtractor_seekTo, status);
273 }
274 if (playerAndroid.VideoCodec)
275 AMediaCodec_flush(playerAndroid.VideoCodec);
276 if (playerAndroid.AudioCodec)
277 AMediaCodec_flush(playerAndroid.VideoCodec);
278 }
279 else
280 {
281 // Emd
282 playerAndroid.InputEnded = playerAndroid.OutputEnded = 1;
283 }
284 }
285 else if (trackIndex == playerAndroid.VideoTrackIndex || trackIndex == playerAndroid.AudioTrackIndex)
286 {
287 auto codec = trackIndex == playerAndroid.VideoTrackIndex ? playerAndroid.VideoCodec : playerAndroid.AudioCodec;
288
289 // Process input buffer
290 bufferIndex = AMediaCodec_dequeueInputBuffer(codec, 2000);
291 if (bufferIndex >= 0)
292 {
293 size_t bufferSize;
294 uint8_t* buffer = AMediaCodec_getInputBuffer(codec, bufferIndex, &bufferSize);
295 ssize_t sampleSize = AMediaExtractor_readSampleData(playerAndroid.Extractor, buffer, bufferSize);
296 uint32_t queueInputFlags = 0;
297 if (sampleSize < 0)
298 {
299 queueInputFlags |= AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM;
300 sampleSize = 0;
301 }
302 status = AMediaCodec_queueInputBuffer(codec, bufferIndex, 0, sampleSize, presentationTimeUs, queueInputFlags);

Callers

nothing calls this directly

Calls 2

ReadCodecOutputFunction · 0.85
TickMethod · 0.45

Tested by

no test coverage detected