~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to src/video.c

  • Committer: Bazaar Package Importer
  • Author(s): John Dong
  • Date: 2008-02-25 15:47:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080225154712-qvr11ekcea4c9ry8
Tags: 1.1.6-0.1ubuntu1
* Merge from debian-multimedia (LP: #120003), Ubuntu Changes:
 - For ffmpeg-related build-deps, remove cvs from package names.
 - Standards-Version 3.7.3
 - Maintainer Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * video.c
3
 
 *
4
 
 * Copyright (C) 1998 Rasca, Berlin
5
 
 *
6
 
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program; if not, write to the Free Software
18
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
 
 */
20
 
 
21
 
#ifdef HasVideo4Linux
22
 
#include <sys/ioctl.h>
23
 
#include <sys/types.h>
24
 
#include <sys/mman.h>
25
 
#include <linux/types.h>
26
 
#include <linux/videodev.h>
27
 
#include <stdlib.h>
28
 
#include <unistd.h>
29
 
#include "video.h"
30
 
 
31
 
/*
32
 
 * get image properties
33
 
 */
34
 
int
35
 
video_prop (VIDEO *v)
36
 
{
37
 
        int rc;
38
 
        struct video_picture vp;
39
 
 
40
 
        if (!v)
41
 
                return -1;
42
 
        rc = ioctl (v->fd, VIDIOCGPICT, &vp);
43
 
        if (rc != -1) {
44
 
                v->brightness = vp.brightness;
45
 
                v->hue = vp.hue;
46
 
                v->colour = vp.colour;
47
 
                v->contrast = vp.contrast;
48
 
                v->whiteness = vp.whiteness;
49
 
                v->depth = vp.depth;
50
 
                v->palette = vp.palette;
51
 
        }
52
 
        return (rc);
53
 
}
54
 
 
55
 
/*
56
 
 */
57
 
int
58
 
video_caps (VIDEO *v)
59
 
{
60
 
        struct video_capability vc;
61
 
 
62
 
        if (!v)
63
 
                return (-1);
64
 
        if (ioctl (v->fd, VIDIOCGCAP, &vc) == -1)
65
 
                return (-1);
66
 
        memcpy (v->name, vc.name, 32);
67
 
        v->type = vc.type;
68
 
        v->channels = vc.channels;
69
 
        v->audios = vc.audios;
70
 
        v->maxwidth = vc.maxwidth;
71
 
        v->maxheight =vc.maxheight;
72
 
        v->minwidth = vc.minwidth;
73
 
        v->minheight =vc.minheight;
74
 
        return (0);
75
 
}
76
 
 
77
 
/*
78
 
 */
79
 
void
80
 
video_free (VIDEO *v)
81
 
{
82
 
        free (v);
83
 
}
84
 
 
85
 
/*
86
 
 */
87
 
int
88
 
video_close (VIDEO *v)
89
 
{
90
 
        int rc = -1;
91
 
        if (!v)
92
 
                return (rc);
93
 
        if (v->fd > -1)
94
 
                rc = close (v->fd);
95
 
        video_free (v);
96
 
        return (rc);
97
 
}
98
 
 
99
 
/*
100
 
 */
101
 
VIDEO *
102
 
video_open (const char *dev, int flags)
103
 
{
104
 
        VIDEO *v = NULL;
105
 
        int fd;
106
 
        fd = open (dev, flags);
107
 
        if (fd == -1)
108
 
                return (NULL);
109
 
        v = malloc (sizeof (VIDEO));
110
 
        if (!v)
111
 
                return (NULL);
112
 
        v->fd = fd;
113
 
        if (video_caps (v) != 0) {
114
 
                video_close (v);
115
 
                return (NULL);
116
 
        }
117
 
        if (video_prop (v) != 0) {
118
 
                video_close (v);
119
 
                return (NULL);
120
 
        }
121
 
        return (v);
122
 
}
123
 
 
124
 
/*
125
 
 */
126
 
int
127
 
video_mmap (VIDEO *vid, int start)
128
 
{
129
 
        if (!vid)
130
 
                return (0);
131
 
        if (start) {
132
 
                vid->mmap = (char *) mmap (0, vid->size,
133
 
                                        PROT_READ | PROT_WRITE, MAP_SHARED, vid->fd, 0);
134
 
                if (vid->mmap == (char *)-1) {
135
 
                        vid->mmap = NULL;
136
 
                        return (0);
137
 
                }
138
 
        } else {
139
 
                /* free the mmap space */
140
 
                if (vid->mmap) {
141
 
                        munmap (vid->mmap, vid->fd);
142
 
                        vid->mmap = NULL;
143
 
                }
144
 
        }
145
 
        return (1);
146
 
}
147
 
#endif
148