remove AVIODir
This commit is contained in:
@@ -7,168 +7,6 @@
|
||||
|
||||
import CFFmpeg
|
||||
|
||||
// MARK: - AVIODirEntry
|
||||
|
||||
typealias CAVIODirEntry = CFFmpeg.AVIODirEntry
|
||||
|
||||
/// Describes single entry of the directory.
|
||||
///
|
||||
/// Only name and type fields are guaranteed be set.
|
||||
/// Rest of fields are protocol or/and platform dependent and might be unknown.
|
||||
public final class AVIODirEntry {
|
||||
var native: UnsafeMutablePointer<CAVIODirEntry>!
|
||||
|
||||
/// Filename.
|
||||
public let name: String
|
||||
/// Type of the entry
|
||||
public let type: Kind
|
||||
/// File size in bytes, -1 if unknown.
|
||||
public let size: Int64
|
||||
/// Time of last modification in microseconds since unix epoch, -1 if unknown.
|
||||
public let modificationTimestamp: Int64
|
||||
/// Time of last access in microseconds since unix epoch, -1 if unknown.
|
||||
public let accessTimestamp: Int64
|
||||
/// Time of last status change in microseconds since unix epoch, -1 if unknown.
|
||||
public let statusChangeTimestamp: Int64
|
||||
/// User ID of owner, -1 if unknown.
|
||||
public let userId: Int64
|
||||
/// Group ID of owner, -1 if unknown.
|
||||
public let groupId: Int64
|
||||
/// Unix file mode, -1 if unknown.
|
||||
public let filemode: Int64
|
||||
|
||||
init(native: UnsafeMutablePointer<CAVIODirEntry>) {
|
||||
self.native = native
|
||||
self.name = String(cString: native.pointee.name)
|
||||
self.type = Kind(rawValue: UInt32(native.pointee.type))!
|
||||
self.size = native.pointee.size
|
||||
self.modificationTimestamp = native.pointee.modification_timestamp
|
||||
self.accessTimestamp = native.pointee.access_timestamp
|
||||
self.statusChangeTimestamp = native.pointee.status_change_timestamp
|
||||
self.userId = native.pointee.user_id
|
||||
self.groupId = native.pointee.group_id
|
||||
self.filemode = native.pointee.filemode
|
||||
}
|
||||
|
||||
deinit {
|
||||
avio_free_directory_entry(&native)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AVIODirEntry.Kind
|
||||
|
||||
extension AVIODirEntry {
|
||||
|
||||
/// Directory entry types.
|
||||
public enum Kind: UInt32 {
|
||||
case unknown
|
||||
case blockDevice
|
||||
case characterDevice
|
||||
case directory
|
||||
case namedPipe
|
||||
case symbolicLink
|
||||
case socket
|
||||
case file
|
||||
case server
|
||||
case share
|
||||
case workgroup
|
||||
}
|
||||
}
|
||||
|
||||
extension AVIODirEntry.Kind: CustomStringConvertible {
|
||||
|
||||
public var description: String {
|
||||
switch self {
|
||||
case .blockDevice:
|
||||
return "block device"
|
||||
case .characterDevice:
|
||||
return "character device"
|
||||
case .directory:
|
||||
return "directory"
|
||||
case .namedPipe:
|
||||
return "pipe"
|
||||
case .symbolicLink:
|
||||
return "symbolic link"
|
||||
case .socket:
|
||||
return "socket"
|
||||
case .file:
|
||||
return "file"
|
||||
case .server:
|
||||
return "server"
|
||||
case .share:
|
||||
return "share"
|
||||
case .workgroup:
|
||||
return "workgroup"
|
||||
default:
|
||||
return "unknown"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - AVIODirContext
|
||||
|
||||
typealias CAVIODirContext = CFFmpeg.AVIODirContext
|
||||
|
||||
public final class AVIODirContext {
|
||||
var native: UnsafeMutablePointer<CAVIODirContext>!
|
||||
var isOpen = false
|
||||
|
||||
init(native: UnsafeMutablePointer<CAVIODirContext>) {
|
||||
self.native = native
|
||||
}
|
||||
|
||||
/// Open directory for reading.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - url: directory to be listed.
|
||||
/// - options: A dictionary filled with protocol-private options.
|
||||
/// - Throws: AVError
|
||||
public init(url: String, options: [String: String]? = nil) throws {
|
||||
var pm = options?.avDict
|
||||
defer { av_dict_free(&pm) }
|
||||
|
||||
try throwIfFail(avio_open_dir(&native, url, &pm))
|
||||
self.isOpen = true
|
||||
|
||||
dumpUnrecognizedOptions(pm)
|
||||
}
|
||||
|
||||
/// Close directory.
|
||||
public func close() {
|
||||
if isOpen {
|
||||
avio_close_dir(&native)
|
||||
isOpen = false
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
assert(!isOpen, "AVIODirContext must be close.")
|
||||
}
|
||||
}
|
||||
|
||||
extension AVIODirContext: Sequence {
|
||||
|
||||
public struct Iterator: IteratorProtocol {
|
||||
let dirCtx: AVIODirContext
|
||||
var nextEntry: UnsafeMutablePointer<CAVIODirEntry>?
|
||||
|
||||
init(dirCtx: AVIODirContext) {
|
||||
self.dirCtx = dirCtx
|
||||
}
|
||||
|
||||
public mutating func next() -> AVIODirEntry? {
|
||||
if avio_read_dir(dirCtx.native, &nextEntry) >= 0, let ptr = nextEntry {
|
||||
return AVIODirEntry(native: ptr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public func makeIterator() -> Iterator {
|
||||
Iterator(dirCtx: self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Callback for checking whether to abort blocking functions.
|
||||
/// `AVError.exit` is returned in this case by the interrupted function.
|
||||
/// During blocking operations, callback is called with opaque as parameter.
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// avio_dir_cmd.swift
|
||||
// SwiftFFmpegExamples
|
||||
//
|
||||
// Created by sunlubo on 2019/1/9.
|
||||
//
|
||||
|
||||
import SwiftFFmpeg
|
||||
|
||||
private func list_op() throws {
|
||||
if CommandLine.argc < 4 {
|
||||
print("Missing argument for list operation.")
|
||||
return
|
||||
}
|
||||
|
||||
let input = CommandLine.arguments[3]
|
||||
let dirCtx = try AVIODirContext(url: input)
|
||||
defer {
|
||||
dirCtx.close()
|
||||
}
|
||||
|
||||
print("TYPE SIZE NAME UID(GID) UGO MODIFIED ACCESSED STATUS_CHANGED")
|
||||
for entry in dirCtx {
|
||||
print(
|
||||
"""
|
||||
\(entry.type) \(entry.size) \(entry.name) \
|
||||
\(entry.userId)(\(entry.groupId)) \
|
||||
\(entry.filemode) \
|
||||
\(entry.modificationTimestamp) \
|
||||
\(entry.accessTimestamp) \
|
||||
\(entry.statusChangeTimestamp)
|
||||
""")
|
||||
}
|
||||
}
|
||||
|
||||
func avio_dir_cmd() throws {
|
||||
if CommandLine.argc < 3 {
|
||||
print(
|
||||
"""
|
||||
Usage: \(CommandLine.arguments[0]) \(CommandLine.arguments[1]) OPERATION entry1 [entry2]
|
||||
|
||||
OPERATIONS:
|
||||
list list content of the directory
|
||||
""")
|
||||
return
|
||||
}
|
||||
|
||||
let op = CommandLine.arguments[2]
|
||||
switch op {
|
||||
case "list":
|
||||
try list_op()
|
||||
default:
|
||||
print("Invalid operation \(op)")
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ if CommandLine.argc < 2 {
|
||||
USAGE: \(CommandLine.arguments[0]) subcommand
|
||||
|
||||
SUBCOMMANDS:
|
||||
avio_dir_cmd API example program to show how to manipulate resources accessed through AVIOContext.
|
||||
decode_video video decoding with libavcodec API example
|
||||
decode_audio audio decoding with libavcodec API example
|
||||
demuxing_decoding API example program to show how to read frames from an input file.
|
||||
@@ -46,8 +45,6 @@ if CommandLine.argc < 2 {
|
||||
|
||||
let subcommand = CommandLine.arguments[1]
|
||||
switch subcommand {
|
||||
case "avio_dir_cmd":
|
||||
try avio_dir_cmd()
|
||||
case "decode_video":
|
||||
try decode_video()
|
||||
case "decode_audio":
|
||||
|
||||
Reference in New Issue
Block a user