Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mark zero-op filters non-cachable.
  • Loading branch information
pylorak committed Jan 2, 2014
1 parent b107a2a commit 50a1e56
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 33 deletions.
2 changes: 1 addition & 1 deletion avs_core/core/audio.cpp
Expand Up @@ -151,7 +151,7 @@ void FilterUD_mmx(short *Xp, unsigned Ph, int _inc, int _dhb, short *p_Imp, unsi
*************************************/

AssumeRate::AssumeRate(PClip _clip, int _rate)
: GenericVideoFilter(_clip) {
: NonCachedGenericVideoFilter(_clip) {
if (_rate < 0)
_rate = 0;
if (vi.SamplesPerSecond() == 0) // Don't add audio if none is present.
Expand Down
2 changes: 1 addition & 1 deletion avs_core/core/audio.h
Expand Up @@ -84,7 +84,7 @@ static int makeFilter(SFLOAT fImp[], double dLpScl, unsigned short Nwing, doubl
/********************************************************************
********************************************************************/

class AssumeRate : public GenericVideoFilter
class AssumeRate : public NonCachedGenericVideoFilter
/**
* Changes the sample rate of a clip
**/
Expand Down
62 changes: 51 additions & 11 deletions avs_core/filters/edit.cpp
Expand Up @@ -81,14 +81,34 @@ extern const AVSFunction Edit_filters[] = {




/******************************
******* NonCachedGenericVideoFilter Filter ******
******************************/

NonCachedGenericVideoFilter::NonCachedGenericVideoFilter(PClip _child) :
GenericVideoFilter(_child)
{
};


int __stdcall NonCachedGenericVideoFilter::SetCacheHints(int cachehints, int frame_range)
{
switch(cachehints)
{
case CACHE_DONT_CACHE_ME:
return 1;
default:
return GenericVideoFilter::SetCacheHints(cachehints, frame_range);
}
}


/******************************
******* AudioTrim Filter ******
******************************/

Trim::Trim(double starttime, double endtime, PClip _child, int mode, IScriptEnvironment* env)
: GenericVideoFilter(_child)
: NonCachedGenericVideoFilter(_child)
{
__int64 esampleno = 0;

Expand Down Expand Up @@ -157,7 +177,7 @@ AVSValue __cdecl Trim::CreateA(AVSValue args, void* mode, IScriptEnvironment* en
******************************/

Trim::Trim(int _firstframe, int _lastframe, bool _padaudio, PClip _child, int mode, IScriptEnvironment* env)
: GenericVideoFilter(_child)
: NonCachedGenericVideoFilter(_child)
{
int lastframe = 0;

Expand Down Expand Up @@ -263,7 +283,7 @@ AVSValue __cdecl Trim::Create(AVSValue args, void* mode, IScriptEnvironment* env
*******************************/

FreezeFrame::FreezeFrame(int _first, int _last, int _source, PClip _child)
: GenericVideoFilter(_child), first(_first), last(_last), source(_source) {}
: NonCachedGenericVideoFilter(_child), first(_first), last(_last), source(_source) {}


PVideoFrame FreezeFrame::GetFrame(int n, IScriptEnvironment* env)
Expand All @@ -289,7 +309,7 @@ AVSValue __cdecl FreezeFrame::Create(AVSValue args, void*, IScriptEnvironment* e
******************************/

DeleteFrame::DeleteFrame(int _frame, PClip _child)
: GenericVideoFilter(_child), frame(_frame) { --vi.num_frames; }
: NonCachedGenericVideoFilter(_child), frame(_frame) { --vi.num_frames; }


PVideoFrame DeleteFrame::GetFrame(int n, IScriptEnvironment* env)
Expand All @@ -303,6 +323,7 @@ bool DeleteFrame::GetParity(int n)
return child->GetParity(n + (n>=frame));
}


AVSValue __cdecl DeleteFrame::Create(AVSValue args, void*, IScriptEnvironment* env)
{
const int n = args[1].ArraySize();
Expand Down Expand Up @@ -342,7 +363,7 @@ AVSValue __cdecl DeleteFrame::Create(AVSValue args, void*, IScriptEnvironment* e
*********************************/

DuplicateFrame::DuplicateFrame(int _frame, PClip _child)
: GenericVideoFilter(_child), frame(_frame) { ++vi.num_frames; }
: NonCachedGenericVideoFilter(_child), frame(_frame) { ++vi.num_frames; }


PVideoFrame DuplicateFrame::GetFrame(int n, IScriptEnvironment* env)
Expand Down Expand Up @@ -482,9 +503,16 @@ bool Splice::GetParity(int n)

int Splice::SetCacheHints(int cachehints,int frame_range)
{
if (passCache) {
child2->SetCacheHints(cachehints, frame_range);
return child->SetCacheHints(cachehints, frame_range);
switch(cachehints)
{
case CACHE_DONT_CACHE_ME:
return 1;
default:
if (passCache) {
child2->SetCacheHints(cachehints, frame_range);
return child->SetCacheHints(cachehints, frame_range);
}
break;
}
return 0; // We do not pass cache requests upwards.
}
Expand Down Expand Up @@ -795,6 +823,18 @@ void AudioDub::GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironm
achild->GetAudio(buf, start, count, env);
}

int __stdcall AudioDub::SetCacheHints(int cachehints,int frame_range)
{
switch(cachehints)
{
case CACHE_DONT_CACHE_ME:
return 1;
default:
return 0;
}
}



AVSValue __cdecl AudioDub::Create(AVSValue args, void* mode, IScriptEnvironment* env)
{
Expand All @@ -813,7 +853,7 @@ AVSValue __cdecl AudioDub::Create(AVSValue args, void* mode, IScriptEnvironment*
******* Reverse Filter ******
*******************************/

Reverse::Reverse(PClip _child) : GenericVideoFilter(_child) {}
Reverse::Reverse(PClip _child) : NonCachedGenericVideoFilter(_child) {}


PVideoFrame Reverse::GetFrame(int n, IScriptEnvironment* env)
Expand Down Expand Up @@ -857,7 +897,7 @@ AVSValue __cdecl Reverse::Create(AVSValue args, void*, IScriptEnvironment* env)
*****************************/

Loop::Loop(PClip _child, int times, int _start, int _end, IScriptEnvironment* env)
: GenericVideoFilter(_child), start(_start), end(_end)
: NonCachedGenericVideoFilter(_child), start(_start), end(_end)
{
start = clamp(start,0,vi.num_frames-1);
end = clamp(end,start,vi.num_frames-1);
Expand Down
15 changes: 8 additions & 7 deletions avs_core/filters/edit.h
Expand Up @@ -36,11 +36,12 @@
#define __Edit_H__

#include <avisynth.h>
#include "../core/internal.h"

/********************************************************************
********************************************************************/

class Trim : public GenericVideoFilter
class Trim : public NonCachedGenericVideoFilter
/**
* Class to select a range of frames from a longer clip
**/
Expand All @@ -64,7 +65,7 @@ class Trim : public GenericVideoFilter



class FreezeFrame : public GenericVideoFilter
class FreezeFrame : public NonCachedGenericVideoFilter
/**
* Class to display a single frame for the duration of several
**/
Expand All @@ -83,7 +84,7 @@ class FreezeFrame : public GenericVideoFilter



class DeleteFrame : public GenericVideoFilter
class DeleteFrame : public NonCachedGenericVideoFilter
/**
* Class to delete a frame
**/
Expand All @@ -102,7 +103,7 @@ class DeleteFrame : public GenericVideoFilter



class DuplicateFrame : public GenericVideoFilter
class DuplicateFrame : public NonCachedGenericVideoFilter
/**
* Class to duplicate a frame
**/
Expand Down Expand Up @@ -183,7 +184,7 @@ class AudioDub : public IClip {
PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env);
void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env);
bool __stdcall GetParity(int n);
int __stdcall SetCacheHints(int cachehints,int frame_range) { return 0; };
int __stdcall SetCacheHints(int cachehints,int frame_range);

static AVSValue __cdecl Create(AVSValue args, void* mode, IScriptEnvironment* env);

Expand All @@ -195,7 +196,7 @@ class AudioDub : public IClip {



class Reverse : public GenericVideoFilter
class Reverse : public NonCachedGenericVideoFilter
/**
* Class to play a clip backwards
**/
Expand All @@ -212,7 +213,7 @@ class Reverse : public GenericVideoFilter



class Loop : public GenericVideoFilter {
class Loop : public NonCachedGenericVideoFilter {
/**
* Class to loop over a range of frames
**/
Expand Down
13 changes: 12 additions & 1 deletion avs_core/filters/field.cpp
Expand Up @@ -426,7 +426,7 @@ SeparateRows::SeparateRows(PClip _child, int _interval, IScriptEnvironment* env)

PVideoFrame SeparateRows::GetFrame(int n, IScriptEnvironment* env)
{
const int m = vi.IsRGB() ? interval-1 - n%interval : n%interval; // RGB upsidedown
const int m = vi.IsRGB() ? interval-1 - n%interval : n%interval; // RGB upside-down
const int f = n/interval;

PVideoFrame frame = child->GetFrame(f, env);
Expand Down Expand Up @@ -616,6 +616,17 @@ Interleave::Interleave(int _num_children, const PClip* _child_array, IScriptEnvi

}

int __stdcall Interleave::SetCacheHints(int cachehints,int frame_range)
{
switch(cachehints)
{
case CACHE_DONT_CACHE_ME:
return 1;
default:
return 0;
}
}

AVSValue __cdecl Interleave::Create(AVSValue args, void*, IScriptEnvironment* env)
{
args = args[0];
Expand Down
15 changes: 8 additions & 7 deletions avs_core/filters/field.h
Expand Up @@ -36,6 +36,7 @@
#define __Field_H__

#include <avisynth.h>
#include "../core/internal.h"


/**********************************************************************
Expand Down Expand Up @@ -87,13 +88,13 @@ class ComplementParity : public GenericVideoFilter
};


class AssumeParity : public GenericVideoFilter
class AssumeParity : public NonCachedGenericVideoFilter
/**
* Class to assume field precedence, AssumeTFF() & AssumeBFF()
**/
{
public:
AssumeParity(PClip _child, bool _parity) : GenericVideoFilter(_child), parity(_parity) {
AssumeParity(PClip _child, bool _parity) : NonCachedGenericVideoFilter(_child), parity(_parity) {
if (parity) {
vi.Clear(VideoInfo::IT_BFF);
vi.Set(VideoInfo::IT_TFF);
Expand All @@ -112,13 +113,13 @@ class AssumeParity : public GenericVideoFilter
bool parity;
};

class AssumeFieldBased : public GenericVideoFilter
class AssumeFieldBased : public NonCachedGenericVideoFilter
/**
* Class to assume field-based video
**/
{
public:
AssumeFieldBased(PClip _child) : GenericVideoFilter(_child)
AssumeFieldBased(PClip _child) : NonCachedGenericVideoFilter(_child)
{ vi.SetFieldBased(true); vi.Clear(VideoInfo::IT_BFF); vi.Clear(VideoInfo::IT_TFF); }
inline bool __stdcall GetParity(int n)
{ return n&1; }
Expand All @@ -128,13 +129,13 @@ class AssumeFieldBased : public GenericVideoFilter
};


class AssumeFrameBased : public GenericVideoFilter
class AssumeFrameBased : public NonCachedGenericVideoFilter
/**
* Class to assume frame-based video
**/
{
public:
AssumeFrameBased(PClip _child) : GenericVideoFilter(_child)
AssumeFrameBased(PClip _child) : NonCachedGenericVideoFilter(_child)
{ vi.SetFieldBased(false); vi.Clear(VideoInfo::IT_BFF); vi.Clear(VideoInfo::IT_TFF); }
inline bool __stdcall GetParity(int n)
{ return false; }
Expand Down Expand Up @@ -284,7 +285,7 @@ class Interleave : public IClip
{ delete[] child_array; }
static AVSValue __cdecl Create(AVSValue args, void*, IScriptEnvironment* env);

int __stdcall SetCacheHints(int cachehints,int frame_range) { return 0; };
int __stdcall SetCacheHints(int cachehints,int frame_range);

private:
const int num_children;
Expand Down
4 changes: 2 additions & 2 deletions avs_core/filters/fps.cpp
Expand Up @@ -400,7 +400,7 @@ void PresetToFPS(const char *name, const char *p, unsigned &num, unsigned &den,
******************************************/

AssumeScaledFPS::AssumeScaledFPS(PClip _child, int multiplier, int divisor, bool sync_audio, IScriptEnvironment* env)
: GenericVideoFilter(_child)
: NonCachedGenericVideoFilter(_child)
{
if (divisor <= 0)
env->ThrowError("AssumeScaledFPS: Divisor must be positive.");
Expand Down Expand Up @@ -430,7 +430,7 @@ AVSValue __cdecl AssumeScaledFPS::Create(AVSValue args, void*, IScriptEnvironmen
************************************/

AssumeFPS::AssumeFPS(PClip _child, unsigned numerator, unsigned denominator, bool sync_audio, IScriptEnvironment* env)
: GenericVideoFilter(_child)
: NonCachedGenericVideoFilter(_child)
{
if (denominator == 0)
env->ThrowError("AssumeFPS: Denominator cannot be 0 (zero).");
Expand Down
6 changes: 3 additions & 3 deletions avs_core/filters/fps.h
Expand Up @@ -35,7 +35,7 @@
#define __FPS_H__

#include <avisynth.h>

#include "../core/internal.h"

/********************************************************************
********************************************************************/
Expand All @@ -46,7 +46,7 @@ void FloatToFPS(const char *name, float n, unsigned &num, unsigned &den, IScript

void PresetToFPS(const char *name, const char *p, unsigned &num, unsigned &den, IScriptEnvironment* env);

class AssumeScaledFPS : public GenericVideoFilter
class AssumeScaledFPS : public NonCachedGenericVideoFilter
/**
* Class to change the framerate without changing the frame count
**/
Expand All @@ -57,7 +57,7 @@ class AssumeScaledFPS : public GenericVideoFilter
};


class AssumeFPS : public GenericVideoFilter
class AssumeFPS : public NonCachedGenericVideoFilter
/**
* Class to change the framerate without changing the frame count
**/
Expand Down

0 comments on commit 50a1e56

Please sign in to comment.