libvalhalla  2.0.0
grabber_common.h
Go to the documentation of this file.
1 /*
2  * GeeXboX Valhalla: tiny media scanner API.
3  * Copyright (C) 2009 Mathieu Schroeter <mathieu.schroeter@gamesover.ch>
4  *
5  * This file is part of libvalhalla.
6  *
7  * libvalhalla is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * libvalhalla is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with libvalhalla; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #ifndef VALHALLA_GRABBER_COMMON_H
23 #define VALHALLA_GRABBER_COMMON_H
24 
62 #include <pthread.h>
63 #include <string.h>
64 
65 #include "stats.h"
66 #include "utils.h"
67 
71 #define GRABBER_CAP_AUDIO (1 << 0)
72 #define GRABBER_CAP_VIDEO (1 << 1)
73 #define GRABBER_CAP_IMAGE (1 << 2)
81 typedef struct grabber_param_s {
82 
83  metadata_plist_t *pl;
85  struct url_ctl_s *url_ctl;
87 
91 typedef struct grabber_list_s {
92  struct grabber_list_s *next;
93 
95  const char *name;
97  int caps_flag;
98 
109  int (*init) (void *priv, const grabber_param_t *param);
110 
120  void (*uninit) (void *priv);
121 
147  int (*grab) (void *priv, file_data_t *data);
148 
158  void (*loop) (void *priv);
159 
165  void *priv;
166 
169 
171  int enable;
172 
174  uint64_t timewait;
176  uint64_t timegrab;
177 
179  pthread_mutex_t mutex;
180 
182  vh_stats_tmr_t *tmr;
184  vh_stats_cnt_t *cnt_success;
186  vh_stats_cnt_t *cnt_failure;
188  vh_stats_cnt_t *cnt_skip;
189 
191 
192 
209 #define GRABBER_REGISTER(p_name, p_caps, p_pl, p_tw, \
210  fct_priv, fct_init, fct_uninit, fct_grab, fct_loop) \
211  grabber_list_t * \
212  vh_grabber_##p_name##_register (struct url_ctl_s *url_ctl) \
213  { \
214  grabber_list_t *grabber; \
215  \
216  vh_log (VALHALLA_MSG_VERBOSE, __FUNCTION__); \
217  \
218  grabber = calloc (1, sizeof (grabber_list_t)); \
219  if (!grabber) \
220  return NULL; \
221  \
222  grabber->name = #p_name; \
223  grabber->caps_flag = p_caps; \
224  grabber->enable = 1; \
225  grabber->timewait = p_tw * 1000000UL; \
226  grabber->priv = fct_priv (); \
227  \
228  grabber->init = fct_init; \
229  grabber->uninit = fct_uninit; \
230  grabber->grab = fct_grab; \
231  grabber->loop = fct_loop; \
232  \
233  grabber->param.url_ctl = url_ctl; \
234  grabber->param.pl = malloc (sizeof (p_pl)); \
235  if (!grabber->param.pl) \
236  { \
237  free (grabber); \
238  return NULL; \
239  } \
240  memcpy (grabber->param.pl, p_pl, sizeof (p_pl)); \
241  \
242  pthread_mutex_init (&grabber->mutex, NULL); \
243  \
244  return grabber; \
245  }
246 
247 #endif /* VALHALLA_GRABBER_COMMON_H */