| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef INDEXING_H |
| 22 |
#define INDEXING_H |
| 23 |
|
| 24 |
#include "utils.h" |
| 25 |
|
| 26 |
#include <set> |
| 27 |
#include <map> |
| 28 |
#include <memory> |
| 29 |
#include <atomic> |
| 30 |
|
| 31 |
extern "C" { |
| 32 |
#include <libavutil/avutil.h> |
| 33 |
} |
| 34 |
|
| 35 |
class Wave64Writer; |
| 36 |
class ZipFile; |
| 37 |
|
| 38 |
struct SharedAVContext { |
| 39 |
AVCodecContext *CodecContext = nullptr; |
| 40 |
AVCodecParserContext *Parser = nullptr; |
| 41 |
int64_t CurrentSample = 0; |
| 42 |
~SharedAVContext(); |
| 43 |
}; |
| 44 |
|
| 45 |
struct FFMS_Index : public std::vector<FFMS_Track> { |
| 46 |
FFMS_Index(FFMS_Index const&) = delete; |
| 47 |
FFMS_Index& operator=(FFMS_Index const&) = delete; |
| 48 |
void ReadIndex(ZipFile &zf, const char* IndexFile); |
| 49 |
void WriteIndex(ZipFile &zf); |
| 50 |
public: |
| 51 |
static void CalculateFileSignature(const char *Filename, int64_t *Filesize, uint8_t Digest[20]); |
| 52 |
|
| 53 |
int ErrorHandling; |
| 54 |
int64_t Filesize; |
| 55 |
uint8_t Digest[20]; |
| 56 |
std::map<std::string, std::string> LAVFOpts; |
| 57 |
|
| 58 |
void Finalize(std::vector<SharedAVContext> const& video_contexts, const char *Format); |
| 59 |
bool CompareFileSignature(const char *Filename); |
| 60 |
void WriteIndexFile(const char *IndexFile); |
| 61 |
uint8_t *WriteIndexBuffer(size_t *Size); |
| 62 |
|
| 63 |
FFMS_Index(const char *IndexFile); |
| 64 |
FFMS_Index(const uint8_t *Buffer, size_t Size); |
| 65 |
FFMS_Index(int64_t Filesize, uint8_t Digest[20], int ErrorHandling, const std::map<std::string, std::string> &LAVFOpts); |
| 66 |
}; |
| 67 |
|
| 68 |
struct FFMS_Indexer { |
| 69 |
private: |
| 70 |
std::map<int, FFMS_AudioProperties> LastAudioProperties; |
| 71 |
FFMS_Indexer(FFMS_Indexer const&) = delete; |
| 72 |
FFMS_Indexer& operator=(FFMS_Indexer const&) = delete; |
| 73 |
AVFormatContext *FormatContext = nullptr; |
| 74 |
std::set<int> IndexMask; |
| 75 |
std::map<std::string, std::string> LAVFOpts; |
| 76 |
int ErrorHandling = FFMS_IEH_CLEAR_TRACK; |
| 77 |
TIndexCallback IC = nullptr; |
| 78 |
void *ICPrivate = nullptr; |
| 79 |
std::string SourceFile; |
| 80 |
AVFrame *DecodeFrame = nullptr; |
| 81 |
|
| 82 |
int64_t Filesize; |
| 83 |
uint8_t Digest[20]; |
| 84 |
|
| 85 |
void ReadTS(const AVPacket *Packet, int64_t &TS, bool &UseDTS); |
| 86 |
void CheckAudioProperties(int Track, AVCodecContext *Context); |
| 87 |
uint32_t IndexAudioPacket(int Track, AVPacket *Packet, SharedAVContext &Context, FFMS_Index &TrackIndices); |
| 88 |
void ParseVideoPacket(SharedAVContext &VideoContext, AVPacket *pkt, int *RepeatPict, int *FrameType, bool *Invisible, bool *SecondField, enum AVPictureStructure *LastPicStruct); |
| 89 |
void Free(); |
| 90 |
public: |
| 91 |
FFMS_Indexer(const char *Filename, const FFMS_KeyValuePair *DemuxerOptions, int NumOptions); |
| 92 |
~FFMS_Indexer(); |
| 93 |
|
| 94 |
void SetIndexTrack(int Track, bool Index); |
| 95 |
void SetIndexTrackType(int TrackType, bool Index); |
| 96 |
void SetErrorHandling(int ErrorHandling_); |
| 97 |
void SetProgressCallback(TIndexCallback IC_, void *ICPrivate_); |
| 98 |
|
| 99 |
FFMS_Index *DoIndexing(); |
| 100 |
int GetNumberOfTracks(); |
| 101 |
FFMS_TrackType GetTrackType(int Track); |
| 102 |
const char *GetTrackCodec(int Track); |
| 103 |
const char *GetFormatName(); |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
#endif |