From cced735e59356bfac49113da90b1a4515516513d Mon Sep 17 00:00:00 2001 From: "N.N." Date: Wed, 8 Aug 2007 19:03:08 +0000 Subject: PiDiP 0.12.21 svn path=/trunk/externals/pidip/; revision=8475 --- modules/pdp_imgloader.c | 37 +++++++------ modules/pdp_theonice~.c | 141 +++++++++++++++++++++++++++--------------------- 2 files changed, 97 insertions(+), 81 deletions(-) (limited to 'modules') diff --git a/modules/pdp_imgloader.c b/modules/pdp_imgloader.c index 2b5e98c..0286167 100644 --- a/modules/pdp_imgloader.c +++ b/modules/pdp_imgloader.c @@ -83,7 +83,7 @@ static void pdp_imgloader_load(t_pdp_imgloader *x, t_symbol *filename, t_floatar { Imlib_Load_Error imliberr; - post( "pdp_imgloader : loading : %s", filename->s_name ); + // post( "pdp_imgloader : loading : %s", filename->s_name ); if ( x->x_image != NULL ) { @@ -101,7 +101,7 @@ static void pdp_imgloader_load(t_pdp_imgloader *x, t_symbol *filename, t_floatar x->x_imdata = imlib_image_get_data(); x->x_iwidth = imlib_image_get_width(); x->x_iheight = imlib_image_get_height(); - post( "pdp_imgloader : loaded : %s (%dx%d)", filename->s_name, x->x_iwidth, x->x_iheight ); + // post( "pdp_imgloader : loaded : %s (%dx%d)", filename->s_name, x->x_iwidth, x->x_iheight ); x->x_xoffset = (int) fx; x->x_yoffset = (int) fy; @@ -335,8 +335,8 @@ static void pdp_imgloader_hide(t_pdp_imgloader *x, t_symbol *s, int argc, t_atom ( (int)fy2 >= 0 ) && ( (int)fy2 < x->x_vheight ) && ( (int)fy3 >= 0 ) && ( (int)fy3 < x->x_vheight ) ) { - post( "pdp_imgloader : hide : coordinates : %d %d %d %d %d %d", - (int)fx1, (int)fy1, (int)fx2, (int)fy2, (int)fx3, (int)fy3 ); + // post( "pdp_imgloader : hide : coordinates : %d %d %d %d %d %d", + // (int)fx1, (int)fy1, (int)fx2, (int)fy2, (int)fx3, (int)fy3 ); for ( ti=0; tix_hiddenzones[ti].used ) @@ -408,10 +408,10 @@ static void pdp_imgloader_hide(t_pdp_imgloader *x, t_symbol *s, int argc, t_atom x->x_hiddenzones[ti].y3 = (int) fy1; } } - post( "pdp_imgloader : hiding : [%d,%d]/[%d,%d]/[%d,%d], ", - x->x_hiddenzones[ti].x1, x->x_hiddenzones[ti].y1, - x->x_hiddenzones[ti].x2, x->x_hiddenzones[ti].y2, - x->x_hiddenzones[ti].x3, x->x_hiddenzones[ti].y3 ); + // post( "pdp_imgloader : hiding : [%d,%d]/[%d,%d]/[%d,%d], ", + // x->x_hiddenzones[ti].x1, x->x_hiddenzones[ti].y1, + // x->x_hiddenzones[ti].x2, x->x_hiddenzones[ti].y2, + // x->x_hiddenzones[ti].x3, x->x_hiddenzones[ti].y3 ); if ( (x->x_hiddenzones[ti].x2-x->x_hiddenzones[ti].x1) != 0 ) { x->x_hiddenzones[ti].a1 = @@ -442,12 +442,12 @@ static void pdp_imgloader_hide(t_pdp_imgloader *x, t_symbol *s, int argc, t_atom ( (float) x->x_hiddenzones[ti].y3 )*( (float) x->x_hiddenzones[ti].x1 ) ) / ( ( (float) x->x_hiddenzones[ti].x3 ) - ( (float) x->x_hiddenzones[ti].x1 ) ); } - post( "pdp_imgloader : hiding : a1=%f b1=%f", - x->x_hiddenzones[ti].a1, x->x_hiddenzones[ti].b1 ); - post( "pdp_imgloader : hiding : a2=%f b2=%f", - x->x_hiddenzones[ti].a2, x->x_hiddenzones[ti].b2 ); - post( "pdp_imgloader : hiding : a3=%f b3=%f", - x->x_hiddenzones[ti].a3, x->x_hiddenzones[ti].b3 ); + // post( "pdp_imgloader : hiding : a1=%f b1=%f", + // x->x_hiddenzones[ti].a1, x->x_hiddenzones[ti].b1 ); + // post( "pdp_imgloader : hiding : a2=%f b2=%f", + // x->x_hiddenzones[ti].a2, x->x_hiddenzones[ti].b2 ); + // post( "pdp_imgloader : hiding : a3=%f b3=%f", + // x->x_hiddenzones[ti].a3, x->x_hiddenzones[ti].b3 ); pdp_imgloader_update_mask( x ); return; } @@ -481,10 +481,10 @@ static void pdp_imgloader_rawhide(t_pdp_imgloader *x, t_symbol *s, int argc, t_a argv[4].a_w.w_float *= x->x_vwidth; argv[5].a_w.w_float *= x->x_vheight; - post( "pdp_imgloader : rawhide : coordinates : %f %f %f %f %f %f (width=%d) (height=%d)", - argv[0].a_w.w_float, argv[1].a_w.w_float, argv[2].a_w.w_float, - argv[3].a_w.w_float, argv[4].a_w.w_float, argv[5].a_w.w_float, - x->x_vwidth, x->x_vheight ); + // post( "pdp_imgloader : rawhide : coordinates : %f %f %f %f %f %f (width=%d) (height=%d)", + // argv[0].a_w.w_float, argv[1].a_w.w_float, argv[2].a_w.w_float, + // argv[3].a_w.w_float, argv[4].a_w.w_float, argv[5].a_w.w_float, + // x->x_vwidth, x->x_vheight ); pdp_imgloader_hide( x, s, argc, argv ); } @@ -781,7 +781,6 @@ void pdp_imgloader_setup(void) class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_operation, gensym("operation"), A_SYMBOL, A_NULL); class_addmethod(pdp_imgloader_class, (t_method)pdp_imgloader_fit, gensym("fit"), A_DEFFLOAT, A_NULL); - } #ifdef __cplusplus diff --git a/modules/pdp_theonice~.c b/modules/pdp_theonice~.c index 01882a8..89c8020 100644 --- a/modules/pdp_theonice~.c +++ b/modules/pdp_theonice~.c @@ -142,14 +142,14 @@ typedef struct pdp_theonice_struct vorbis_block x_vorbis_block; // vorbis block vorbis_comment x_vorbis_comment; // vorbis comment yuv_buffer x_yuvbuffer; // yuv buffer - int x_eos; // end of stream + int x_eos; // end of stream - int x_akbps; // audio bit rate - int x_vkbps; // video bit rate + int x_akbps; // audio bit rate + int x_vkbps; // video bit rate t_float x_aquality; // audio quality - int x_vquality; // video quality - int x_abytesout; // audio bytes written - int x_vbytesout; // video bytes written + int x_vquality; // video quality + int x_abytesout; // audio bytes written + int x_vbytesout; // video bytes written double x_audiotime; // audio stream time double x_paudiotime; // previous value double x_videotime; // video stream time @@ -906,6 +906,9 @@ static void pdp_theonice_framerate(t_pdp_theonice *x, t_floatarg fframerate ) x->x_framerate = (int) fframerate; } +static void pdp_theonice_send_video(t_pdp_theonice *x); +static void pdp_theonice_send_audio(t_pdp_theonice *x); + /* store audio data in PCM format in a buffer for now */ static t_int *pdp_theonice_perform(t_int *w) { @@ -932,7 +935,7 @@ static t_int *pdp_theonice_perform(t_int *w) x->x_audioin_position=(x->x_audioin_position+1)%(MAX_AUDIO_PACKET_SIZE); if ( x->x_audioin_position >= MAX_AUDIO_PACKET_SIZE-1 ) { - post( "pdp_theonice~ : reaching end of audio buffer" ); + post( "pdp_theonice~ : audio x-run" ); } } } @@ -968,6 +971,8 @@ static t_int *pdp_theonice_perform(t_int *w) if ( x->x_videotime >= 0. ) outlet_float(x->x_outlet_vtime, x->x_videotime); } + pdp_theonice_send_audio(x); + return (w+5); } @@ -980,35 +985,47 @@ static void pdp_theonice_process_yv12(t_pdp_theonice *x) { t_pdp *header = pdp_packet_header(x->x_packet0); unsigned char *data = (unsigned char *)pdp_packet_data(x->x_packet0); - int i, ret; + int i; int px, py; unsigned char *pY, *pU, *pV; - struct timeval tstream; - struct timeval etime; - int nbaudiosamples, nbusecs, nbsamples; t_float fframerate=0.0; - int ttime, atime; - if ( ( (int)(header->info.image.width) != x->x_vwidth ) || - ( (int)(header->info.image.height) != x->x_vheight ) ) - { - post( "pdp_theonice~: reallocating ressources" ); - pdp_theonice_free_ressources( x ); - pdp_theonice_shutdown_encoder( x ); - x->x_vwidth = header->info.image.width; - x->x_vheight = header->info.image.height; - x->x_vsize = x->x_vwidth*x->x_vheight; - x->x_tvwidth=((x->x_vwidth + 15) >>4)<<4; - x->x_tvheight=((x->x_vheight + 15) >>4)<<4; - pdp_theonice_allocate( x ); - if ( x->x_tzero.tv_sec != 0 ) - { - pdp_theonice_init_encoder( x ); - pdp_theonice_write_headers( x ); - } - } + if ( ( (int)(header->info.image.width) != x->x_vwidth ) || + ( (int)(header->info.image.height) != x->x_vheight ) ) + { + post( "pdp_theonice~: reallocating ressources" ); + pdp_theonice_free_ressources( x ); + pdp_theonice_shutdown_encoder( x ); + x->x_vwidth = header->info.image.width; + x->x_vheight = header->info.image.height; + x->x_vsize = x->x_vwidth*x->x_vheight; + x->x_tvwidth=((x->x_vwidth + 15) >>4)<<4; + x->x_tvheight=((x->x_vheight + 15) >>4)<<4; + pdp_theonice_allocate( x ); + if ( x->x_tzero.tv_sec != 0 ) + { + pdp_theonice_init_encoder( x ); + pdp_theonice_write_headers( x ); + } + } - x->x_frames++; + pY = x->x_yuvbuffer.y; + memcpy( (void*)pY, (void*)&data[0], x->x_vsize ); + pV = x->x_yuvbuffer.v; + memcpy( (void*)pV, (void*)&data[x->x_vsize], (x->x_vsize>>2) ); + pU = x->x_yuvbuffer.u; + memcpy( (void*)pU, (void*)&data[x->x_vsize+(x->x_vsize>>2)], (x->x_vsize>>2) ); + + x->x_frames++; + + pdp_theonice_send_video(x); +} + +static void pdp_theonice_send_video(t_pdp_theonice *x) +{ + struct timeval etime; + int ttime, atime, ret; + struct timeval tstream; if ( x->x_frameswritten == 0 ) { @@ -1042,36 +1059,8 @@ static void pdp_theonice_process_yv12(t_pdp_theonice *x) return; } - pY = x->x_yuvbuffer.y; - memcpy( (void*)pY, (void*)&data[0], x->x_vsize ); - pV = x->x_yuvbuffer.v; - memcpy( (void*)pV, (void*)&data[x->x_vsize], (x->x_vsize>>2) ); - pU = x->x_yuvbuffer.u; - memcpy( (void*)pU, (void*)&data[x->x_vsize+(x->x_vsize>>2)], (x->x_vsize>>2) ); - if ( x->x_socketfd > 0 && x->x_streaming ) { - // calculate the number of audio samples to output - if ( gettimeofday(&tstream, NULL) == -1) - { - post("pdp_theonice~ : could set stop time" ); - } - // calculate time diff in micro seconds - nbusecs = ( tstream.tv_usec - x->x_tprevstream.tv_usec ) + - ( tstream.tv_sec - x->x_tprevstream.tv_sec )*1000000; - nbaudiosamples = (sys_getsr()*1000000)/nbusecs; - memcpy( &x->x_tprevstream, &tstream, sizeof( struct timeval) ); - - if ( x->x_audioin_position > nbaudiosamples ) - { - nbsamples = nbaudiosamples; - } - else - { - nbsamples = x->x_audioin_position; - } - // if ( x->x_audiotime > x->x_videotime ) nbsamples = -1; - if ( ( ret = theora_encode_YUVin( &x->x_theora_state, &x->x_yuvbuffer ) ) != 0 ) { post( "pdp_theonice~ : could not encode yuv image (ret=%d).", ret ); @@ -1109,9 +1098,38 @@ static void pdp_theonice_process_yv12(t_pdp_theonice *x) x->x_secondcount++; } - // audio is ahead, don't send no audio - if ( nbsamples < 0 ) return; + } +} + +static void pdp_theonice_send_audio(t_pdp_theonice *x) +{ + int nbaudiosamples, nbusecs, nbsamples, ret; + struct timeval tstream; + // calculate the number of audio samples to output + if ( gettimeofday(&tstream, NULL) == -1) + { + post("pdp_theonice~ : could set stop time" ); + } + // calculate time diff in micro seconds + nbusecs = ( tstream.tv_usec - x->x_tprevstream.tv_usec ) + + ( tstream.tv_sec - x->x_tprevstream.tv_sec )*1000000; + nbaudiosamples = (sys_getsr()*1000000)/nbusecs; + memcpy( &x->x_tprevstream, &tstream, sizeof( struct timeval) ); + + if ( x->x_audioin_position > nbaudiosamples ) + { + nbsamples = nbaudiosamples; + } + else + { + nbsamples = x->x_audioin_position; + } + // audio is ahead of video, do not send audio + if ( x->x_audiotime > x->x_videotime ) return; + + if ( x->x_socketfd > 0 && x->x_streaming ) + { x->x_vbuffer=vorbis_analysis_buffer( &x->x_dsp_state, nbsamples ); if ( !x->x_vbuffer ) return; @@ -1330,7 +1348,6 @@ void pdp_theonice_tilde_setup(void) class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_description, gensym("description"), A_GIMME, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_genre, gensym("genre"), A_GIMME, A_NULL); - } #ifdef __cplusplus -- cgit v1.2.1