001package net.bramp.ffmpeg.probe;
002
003import com.google.common.collect.ImmutableList;
004import java.util.ArrayList;
005import java.util.Collections;
006import java.util.List;
007
008/** TODO Make this immutable. */
009public class FFmpegProbeResult {
010  public FFmpegError error;
011  public FFmpegFormat format;
012  public List<FFmpegStream> streams;
013  public List<FFmpegChapter> chapters;
014
015  private List<FFmpegPacket> packets;
016  private List<FFmpegFrame> frames;
017  public List<FFmpegFrameOrPacket> packets_and_frames;
018
019  public FFmpegError getError() {
020    return error;
021  }
022
023  /** Returns whether the probe result contains an error. */
024  public boolean hasError() {
025    return error != null;
026  }
027
028  /** Returns the format information from the probe result. */
029  public FFmpegFormat getFormat() {
030    return format;
031  }
032
033  /** Returns the list of streams in the probe result. */
034  public List<FFmpegStream> getStreams() {
035    if (streams == null) {
036      return Collections.emptyList();
037    }
038    return ImmutableList.copyOf(streams);
039  }
040
041  /** Returns the list of chapters in the probe result. */
042  public List<FFmpegChapter> getChapters() {
043    if (chapters == null) {
044      return Collections.emptyList();
045    }
046    return ImmutableList.copyOf(chapters);
047  }
048
049  /** Returns the list of packets from the probe result. */
050  public List<FFmpegPacket> getPackets() {
051    if (packets == null) {
052      if (packets_and_frames != null) {
053        List<FFmpegPacket> tmp = new ArrayList<>();
054        for (FFmpegFrameOrPacket packetsAndFrame : packets_and_frames) {
055          if (packetsAndFrame instanceof FFmpegPacket) {
056            tmp.add((FFmpegPacket) packetsAndFrame);
057          }
058        }
059        packets = tmp;
060      } else {
061        return Collections.emptyList();
062      }
063    }
064
065    return ImmutableList.copyOf(packets);
066  }
067
068  /** Returns the list of frames in the probe result. */
069  public List<FFmpegFrame> getFrames() {
070    if (frames == null) {
071      if (packets_and_frames != null) {
072        List<FFmpegFrame> tmp = new ArrayList<>();
073        for (FFmpegFrameOrPacket packetsAndFrame : packets_and_frames) {
074          if (packetsAndFrame instanceof FFmpegFrame) {
075            tmp.add((FFmpegFrame) packetsAndFrame);
076          }
077        }
078        frames = tmp;
079      } else {
080        return Collections.emptyList();
081      }
082    }
083    return ImmutableList.copyOf(frames);
084  }
085}