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 * ------------------------------------------------------------------------
26 #define VIDEOCODEC_VERSION "v0.2"
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/types.h>
32 #include <linux/slab.h>
34 // kernel config is here (procfs flag)
37 #include <linux/proc_fs.h>
38 #include <linux/seq_file.h>
39 #include <linux/uaccess.h>
42 #include "videocodec.h"
45 module_param(debug
, int, 0);
46 MODULE_PARM_DESC(debug
, "Debug level (0-4)");
48 #define dprintk(num, format, args...) \
51 printk(format, ##args); \
54 struct attached_list
{
55 struct videocodec
*codec
;
56 struct attached_list
*next
;
60 const struct videocodec
*codec
;
62 struct attached_list
*list
;
63 struct codec_list
*next
;
66 static struct codec_list
*codeclist_top
= NULL
;
68 /* ================================================= */
69 /* function prototypes of the master/slave interface */
70 /* ================================================= */
73 videocodec_attach (struct videocodec_master
*master
)
75 struct codec_list
*h
= codeclist_top
;
76 struct attached_list
*a
, *ptr
;
77 struct videocodec
*codec
;
81 dprintk(1, KERN_ERR
"videocodec_attach: no data\n");
86 "videocodec_attach: '%s', flags %lx, magic %lx\n",
87 master
->name
, master
->flags
, master
->magic
);
92 "videocodec_attach: no device available\n");
97 // attach only if the slave has at least the flags
98 // expected by the master
99 if ((master
->flags
& h
->codec
->flags
) == master
->flags
) {
100 dprintk(4, "videocodec_attach: try '%s'\n",
103 if (!try_module_get(h
->codec
->owner
))
106 codec
= kmemdup(h
->codec
, sizeof(struct videocodec
),
111 "videocodec_attach: no mem\n");
115 res
= strlen(codec
->name
);
116 snprintf(codec
->name
+ res
, sizeof(codec
->name
) - res
,
117 "[%d]", h
->attached
);
118 codec
->master_data
= master
;
119 res
= codec
->setup(codec
);
121 dprintk(3, "videocodec_attach '%s'\n",
123 ptr
= kzalloc(sizeof(struct attached_list
), GFP_KERNEL
);
127 "videocodec_attach: no memory\n");
136 "videocodec: first element\n");
139 a
= a
->next
; // find end
142 "videocodec: in after '%s'\n",
155 dprintk(1, KERN_ERR
"videocodec_attach: no codec found!\n");
159 module_put(h
->codec
->owner
);
166 videocodec_detach (struct videocodec
*codec
)
168 struct codec_list
*h
= codeclist_top
;
169 struct attached_list
*a
, *prev
;
173 dprintk(1, KERN_ERR
"videocodec_detach: no data\n");
178 "videocodec_detach: '%s', type: %x, flags %lx, magic %lx\n",
179 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
183 KERN_ERR
"videocodec_detach: no device left...\n");
191 if (codec
== a
->codec
) {
192 res
= a
->codec
->unset(a
->codec
);
195 "videocodec_detach: '%s'\n",
197 a
->codec
->master_data
= NULL
;
201 "videocodec_detach: '%s'\n",
203 a
->codec
->master_data
= NULL
;
208 "videocodec: delete first\n");
210 prev
->next
= a
->next
;
212 "videocodec: delete middle\n");
214 module_put(a
->codec
->owner
);
226 dprintk(1, KERN_ERR
"videocodec_detach: given codec not found!\n");
231 videocodec_register (const struct videocodec
*codec
)
233 struct codec_list
*ptr
, *h
= codeclist_top
;
236 dprintk(1, KERN_ERR
"videocodec_register: no data!\n");
241 "videocodec: register '%s', type: %x, flags %lx, magic %lx\n",
242 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
244 ptr
= kzalloc(sizeof(struct codec_list
), GFP_KERNEL
);
246 dprintk(1, KERN_ERR
"videocodec_register: no memory\n");
253 dprintk(4, "videocodec: hooked in as first element\n");
256 h
= h
->next
; // find the end
258 dprintk(4, "videocodec: hooked in after '%s'\n",
266 videocodec_unregister (const struct videocodec
*codec
)
268 struct codec_list
*prev
= NULL
, *h
= codeclist_top
;
271 dprintk(1, KERN_ERR
"videocodec_unregister: no data!\n");
276 "videocodec: unregister '%s', type: %x, flags %lx, magic %lx\n",
277 codec
->name
, codec
->type
, codec
->flags
, codec
->magic
);
282 "videocodec_unregister: no device left...\n");
287 if (codec
== h
->codec
) {
291 "videocodec: '%s' is used\n",
295 dprintk(3, "videocodec: unregister '%s' is ok.\n",
298 codeclist_top
= h
->next
;
300 "videocodec: delete first element\n");
302 prev
->next
= h
->next
;
304 "videocodec: delete middle element\n");
315 "videocodec_unregister: given codec not found!\n");
319 #ifdef CONFIG_PROC_FS
320 static int proc_videocodecs_show(struct seq_file
*m
, void *v
)
322 struct codec_list
*h
= codeclist_top
;
323 struct attached_list
*a
;
325 seq_printf(m
, "<S>lave or attached <M>aster name type flags magic ");
326 seq_printf(m
, "(connected as)\n");
329 seq_printf(m
, "S %32s %04x %08lx %08lx (TEMPLATE)\n",
330 h
->codec
->name
, h
->codec
->type
,
331 h
->codec
->flags
, h
->codec
->magic
);
334 seq_printf(m
, "M %32s %04x %08lx %08lx (%s)\n",
335 a
->codec
->master_data
->name
,
336 a
->codec
->master_data
->type
,
337 a
->codec
->master_data
->flags
,
338 a
->codec
->master_data
->magic
,
348 static int proc_videocodecs_open(struct inode
*inode
, struct file
*file
)
350 return single_open(file
, proc_videocodecs_show
, NULL
);
353 static const struct file_operations videocodecs_proc_fops
= {
354 .owner
= THIS_MODULE
,
355 .open
= proc_videocodecs_open
,
358 .release
= single_release
,
362 /* ===================== */
363 /* hook in driver module */
364 /* ===================== */
366 videocodec_init (void)
368 #ifdef CONFIG_PROC_FS
369 static struct proc_dir_entry
*videocodec_proc_entry
;
372 printk(KERN_INFO
"Linux video codec intermediate layer: %s\n",
375 #ifdef CONFIG_PROC_FS
376 videocodec_proc_entry
= proc_create("videocodecs", 0, NULL
, &videocodecs_proc_fops
);
377 if (!videocodec_proc_entry
) {
378 dprintk(1, KERN_ERR
"videocodec: can't init procfs.\n");
385 videocodec_exit (void)
387 #ifdef CONFIG_PROC_FS
388 remove_proc_entry("videocodecs", NULL
);
392 EXPORT_SYMBOL(videocodec_attach
);
393 EXPORT_SYMBOL(videocodec_detach
);
394 EXPORT_SYMBOL(videocodec_register
);
395 EXPORT_SYMBOL(videocodec_unregister
);
397 module_init(videocodec_init
);
398 module_exit(videocodec_exit
);
400 MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
401 MODULE_DESCRIPTION("Intermediate API module for video codecs "
403 MODULE_LICENSE("GPL");