Skip to content

Commit

Permalink
Fix compilation with older ffmpeg/libav
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Sep 7, 2015
1 parent 0be6788 commit c5712e0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
17 changes: 11 additions & 6 deletions include/ffmscompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,25 @@ static void av_frame_free(AVFrame **frame) { av_freep(frame); }
# define av_get_packed_sample_fmt(fmt) (fmt < AV_SAMPLE_FMT_U8P ? fmt : fmt - (AV_SAMPLE_FMT_U8P - AV_SAMPLE_FMT_U8))
# endif
# if VERSION_CHECK(LIBAVUTIL_VERSION_INT, <, 51, 44, 0, 51, 76, 100)
// Needs to be included before the AVPixelFormat define
# include <libavutil/pixdesc.h>
# endif

# if VERSION_CHECK(LIBAVUTIL_VERSION_INT, <, 51, 42, 0, 51, 74, 100)
# define AVPixelFormat PixelFormat
# define AV_PIX_FMT_NB PIX_FMT_NB
# endif
# if VERSION_CHECK(LIBAVUTIL_VERSION_INT, <, 51, 42, 0, 51, 74, 100)
# define AVPixelFormat PixelFormat
# define FFMS_PIX_FMT(x) PIX_FMT_##x
# define FFMS_PIX_FMT_FLAG(x) PIX_FMT_##x
# else
# define FFMS_PIX_FMT_FLAG(x) AV_PIX_FMT_FLAG_##x
# endif

# if VERSION_CHECK(LIBAVUTIL_VERSION_INT, <, 51, 44, 0, 51, 76, 100)
static const AVPixFmtDescriptor *av_pix_fmt_desc_get(AVPixelFormat pix_fmt) {
if (pix_fmt < 0 || pix_fmt >= AV_PIX_FMT_NB)
if (pix_fmt < 0 || pix_fmt >= FFMS_PIX_FMT(NB))
return NULL;

return &av_pix_fmt_descriptors[pix_fmt];
}

