libvalhalla
2.1.0
|
00001 /* 00002 * GeeXboX Valhalla: tiny media scanner API. 00003 * Copyright (C) 2009 Mathieu Schroeter <mathieu@schroetersa.ch> 00004 * 00005 * This file is part of libvalhalla. 00006 * 00007 * libvalhalla is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * libvalhalla is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with libvalhalla; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #ifndef VALHALLA_GRABBER_COMMON_H 00023 #define VALHALLA_GRABBER_COMMON_H 00024 00062 #include <pthread.h> 00063 #include <string.h> 00064 00065 #include "stats.h" 00066 #include "utils.h" 00067 00071 #define GRABBER_CAP_AUDIO (1 << 0) 00072 #define GRABBER_CAP_VIDEO (1 << 1) 00073 #define GRABBER_CAP_IMAGE (1 << 2) 00081 typedef struct grabber_param_s { 00082 00083 metadata_plist_t *pl; 00085 struct url_ctl_s *url_ctl; 00086 } grabber_param_t; 00087 00091 typedef struct grabber_list_s { 00092 struct grabber_list_s *next; 00093 00095 const char *name; 00097 int caps_flag; 00098 00109 int (*init) (void *priv, const grabber_param_t *param); 00110 00120 void (*uninit) (void *priv); 00121 00147 int (*grab) (void *priv, file_data_t *data); 00148 00158 void (*loop) (void *priv); 00159 00165 void *priv; 00166 00168 grabber_param_t param; 00169 00171 int enable; 00172 00174 uint64_t timewait; 00176 uint64_t timegrab; 00177 00179 pthread_mutex_t mutex; 00180 00182 vh_stats_tmr_t *tmr; 00184 vh_stats_cnt_t *cnt_success; 00186 vh_stats_cnt_t *cnt_failure; 00188 vh_stats_cnt_t *cnt_skip; 00189 00190 } grabber_list_t; 00191 00192 00209 #define GRABBER_REGISTER(p_name, p_caps, p_pl, p_tw, \ 00210 fct_priv, fct_init, fct_uninit, fct_grab, fct_loop) \ 00211 grabber_list_t * \ 00212 vh_grabber_##p_name##_register (struct url_ctl_s *url_ctl) \ 00213 { \ 00214 grabber_list_t *grabber; \ 00215 \ 00216 vh_log (VALHALLA_MSG_VERBOSE, __FUNCTION__); \ 00217 \ 00218 grabber = calloc (1, sizeof (grabber_list_t)); \ 00219 if (!grabber) \ 00220 return NULL; \ 00221 \ 00222 grabber->name = #p_name; \ 00223 grabber->caps_flag = p_caps; \ 00224 grabber->enable = 1; \ 00225 grabber->timewait = p_tw * 1000000UL; \ 00226 grabber->priv = fct_priv (); \ 00227 \ 00228 grabber->init = fct_init; \ 00229 grabber->uninit = fct_uninit; \ 00230 grabber->grab = fct_grab; \ 00231 grabber->loop = fct_loop; \ 00232 \ 00233 grabber->param.url_ctl = url_ctl; \ 00234 grabber->param.pl = malloc (sizeof (p_pl)); \ 00235 if (!grabber->param.pl) \ 00236 { \ 00237 free (grabber); \ 00238 return NULL; \ 00239 } \ 00240 memcpy (grabber->param.pl, p_pl, sizeof (p_pl)); \ 00241 \ 00242 pthread_mutex_init (&grabber->mutex, NULL); \ 00243 \ 00244 return grabber; \ 00245 } 00246 00247 #endif /* VALHALLA_GRABBER_COMMON_H */