2 * VIDEO MOTION CODECs internal API for video devices
4 * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
5 * bound to a master device.
7 * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
9 * $Id: videocodec.c,v 1.1.2.8 2003/03/29 07:16:04 rbultje Exp $
11 * ------------------------------------------------------------------------
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * ------------------------------------------------------------------------
30 #define VIDEOCODEC_VERSION "v0.2"
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/types.h>
36 #include <linux/slab.h>
38 // kernel config is here (procfs flag)
41 #include <linux/proc_fs.h>
42 #include <linux/seq_file.h>
43 #include <linux/uaccess.h>
46 #include "videocodec.h"
49 module_param(debug
, int, 0);
50 MODULE_PARM_DESC(debug
, "Debug level (0-4)");
52 #define dprintk(num, format, args...) \
55 printk(format, ##args); \
58 struct attached_list
{
59 struct videocodec
*codec
;
60 struct attached_list
*next
;
64 const struct videocodec
*codec
;
66 struct attached_list
*list
;
67 struct codec_list
*next
;
70 static struct codec_list
*codeclist_top
= NULL
;
72 /* ================================================= */
73 /* function prototypes of the master/slave interface */
74 /* ================================================= */
77 videocodec_attach (struct videocodec_master
*master
)
79 struct codec_list
*h
= codeclist_top
;
80 struct attached_list
*a
, *ptr
;
81 struct videocodec
*codec
;
85 dprintk(1, KERN_ERR
"videocodec_attach: no data\n");
90 "videocodec_attach: '%s', flags %lx, magic %lx\n",
91 master
->name
, master
->flags
, master
->magic
);
96 "videocodec_attach: no device available\n");
101 // attach only if the slave has at least the flags
102 // expected by the master
103 if ((master
->flags
& h
->codec
->flags
) == master
->flags
) {
104 dprintk(4, "videocodec_attach: try '%s'\n",
107 if (!try_module_get(h
->codec
->owner
))
110 codec
= kmemdup(h
->codec
, sizeof(struct videocodec
),
115 "videocodec_attach: no mem\n");
119 res
= strlen(codec
->name
);
120 snprintf(codec
->name
+ res
, sizeof(codec
->name
) - res
,
121 "[%d]", h
->attached
);
122 codec
->master_data
= master
;
123 res
= codec
->setup(codec
);
125 dprintk(3, "videocodec_attach '%s'\n",
127 ptr
= kzalloc(sizeof(struct attached_list
), GFP_KERNEL
);
131 "videocodec_attach: no memory\n");
140 "videocodec: first element\n");
143 a
= a
->next
; // find end
146 "videocodec: in after '%s'\n",
159 dprintk(1, KERN_ERR
"videocodec_attach: no codec found!\n");
163 module_put(h
->codec
->owner
);
170 videocodec_detach (struct videocodec
*codec
)
172 struct codec_list
*h
= codeclist_top
;
173 struct attached_list
*a
, *prev
;
177 dprintk(1, KERN_ERR
"videocodec_detach: no data\n");
182 "videocodec_detach: '%s', type: %x, flags %lx, magic %lx\n",
183 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
187 KERN_ERR
"videocodec_detach: no device left...\n");
195 if (codec
== a
->codec
) {
196 res
= a
->codec
->unset(a
->codec
);
199 "videocodec_detach: '%s'\n",
201 a
->codec
->master_data
= NULL
;
205 "videocodec_detach: '%s'\n",
207 a
->codec
->master_data
= NULL
;
212 "videocodec: delete first\n");
214 prev
->next
= a
->next
;
216 "videocodec: delete middle\n");
218 module_put(a
->codec
->owner
);
230 dprintk(1, KERN_ERR
"videocodec_detach: given codec not found!\n");
235 videocodec_register (const struct videocodec
*codec
)
237 struct codec_list
*ptr
, *h
= codeclist_top
;
240 dprintk(1, KERN_ERR
"videocodec_register: no data!\n");
245 "videocodec: register '%s', type: %x, flags %lx, magic %lx\n",
246 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
248 ptr
= kzalloc(sizeof(struct codec_list
), GFP_KERNEL
);
250 dprintk(1, KERN_ERR
"videocodec_register: no memory\n");
257 dprintk(4, "videocodec: hooked in as first element\n");
260 h
= h
->next
; // find the end
262 dprintk(4, "videocodec: hooked in after '%s'\n",
270 videocodec_unregister (const struct videocodec
*codec
)
272 struct codec_list
*prev
= NULL
, *h
= codeclist_top
;
275 dprintk(1, KERN_ERR
"videocodec_unregister: no data!\n");
280 "videocodec: unregister '%s', type: %x, flags %lx, magic %lx\n",
281 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
286 "videocodec_unregister: no device left...\n");
291 if (codec
== h
->codec
) {
295 "videocodec: '%s' is used\n",
299 dprintk(3, "videocodec: unregister '%s' is ok.\n",
302 codeclist_top
= h
->next
;
304 "videocodec: delete first element\n");
306 prev
->next
= h
->next
;
308 "videocodec: delete middle element\n");
319 "videocodec_unregister: given codec not found!\n");
323 #ifdef CONFIG_PROC_FS
324 static int proc_videocodecs_show(struct seq_file
*m
, void *v
)
326 struct codec_list
*h
= codeclist_top
;
327 struct attached_list
*a
;
329 seq_printf(m
, "<S>lave or attached <M>aster name type flags magic ");
330 seq_printf(m
, "(connected as)\n");
334 seq_printf(m
, "S %32s %04x %08lx %08lx (TEMPLATE)\n",
335 h
->codec
->name
, h
->codec
->type
,
336 h
->codec
->flags
, h
->codec
->magic
);
339 seq_printf(m
, "M %32s %04x %08lx %08lx (%s)\n",
340 a
->codec
->master_data
->name
,
341 a
->codec
->master_data
->type
,
342 a
->codec
->master_data
->flags
,
343 a
->codec
->master_data
->magic
,
353 static int proc_videocodecs_open(struct inode
*inode
, struct file
*file
)
355 return single_open(file
, proc_videocodecs_show
, NULL
);
358 static const struct file_operations videocodecs_proc_fops
= {
359 .owner
= THIS_MODULE
,
360 .open
= proc_videocodecs_open
,
363 .release
= single_release
,
367 /* ===================== */
368 /* hook in driver module */
369 /* ===================== */
371 videocodec_init (void)
373 #ifdef CONFIG_PROC_FS
374 static struct proc_dir_entry
*videocodec_proc_entry
;
377 printk(KERN_INFO
"Linux video codec intermediate layer: %s\n",
380 #ifdef CONFIG_PROC_FS
381 videocodec_proc_entry
= proc_create("videocodecs", 0, NULL
, &videocodecs_proc_fops
);
382 if (!videocodec_proc_entry
) {
383 dprintk(1, KERN_ERR
"videocodec: can't init procfs.\n");
390 videocodec_exit (void)
392 #ifdef CONFIG_PROC_FS
393 remove_proc_entry("videocodecs", NULL
);
397 EXPORT_SYMBOL(videocodec_attach
);
398 EXPORT_SYMBOL(videocodec_detach
);
399 EXPORT_SYMBOL(videocodec_register
);
400 EXPORT_SYMBOL(videocodec_unregister
);
402 module_init(videocodec_init
);
403 module_exit(videocodec_exit
);
405 MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
406 MODULE_DESCRIPTION("Intermediate API module for video codecs "
408 MODULE_LICENSE("GPL");