示例#1
0
//Here is the actual constructor code used
Deflicker::Deflicker(PClip _child, float _percent, int _lag, float _noise, int _scene, int _lmin, int _lmax, int _border, int _info, int _debug, IScriptEnvironment* env) :
	GenericVideoFilter(_child), percent(_percent), lag(_lag), noise(_noise), scene(_scene), lmin(_lmin), lmax(_lmax), border(_border), info(_info), debug(_debug) {
  // This is the implementation of the constructor.
  // The child clip (source clip) is inherited by the GenericVideoFilter,
  //  where the following variables gets defined:
  //   PClip child;   // Contains the source clip.
  //   VideoInfo vi;  // Contains videoinfo on the source clip.

	if (vi.IsYV12()) // added in v.0.4
		isYUY2 = false;
	else if (vi.IsYUY2())
		isYUY2 = true;
	else
		env->ThrowError("Deflicker: input to filter must be in YV12 or YUY2!");

	range =abs(lag);

	if (percent < 0 || percent >100)
		env->ThrowError("Deflicker: percent must be from 0 to 100 !");
//	else if (percent == 0) 	range = 0;
//	else if (percent == 100) range = 1;
//	else if (range <= 0) range = int( 5*log(100/(100-percent)) );
	
	cachecapacity = range*2+2; // with some reserve

	cachelist = (int *)malloc(cachecapacity*sizeof(int));
	meancache= (int *)malloc(cachecapacity*sizeof(float));
	varcache= (int *)malloc(cachecapacity*sizeof(float));

	for (int i=0; i<cachecapacity; i++) {
		cachelist[i] = -1; // unused, free
	}

	varnoise = noise*noise;

	debugbuf = (char *)malloc(256);
	messagebuf = (char *)malloc(64);

	// avisynth frame cache
	SetCacheHints(CACHE_RANGE,cachecapacity);

	fieldbased = vi.IsFieldBased();  // after separatefields


}
示例#2
0
Cache::Cache(PClip _child, IScriptEnvironment* env)
 : GenericVideoFilter(_child), nextCache(NULL), cache(0), priorCache(NULL), Tick(0)
{
//  InitializeCriticalSectionAndSpinCount(&cs_cache_V, 4000);
//  InitializeCriticalSectionAndSpinCount(&cs_cache_A, 4000);

  h_policy = vi.HasVideo() ? CACHE_GENERIC : CACHE_NOTHING;  // Since hints are not used per default, this is to describe the lowest default cache mode.
  h_audiopolicy = vi.HasAudio() ? CACHE_AUDIO_NONE : CACHE_AUDIO_NOTHING;  // Don't cache audio per default, auto mode.

//h_total_frames = 0; // Hint cache not init'ed
  h_span = 0;
  protectcount = 0;

  samplesize = vi.BytesPerAudioSample();

  maxsamplecount = 0;
  cache_start = 0;
  cache_count = 0;
  ac_expected_next = 0;
  ac_too_small_count = 0;
  ac_currentscore = 20;

  minframe = vi.num_frames;
  maxframe = -1;

  cache_init  = 0;
  cache_limit = CACHE_SCALE_FACTOR / 2;  // Start half way towards 1 buffer
  fault_rate = 0;
  miss_count = 0x80000000; // Hugh negative

  childcost = 0; // Unsupported by child
  childaccesscost = 0; // Unsupported by child

  // Join all the rest of the caches
  env->ManageCache(MC_RegisterCache, this);

  // For 2.6 filters ask about desired parent cache parameters
  if (child->GetVersion() < 5) {
    childthreadmode = CACHE_THREAD_UNSAFE; // 2.5 Default
  }
  else {
    childthreadmode = CACHE_THREAD_CLASS; // 2.6 Default

    const int vmode = child->SetCacheHints(CACHE_GETCHILD_CACHE_MODE, h_policy); // Cache ask Child for desired video cache mode
    switch (vmode) {
      case 0: // Unsupported by child
        break;
      case CACHE_NOTHING:       // Do not cache video.
      case CACHE_WINDOW:        // Hard protect upto X frames within a range of X from the current frame N.
      case CACHE_GENERIC:       // LRU cache upto X frames.
      case CACHE_FORCE_GENERIC: // LRU cache upto X frames, override any previous CACHE_WINDOW.
        // Cache ask Child for desired video cache size
        SetCacheHints(vmode, child->SetCacheHints(CACHE_GETCHILD_CACHE_SIZE, h_policy == CACHE_WINDOW ? h_span : cache_init));
        break;
      default:
        env->ThrowError("Cache: Filter returned invalid response to CACHE_GETCHILD_CACHE_MODE. %d", vmode);
        break;
    }

    const int amode = child->SetCacheHints(CACHE_GETCHILD_AUDIO_MODE, h_audiopolicy); // Cache ask Child for desired audio cache mode
    switch (amode) {
      case 0: // Unsupported by child
        break;
      case CACHE_AUDIO:         // Explicitly do cache audio, X byte cache.
      case CACHE_AUDIO_NOTHING: // Explicitly do not cache audio.
      case CACHE_AUDIO_NONE:    // Audio cache off (auto mode), X byte intial cache.
      case CACHE_AUDIO_AUTO:    // Audio cache on (auto mode), X byte intial cache.
        // Cache ask Child for desired audio cache size
        SetCacheHints(amode, child->SetCacheHints(CACHE_GETCHILD_AUDIO_SIZE, maxsamplecount * samplesize));
        break;
      default:
        env->ThrowError("Cache: Filter returned invalid response to CACHE_GETCHILD_AUDIO_MODE. %d", amode);
        break;
    }

    const int cost = child->SetCacheHints(CACHE_GETCHILD_COST, 0); // Cache ask Child for estimated processing cost.
    switch (cost) {
      case 0: // Unsupported by child
        break;
      case CACHE_COST_ZERO: // Child response of zero cost (ptr arithmetic only).
      case CACHE_COST_UNIT: // Child response of unit cost (less than or equal 1 full frame blit).
      case CACHE_COST_LOW:  // Child response of light cost. (Fast)
      case CACHE_COST_MED:  // Child response of medium cost. (Real time)
      case CACHE_COST_HI:   // Child response of heavy cost. (Slow)
        childcost = cost;
        break;
      default:
        env->ThrowError("Cache: Filter returned invalid response to CACHE_GETCHILD_COST. %d", cost);
        break;
    }

    const int thread = child->SetCacheHints(CACHE_GETCHILD_THREAD_MODE, 0); // Cache ask Child for thread safetyness.
    switch (thread) {
      case 0: // Unsupported by child
        break;
      case CACHE_THREAD_UNSAFE: // Only 1 thread allowed for all instances. 2.5 filters default!
      case CACHE_THREAD_CLASS: // Only 1 thread allowed for each instance. 2.6 filters default!
      case CACHE_THREAD_SAFE: //  Allow all threads in any instance.
      case CACHE_THREAD_OWN: // Safe but limit to 1 thread, internally threaded.
        childthreadmode = thread;
        break;
      default:
        env->ThrowError("Cache: Filter returned invalid response to CACHE_GETCHILD_THREAD_MODE. %d", thread);
        break;
    }

    const int access = child->SetCacheHints(CACHE_GETCHILD_ACCESS_COST, 0); // Cache ask Child for preferred access pattern.
    switch (access) {
      case 0: // Unsupported by child
        break;
      case CACHE_ACCESS_RAND: // Filter is access order agnostic.
      case CACHE_ACCESS_SEQ0: // Filter prefers sequential access (low cost)
      case CACHE_ACCESS_SEQ1: // Filter needs sequential access (high cost)
        childaccesscost = access;
        break;
      default:
        env->ThrowError("Cache: Filter returned invalid response to CACHE_GETCHILD_ACCESS_COST. %d", access);
        break;
    }
  }
}