# endif
# if VERSION_CHECK(LIBAVUTIL_VERSION_INT, <, 52, 9, 0, 52, 20, 100)
# define av_frame_alloc avcodec_alloc_frame
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,4 @@ bool IsSamePath(const char *p1, const char *p2) {
#else
return !_stricmp(p1, p2);
#endif
}
}
40 changes: 20 additions & 20 deletions src/core/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ FFMS_Frame *FFMS_VideoSource::OutputFrame(AVFrame *Frame) {
if (LastFrameWidth != CodecContext->width || LastFrameHeight != CodecContext->height || LastFramePixelFormat != CodecContext->pix_fmt) {
if (TargetHeight > 0 && TargetWidth > 0 && !TargetPixelFormats.empty()) {
if (!InputFormatOverridden) {
InputFormat = AV_PIX_FMT_NONE;
InputFormat = FFMS_PIX_FMT(NONE);
InputColorSpace = AVCOL_SPC_UNSPECIFIED;
InputColorRange = AVCOL_RANGE_UNSPECIFIED;
}
Expand Down Expand Up @@ -134,18 +134,18 @@ FFMS_VideoSource::FFMS_VideoSource(const char *SourceFile, FFMS_Index &Index, in

LastFrameHeight = -1;
LastFrameWidth = -1;
LastFramePixelFormat = AV_PIX_FMT_NONE;
LastFramePixelFormat = FFMS_PIX_FMT(NONE);

TargetHeight = -1;
TargetWidth = -1;
TargetResizer = 0;

OutputFormat = AV_PIX_FMT_NONE;
OutputFormat = FFMS_PIX_FMT(NONE);
OutputColorSpace = AVCOL_SPC_UNSPECIFIED;
OutputColorRange = AVCOL_RANGE_UNSPECIFIED;

InputFormatOverridden = false;
InputFormat = AV_PIX_FMT_NONE;
InputFormat = FFMS_PIX_FMT(NONE);
InputColorSpace = AVCOL_SPC_UNSPECIFIED;
InputColorRange = AVCOL_RANGE_UNSPECIFIED;
if (Threads < 1)
Expand All @@ -157,7 +157,7 @@ FFMS_VideoSource::FFMS_VideoSource(const char *SourceFile, FFMS_Index &Index, in
LastDecodedFrame = av_frame_alloc();

// Dummy allocations so the unallocated case doesn't have to be handled later
avpicture_alloc(&SWSFrame, AV_PIX_FMT_GRAY8, 16, 16);
avpicture_alloc(&SWSFrame, FFMS_PIX_FMT(GRAY8), 16, 16);

Index.AddRef();
}
Expand All @@ -180,11 +180,11 @@ FFMS_Frame *FFMS_VideoSource::GetFrameByTime(double Time) {

static AVColorRange handle_jpeg(AVPixelFormat *format) {
switch (*format) {
case AV_PIX_FMT_YUVJ420P: *format = AV_PIX_FMT_YUV420P; return AVCOL_RANGE_JPEG;
case AV_PIX_FMT_YUVJ422P: *format = AV_PIX_FMT_YUV422P; return AVCOL_RANGE_JPEG;
case AV_PIX_FMT_YUVJ444P: *format = AV_PIX_FMT_YUV444P; return AVCOL_RANGE_JPEG;
case AV_PIX_FMT_YUVJ440P: *format = AV_PIX_FMT_YUV440P; return AVCOL_RANGE_JPEG;
default: return AVCOL_RANGE_UNSPECIFIED;
case FFMS_PIX_FMT(YUVJ420P): *format = FFMS_PIX_FMT(YUV420P); return AVCOL_RANGE_JPEG;
case FFMS_PIX_FMT(YUVJ422P): *format = FFMS_PIX_FMT(YUV422P); return AVCOL_RANGE_JPEG;
case FFMS_PIX_FMT(YUVJ444P): *format = FFMS_PIX_FMT(YUV444P); return AVCOL_RANGE_JPEG;
case FFMS_PIX_FMT(YUVJ440P): *format = FFMS_PIX_FMT(YUV440P); return AVCOL_RANGE_JPEG;
default: return AVCOL_RANGE_UNSPECIFIED;
}
}

Expand All @@ -193,9 +193,9 @@ void FFMS_VideoSource::SetOutputFormat(const AVPixelFormat *TargetFormats, int W
TargetHeight = Height;
TargetResizer = Resizer;
TargetPixelFormats.clear();
while (*TargetFormats != AV_PIX_FMT_NONE)
while (*TargetFormats != FFMS_PIX_FMT(NONE))
TargetPixelFormats.push_back(*TargetFormats++);
OutputFormat = AV_PIX_FMT_NONE;
OutputFormat = FFMS_PIX_FMT(NONE);

ReAdjustOutputFormat();
OutputFrame(DecodeFrame);
Expand All @@ -204,7 +204,7 @@ void FFMS_VideoSource::SetOutputFormat(const AVPixelFormat *TargetFormats, int W
void FFMS_VideoSource::SetInputFormat(int ColorSpace, int ColorRange, AVPixelFormat Format) {
InputFormatOverridden = true;

if (Format != AV_PIX_FMT_NONE)
if (Format != FFMS_PIX_FMT(NONE))
InputFormat = Format;
if (ColorRange != AVCOL_RANGE_UNSPECIFIED)
InputColorRange = (AVColorRange)ColorRange;
Expand All @@ -218,7 +218,7 @@ void FFMS_VideoSource::SetInputFormat(int ColorSpace, int ColorRange, AVPixelFor
}

void FFMS_VideoSource::DetectInputFormat() {
if (InputFormat == AV_PIX_FMT_NONE)
if (InputFormat == FFMS_PIX_FMT(NONE))
InputFormat = CodecContext->pix_fmt;

AVColorRange RangeFromFormat = handle_jpeg(&InputFormat);
Expand All @@ -245,7 +245,7 @@ void FFMS_VideoSource::ReAdjustOutputFormat() {
DetectInputFormat();

OutputFormat = FindBestPixelFormat(TargetPixelFormats, InputFormat);
if (OutputFormat == AV_PIX_FMT_NONE) {
if (OutputFormat == FFMS_PIX_FMT(NONE)) {
ResetOutputFormat();
throw FFMS_Exception(FFMS_ERROR_SCALING, FFMS_ERROR_INVALID_ARGUMENT,
"No suitable output format found");
Expand Down Expand Up @@ -293,7 +293,7 @@ void FFMS_VideoSource::ResetOutputFormat() {
TargetHeight = -1;
TargetPixelFormats.clear();

OutputFormat = AV_PIX_FMT_NONE;
OutputFormat = FFMS_PIX_FMT(NONE);
OutputColorSpace = AVCOL_SPC_UNSPECIFIED;
OutputColorRange = AVCOL_RANGE_UNSPECIFIED;

Expand All @@ -302,7 +302,7 @@ void FFMS_VideoSource::ResetOutputFormat() {

void FFMS_VideoSource::ResetInputFormat() {
InputFormatOverridden = false;
InputFormat = AV_PIX_FMT_NONE;
InputFormat = FFMS_PIX_FMT(NONE);
InputColorSpace = AVCOL_SPC_UNSPECIFIED;
InputColorRange = AVCOL_RANGE_UNSPECIFIED;

Expand All @@ -324,9 +324,9 @@ void FFMS_VideoSource::SetVideoProperties() {
VP.ColorSpace = CodecContext->colorspace;
VP.ColorRange = CodecContext->color_range;
// these pixfmt's are deprecated but still used
if (CodecContext->pix_fmt == AV_PIX_FMT_YUVJ420P ||
CodecContext->pix_fmt == AV_PIX_FMT_YUVJ422P ||
CodecContext->pix_fmt == AV_PIX_FMT_YUVJ444P
if (CodecContext->pix_fmt == FFMS_PIX_FMT(YUVJ420P) ||
CodecContext->pix_fmt == FFMS_PIX_FMT(YUVJ422P) ||
CodecContext->pix_fmt == FFMS_PIX_FMT(YUVJ444P)
)
VP.ColorRange = AVCOL_RANGE_JPEG;

Expand Down
8 changes: 4 additions & 4 deletions src/core/videoutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ enum BCSType {

static BCSType GuessCSType(AVPixelFormat p) {
// guessing the colorspace type from the name is kinda hackish but libav doesn't export this kind of metadata
if (av_pix_fmt_desc_get(p)->flags & AV_PIX_FMT_FLAG_HWACCEL)
if (av_pix_fmt_desc_get(p)->flags & FFMS_PIX_FMT_FLAG(HWACCEL))
return cUNUSABLE;
const char *n = av_get_pix_fmt_name(p);
if (strstr(n, "gray") || strstr(n, "mono") || strstr(n, "y400a"))
Expand Down Expand Up @@ -193,7 +193,7 @@ static LossAttributes CalculateLoss(AVPixelFormat Dst, AVPixelFormat Src) {
AVPixelFormat FindBestPixelFormat(const std::vector<AVPixelFormat> &Dsts, AVPixelFormat Src) {
// some trivial special cases to make sure there's as little conversion as possible
if (Dsts.empty())
return AV_PIX_FMT_NONE;
return FFMS_PIX_FMT(NONE);
if (Dsts.size() == 1)
return Dsts[0];

Expand All @@ -203,8 +203,8 @@ AVPixelFormat FindBestPixelFormat(const std::vector<AVPixelFormat> &Dsts, AVPixe
return Src;

// If it's an evil paletted format pretend it's normal RGB when calculating loss
if (Src == AV_PIX_FMT_PAL8)
Src = AV_PIX_FMT_RGB32;
if (Src == FFMS_PIX_FMT(PAL8))
Src = FFMS_PIX_FMT(RGB32);

i = Dsts.begin();
LossAttributes Loss = CalculateLoss(*i++, Src);
Expand Down
20 changes: 12 additions & 8 deletions src/vapoursynth/vapoursource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ static bool IsRealNativeEndianPlanar(const AVPixFmtDescriptor &desc) {
for (int i = 0; i < desc.nb_components; i++)
used_planes = std::max(used_planes, (int)desc.comp[i].plane + 1);
bool temp = (used_planes == desc.nb_components) && (desc.comp[0].depth_minus1 + 1 >= 8) &&
(!(desc.flags & AV_PIX_FMT_FLAG_PAL));
(!(desc.flags & FFMS_PIX_FMT_FLAG(PAL)));
if (!temp)
return false;
else if (desc.comp[0].depth_minus1 + 1 == 8)
return temp;
else
return (AV_PIX_FMT_YUV420P10 == AV_PIX_FMT_YUV420P10BE ? !!(desc.flags & AV_PIX_FMT_FLAG_BE) : !(desc.flags & AV_PIX_FMT_FLAG_BE));
return (FFMS_PIX_FMT(YUV420P10) == FFMS_PIX_FMT(YUV420P10BE) ? !!(desc.flags & FFMS_PIX_FMT_FLAG(BE)) : !(desc.flags & FFMS_PIX_FMT_FLAG(BE)));
}

static bool HasAlpha(const AVPixFmtDescriptor &desc) {
return !!(desc.flags & AV_PIX_FMT_FLAG_ALPHA);
#if VERSION_CHECK(LIBAVUTIL_VERSION_INT, >, 52, 2, 0, 52, 8, 100)
return !!(desc.flags & FFMS_PIX_FMT_FLAG(ALPHA));
#else
return false;
#endif
}

static int GetColorFamily(const AVPixFmtDescriptor &desc) {
if (desc.nb_components <= 2)
return cmGray;
else if (desc.flags & AV_PIX_FMT_FLAG_RGB)
else if (desc.flags & FFMS_PIX_FMT_FLAG(RGB))
return cmRGB;
else
return cmYUV;
Expand Down Expand Up @@ -88,7 +92,7 @@ static int FormatConversionToPixelFormat(int id, bool Alpha, VSCore *core, const
&& desc.log2_chroma_h == f->subSamplingH)
return i;
}
return AV_PIX_FMT_NONE;
return FFMS_PIX_FMT(NONE);
}

static const VSFormat *FormatConversionToVS(int id, VSCore *core, const VSAPI *vsapi) {
Expand Down Expand Up @@ -269,12 +273,12 @@ void VSVideoSource::InitOutputFormat(int ResizeToWidth, int ResizeToHeight,
for (int i = 0; i < npixfmt; i++)
if (IsRealNativeEndianPlanar(*av_pix_fmt_desc_get((AVPixelFormat)i)))
TargetFormats.push_back(i);
TargetFormats.push_back(AV_PIX_FMT_NONE);
TargetFormats.push_back(FFMS_PIX_FMT(NONE));

int TargetPixelFormat = AV_PIX_FMT_NONE;
int TargetPixelFormat = FFMS_PIX_FMT(NONE);
if (ConvertToFormat != pfNone) {
TargetPixelFormat = FormatConversionToPixelFormat(ConvertToFormat, OutputAlpha, core, vsapi);
if (TargetPixelFormat == AV_PIX_FMT_NONE)
if (TargetPixelFormat == FFMS_PIX_FMT(NONE))
throw std::runtime_error(std::string("Source: Invalid output colorspace specified"));

TargetFormats.clear();
Expand Down

0 comments on commit c5712e0

Please sign in to comment.