File: video_capture.c

package info (click to toggle)
ayttm 0.6.3-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 8,368 kB
  • ctags: 8,851
  • sloc: ansic: 65,755; sh: 10,810; cpp: 3,092; makefile: 561; yacc: 294; lex: 53; sed: 16
file content (136 lines) | stat: -rw-r--r-- 3,344 bytes parent folder | download | duplicates (2)
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
/*
 * VideoCapture Plugin for Ayttm
 *
 * Copyright (C) 2003, Philip S Tellis <bluesmoon @ users.sourceforge.net>
 *
 * 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 "intl.h"
#ifdef __MINGW32__
#define __IN_PLUGIN__ 1
#endif
#include <stdio.h>
#include <string.h>
#include "plugin_api.h"
#include "video.h"
#include "mem_util.h"
#include "debug.h"

/*******************************************************************************
 *                             Begin Module Code
 ******************************************************************************/
/*  Module defines */
#ifndef USE_POSIX_DLOPEN
#define plugin_info video_capture_LTX_plugin_info
#define module_version video_capture_LTX_module_version
#endif

static int plugin_init();
static int plugin_finish();

static char frame_grabber[MAX_PREF_LEN] =
	AYTTM_BIN_DIR "/ayttm_streamer_wrapper -d %d";

/*  Module Exports */
PLUGIN_INFO plugin_info = {
	PLUGIN_UTILITY,
	"Video Capture",
	"Capture video images from some source",
	"$Revision: 1.5 $",
	"$Date: 2009/09/17 12:04:58 $",
	0,
	plugin_init,
	plugin_finish,
	0,
	0
};

/* End Module Exports */

unsigned int module_version()
{
	return CORE_VERSION;
}

static long int grab_frame(unsigned char **image);

static long int (*old_grab_frame) (unsigned char **);

static int plugin_init()
{
	input_list *il = ay_new0(input_list, 1);

	plugin_info.prefs = il;
	il->widget.entry.value = frame_grabber;
	il->name = "frame_grabber";
	il->label = _("Frame grabber command:");
	il->type = EB_INPUT_ENTRY;

	old_grab_frame = video_grab_frame;
	video_grab_frame = grab_frame;

	return 0;
}

static int plugin_finish()
{
	video_grab_frame = old_grab_frame;

	return 0;
}

/*******************************************************************************
 *                             End Module Code
 ******************************************************************************/

static long int grab_frame(unsigned char **image)
{
	FILE *grabber_fp;
	unsigned char buff[1024];
	unsigned char *outbuf = 0;
	long int nsize = 0, n;

	char *cmd = strdup(frame_grabber);
	while (strstr(cmd, "%d")) {
		char *tmp = strstr(cmd, "%d");
		char *rest = 0;
		if (*(tmp + 2))
			rest = strdup(tmp + 2);
		*tmp = 0;
		cmd = ay_string_append(cmd, eb_config_dir());
		if (rest)
			cmd = ay_string_append(cmd, rest);
	}

	grabber_fp = popen(cmd, "r");
	ay_free(cmd);

	if (!grabber_fp)
		return -1;

	while (!(feof(grabber_fp) || ferror(grabber_fp))) {
		n = fread(buff, 1, sizeof(buff), grabber_fp);
		outbuf = ay_renew(unsigned char, outbuf, n + nsize);
		memcpy(outbuf + nsize, buff, n);
		nsize += n;
	}

	pclose(grabber_fp);

	*image = outbuf;
	return nsize;
}