MediaFileManager

public class MediaFileManager : Codable

映像、音声データをファイル管理するクラス。 指定したディレクトリへ映像、音声データを書き出したり、読み込んだりすることができます。

書き出しには、 MediaFileManager.writeFrame(frameData:elapsedTime:withUpdateDataSize:) を使用することができます。

書き出されたデータは、1秒ごとに1セットとして扱われます。 同一秒のセットのなかで、さらに同一経過時間をもつものどうしで一つにまとめられ、小さい方から順に、 index を割り振られます。

保存されているデータは、 MediaFileManager.readFrame(elapsedTime:index:completion:) により、 取得対象の秒数および index を指定して取得することができます。

  • データを保存する親パス(ディレクトリのパス)。

    Declaration

    Swift

    public private(set) var parentPath: String
  • フレームレート。

    Declaration

    Swift

    public let frameRate: Int
  • 格納されたデータの総データサイズ。

    Declaration

    Swift

    public var dataSize: UInt64 { get }
  • 格納したデータが紐づく1つめの基準時刻(通常、EdgeRTCより取得した基準時刻が使用されることを想定)。

    Declaration

    Swift

    public var baseTime: TimeInterval?
  • baseTime を設定します。 なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setBaseTime(time: TimeInterval?) throws

    Parameters

    time

    基準時刻

  • 格納したデータが紐づく2つめの基準時刻(通常、NTP等より取得した基準時刻が使用されることを想定)。

    Declaration

    Swift

    public var baseTime2: TimeInterval?
  • baseTime2 を設定します。 なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setBaseTime2(time: TimeInterval?) throws

    Parameters

    time

    基準時刻

  • 格納したデータが紐づく計測のUUID。

    Declaration

    Swift

    public var measurementId: String?
  • measurementId を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setMeasurementId(id: String) throws

    Parameters

    id

    計測のUUID

  • 格納したデータが紐づく intdash のチャンネル番号。

    Declaration

    Swift

    public var streamChannels: Int?
  • streamChannels を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setStreamChannels(channels: Int?) throws

    Parameters

    channels

    ストリーム用チャンネル番号

  • 格納したデータの期間(格納した時系列データがどのくらいの時間的長さをもつか)。 getDataDuration() と異なり、利用者により任意の値を設定することができます。

    Declaration

    Swift

    public var duration: TimeInterval?
  • duration を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setDuration(duration: TimeInterval?) throws

    Parameters

    duration

    期間

  • サンプリングレート。

    Declaration

    Swift

    public var sampleRate: Double?
  • sampleRate を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setSampleRate(sampleRate: Double?) throws

    Parameters

    sampleRate

    サンプリングレート

  • チャンネル数。

    Declaration

    Swift

    public var channels: Int?
  • channels を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setChannels(channels: Int?) throws

    Parameters

    channels

    チャンネル数

  • フォーマットID。

    Declaration

    Swift

    public var formatId: String?
  • formatId を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setFormatId(id: String?) throws

    Parameters

    id

    フォーマットID

  • 1サンプルあたりのビット数。

    Declaration

    Swift

    public var bitsPerSample: Int?
  • bitsPerSample を設定します。なお、ファイルへの保存も同時に行います。

    Declaration

    Swift

    public func setBitsPerSample(bitsPerSample: Int?) throws

    Parameters

    bitsPerSample

    1サンプルあたりのビット数

  • MediaFileManagerを生成します。

    Declaration

    Swift

    public required init(from decoder: Decoder) throws
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • MediaFileManager を生成します。

    Declaration

    Swift

    public init(parentPath: String, frameRate: Int = 0, isOverwrite: Bool = false) throws

    Parameters

    parentPath

    データを保存する親パス(ディレクトリのパス)

    frameRate

    フレームレート

    isOverwirte

    上書きを許可するか

  • 指定したパスからデータをロードして、 MediaFileManager を生成します。

    Declaration

    Swift

    public static func load(parentPath: String) throws -> MediaFileManager

    Parameters

    parentPath

    データが保存されている親パス(ディレクトリのパス)

    Return Value

    MediaFileManager

  • 保持しているデータを書き出します。

    Declaration

    Swift

    public func write() throws
  • 格納したデータを除去します。

    Declaration

    Swift

    public func remove() throws
  • Declaration

    Swift

    public static func remove(parentPath: String) throws

    Parameters

    parentPath

    データを削除する親パス(ディレクトリのパス)

    parentPath

    データを削除する親パス(ディレクトリのパス)

  • 保持しているデータをクリアします。

    Declaration

    Swift

    public func clear() throws
  • フレームデータを書き込みます。

    Declaration

    Swift

    public func writeFrame(frameData: Data, withUpdateDataSize: Bool = true) throws

    Parameters

    frameData

    書き込むフレームデータ

    withUpdateDataSize

    書き込んだ総データサイズを同時に書き込むか

  • タイムスタンプ(絶対時刻)を使用して、フレームデータを書き込みます。

    Declaration

    Swift

    public func writeFrame(frameData: Data, timestamp: TimeInterval, withUpdateDataSize: Bool = true) throws

    Parameters

    frameData

    書き込むフレームデータ

    timestamp

    タイムスタンプ(絶対時刻)

    withUpdateDataSize

    書き込んだ総データサイズを同時に書き込むか

  • 相対時間を指定して、フレームデータを書き込みます。

    Declaration

    Swift

    public func writeFrame(frameData: Data, elapsedTime: TimeInterval, withUpdateDataSize: Bool = true) throws

    Parameters

    frameData

    書き込むフレームデータ

    elapsedTime

    相対時間

    withUpdateDataSize

    書き込んだ総データサイズを同時に書き込むか

  • ある経過時間に保存された複数のフレームデータのうち、 index 番目のものを取得します。

    Declaration

    Swift

    public func readFrame(elapsedTime: Int, index: Int, completion: @escaping (_ error: Error?, _ frameData: Data?, _ timestamp: TimeInterval?) -> ())

    Parameters

    elapsedTime

    取得対象とする経過時間

    index

    取得対象とする経過時間に格納された複数のフレームデータのうち、何番目のものを取得対象とするか

    completion

    処理完了時のコールバック

    error

    エラー情報

    frameData

    取得したフレームデータ

    timestamp

    取得したフレームデータに対応するタイムスタンプ

  • 保存されているデータが持つデータの期間を算出します。 duration と異なり、保存されているデータが持つ情報から、期間を算出します。

    Declaration

    Swift

    public func getDataDuration() -> Int

    Return Value

    保存されているデータの期間(秒)

  • 指定されたパスに保存されているデータが持つデータの期間を算出します。

    Declaration

    Swift

    public static func getDataDuration(parentPath: String) -> Int

    Parameters

    parentPath

    データが配置されている親パス(ディレクトリのパス)

    Return Value

    保存されているデータの期間(秒)

  • その経過時間に対して保存されているフレームデータの数を取得します。

    Declaration

    Swift

    public func getFrameSizePerSecond(elapsedTime: Int) -> Int

    Parameters

    elapsedTime

    取得対象とする経過時間

    Return Value

    その経過時間に保存されているフレームデータの数

  • 指定されたパスから、その経過時間に対して保存されているフレームデータの数を取得します。

    Declaration

    Swift

    public static func getFrameSizePerSecond(parentPath: String, elapsedTime: Int) -> Int

    Parameters

    parentPath

    取得対象とする親パス

    elapsedTime

    取得対象とする経過時間

    Return Value

    その経過時間に保存されているフレームデータの数

  • 保存されているデータを移動します。

    Declaration

    Swift

    public func move(toParentPath: String) throws

    Parameters

    toParentPath

    移動先親パス

  • 指定されたパスからパスへ、保存されているデータを移動します。

    Declaration

    Swift

    public static func move(fromParentPath: String, toParentPath: String) throws

    Parameters

    fromParentPath

    移動前親パス

    toParentPath

    移動先親パス

  • 保存されているデータを移動します。

    Declaration

    Swift

    public func move(toParentPath: String, isOverwrite: Bool) throws

    Parameters

    toParentPath

    移動先親パス

    isOverwrite

    上書きを許可するか

  • 指定されたパスからパスへ、保存されているデータを移動します。

    Declaration

    Swift

    public static func move(fromParentPath: String, toParentPath: String, isOverwrite: Bool) throws

    Parameters

    fronParentPath

    移動前親パス

    toParentPath

    移動先親パス

    isOverwrite

    上書きを許可するか

  • 保存されているデータをコピーします。

    Declaration

    Swift

    public func copy(toParentPath: String) throws

    Parameters

    toParentPath

    コピー先親パス

  • 指定されたパスからパスへ、保存されているデータをコピーします。

    Declaration

    Swift

    public static func copy(fromParentPath: String, toParentPath: String) throws

    Parameters

    fromParentPath

    コピーする親パス

    toParentPath

    コピー先親パス

  • 保存されているデータをコピーします。

    Declaration

    Swift

    public func copy(toParentPath: String, isOverwrite: Bool) throws

    Parameters

    toParentPath

    コピー先親パス

    isOverwrite

    上書きを許可するか

  • 指定されたパスからパスへ、保存されているデータをコピーします。

    Declaration

    Swift

    public static func copy(fromParentPath: String, toParentPath: String, isOverwrite: Bool) throws

    Parameters

    fronParentPath

    コピーする親パス

    toParentPath

    コピー先親パス

    isOverwrite

    上書きを許可するか