MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / fillData

Method fillData

framework/video/smk.cpp:360–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

358const UString &SMKMusicTrack::getName() const { return this->video->file_path; }
359
360MusicTrack::MusicCallbackReturn SMKMusicTrack::fillData(unsigned int maxSamples, void *sampleBuffer,
361 unsigned int *returnedSamples)
362{
363 *returnedSamples = 0;
364
365 if (!this->current_frame)
366 {
367 LogWarning("Playing beyond end of video");
368 return MusicCallbackReturn::End;
369 }
370
371 unsigned int output_offset_bytes = 0;
372 while (*returnedSamples < maxSamples && this->current_frame)
373 {
374 unsigned int samples_in_this_frame =
375 std::min(maxSamples - *returnedSamples,
376 this->current_frame->sample_count - this->current_frame_sample_position);
377
378 unsigned int audio_size_bytes = samples_in_this_frame *
379 this->current_frame->format.getSampleSize() *
380 this->current_frame->format.channels;
381
382 unsigned int audio_offset_bytes = this->current_frame_sample_position *
383 this->current_frame->format.getSampleSize() *
384 this->current_frame->format.channels;
385
386 memcpy((uint8_t *)sampleBuffer + output_offset_bytes,
387 this->current_frame->samples.get() + audio_offset_bytes, audio_size_bytes);
388
389 output_offset_bytes += audio_size_bytes;
390
391 *returnedSamples += samples_in_this_frame;
392
393 this->current_frame_sample_position += samples_in_this_frame;
394 LogAssert(this->current_frame_sample_position <= this->current_frame->sample_count);
395
396 if (this->current_frame_sample_position == this->current_frame->sample_count)
397 {
398 this->current_frame = video->popAudio();
399 this->current_frame_sample_position = 0;
400 }
401 }
402
403 if (this->current_frame)
404 {
405 return MusicCallbackReturn::Continue;
406 }
407 else
408 {
409 return MusicCallbackReturn::End;
410 }
411}
412sp<Video> loadSMKVideo(IFile &file)
413{
414 auto vid = mksp<SMKVideo>();

Callers 1

fillSMKMusicDataFunction · 0.45

Calls 3

getSampleSizeMethod · 0.80
popAudioMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected