File: video.c

package info (click to toggle)
camserv 0.42-9
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,884 kB
  • ctags: 1,123
  • sloc: ansic: 19,694; sh: 7,454; makefile: 206
file content (147 lines) | stat: -rw-r--r-- 4,398 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*  camserv - An internet streaming picture application
 *
 *  Copyright (C) 1999  Jon Travis (jon@dsndata.com)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ltdl.h"
#include "log.h"
#include "video.h"


#define MODNAME "video"

/*
 * video_query_active_section: Query the active video section in the
 *                             camconfig.
 *
 * Arguments:                  ccfg  = Camera configuration
 *                             place = Location to place the section name
 *                             size  = Size of memory @ place
 *
 * Return values:              Returns NULL on failure, else a valid ptr
 *                             to 'place'
 */

char *video_query_active_section( CamConfig *ccfg, char *place, int size){
  const char *val;

  val = camconfig_query_str( ccfg, SEC_VIDEO, "video_section" );
  if( val == NULL ){
    camserv_log( MODNAME, "[%s]:video_section has not been set!",
		 SEC_VIDEO );
    return NULL;
  }

  strncpy( place, val, size - 1 );
  place[ size - 1 ] = '\0';
  return place;
}

/*
 * video_setup_funcs:  Open the video module, and fill out the structure
 *                     with all of the video accessing routines.
 *                     
 * Arguments:          ccfg = Camera configuration structure which
 *                            should contain VIDCONFIG_PATH which holds
 *                            the location for the video module.
 *                     vfuncs = Structure to place all of the video functions
 *                              as they are grabbed from the symbol table.
 *
 * Return values:      Returns -1 on failure (if the module could not be
 *                     opened, or a symbol could not be found), 0 on success.
 */

int video_setup_funcs( CamConfig *ccfg, Video_Funcs *vfuncs ){
  lt_dlhandle dlhandle;
  char key[ 1024 ];
  const char *module_path;

  if( video_query_active_section( ccfg, key, sizeof( key )) == NULL )
    return -1;

  if( (module_path = camconfig_query_str( ccfg, key, "path" )) == NULL ){
    camserv_log( MODNAME, "[%s]:path not set!", key );
    return -1;
  }

  if( lt_dlinit() ) {
    camserv_log( MODNAME, "%s", lt_dlerror());
    return -1;
  }

  if( (dlhandle = lt_dlopen( module_path )) == NULL ){
    camserv_log( MODNAME, "%s", lt_dlerror());
    camserv_log( MODNAME, "Error opening video driver; \"%s\"", module_path );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_open = lt_dlsym( dlhandle, VIDSYM_OPEN ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_close = lt_dlsym( dlhandle, VIDSYM_CLOSE ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_init = lt_dlsym( dlhandle, VIDSYM_INIT ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_deinit = lt_dlsym( dlhandle, VIDSYM_DEINIT ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_snap = lt_dlsym( dlhandle, VIDSYM_SNAP ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_get_geom = lt_dlsym( dlhandle, VIDSYM_GET_GEOM ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  if( !(vfuncs->video_modinfo_query = lt_dlsym( dlhandle, VIDSYM_MODINFO ))){
    camserv_log( MODNAME, lt_dlerror() );
    lt_dlclose( dlhandle );
    lt_dlexit();
    return -1;
  }

  return 0;
}