diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/Makefile | 7 | ||||
-rw-r--r-- | modules/Makefile.in | 7 | ||||
-rw-r--r-- | modules/pdp_cmap.c | 9 | ||||
-rw-r--r-- | modules/pdp_compose.c | 9 | ||||
-rw-r--r-- | modules/pdp_ctrack.c | 10 | ||||
-rw-r--r-- | modules/pdp_ffmpeg~.c | 37 | ||||
-rw-r--r-- | modules/pdp_imgloader.c | 4 | ||||
-rw-r--r-- | modules/pdp_live~.c | 121 | ||||
-rw-r--r-- | modules/pdp_shape.c | 20 | ||||
-rw-r--r-- | modules/pdp_simura.c | 4 | ||||
-rw-r--r-- | modules/pdp_spigot.c | 4 | ||||
-rw-r--r-- | modules/pdp_xcanvas.c | 3 | ||||
-rw-r--r-- | modules/pdp_yqt.c | 4 | ||||
-rw-r--r-- | modules/pdp_yvu2rgb.c | 4 |
14 files changed, 172 insertions, 71 deletions
diff --git a/modules/Makefile b/modules/Makefile index 14b6c92..5d93176 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -11,10 +11,11 @@ OBJECTS = pdp_intrusion.o pdp_yqt.o pdp_simura.o pdp_underwatch.o \ pdp_cycle.o pdp_transform.o pdp_shagadelic.o \ pdp_dice.o pdp_puzzle.o pdp_text.o pdp_form.o \ pdp_compose.o pdp_cmap.o pdp_ascii.o \ - pdp_ffmpeg~.o pdp_live~.o pdp_segsnd~.o pdp_noquark.o \ - pdp_juxta.o pdp_capture.o pdp_smuck.o pdp_lumafilt.o \ + pdp_segsnd~.o pdp_noquark.o pdp_juxta.o \ + pdp_capture.o pdp_smuck.o pdp_lumafilt.o \ pdp_transition.o pdp_imgloader.o pdp_imgsaver.o pdp_cache.o \ pdp_canvas.o pdp_pen.o pdp_shape.o pdp_fqt.o pdp_fcqt.o \ - pdp_ocanvas.o # pdp_xcanvas.o pdp_aa.o + pdp_ocanvas.o pdp_spotlight.o pdp_live~.o pdp_ffmpeg~.o + # pdp_xcanvas.o pdp_aa.o all_modules: $(OBJECTS) diff --git a/modules/Makefile.in b/modules/Makefile.in index 14b6c92..0b221e6 100644 --- a/modules/Makefile.in +++ b/modules/Makefile.in @@ -11,10 +11,11 @@ OBJECTS = pdp_intrusion.o pdp_yqt.o pdp_simura.o pdp_underwatch.o \ pdp_cycle.o pdp_transform.o pdp_shagadelic.o \ pdp_dice.o pdp_puzzle.o pdp_text.o pdp_form.o \ pdp_compose.o pdp_cmap.o pdp_ascii.o \ - pdp_ffmpeg~.o pdp_live~.o pdp_segsnd~.o pdp_noquark.o \ - pdp_juxta.o pdp_capture.o pdp_smuck.o pdp_lumafilt.o \ + pdp_segsnd~.o pdp_noquark.o pdp_juxta.o \ + pdp_capture.o pdp_smuck.o pdp_lumafilt.o \ pdp_transition.o pdp_imgloader.o pdp_imgsaver.o pdp_cache.o \ pdp_canvas.o pdp_pen.o pdp_shape.o pdp_fqt.o pdp_fcqt.o \ - pdp_ocanvas.o # pdp_xcanvas.o pdp_aa.o + pdp_ocanvas.o pdp_spotlight.o @PDP_STREAMING_OBJECTS@ + # pdp_xcanvas.o pdp_aa.o all_modules: $(OBJECTS) diff --git a/modules/pdp_cmap.c b/modules/pdp_cmap.c index ae2f516..547208d 100644 --- a/modules/pdp_cmap.c +++ b/modules/pdp_cmap.c @@ -22,6 +22,7 @@ */ #include "pdp.h" +#include "g_canvas.h" #include "yuv.h" #include <math.h> #include <stdio.h> @@ -118,7 +119,7 @@ static void pdp_cmap_r(t_pdp_cmap *x, t_floatarg fr ) x->x_colors[x->x_current].y = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colors[x->x_current].u = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colors[x->x_current].v = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); + if (glist_isvisible(x->x_canvas)) pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); } } @@ -130,7 +131,7 @@ static void pdp_cmap_g(t_pdp_cmap *x, t_floatarg fg ) x->x_colors[x->x_current].y = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colors[x->x_current].u = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colors[x->x_current].v = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); + if (glist_isvisible(x->x_canvas)) pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); } } @@ -142,7 +143,7 @@ static void pdp_cmap_b(t_pdp_cmap *x, t_floatarg fb ) x->x_colors[x->x_current].y = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colors[x->x_current].u = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colors[x->x_current].v = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); + if (glist_isvisible(x->x_canvas)) pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); } } @@ -280,7 +281,7 @@ static void pdp_cmap_pick(t_pdp_cmap *x) x->x_colorR = yuv_YUVtoR( y, u, v ); x->x_colorG = yuv_YUVtoG( y, u, v ); x->x_colorB = yuv_YUVtoB( y, u, v ); - pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); + if (glist_isvisible(x->x_canvas)) pdp_cmap_draw_color( x, x->x_colorR, x->x_colorG, x->x_colorB ); x->x_colors[x->x_current].y = 255; x->x_colors[x->x_current].u = 255; x->x_colors[x->x_current].v = 255; diff --git a/modules/pdp_compose.c b/modules/pdp_compose.c index e3fda24..aad03a9 100644 --- a/modules/pdp_compose.c +++ b/modules/pdp_compose.c @@ -23,6 +23,7 @@ */ #include "pdp.h" +#include "g_canvas.h" #include "yuv.h" #include <math.h> #include <stdio.h> @@ -117,7 +118,7 @@ static void pdp_compose_r(t_pdp_compose *x, t_floatarg fr ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_compose_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_compose_draw_color( x ); } } @@ -129,7 +130,7 @@ static void pdp_compose_g(t_pdp_compose *x, t_floatarg fg ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_compose_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_compose_draw_color( x ); } } @@ -141,7 +142,7 @@ static void pdp_compose_b(t_pdp_compose *x, t_floatarg fb ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_compose_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_compose_draw_color( x ); } } @@ -201,7 +202,7 @@ static void pdp_compose_pick(t_pdp_compose *x) x->x_colorR = yuv_YUVtoR( y, u, v ); x->x_colorG = yuv_YUVtoG( y, u, v ); x->x_colorB = yuv_YUVtoB( y, u, v ); - pdp_compose_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_compose_draw_color( x ); } } diff --git a/modules/pdp_ctrack.c b/modules/pdp_ctrack.c index e9e631b..ed35c9b 100644 --- a/modules/pdp_ctrack.c +++ b/modules/pdp_ctrack.c @@ -22,6 +22,7 @@ */ #include "pdp.h" +#include "g_canvas.h" #include "yuv.h" #include <math.h> #include <stdio.h> @@ -124,7 +125,7 @@ static void pdp_ctrack_r(t_pdp_ctrack *x, t_floatarg fr ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_ctrack_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_ctrack_draw_color( x ); outlet_float( x->x_R, x->x_colorR ); } } @@ -137,7 +138,7 @@ static void pdp_ctrack_g(t_pdp_ctrack *x, t_floatarg fg ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_ctrack_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_ctrack_draw_color( x ); outlet_float( x->x_G, x->x_colorG ); } } @@ -150,7 +151,7 @@ static void pdp_ctrack_b(t_pdp_ctrack *x, t_floatarg fb ) x->x_colorY = (yuv_RGBtoY( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB ))<<7; x->x_colorU = (yuv_RGBtoU( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; x->x_colorV = (yuv_RGBtoV( (x->x_colorR << 16) + (x->x_colorG << 8) + x->x_colorB )-128)<<8; - pdp_ctrack_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_ctrack_draw_color( x ); outlet_float( x->x_B, x->x_colorB ); } } @@ -218,6 +219,7 @@ static void pdp_ctrack_pick(t_pdp_ctrack *x) if ( x->x_frame && ( x->x_cursX > 0 ) && ( x->x_cursX < x->x_vwidth ) && ( x->x_cursY > 0 ) && ( x->x_cursY < x->x_vheight ) ) { + // post( "pdp_ctrack : picking up color : x=%d y=%d", x->x_cursX, x->x_cursY ); x->x_colorY = x->x_frame[ x->x_cursY*x->x_vwidth+x->x_cursX ]; x->x_colorV = x->x_frame[ x->x_vsize + (x->x_cursY>>1)*(x->x_vwidth>>1)+(x->x_cursX>>1) ]; x->x_colorU = x->x_frame[ x->x_vsize + (x->x_vsize>>2) + (x->x_cursY>>1)*(x->x_vwidth>>1)+(x->x_cursX>>1) ]; @@ -230,7 +232,7 @@ static void pdp_ctrack_pick(t_pdp_ctrack *x) outlet_float( x->x_G, x->x_colorG ); x->x_colorB = yuv_YUVtoB( y, u, v ); outlet_float( x->x_B, x->x_colorB ); - pdp_ctrack_draw_color( x ); + if (glist_isvisible(x->x_canvas)) pdp_ctrack_draw_color( x ); } } diff --git a/modules/pdp_ffmpeg~.c b/modules/pdp_ffmpeg~.c index ef215ad..5669e96 100644 --- a/modules/pdp_ffmpeg~.c +++ b/modules/pdp_ffmpeg~.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ typedef struct pdp_ffmpeg_struct t_outlet *x_outlet_streaming; // indicates the action of streaming t_outlet *x_outlet_nbframes; // number of frames emitted + t_outlet *x_outlet_framerate; // real framerate t_outlet *x_outlet_nbframes_dropped; // number of frames dropped char *x_feedname; @@ -310,7 +311,7 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x) short int *data = (short int *)pdp_packet_data(x->x_packet0); t_pdp *newheader = 0; short int *newdata = 0; - t_int newpacket = -1, i; + t_int newpacket = -1, i, j; short int *pY, *pU, *pV; uint8_t *pnY, *pnU, *pnV; t_int px, py; @@ -348,14 +349,11 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x) for(px=0; px<x->x_vwidth; px++) { *pnY = (uint8_t) (*(pY++)>>7); - if ( *pnY > 255 ) *pnY=255; pnY++; if ( (px%2==0) && (py%2==0) ) { *pnV = (uint8_t) (((*(pV++))>>8)+128); - if ( *pnV > 255 ) *pnV=255; *pnU = (uint8_t) (((*(pU++))>>8)+128); - if ( *pnU > 255 ) *pnU=255; pnU++;pnV++; } } @@ -387,12 +385,20 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x) if ( etime.tv_sec != x->x_cursec ) { x->x_cursec = etime.tv_sec; - x->x_secondcount[ svideoindex ] = 0; + outlet_float( x->x_outlet_framerate, x->x_secondcount[ svideoindex ] ); + for (j=0; j<x->x_nbvideostreams; j++) + { + x->x_secondcount[ j ] = 0; + } } - if ( x->x_secondcount[ svideoindex ] >= x->x_avcontext->streams[i]->codec.frame_rate/10000 ) + if ( x->x_secondcount[ svideoindex ] >= (x->x_avcontext->streams[i]->codec.frame_rate/10000) ) { - x->x_nbframes_dropped++; - continue; + // post("pdp_ffmpeg : index=%d actual : %d, nominal : %d", + // svideoindex, + // x->x_secondcount[ svideoindex ], + // (x->x_avcontext->streams[i]->codec.frame_rate/10000) ); + x->x_nbframes_dropped++; + continue; } if ( x->x_avcontext->streams[i]->codec.pix_fmt != PIX_FMT_YUV420P ) @@ -463,14 +469,14 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x) x->x_final_picture = x->x_formatted_picture; } - // encode and send the picture + // encode and send the picture { AVFrame aframe; t_int fsize, ret; memset(&aframe, 0, sizeof(AVFrame)); *(AVPicture*)&aframe= *x->x_final_picture; - + aframe.pts = etime.tv_sec*1000000 + etime.tv_usec; aframe.quality = x->x_avcontext->streams[i]->quality; fsize = avcodec_encode_video(&x->x_avcontext->streams[i]->codec, @@ -484,7 +490,9 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x) else { x->x_nbframes++; - x->x_secondcount[ svideoindex++ ]++; + x->x_secondcount[ svideoindex ]++; + // post ("pdp_ffmpeg~ : index=%d count=%d", svideoindex, x->x_secondcount[ svideoindex ] ); + svideoindex++; } } } @@ -583,7 +591,7 @@ static t_int *pdp_ffmpeg_perform(t_int *w) x->x_audioin_position=(x->x_audioin_position+1)%(2*MAX_AUDIO_PACKET_SIZE); if ( x->x_audioin_position == 2*MAX_AUDIO_PACKET_SIZE-1 ) { - post( "pdp_ffmpeg~ : reaching end of audio buffer" ); + // post( "pdp_ffmpeg~ : reaching end of audio buffer" ); } fsample=*(in2++); if (fsample > 1.0) { fsample = 1.0; } @@ -686,6 +694,7 @@ void *pdp_ffmpeg_new(void) x->x_outlet_streaming = outlet_new(&x->x_obj, &s_float); x->x_outlet_nbframes = outlet_new(&x->x_obj, &s_float); x->x_outlet_nbframes_dropped = outlet_new(&x->x_obj, &s_float); + x->x_outlet_framerate = outlet_new(&x->x_obj, &s_float); x->x_packet0 = -1; x->x_queue_id = -1; diff --git a/modules/pdp_imgloader.c b/modules/pdp_imgloader.c index fbc0714..752e4bc 100644 --- a/modules/pdp_imgloader.c +++ b/modules/pdp_imgloader.c @@ -98,8 +98,8 @@ static void pdp_imgloader_load(t_pdp_imgloader *x, t_symbol *filename, t_floatar 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 ); - x->x_xoffset = (int) fx; - x->x_yoffset = (int) fy; + if ( fx!= 0.) x->x_xoffset = (int) fx; + if ( fy!= 0.) x->x_yoffset = (int) fy; } static void pdp_imgloader_xoffset(t_pdp_imgloader *x, t_floatarg fx ) diff --git a/modules/pdp_live~.c b/modules/pdp_live~.c index 6b8823f..cae6a65 100644 --- a/modules/pdp_live~.c +++ b/modules/pdp_live~.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,14 +38,22 @@ #define VIDEO_BUFFER_SIZE (1024*1024) #define MAX_AUDIO_PACKET_SIZE (128 * 1024) -#define MIN_AUDIO_SIZE (64 * 1024) +#define MIN_AUDIO_SIZE (512) #define AUDIO_PACKET_SIZE (2*1152) #define DEFAULT_CHANNELS 1 -#define DEFAULT_FRAME_RATE 25 #define DEFAULT_WIDTH 320 #define DEFAULT_HEIGHT 240 +#define DEFAULT_FRAME_RATE 25 +#define END_OF_STREAM 20 +#define MIN_PRIORITY -20 #define DEFAULT_PRIORITY 0 +#define MAX_PRIORITY 20 + +/* a trick to cope with ffmpeg versions */ +#ifndef AVFMT_NOHEADER +#define AVFMT_NOHEADER AVFMTCTX_NOHEADER +#endif static char *pdp_live_version = "pdp_live~: version 0.1, a video stream decoder ( ydegoyon@free.fr)."; @@ -68,6 +76,8 @@ typedef struct pdp_live_struct t_outlet *x_outlet_right; // right audio output t_outlet *x_outlet_streaming; // indicates the action of streaming t_outlet *x_outlet_nbframes; // number of frames emitted + t_outlet *x_outlet_framerate; // real framerate + t_outlet *x_outlet_endofstream;// for signaling the end of the stream pthread_t x_connectchild; // thread used for connecting to a stream pthread_t x_decodechild; // stream decoding thread @@ -76,22 +86,28 @@ typedef struct pdp_live_struct char *x_url; t_int x_streaming; // streaming flag + t_int x_nopackets; // no packet to decode + t_int x_endofstream; // end of the stream reached t_int x_nbframes; // number of frames emitted t_int x_framerate; // framerate t_int x_samplerate; // audio sample rate t_int x_audiochannels; // audio channels t_int x_audioon; // enough audio data to start playing + t_int x_blocksize; // audio block size struct timeval x_starttime; // streaming starting time t_int x_cursec; // current second t_int x_secondcount; // number of frames received in the current second t_int x_nbvideostreams; // number of video streams t_int x_nbaudiostreams; // number of audio streams + t_int x_videoindex; // index of the first video stream /* AV data structures */ AVFormatContext *x_avcontext; AVFormatParameters x_avparameters; // unused but the call is necessary to allocate structures AVPacket x_pkt; // packet received on the stream AVPicture x_picture_decoded; + long long int x_pts; // presentation time stamp + long long int x_previouspts; // previous presentation time stamp t_int x_newpicture; /* audio structures */ @@ -105,7 +121,10 @@ typedef struct pdp_live_struct static void pdp_live_priority(t_pdp_live *x, t_floatarg fpriority ) { - x->x_priority = (int)fpriority; + if ( ( x->x_priority >= MIN_PRIORITY ) && ( x->x_priority <= MAX_PRIORITY ) ) + { + x->x_priority = (int)fpriority; + } } static void pdp_live_threadify(t_pdp_live *x, t_floatarg fusethread ) @@ -131,24 +150,32 @@ static t_int pdp_live_decode_packet(t_pdp_live *x) AVFrame frame; uint8_t *pcktptr; struct timeval etime; + struct timespec mwait; if ( !x->x_streaming ) { return -1; } + // post( "pdp_live~ : trying to read packet" ); // read new packet on the stream if (av_read_packet(x->x_avcontext, &x->x_pkt) < 0) { - // post( "pdp_live~ : decoding thread : nothing to decode" ); + x->x_nopackets++; + // post( "pdp_live~ : decoding thread : nothing to decode : no packets :%d", x->x_nopackets ); + if ( x->x_nopackets > END_OF_STREAM ) + { + x->x_endofstream = 1; + } return -1; } // post( "pdp_live~ : read packet ( size=%d )", x->x_pkt.size ); + x->x_nopackets = 0; if (x->x_pkt.stream_index >= x->x_avcontext->nb_streams) { post("pdp_live~ : stream received out of range !! "); - return 0; + return -1; } length = x->x_pkt.size; @@ -211,8 +238,9 @@ static t_int pdp_live_decode_packet(t_pdp_live *x) else { post( "pdp_live~ : audio overflow : packet ignored..."); + x->x_audioin_position = 0; } - if ( ( x->x_audioin_position > MIN_AUDIO_SIZE ) && (!x->x_audioon) ) + if ( ( x->x_audioin_position > x->x_blocksize ) && (!x->x_audioon) ) { x->x_audioon = 1; // post( "pdp_live~ : audio on" ); @@ -224,19 +252,19 @@ static t_int pdp_live_decode_packet(t_pdp_live *x) imagesize = (x->x_avcontext->streams[x->x_pkt.stream_index]->codec.width * x->x_avcontext->streams[x->x_pkt.stream_index]->codec.height * 3) / 2; // yuv planar - // do not believe the declared framerate - // x->x_framerate = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.frame_rate / 10000; + x->x_framerate = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.frame_rate / 10000; + x->x_videoindex = x->x_pkt.stream_index; // calculate actual frame rate - if ( gettimeofday(&etime, NULL) == -1) - { - post("pdp_live~ : could not read time" ); - } - if ( ( etime.tv_sec - x->x_starttime.tv_sec ) > 0 ) - { - x->x_framerate = x->x_nbframes / ( etime.tv_sec - x->x_starttime.tv_sec ); - } - if ( x->x_framerate == 0 ) x->x_framerate = 1; + // if ( gettimeofday(&etime, NULL) == -1) + // { + // post("pdp_live~ : could not read time" ); + // } + // if ( ( etime.tv_sec - x->x_starttime.tv_sec ) > 0 ) + // { + // x->x_framerate = x->x_nbframes / ( etime.tv_sec - x->x_starttime.tv_sec ); + // } + // if ( x->x_framerate == 0 ) x->x_framerate = 1; // post ("pdp_live~ : frame rate is %d", x->x_framerate ); chunksize = avcodec_decode_video( @@ -276,9 +304,31 @@ static t_int pdp_live_decode_packet(t_pdp_live *x) else { x->x_newpicture=1; + x->x_previouspts = x->x_pts; + x->x_pts = frame.pts; + // post( "pdp_live : frame pts : %ld", x->x_pts ); x->x_vwidth = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.width; x->x_vheight = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.height; x->x_vsize = x->x_vwidth*x->x_vheight; + + if ( x->x_previouspts != -1 ) + { + mwait.tv_sec = 0; + mwait.tv_nsec = (x->x_pts - x->x_previouspts)*1000; + + if ( ( x->x_pts == 0 ) ) + { + // post("pdp_live~ : no presentation time stamp, using framerate :%d", + // x->x_framerate ); + mwait.tv_sec = 0; + mwait.tv_nsec = 1000000000/((x->x_framerate+5)); // the +5 is experimental + // it comes from the time used in decoding + } + + nanosleep( &mwait, NULL ); // wait between the two successive frames + // i know, cheap flow control + } + } break; } @@ -335,6 +385,7 @@ static void *pdp_decode_stream_from_url(void *tdata) { nanosleep( &twait, NULL ); // nothing to read, just wait } + } post( "pdp_live~ : decoding thread %d exiting....", x->x_decodechild ); @@ -353,6 +404,7 @@ static void *pdp_live_connect_to_url(void *tdata) x->x_avparameters.channels = DEFAULT_CHANNELS; x->x_avparameters.frame_rate = DEFAULT_FRAME_RATE; x->x_avparameters.width = DEFAULT_WIDTH; + if ( x->x_framerate = 0 ) x->x_framerate = DEFAULT_FRAME_RATE; x->x_avparameters.height = DEFAULT_HEIGHT; x->x_avparameters.image_format = PIX_FMT_YUV420P; @@ -452,6 +504,8 @@ static void *pdp_live_connect_to_url(void *tdata) post("pdp_live~ : could not set start time" ); } x->x_streaming = 1; + x->x_nopackets = 0; + x->x_endofstream = 0; x->x_nbframes = 0; x->x_connectchild = 0; @@ -490,7 +544,7 @@ static void pdp_live_disconnect(t_pdp_live *x) struct timespec twait; twait.tv_sec = 0; - twait.tv_nsec = 100000000; // 100 ms + twait.tv_nsec = 10000000; // 10 ms if (!x->x_streaming) { @@ -520,6 +574,8 @@ static void pdp_live_disconnect(t_pdp_live *x) outlet_float( x->x_outlet_streaming, x->x_streaming ); x->x_nbframes = 0; outlet_float( x->x_outlet_nbframes, x->x_nbframes ); + x->x_framerate = 0; + outlet_float( x->x_outlet_framerate, x->x_framerate ); if (x->x_audio_resample_ctx) { @@ -583,11 +639,13 @@ static t_int *pdp_live_perform(t_int *w) t_int sn; // decode a packet if not in thread mode - if ( !x->x_usethread ) + if ( !x->x_usethread && x->x_streaming ) { pdp_live_decode_packet( x ); } + x->x_blocksize = n; + // just read the buffer if ( x->x_audioon ) { @@ -609,8 +667,8 @@ static t_int *pdp_live_perform(t_int *w) out1++; out2++; } - x->x_audioin_position-=sn; memcpy( &x->x_audio_in[0], &x->x_audio_in[sn], 4*MAX_AUDIO_PACKET_SIZE-sn ); + x->x_audioin_position-=sn; // post( "pdp_live~ : audio in position : %d", x->x_audioin_position ); if ( x->x_audioin_position <= sn ) { @@ -636,6 +694,7 @@ static t_int *pdp_live_perform(t_int *w) if ( etime.tv_sec != x->x_cursec ) { x->x_cursec = etime.tv_sec; + if (x->x_streaming) outlet_float( x->x_outlet_framerate, x->x_framerate ); x->x_secondcount = 0; } if ( x->x_secondcount >= x->x_framerate ) @@ -680,13 +739,14 @@ static t_int *pdp_live_perform(t_int *w) pdp_packet_pass_if_valid(x->x_pdp_out, &x->x_packet0); // update streaming status - outlet_float( x->x_outlet_streaming, x->x_streaming ); x->x_nbframes++; x->x_secondcount++; outlet_float( x->x_outlet_nbframes, x->x_nbframes ); x->x_newpicture = 0; } + outlet_float( x->x_outlet_streaming, x->x_streaming ); + outlet_float( x->x_outlet_endofstream, x->x_endofstream ); return (w+5); } @@ -730,22 +790,32 @@ void *pdp_live_new(void) x->x_outlet_streaming = outlet_new(&x->x_obj, &s_float); x->x_outlet_nbframes = outlet_new(&x->x_obj, &s_float); + x->x_outlet_framerate = outlet_new(&x->x_obj, &s_float); + x->x_outlet_endofstream = outlet_new(&x->x_obj, &s_float); x->x_packet0 = -1; x->x_connectchild = 0; x->x_decodechild = 0; x->x_usethread = 1; x->x_priority = DEFAULT_PRIORITY; - x->x_nbframes = 0; x->x_framerate = DEFAULT_FRAME_RATE; + x->x_nbframes = 0; + x->x_framerate = 0; x->x_samplerate = 0; x->x_audiochannels = 0; x->x_cursec = 0; x->x_secondcount = 0; x->x_audio_resample_ctx = NULL; x->x_nbvideostreams = 0; + x->x_videoindex = 0; x->x_audioin_position = 0; x->x_newpicture = 0; + x->x_endofstream = 0; + x->x_nopackets = 0; + x->x_blocksize = MIN_AUDIO_SIZE; + + x->x_pts = -1; + x->x_previouspts = -1; x->x_avcontext = av_mallocz(sizeof(AVFormatContext)); if ( !x->x_avcontext ) @@ -776,11 +846,12 @@ void pdp_live_tilde_setup(void) pdp_live_class = class_new(gensym("pdp_live~"), (t_newmethod)pdp_live_new, (t_method)pdp_live_free, sizeof(t_pdp_live), 0, A_NULL); - class_addmethod(pdp_live_class, (t_method)pdp_live_dsp, gensym("dsp"), 0); + class_addmethod(pdp_live_class, (t_method)pdp_live_dsp, gensym("dsp"), A_NULL); class_addmethod(pdp_live_class, (t_method)pdp_live_connect, gensym("connect"), A_SYMBOL, A_NULL); class_addmethod(pdp_live_class, (t_method)pdp_live_disconnect, gensym("disconnect"), A_NULL); class_addmethod(pdp_live_class, (t_method)pdp_live_priority, gensym("priority"), A_FLOAT, A_NULL); class_addmethod(pdp_live_class, (t_method)pdp_live_audio, gensym("audio"), A_FLOAT, A_NULL); + class_addmethod(pdp_live_class, (t_method)pdp_live_threadify, gensym("thread"), A_FLOAT, A_NULL); class_sethelpsymbol( pdp_live_class, gensym("pdp_live~.pd") ); } diff --git a/modules/pdp_shape.c b/modules/pdp_shape.c index d437144..27239c4 100644 --- a/modules/pdp_shape.c +++ b/modules/pdp_shape.c @@ -56,6 +56,7 @@ typedef struct pdp_shape_struct t_int x_tolerance; // tolerance t_int x_paint; // paint option + t_int x_shape; // drawing shape option t_int x_luminosity; // use luminosity or not short int *x_bdata; @@ -113,6 +114,14 @@ static void pdp_shape_paint(t_pdp_shape *x, t_floatarg fpaint ) } } +static void pdp_shape_shape(t_pdp_shape *x, t_floatarg fshape ) +{ + if ( ( (t_int)fshape == 0 ) || ( (t_int)fshape == 1 ) ) + { + x->x_shape = (t_int)fshape; + } +} + static void pdp_shape_do_detect(t_pdp_shape *x, t_floatarg X, t_floatarg Y); static void pdp_shape_frame_detect(t_pdp_shape *x, t_floatarg X, t_floatarg Y); @@ -191,9 +200,12 @@ static void pdp_shape_do_detect(t_pdp_shape *x, t_floatarg X, t_floatarg Y) { // paint it white // post( "pdp_shape_do_detect : paint : %d %d", nX, nY ); - *(pbbY+nY*x->x_vwidth+nX) = (0xff<<7); - *(pbbU+(nY>>1)*(x->x_vwidth>>1)+(nX>>1)) = (0xff<<8); - *(pbbV+(nY>>1)*(x->x_vwidth>>1)+(nX>>1)) = (0xff<<8); + if ( x->x_shape ) + { + *(pbbY+nY*x->x_vwidth+nX) = (0xff<<7); + *(pbbU+(nY>>1)*(x->x_vwidth>>1)+(nX>>1)) = (0xff<<8); + *(pbbV+(nY>>1)*(x->x_vwidth>>1)+(nX>>1)) = (0xff<<8); + } if ( ( nX < x->x_vx1 ) || ( x->x_vx1 == -1 ) ) { @@ -542,6 +554,7 @@ void *pdp_shape_new(void) x->x_tolerance = 20; x->x_paint = 0; + x->x_shape = 1; x->x_luminosity = 1; x->x_cursX = -1; @@ -574,6 +587,7 @@ void pdp_shape_setup(void) class_addmethod(pdp_shape_class, (t_method)pdp_shape_rgb, gensym("rgb"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_NULL); class_addmethod(pdp_shape_class, (t_method)pdp_shape_tolerance, gensym("tolerance"), A_FLOAT, A_NULL); class_addmethod(pdp_shape_class, (t_method)pdp_shape_paint, gensym("paint"), A_FLOAT, A_NULL); + class_addmethod(pdp_shape_class, (t_method)pdp_shape_shape, gensym("shape"), A_FLOAT, A_NULL); class_addmethod(pdp_shape_class, (t_method)pdp_shape_luminosity, gensym("luminosity"), A_FLOAT, A_NULL); } diff --git a/modules/pdp_simura.c b/modules/pdp_simura.c index 87a471c..3bae7a8 100644 --- a/modules/pdp_simura.c +++ b/modules/pdp_simura.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/modules/pdp_spigot.c b/modules/pdp_spigot.c index c25859c..4fd5d6a 100644 --- a/modules/pdp_spigot.c +++ b/modules/pdp_spigot.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/modules/pdp_xcanvas.c b/modules/pdp_xcanvas.c index 071f530..90f2700 100644 --- a/modules/pdp_xcanvas.c +++ b/modules/pdp_xcanvas.c @@ -18,7 +18,8 @@ * */ -/* This object is an object allowing juxtaposition of frames from two inlets +/* This object is a video canvas which is also handling the graphical operations + * ( no need to plug it in pdp_xv ) * Written by Yves Degoyon */ diff --git a/modules/pdp_yqt.c b/modules/pdp_yqt.c index 2a37414..d0ada83 100644 --- a/modules/pdp_yqt.c +++ b/modules/pdp_yqt.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/modules/pdp_yvu2rgb.c b/modules/pdp_yvu2rgb.c index 2a9156c..a536268 100644 --- a/modules/pdp_yvu2rgb.c +++ b/modules/pdp_yvu2rgb.c @@ -1,6 +1,6 @@ /* - * Pure Data Packet module. - * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org> + * PiDiP module. + * Copyright (c) by Yves Degoyon (ydegoyon@free.fr) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by |