| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#ifndef FFVIDEOSOURCE_H |
| 22 |
#define FFVIDEOSOURCE_H |
| 23 |
|
| 24 |
extern "C" { |
| 25 |
#include <libavformat/avformat.h> |
| 26 |
#include <libavcodec/avcodec.h> |
| 27 |
#include <libswscale/swscale.h> |
| 28 |
#include <libavutil/imgutils.h> |
| 29 |
#include <libavutil/stereo3d.h> |
| 30 |
#include <libavutil/display.h> |
| 31 |
#include <libavutil/mastering_display_metadata.h> |
| 32 |
|
| 33 |
#include "ffmscompat.h" |
| 34 |
#include <libavutil/hdr_dynamic_metadata.h> |
| 35 |
} |
| 36 |
|
| 37 |
#include <vector> |
| 38 |
|
| 39 |
#include "track.h" |
| 40 |
#include "utils.h" |
| 41 |
|
| 42 |
enum class DecodeStage { |
| 43 |
INITIALIZE_SOURCE, |
| 44 |
INITIALIZE, |
| 45 |
APPLY_DELAY, |
| 46 |
DECODE_LOOP, |
| 47 |
}; |
| 48 |
|
| 49 |
struct DecoderDelay { |
| 50 |
int ThreadDelay = 0; |
| 51 |
int ReorderDelay = 0; |
| 52 |
|
| 53 |
int ThreadDelayCounter = 0; |
| 54 |
int ReorderDelayCounter = 0; |
| 55 |
|
| 56 |
void Reset(); |
| 57 |
void Increment(bool Hidden, bool SecondField); |
| 58 |
void Decrement(); |
| 59 |
bool IsExceeded(); |
| 60 |
}; |
| 61 |
|
| 62 |
struct FFMS_VideoSource { |
| 63 |
private: |
| 64 |
SwsContext *SWS = nullptr; |
| 65 |
|
| 66 |
DecoderDelay Delay; |
| 67 |
DecodeStage Stage = DecodeStage::INITIALIZE_SOURCE; |
| 68 |
|
| 69 |
int LastFrameHeight = -1; |
| 70 |
int LastFrameWidth = -1; |
| 71 |
AVPixelFormat LastFramePixelFormat = AV_PIX_FMT_NONE; |
| 72 |
|
| 73 |
int TargetHeight = -1; |
| 74 |
int TargetWidth = -1; |
| 75 |
std::vector<AVPixelFormat> TargetPixelFormats; |
| 76 |
int TargetResizer = 0; |
| 77 |
|
| 78 |
AVPixelFormat OutputFormat = AV_PIX_FMT_NONE; |
| 79 |
AVColorRange OutputColorRange = AVCOL_RANGE_UNSPECIFIED; |
| 80 |
AVColorSpace OutputColorSpace = AVCOL_SPC_UNSPECIFIED; |
| 81 |
bool OutputColorRangeSet = false; |
| 82 |
bool OutputColorSpaceSet = false; |
| 83 |
|
| 84 |
int OutputColorPrimaries = -1; |
| 85 |
int OutputTransferCharateristics = -1; |
| 86 |
int OutputChromaLocation = -1; |
| 87 |
|
| 88 |
bool InputFormatOverridden = false; |
| 89 |
AVPixelFormat InputFormat = AV_PIX_FMT_NONE; |
| 90 |
AVColorRange InputColorRange = AVCOL_RANGE_UNSPECIFIED; |
| 91 |
AVColorSpace InputColorSpace = AVCOL_SPC_UNSPECIFIED; |
| 92 |
|
| 93 |
uint8_t *SWSFrameData[4] = {}; |
| 94 |
int SWSFrameLinesize[4] = {}; |
| 95 |
|
| 96 |
AVPacket *StashedPacket = nullptr; |
| 97 |
bool ResendPacket = false; |
| 98 |
|
| 99 |
void DetectInputFormat(); |
| 100 |
bool HasPendingDelayedFrames(); |
| 101 |
|
| 102 |
FFMS_VideoProperties VP = {}; |
| 103 |
FFMS_Frame LocalFrame = {}; |
| 104 |
uint8_t *RPUBuffer = nullptr; |
| 105 |
size_t RPUBufferSize = 0; |
| 106 |
uint8_t *HDR10PlusBuffer = nullptr; |
| 107 |
size_t HDR10PlusBufferSize = 0; |
| 108 |
AVFrame *DecodeFrame = nullptr; |
| 109 |
AVFrame *LastDecodedFrame = nullptr; |
| 110 |
int LastFrameNum = 0; |
| 111 |
FFMS_Index &Index; |
| 112 |
FFMS_Track Frames; |
| 113 |
int VideoTrack; |
| 114 |
int CurrentFrame = 1; |
| 115 |
int DecodingThreads; |
| 116 |
AVCodecContext *CodecContext = nullptr; |
| 117 |
AVFormatContext *FormatContext = nullptr; |
| 118 |
int SeekMode; |
| 119 |
bool SeekByPos = false; |
| 120 |
bool HaveSeenInterlacedFrame = false; |
| 121 |
|
| 122 |
void ReAdjustOutputFormat(AVFrame *Frame); |
| 123 |
FFMS_Frame *OutputFrame(AVFrame *Frame); |
| 124 |
void SetVideoProperties(); |
| 125 |
bool DecodePacket(AVPacket *Packet); |
| 126 |
void DecodeNextFrame(int64_t &PTS, int64_t &Pos); |
| 127 |
bool SeekTo(int n, int SeekOffset); |
| 128 |
int Seek(int n); |
| 129 |
void Free(); |
| 130 |
static void SanityCheckFrameForData(AVFrame *Frame); |
| 131 |
public: |
| 132 |
FFMS_VideoSource(const char *SourceFile, FFMS_Index &Index, int Track, int Threads, int SeekMode); |
| 133 |
~FFMS_VideoSource(); |
| 134 |
const FFMS_VideoProperties& GetVideoProperties() { return VP; } |
| 135 |
FFMS_Track *GetTrack() { return &Frames; } |
| 136 |
FFMS_Frame *GetFrame(int n); |
| 137 |
void GetFrameCheck(int n); |
| 138 |
FFMS_Frame *GetFrameByTime(double Time); |
| 139 |
void SetOutputFormat(const AVPixelFormat *TargetFormats, int Width, int Height, int Resizer); |
| 140 |
void ResetOutputFormat(); |
| 141 |
void SetInputFormat(int ColorSpace, int ColorRange, AVPixelFormat Format); |
| 142 |
void ResetInputFormat(); |
| 143 |
}; |
| 144 |
|
| 145 |
#endif |