
/* LiViDO plugin example
 *
 * make it with:
 * $ gcc $CFLAGS -c plugin_example.c
 * $ ld -E -z now -shared plugin_example.o -o plugin_example.so
 *
 * (C) 2004 Denis "jaromil" Rojo - http://rastasoft.org
 *
 * This source code is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Public License as published 
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * This source code 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.
 * Please refer to the GNU Public License for more details.
 *
 * You should have received a copy of the GNU Public License along with
 * this source code; if not, write to:
 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: plugin_example.c,v 1.1.1.1 2004/05/02 14:28:32 jaromil Exp $
 *
 */

/** @file plugin_example.c
    
    @brief LiViDO plugin implementation example
    
    @todo comment the plugin example
 */

#include <stdio.h>

#include <livido.h>

/* declare public parameters */

int param0_def = 1; // bool test

int param1_max = 5; // int test
int param1_min = 0;
int param1_def = 1;

float param2_max = 1.0f; //float test
float param2_min = 0.0f;
float param2_def = 0.5f;

// color test (r, g, b)
int param3_def[] = { 0xff, 0xee, 0xdd };

// coord test (x, y)
int param4_max[] = { 640, 480 };
int param4_min[] = { 10, 10 };
int param4_def[] = { 300, 300 };

// string test
char param5_def[] = "e' dio lo gnomo mongoloide";

/* form a NULL terminated property list */
livido_parameter_t plugin_example_parameters[] =
  {

	  /* name, description, type
	   * min, max, default, need_init */

    { "bool", "test parameter 0", LVD_PARAM_BOOL,
      NULL, NULL, (void*)&param0_def, 0 },
      
    { "int", "test parameter 1", LVD_PARAM_INT,
      (void*)&param1_min, (void*)&param1_max, (void*)&param1_def, 0 },
      
    { "float", "test parameter 2", LVD_PARAM_FLOAT,
      (void*)&param2_min, (void*)&param2_max, (void*)&param2_def, 0 },
    
    { "color", "test parameter 3", LVD_PARAM_COLOR,
      NULL, NULL, (void*)&param3_def, 0 },

    { "coord", "test parameter 4", LVD_PARAM_COORD,
      (void*)&param4_min, (void*)&param4_max, (void*)&param4_def, 0 },

    { "string", "test parameter 5", LVD_PARAM_STRING,
      NULL, NULL, (void*)param5_def, 0 },

    { "data", "test parameter 6", LVD_PARAM_DATA,
      NULL, NULL, (void*)param5_def, 0 },

    LIVIDO_PARAM_END

  };

int plugin_example_deinit(livido_instance_t *inst) {
  /* TODO
   * here free the internal buffers
   * and then the instance */
  fprintf(stderr,"plugin example deinit called on instance %p",inst);
  if(inst->internal) {
	  fprintf(stderr,"free internal buffer %p\n",inst->internal);
	  free(inst->internal);
  }
  return 1; // success
}

/* declare our init function */
livido_instance_t *plugin_example_init(livido_instance_t *inst, livido_frame_t *frame) {
  /* TODOOO 
   * create an instance buffer
   * fill up the default parameters of the instance */
  fprintf(stderr,"plugin example init called on instance %p\n",inst);
  fprintf(stderr,"frame description is %ix%i\n",frame->width,frame->height);

  /* this is because the init must be reentrant
     you got to take care that the plugin frees and instances all things in their place
     then it's all more stable i tell you :) */
  if(inst->internal) plugin_example_deinit(inst->internal);
  else inst->internal = malloc(666);

  fprintf(stderr,"allocated internal buffer %p\n",inst->internal);
  return inst;
}


int plugin_example_process
(livido_instance_t *env, livido_frame_t **in, livido_frame_t **out) {
  fprintf(stderr,"plugin example: process called on env=%p in=%p out=%p\n",
		  env,in,out);
  return 1;
}


int palettes[] =  
  { LVD_PALETTE_RGB32, LVD_PALETTE_YUV420P }; // palettes accepted

/* declare my livido filter class */
livido_class_t plugin_example_class[] = {
  {
  /* name, author,
   * long description, version, livido api version */
  "example filter", "jaromil",
  "linux dynamic video objects example", 1, 1,

  /* here declare list of accepted palettes (or'd flags)
   * and the one which is preferred */

  palettes,

  (LIVIDO_PROPERTY_REALTIME | LIVIDO_PROPERTY_INPLACE),

  1, 1, // input frame min e max
  1, 1, // output frames min e max

  plugin_example_parameters,

  plugin_example_init,
  plugin_example_deinit,
  plugin_example_process
  },

  // you can place here more classes
  
  LIVIDO_CLASS_END
};


livido_class_t *livido_setup() {
  return plugin_example_class;
}

