#ifndef movement_HEADER_GUARD
#define movement_HEADER_GUARD
/*
 * movement.h : Framefilter implementing a movement detector
 * 
 * (c) Copyright 2017-2024 Sampsa Riikonen
 * 
 * Authors: Petri Eranko <petri.eranko@dasys.fi>
 * 
 * This file is part of the Valkka library.
 * 
 * Valkka is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
 *
 */

/** 
 *  @file    movement.h
 *  @author  Petri Eranko
 *  @date    2019
 *  @version 1.6.1 
 *  
 *  @brief   Framefilter implementing a movement detector
 */ 


#include "framefilter.h"
#include "Python.h"

class MovementFrameFilter : public FrameFilter {                                           // <pyapi>
  
public:                                                                                    // <pyapi>
    /**
     * @param interval  How often the frame is checked (milliseconds).  This also defines how often a frame is passed downstream, if the movement is on.
     * @param treshold  Treshold value for movement
     * @param duration  Duration of a single event (milliseconds)
     * 
     */
    MovementFrameFilter(const char* name, long int interval, float treshold, long int duration, FrameFilter* next=NULL);     // <pyapi>
    virtual ~MovementFrameFilter(); // <pyapi>
    
protected:
    long int  movement_start; ///< State of the movement detector & the timestamp when movement was first detected
    long int  mstimestamp;    ///< Saved timestamp: time of the previous frame
    long int  duration;       ///< Movement events within this time are the same event
    long int  interval;       ///< How often check the frames
    int       y_size;         ///< Size of the last cached luma plane
    uint8_t*  luma;           ///< Cached luma component of the yuv image
    PyObject* pycallback;    ///< Python method to be called at movement & still events
    float     treshold;
  
  
protected:
    /** Takes AVBitmapFrame */
    void run(Frame* frame);
    void go(Frame* frame);
    
public:
    void reset();                                                                         // <pyapi>
    /** Set a python callable on movement start & stop events */
    void setCallback(PyObject* pycallback);                                               // <pyapi>
};                                                                                        // <pyapi>



#endif
