[asterisk-dev] how to generate periodic wakeup signals for a channel driver ?

Luigi Rizzo rizzo at icir.org
Mon Sep 17 15:49:00 CDT 2007


On Mon, Sep 17, 2007 at 01:03:00PM -0700, Luigi Rizzo wrote:
> sorry if the question is trivial...
> 
> while adding videosupport to chan_oss/chan_alsa, which you can find at
> 
>     http://svn.digium.com/view/asterisk/team/rizzo/video_v2/
> 
> I just realised that the various video sources that I am using
> (webcam using the 'gspca' driver, or X11 grabber) do not support
> a select()/poll() interface, so i cannot rely on that (and on
> ast_channel_set_fd() ) to wakeup the channel driver when data
> is ready; I need a separate timing source.
> 
> What are the options ? Right now I am [ab]using the audio source
> to poll the video source, but audio too is not always available.
> 
> Maybe i should create a new thread, and a scheduler context
> with sched_context_create(), and then have a periodic
> event fire every 20-50ms to call the video handler ?

actually the first part is somewhat simpler - when the 'new'
channel is created i also create a new thread, and destroy it
by setting a flag in the descriptor and waiting with pthread_join().o
The code is below. What i am a bit unclear about is how do i
push the frames to the channel's queue - is the code below
correct ? (lock-enqueue on readq - unlock)

    static void *video_thread(void *arg)
    {
        struct video_desc *env = arg;
        for (;;) {
                struct timeval t = { 0, 50 }; // 1000/fps
                struct ast_frame *f;
                if (env->shutdown)
                        break;
                ast_select(0, NULL, NULL, NULL, &t); // sleep a bit
		f = get_video_frames(env);
                if (f) {
		    ast_channel_lock(env->owner);
                    // enqueue on env->owner->readq ?
		    ast_channel_unlock(env->owner);
                }
        }
        return NULL;
    }

cheers
luigi



More information about the asterisk-dev mailing list