MediaInfo.from constructor

MediaInfo.from(
  1. Pointer<mdkMediaInfo> pci
)

Implementation

MediaInfo.from(Pointer<mdkMediaInfo> pci) {
  final ci = pci.ref;
  startTime = ci.start_time;
  duration = ci.duration;
  bitRate = ci.bit_rate;
  if (ci.format != nullptr) {
    format = ci.format.cast<Utf8>().toDartString();
  }
  streams = ci.streams;

  var entry = calloc<mdkStringMapEntry>();
  while (Libmdk.instance.MDK_MediaMetadata(pci, entry)) {
    try {
      metadata[entry.ref.key.cast<Utf8>().toDartString()] =
          entry.ref.value.cast<Utf8>().toDartString();
      // ignore: empty_catches
    } catch (e) {}
  }
  calloc.free(entry);

  if (ci.nb_audio > 0) {
    audio = <AudioStreamInfo>[];
    for (int i = 0; i < ci.nb_audio; ++i) {
      //final cci = ci.audio + i; // since dart3.3, elememtAt() is deprecated
      final cci = Pointer<mdkAudioStreamInfo>.fromAddress(
          ci.audio.address + i * sizeOf<mdkAudioStreamInfo>());
      audio!.add(AudioStreamInfo._from(cci));
    }
  }
  if (ci.nb_video > 0) {
    video = <VideoStreamInfo>[];
    for (int i = 0; i < ci.nb_video; ++i) {
      //final cci = ci.video + i; // since dart3.3, elememtAt() is deprecated
      final cci = Pointer<mdkVideoStreamInfo>.fromAddress(
          ci.video.address + i * sizeOf<mdkVideoStreamInfo>());
      video!.add(VideoStreamInfo._from(cci));
    }
  }
  if (ci.nb_subtitle > 0) {
    subtitle = <SubtitleStreamInfo>[];
    for (int i = 0; i < ci.nb_subtitle; ++i) {
      //final cci = ci.subtitle + i; // since dart3.3, elememtAt() is deprecated
      final cci = Pointer<mdkSubtitleStreamInfo>.fromAddress(ci
              .subtitle.address +
          i *
              sizeOf<
                  mdkSubtitleStreamInfo>()); // Pointer.fromAddress(address + index * sizeOf<T>());
      subtitle!.add(SubtitleStreamInfo._from(cci));
    }
  }
  if (ci.nb_chapters > 0) {
    chapters = <ChapterInfo>[];
    for (int i = 0; i < ci.nb_chapters; ++i) {
      chapters!.add(ChapterInfo._from(ci.chapters[i]));
    }
  }
  if (ci.nb_programs > 0) {
    programs = <ProgramInfo>[];
    for (int i = 0; i < ci.nb_programs; ++i) {
      //final cci = ci.programs + i; // since dart3.3, elememtAt() is deprecated
      final cci = Pointer<mdkProgramInfo>.fromAddress(
          ci.programs.address + i * sizeOf<mdkProgramInfo>());
      programs!.add(ProgramInfo._from(cci));
    }
  }
}