multiFileInput.hpp 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#pragma once

#include <string>

#include "libvideostitch/input.hpp"
#include "libvideostitch/plugin.hpp"

namespace VideoStitch {
namespace Ptv {
class Value;
}

namespace Input {
/**
 * @brief An abstract helper for readers that read numbered image files instead of video.
 */
class MultiFileReader : public VideoReader {
 public:
  virtual Status seekFrame(frameid_t date);

  /**
   * Some readers need to read a string from config.
   * \returns 0 if config is not a string.
   */
  static std::string const* hasStringContent(Ptv::Value const* config);

 protected:
  /**
   * Probes the given filename template to see if the file range exist and possible detect the last frame.
   * @param fileNameTemplate The file name template. Same format as printf.
   * @return NULL on error. The result must be deleted.
   */
  static ProbeResult probe(const std::string& fileNameTemplate);

  /**
   * Creates a MultiFileReader.
   * @param fileNameTemplate The file name template. Same format as printf.
   * @param probeResult The result of a previous call to probe(). We take ownership of the pointer.
   * @param width See Reader class.
   * @param height See Reader class.
   * @param frameDataSize See Reader class.
   */
  MultiFileReader(const std::string& fileNameTemplate, const ProbeResult& probeResult, int64_t width, int64_t height,
                  int64_t frameDataSize, VideoStitch::PixelFormat);

  virtual ~MultiFileReader();

  /**
   * @returns true if and only if probeResult and runtime are
   * consistent for a Reader instantiation.
   */
  static bool checkProbeResult(const Input::ProbeResult& probeResult, const Plugin::VSReaderPlugin::Config& runtime);

  virtual ReadStatus readFrame(mtime_t& timestamp, unsigned char* data);

  /**
   * Returns the file name for the given frame.
   * @param frame The frame whose filename to get.
   */
  std::string filenameFromTemplate(int frame) const;

  /**
   * Static version of the above.
   * @param frame The frame whose filename to get. Has to be a template.
   * @param filenameIsTemplate true if @a fileNameTemplate is a template.
   */
  static std::string filenameFromTemplate(const std::string& fileNameTemplate, int frame);

  /**
   * Returns true if filename mathes the given template.
   * @param filename Filename to test.
   * @param filenameTemplate template to test against
   * @param frame On output, contains the matching frame if the filename matches, -1 else.
   * @return True if the filename matches.
   */
  static bool matchesFilenameTemplate(const char* filename, const std::string& filenameTemplate, int& frame);

  void resetDisplayName();

  const std::string fileNameTemplate;

 protected:
  virtual ReadStatus readFrameInternal(unsigned char* data) = 0;

  /**
   * Returns the display type (e.g. JPEG) of the file.
   * @param os Output stream.
   */
  virtual void getDisplayType(std::ostream& os) const = 0;

  bool filenameIsTemplate;
  int curFrame;
};
}  // namespace Input
}  // namespace VideoStitch