FFmpegfs Fuse Multi Media Filesystem 2.16
fileio.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2024 by Norbert Schlia (nschlia@oblivion-software.de)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 * On Debian systems, the complete text of the GNU General Public License
19 * Version 3 can be found in `/usr/share/common-licenses/GPL-3'.
20 */
21
35#ifndef FILEIO_H
36#define FILEIO_H
37
38#pragma once
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#include <sys/stat.h>
45
46#include <string>
47#include <vector>
48#include <map>
49#include <cstring>
50#include <memory>
51#include <array>
52
53// Disable annoying warnings outside our code
54#ifdef __cplusplus
55extern "C" {
56#endif
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wconversion"
59#pragma GCC diagnostic ignored "-Wsign-conversion"
60#include <libavutil/avutil.h>
61#pragma GCC diagnostic pop
62#ifdef __cplusplus
63}
64#endif
65
66#pragma pack(push, 1)
67
68#define IMAGE_FRAME_TAG "IMGFRAME"
76typedef struct IMAGE_FRAME
77{
78 std::array<char, 8> m_tag;
79 uint32_t m_frame_no;
80 uint64_t m_offset;
81 uint32_t m_size;
82 std::array<uint8_t, 8> m_reserved;
83 // ...data
85#pragma pack(pop)
91enum class VIRTUALTYPE
92{
94 DISK,
95 SCRIPT,
96#ifdef USE_LIBVCD
97 VCD,
98#endif // USE_LIBVCD
99#ifdef USE_LIBDVD
100 DVD,
101#endif // USE_LIBDVD
102#ifdef USE_LIBBLURAY
103 BLURAY,
104#endif // USE_LIBBLURAY
105
106 BUFFER,
107};
111#define VIRTUALFLAG_NONE 0x00000000
112#define VIRTUALFLAG_PASSTHROUGH 0x00000001
113#define VIRTUALFLAG_DIRECTORY 0x00000002
114#define VIRTUALFLAG_FILESET 0x00000004
115#define VIRTUALFLAG_FRAME 0x00000008
116#define VIRTUALFLAG_HLS 0x00000010
117#define VIRTUALFLAG_CUESHEET 0x00000020
118#define VIRTUALFLAG_HIDDEN 0x00000040
122typedef struct VIRTUALFILE
123{
127 , m_format_idx(0)
128 , m_full_title(false)
129 , m_duration(0)
132 , m_has_audio(false)
133 , m_has_video(false)
134 , m_has_subtitle(false)
135 , m_channels(0)
136 , m_sample_rate(0)
137 , m_width(0)
138 , m_height(0)
139 , m_framerate{ 0, 0 }
140 {
141 std::memset(&m_st, 0, sizeof(m_st));
142 }
143
144 uint32_t get_segment_count() const;
150 std::string m_destfile;
151 std::string m_virtfile;
152 std::string m_origfile;
153 struct stat m_st;
156 int64_t m_duration;
164 std::vector<char> m_file_contents;
166#ifdef USE_LIBVCD
171 {
173 : m_track_no(0)
174 , m_chapter_no(0)
175 , m_start_pos(0)
176 , m_end_pos(0)
177 {}
180 uint64_t m_start_pos;
181 uint64_t m_end_pos;
183#endif //USE_LIBVCD
184#ifdef USE_LIBDVD
189 {
191 : m_title_no(0)
192 , m_chapter_no(0)
193 , m_angle_no(0)
194 {}
199#endif // USE_LIBDVD
200#ifdef USE_LIBBLURAY
205 {
207 : m_title_no(0)
208 , m_playlist_no(0)
209 , m_chapter_no(0)
210 , m_angle_no(0)
211 {}
212 uint32_t m_title_no;
213 uint32_t m_playlist_no;
214 unsigned m_chapter_no;
215 unsigned m_angle_no;
217#endif // USE_LIBBLURAY
220 struct CUESHEET_TRACK
221 {
223 : m_tracktotal(0)
224 , m_trackno(0)
225 , m_start(0)
226 , m_duration(0)
227 , m_nextfile(nullptr)
228 {}
229
232 std::string m_artist;
233 std::string m_title;
234 std::string m_album;
235 std::string m_genre;
236 std::string m_date;
238 int64_t m_start;
239 int64_t m_duration;
243 std::string m_cuesheet;
245 // These may be filled in for DVD/Blu-ray
251 AVRational m_framerate;
260{
261public:
265 explicit FileIO();
269 virtual ~FileIO() = default;
270
279 static std::shared_ptr<FileIO> alloc(VIRTUALTYPE type);
280
285 virtual VIRTUALTYPE type() const = 0;
290 virtual size_t bufsize() const = 0;
305 virtual size_t readio(void *data, size_t size) = 0;
310 virtual int error() const = 0;
316 virtual int64_t duration() const = 0;
321 virtual size_t size() const = 0;
326 virtual size_t tell() const = 0;
340 virtual int seek(int64_t offset, int whence) = 0;
345 virtual bool eof() const = 0;
349 virtual void closeio() = 0;
359 const std::string & filename() const;
364 const std::string & path() const;
365
366protected:
371
372private:
373 std::string m_path;
375};
376
377#endif // FILEIO_H
struct bluray BLURAY
Forward declaration of libbluray handle.
Definition: blurayio.h:45
Base class for I/O.
Definition: fileio.h:260
virtual int seek(int64_t offset, int whence)=0
Seek to position in file.
const std::string & path() const
Path to source file (without file name)
Definition: fileio.cc:118
std::string m_path
Source path (directory without file name)
Definition: fileio.h:373
virtual size_t size() const =0
Get the file size.
LPVIRTUALFILE virtualfile()
Get virtual file object.
Definition: fileio.cc:113
virtual size_t tell() const =0
Get current read position.
virtual size_t readio(void *data, size_t size)=0
Read data from a file.
LPVIRTUALFILE m_virtualfile
Virtual file object of current file.
Definition: fileio.h:374
virtual ~FileIO()=default
Free FileIO object.
void set_virtualfile(LPVIRTUALFILE virtualfile)
Set the virtual file object.
Definition: fileio.cc:96
virtual void closeio()=0
Close virtual file.
virtual VIRTUALTYPE type() const =0
Get type of the virtual file.
virtual int error() const =0
Get last error.
FileIO()
Create FileIO object.
Definition: fileio.cc:57
virtual size_t bufsize() const =0
Get the ideal buffer size.
virtual int64_t duration() const =0
Get the duration of the file, in AV_TIME_BASE fractional seconds.
static std::shared_ptr< FileIO > alloc(VIRTUALTYPE type)
Allocate the correct object for type().
Definition: fileio.cc:63
virtual int openio(LPVIRTUALFILE virtualfile)=0
Open a virtual file.
virtual bool eof() const =0
Check if at end of file.
const std::string & filename() const
Get source filename.
Definition: fileio.cc:123
VIRTUALTYPE
Virtual file types enum.
Definition: fileio.h:92
@ BUFFER
Buffer file.
@ DVD
DVD file.
@ DISK
Regular disk file to transcode.
@ SCRIPT
Virtual script.
@ PASSTHROUGH
passthrough file, not used
@ VCD
Video CD file.
VIRTUALTYPE LPVIRTUALTYPE
Pointer to const version of VIRTUALTYPE.
Definition: fileio.h:109
struct IMAGE_FRAME IMAGE_FRAME
Image frame header.
IMAGE_FRAME * LPIMAGE_FRAME
Pointer to const version of IMAGE_FRAME.
Definition: fileio.h:87
IMAGE_FRAME const * LPCIMAGE_FRAME
Pointer version of IMAGE_FRAME.
Definition: fileio.h:86
VIRTUALFILE const * LPCVIRTUALFILE
Pointer to const version of VIRTUALFILE.
Definition: fileio.h:254
VIRTUALTYPE const * LPCVIRTUALTYPE
Pointer version of VIRTUALTYPE.
Definition: fileio.h:108
#define VIRTUALFLAG_NONE
No flags.
Definition: fileio.h:111
struct VIRTUALFILE VIRTUALFILE
Virtual file definition.
VIRTUALFILE * LPVIRTUALFILE
Pointer version of VIRTUALFILE.
Definition: fileio.h:255
Image frame header.
Definition: fileio.h:77
uint64_t m_offset
Offset in index file.
Definition: fileio.h:80
uint32_t m_size
Image size in bytes.
Definition: fileio.h:81
std::array< uint8_t, 8 > m_reserved
Reserved. Pad structure to 32 bytes.
Definition: fileio.h:82
uint32_t m_frame_no
Number of the frame image. 0 if not yet decoded.
Definition: fileio.h:79
std::array< char, 8 > m_tag
Start tag, always ascii "IMGFRAME".
Definition: fileio.h:78
Extra value structure for Blu-ray disks.
Definition: fileio.h:205
unsigned m_chapter_no
Chapter number (1...n)
Definition: fileio.h:214
uint32_t m_title_no
Track number (1...n)
Definition: fileio.h:212
uint32_t m_playlist_no
Playlist number (1...n)
Definition: fileio.h:213
unsigned m_angle_no
Selected angle number (1...n)
Definition: fileio.h:215
Extra value structure for cue sheets.
Definition: fileio.h:221
std::string m_artist
Track artist.
Definition: fileio.h:232
int64_t m_duration
Track/chapter duration, in AV_TIME_BASE fractional seconds.
Definition: fileio.h:239
std::string m_album
Album title.
Definition: fileio.h:234
std::string m_title
Track title.
Definition: fileio.h:233
int64_t m_start
Track start time, in AV_TIME_BASE fractional seconds.
Definition: fileio.h:238
VIRTUALFILE * m_nextfile
Next (probable) file to be played. Used for cuesheet lists.
Definition: fileio.h:241
int m_trackno
Track number.
Definition: fileio.h:231
int m_tracktotal
Total number of tracks in cue sheet.
Definition: fileio.h:230
std::string m_genre
Album genre.
Definition: fileio.h:235
std::string m_date
Publishing date.
Definition: fileio.h:236
Extra value structure for DVDs.
Definition: fileio.h:189
int m_angle_no
Selected angle number (1...n)
Definition: fileio.h:197
int m_title_no
Track number (1...n)
Definition: fileio.h:195
int m_chapter_no
Chapter number (1...n)
Definition: fileio.h:196
Extra value structure for Video CDs.
Definition: fileio.h:171
int m_chapter_no
Chapter number (1..)
Definition: fileio.h:179
uint64_t m_start_pos
Start offset in bytes.
Definition: fileio.h:180
uint64_t m_end_pos
End offset in bytes (not including this byte)
Definition: fileio.h:181
int m_track_no
Track number (1..)
Definition: fileio.h:178
Virtual file definition.
Definition: fileio.h:123
int m_sample_rate
Audio sample rate - Filled in for the DVD/Blu-ray directory.
Definition: fileio.h:247
struct VIRTUALFILE::DVD_CHAPTER m_dvd
DVD title/chapter info.
bool m_full_title
If true, ignore m_chapter_no and provide full track.
Definition: fileio.h:155
std::string m_destfile
Name and path of destination file.
Definition: fileio.h:150
size_t m_predicted_size
Use this as the size instead of computing it over and over.
Definition: fileio.h:157
VIRTUALTYPE m_type
Type of this virtual file.
Definition: fileio.h:146
bool m_has_audio
True if file has an audio track.
Definition: fileio.h:160
std::string m_origfile
Sanitised name and path of original file.
Definition: fileio.h:152
int m_flags
One of the VIRTUALFLAG_* flags.
Definition: fileio.h:147
int m_width
Video width - Filled in for the DVD/Blu-ray directory.
Definition: fileio.h:249
int m_height
Video height - Filled in for the DVD/Blu-ray directory.
Definition: fileio.h:250
int m_channels
Audio channels - Filled in for the DVD/Blu-ray directory.
Definition: fileio.h:246
std::string m_virtfile
Name and path of virtual file.
Definition: fileio.h:151
AVRational m_framerate
Video frame rate - Filled in for the DVD/Blu-ray directory.
Definition: fileio.h:251
bool m_has_video
True if file has a video track.
Definition: fileio.h:161
struct stat m_st
stat structure with size etc.
Definition: fileio.h:153
bool m_has_subtitle
True if file has a subtitle track.
Definition: fileio.h:162
std::vector< char > m_file_contents
Buffer for virtual files.
Definition: fileio.h:164
std::string m_cuesheet
Cue sheet file contents for physical file.
Definition: fileio.h:243
struct VIRTUALFILE::BLURAY_CHAPTER m_bluray
Blu-ray title/chapter info.
size_t m_format_idx
Index into params.format[] array.
Definition: fileio.h:149
struct VIRTUALFILE::CUESHEET_TRACK m_cuesheet_track
Cue sheet data for track.
struct VIRTUALFILE::VCD_CHAPTER m_vcd
S/VCD track/chapter info.
uint32_t get_segment_count() const
Number of HLS segments in set.
Definition: fileio.cc:45
uint32_t m_video_frame_count
Number of frames in video or 0 if not a video.
Definition: fileio.h:158
int64_t m_duration
Track/chapter duration, in AV_TIME_BASE fractional seconds.
Definition: fileio.h:156