Skip to content

Commit

Permalink
Add BS prefix to generically named structs to avoid evil linker colli…
Browse files Browse the repository at this point in the history
…sions
  • Loading branch information
myrsloik committed Jul 13, 2024
1 parent ff911fa commit 55fb7fd
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void LWAudioDecoder::SetFrameNumber(int64_t N, int64_t SampleNumber) {
CurrentSample = SampleNumber;
}

void LWAudioDecoder::GetAudioProperties(AudioProperties &AP) {
void LWAudioDecoder::GetAudioProperties(BSAudioProperties &AP) {
assert(CurrentFrame == 0);
AP = {};
AVFrame *PropFrame = GetNextFrame();
Expand Down Expand Up @@ -272,7 +272,7 @@ bool LWAudioDecoder::HasSeeked() const {
return Seeked;
}

void AudioFormat::Set(int Format, int BitsPerRawSample) {
void BSAudioFormat::Set(int Format, int BitsPerRawSample) {
Float = (Format == AV_SAMPLE_FMT_FLTP || Format == AV_SAMPLE_FMT_FLT || Format == AV_SAMPLE_FMT_DBLP || Format == AV_SAMPLE_FMT_DBL);
BytesPerSample = av_get_bytes_per_sample(static_cast<AVSampleFormat>(Format));
Bits = BitsPerRawSample ? BitsPerRawSample : (BytesPerSample * 8);
Expand Down Expand Up @@ -467,7 +467,7 @@ double BestAudioSource::GetRelativeStartTime(int Track) const {
if (Track < 0) {
try {
std::unique_ptr<LWVideoDecoder> Dec(new LWVideoDecoder(Source, "", 0, Track, true, 0, LAVFOptions));
VideoProperties VP;
BSVideoProperties VP;
Dec->GetVideoProperties(VP);
return AP.StartTime - VP.StartTime;
} catch (BestSourceException &) {
Expand All @@ -476,13 +476,13 @@ double BestAudioSource::GetRelativeStartTime(int Track) const {
} else {
try {
std::unique_ptr<LWVideoDecoder> Dec(new LWVideoDecoder(Source, "", 0, Track, true, 0, LAVFOptions));
VideoProperties VP;
BSVideoProperties VP;
Dec->GetVideoProperties(VP);
return AP.StartTime - VP.StartTime;
} catch (BestSourceException &) {
try {
std::unique_ptr<LWAudioDecoder> Dec(new LWAudioDecoder(Source, false, Track, Threads, LAVFOptions, 0));
AudioProperties AP2;
BSAudioProperties AP2;
Dec->GetAudioProperties(AP2);
return AP.StartTime - AP2.StartTime;
} catch (BestSourceException &) {
Expand All @@ -492,7 +492,7 @@ double BestAudioSource::GetRelativeStartTime(int Track) const {
}
}

const AudioProperties &BestAudioSource::GetAudioProperties() const {
const BSAudioProperties &BestAudioSource::GetAudioProperties() const {
return AP;
}

Expand Down
14 changes: 7 additions & 7 deletions src/audiosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ struct AVBufferRef;
struct AVFrame;
struct AVPacket;

struct AudioFormat {
struct BSAudioFormat {
bool Float;
int Bits;
int BytesPerSample; // FIXME, kinda odd to have it exposed here but very useful to store internally

void Set(int Format, int BitsPerRawSample);
};

struct AudioProperties {
AudioFormat AF;
struct BSAudioProperties {
BSAudioFormat AF;
int SampleRate;
int Channels;
uint64_t ChannelLayout;
Expand Down Expand Up @@ -80,7 +80,7 @@ struct LWAudioDecoder {
[[nodiscard]] int64_t GetFrameNumber() const; // The frame you will get when calling GetNextFrame()
[[nodiscard]] int64_t GetSamplePos() const; // The frame you will get when calling GetNextFrame()
void SetFrameNumber(int64_t N, int64_t SampleNumber); // Use after seeking to update internal frame number
void GetAudioProperties(AudioProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation
void GetAudioProperties(BSAudioProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation
[[nodiscard]] AVFrame *GetNextFrame();
bool SkipFrames(int64_t Count);
[[nodiscard]] bool HasMoreFrames() const;
Expand All @@ -96,7 +96,7 @@ class BestAudioFrame {
BestAudioFrame(AVFrame *Frame);
~BestAudioFrame();
[[nodiscard]] const AVFrame *GetAVFrame() const;
AudioFormat AF;
BSAudioFormat AF;
int NumChannels;

int64_t Pts;
Expand Down Expand Up @@ -147,7 +147,7 @@ class BestAudioSource {
static constexpr int MaxVideoSources = 4;
std::map<std::string, std::string> LAVFOptions;
double DrcScale;
AudioProperties AP = {};
BSAudioProperties AP = {};
std::filesystem::path Source;
int AudioTrack;
bool VariableFormat;
Expand Down Expand Up @@ -185,7 +185,7 @@ class BestAudioSource {
void SetMaxCacheSize(size_t Bytes); /* default max size is 1GB */
void SetSeekPreRoll(int64_t Frames); /* the number of frames to cache before the position being fast forwarded to */
double GetRelativeStartTime(int Track) const;
[[nodiscard]] const AudioProperties &GetAudioProperties() const;
[[nodiscard]] const BSAudioProperties &GetAudioProperties() const;
[[nodiscard]] BestAudioFrame *GetFrame(int64_t N, bool Linear = false);
[[nodiscard]] FrameRange GetFrameRangeBySamples(int64_t Start, int64_t Count) const;
void GetPackedAudio(uint8_t *Data, int64_t Start, int64_t Count);
Expand Down
6 changes: 3 additions & 3 deletions src/avisynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class AvisynthVideoSource : public IClip {

V.reset(new BestVideoSource(CreateProbablyUTF8Path(Source), HWDevice ? HWDevice : "", ExtraHWFrames, Track, false, Threads, CacheMode, CachePath, &Opts));

const VideoProperties &VP = V->GetVideoProperties();
const BSVideoProperties &VP = V->GetVideoProperties();
if (VP.VF.ColorFamily == cfGray) {
VI.pixel_type = VideoInfo::CS_GENERIC_Y;
} else if (VP.VF.ColorFamily == cfYUV && VP.VF.Alpha) {
Expand Down Expand Up @@ -246,7 +246,7 @@ class AvisynthVideoSource : public IClip {
Env->ThrowError("BestVideoSource: %s", e.what());
}

const VideoProperties &VP = V->GetVideoProperties();
const BSVideoProperties &VP = V->GetVideoProperties();
AVSMap *Props = Env->getFramePropsRW(Dst);

SetSynthFrameProperties(Src, VP, RFF, V->GetFrameIsTFF(n, RFF),
Expand Down Expand Up @@ -300,7 +300,7 @@ class AvisynthAudioSource : public IClip {
try {
A.reset(new BestAudioSource(CreateProbablyUTF8Path(Source), Track, AdjustDelay, false, Threads, CacheMode, CachePath ? CachePath : "", &Opts, DrcScale));

const AudioProperties &AP = A->GetAudioProperties();
const BSAudioProperties &AP = A->GetAudioProperties();
if (AP.AF.Float && AP.AF.Bits == 32) {
VI.sample_type = SAMPLE_FLOAT;
} else if (!AP.AF.Float && AP.AF.Bits <= 8) {
Expand Down
2 changes: 1 addition & 1 deletion src/synthshared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "synthshared.h"
#include "VSHelper4.h"

void SetSynthFrameProperties(const std::unique_ptr<BestVideoFrame> &Src, const VideoProperties &VP, bool RFF, bool TFF, const std::function<void(const char *, int64_t)> &mapSetInt, const std::function<void(const char *, double)> &mapSetFloat, const std::function<void(const char *, const char *, int, bool)> &mapSetData) {
void SetSynthFrameProperties(const std::unique_ptr<BestVideoFrame> &Src, const BSVideoProperties &VP, bool RFF, bool TFF, const std::function<void(const char *, int64_t)> &mapSetInt, const std::function<void(const char *, double)> &mapSetFloat, const std::function<void(const char *, const char *, int, bool)> &mapSetData) {
// Set AR variables
if (VP.SAR.Num > 0 && VP.SAR.Den > 0) {
mapSetInt("_SARNum", VP.SAR.Num);
Expand Down
2 changes: 1 addition & 1 deletion src/synthshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
#include <functional>
#include <cstdint>

void SetSynthFrameProperties(const std::unique_ptr<BestVideoFrame> &Src, const VideoProperties &VP, bool RFF, bool TFF, const std::function<void(const char *, int64_t)> &mapSetInt, const std::function<void(const char *, double)> &mapSetFloat, const std::function<void(const char *, const char *, int, bool)> &mapSetData);
void SetSynthFrameProperties(const std::unique_ptr<BestVideoFrame> &Src, const BSVideoProperties &VP, bool RFF, bool TFF, const std::function<void(const char *, int64_t)> &mapSetInt, const std::function<void(const char *, double)> &mapSetFloat, const std::function<void(const char *, const char *, int, bool)> &mapSetData);

#endif
6 changes: 3 additions & 3 deletions src/vapoursynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static const VSFrame *VS_CC BestVideoSourceGetFrame(int n, int ActivationReason,
return nullptr;
}

const VideoProperties &VP = D->V->GetVideoProperties();
const BSVideoProperties &VP = D->V->GetVideoProperties();
VSMap *Props = vsapi->getFramePropertiesRW(Dst);
if (AlphaDst)
vsapi->mapConsumeFrame(Props, "_Alpha", AlphaDst, maAppend);
Expand Down Expand Up @@ -201,7 +201,7 @@ static void VS_CC CreateBestVideoSource(const VSMap *In, VSMap *Out, void *, VSC
D->V.reset(new BestVideoSource(Source, HWDevice ? HWDevice : "", ExtraHWFrames, Track, VariableFormat, Threads, CacheMode, CachePath ? CachePath : "", &Opts));
}

const VideoProperties &VP = D->V->GetVideoProperties();
const BSVideoProperties &VP = D->V->GetVideoProperties();
if (VP.VF.ColorFamily == 0 || !vsapi->queryVideoFormat(&D->VI.format, VP.VF.ColorFamily, VP.VF.Float, VP.VF.Bits, VP.VF.SubSamplingW, VP.VF.SubSamplingH, Core))
throw BestSourceException("Unsupported video format from decoder (probably less than 8 bit or palette)");
D->VI.width = VP.SSModWidth;
Expand Down Expand Up @@ -338,7 +338,7 @@ static void VS_CC CreateBestAudioSource(const VSMap *In, VSMap *Out, void *, VSC
D->A.reset(new BestAudioSource(Source, Track, AdjustDelay, false, Threads, CacheMode, CachePath ? CachePath : "", &Opts, DrcScale));
}

const AudioProperties &AP = D->A->GetAudioProperties();
const BSAudioProperties &AP = D->A->GetAudioProperties();
D->Is8Bit = (AP.AF.Bits <= 8);
if (!vsapi->queryAudioFormat(&D->AI.format, AP.AF.Float, D->Is8Bit ? 16 : AP.AF.Bits, AP.ChannelLayout, Core))
throw BestSourceException("Unsupported audio format from decoder (probably 8-bit)");
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef VERSION_H
#define VERSION_H

#define BEST_SOURCE_VERSION_MAJOR 4
#define BEST_SOURCE_VERSION_MAJOR 6
#define BEST_SOURCE_VERSION_MINOR 0

#endif
8 changes: 4 additions & 4 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void LWVideoDecoder::SetFrameNumber(int64_t N) {
CurrentFrame = N;
}

void LWVideoDecoder::GetVideoProperties(VideoProperties &VP) {
void LWVideoDecoder::GetVideoProperties(BSVideoProperties &VP) {
assert(CurrentFrame == 0);
VP = {};
AVFrame *PropFrame = GetNextFrame();
Expand Down Expand Up @@ -458,7 +458,7 @@ bool LWVideoDecoder::HasSeeked() const {
return Seeked;
}

void VideoFormat::Set(const AVPixFmtDescriptor *Desc) {
void BSVideoFormat::Set(const AVPixFmtDescriptor *Desc) {
Alpha = HasAlpha(Desc);
Float = GetSampleTypeIsFloat(Desc);
ColorFamily = GetColorFamily(Desc);
Expand Down Expand Up @@ -1057,7 +1057,7 @@ bool BestVideoSource::IndexTrack(const ProgressFunction &Progress) {
return !TrackIndex.Frames.empty();
}

const VideoProperties &BestVideoSource::GetVideoProperties() const {
const BSVideoProperties &BestVideoSource::GetVideoProperties() const {
return VP;
}

Expand Down Expand Up @@ -1456,7 +1456,7 @@ BestVideoFrame *BestVideoSource::GetFrameWithRFF(int64_t N, bool Linear) {
}

BestVideoFrame *BestVideoSource::GetFrameByTime(double Time, bool Linear) {
int64_t PTS = static_cast<int64_t>(((Time * 1000 * VP.TimeBase.Den) / VP.TimeBase.Num) + .001);
int64_t PTS = static_cast<int64_t>(((Time * VP.TimeBase.Den) / VP.TimeBase.Num) + .001);
FrameInfo F{ PTS };

auto Pos = std::lower_bound(TrackIndex.Frames.begin(), TrackIndex.Frames.end(), F, [](const FrameInfo &FI1, const FrameInfo &FI2) { return FI1.PTS < FI2.PTS; });
Expand Down
20 changes: 10 additions & 10 deletions src/videosource.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AVFrame;
struct AVPacket;
struct AVPixFmtDescriptor;

struct VideoFormat {
struct BSVideoFormat {
int ColorFamily; /* Unknown = 0, Gray = 1, RGB = 2, YUV = 3 */
bool Alpha;
bool Float;
Expand All @@ -49,7 +49,7 @@ struct VideoFormat {
void Set(const AVPixFmtDescriptor *Desc);
};

struct VideoProperties {
struct BSVideoProperties {
BSRational TimeBase;
double StartTime; // in seconds
int64_t Duration;
Expand All @@ -59,7 +59,7 @@ struct VideoProperties {
BSRational FPS;
BSRational SAR;

VideoFormat VF;
BSVideoFormat VF;
int Width;
int Height;

Expand Down Expand Up @@ -121,7 +121,7 @@ struct LWVideoDecoder {
[[nodiscard]] int GetTrack() const; // Useful when opening nth video track to get the actual number
[[nodiscard]] int64_t GetFrameNumber() const; // The frame you will get when calling GetNextFrame()
void SetFrameNumber(int64_t N); // Use after seeking to update internal frame number
void GetVideoProperties(VideoProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation
void GetVideoProperties(BSVideoProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation
[[nodiscard]] AVFrame *GetNextFrame();
bool SkipFrames(int64_t Count);
[[nodiscard]] bool HasMoreFrames() const;
Expand All @@ -140,7 +140,7 @@ class BestVideoFrame {
void MergeField(bool Top, const BestVideoFrame *FieldSrc); // Useful for RFF and other such things where fields from multiple decoded frames need to be combined, retains original frame's properties
bool ExportAsPlanar(uint8_t *const *const Dsts1, const ptrdiff_t *const Stride, uint8_t *AlphaDst = nullptr, ptrdiff_t AlphaStride = 0) const;

VideoFormat VF;
BSVideoFormat VF;
int Width;
int Height;

Expand Down Expand Up @@ -242,7 +242,7 @@ class BestVideoSource {

static constexpr int MaxVideoSources = 4;
std::map<std::string, std::string> LAVFOptions;
VideoProperties VP = {};
BSVideoProperties VP = {};
std::filesystem::path Source;
std::string HWDevice;
int ExtraHWFrames;
Expand All @@ -268,12 +268,12 @@ class BestVideoSource {
public:
BestVideoSource(const std::filesystem::path &SourceFile, const std::string &HWDeviceName, int ExtraHWFrames, int Track, bool VariableFormat, int Threads, int CacheMode, const std::filesystem::path &CachePath, const std::map<std::string, std::string> *LAVFOpts, const ProgressFunction &Progress = nullptr);
[[nodiscard]] int GetTrack() const; // Useful when opening nth video track to get the actual number
void SetMaxCacheSize(size_t Bytes); /* default max size is 1GB */
void SetSeekPreRoll(int64_t Frames); /* the number of frames to cache before the position being fast forwarded to */
[[nodiscard]] const VideoProperties &GetVideoProperties() const;
void SetMaxCacheSize(size_t Bytes); /* Default max size is 1GB */
void SetSeekPreRoll(int64_t Frames); /* The number of frames to cache before the position being fast forwarded to */
[[nodiscard]] const BSVideoProperties &GetVideoProperties() const;
[[nodiscard]] BestVideoFrame *GetFrame(int64_t N, bool Linear = false);
[[nodiscard]] BestVideoFrame *GetFrameWithRFF(int64_t N, bool Linear = false);
[[nodiscard]] BestVideoFrame *GetFrameByTime(double Time, bool Linear = false);
[[nodiscard]] BestVideoFrame *GetFrameByTime(double Time, bool Linear = false); /* Time is in seconds */
[[nodiscard]] bool GetFrameIsTFF(int64_t N, bool RFF = false);
void WriteTimecodes(const std::filesystem::path &TimecodeFile) const;
[[nodiscard]] const FrameInfo &GetFrameInfo(int64_t N) const;
Expand Down

0 comments on commit 55fb7fd

Please sign in to comment.