Update of /cvsroot/pure-data/externals/pidip/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5325/modules
Modified Files: Makefile Makefile.in pdp_ascii.c pdp_binary.c pdp_ffmpeg~.c pdp_i.c pdp_live~.c pdp_theorin~.c pdp_theorout~.c Added Files: pdp_icedthe~.c pdp_mapper.c pdp_theonice~.c Log Message: PiDiP 0.12.18
Index: pdp_theorout~.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_theorout~.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pdp_theorout~.c 14 Nov 2004 23:00:58 -0000 1.1 --- pdp_theorout~.c 2 Jan 2005 06:02:49 -0000 1.2 *************** *** 167,172 **** x->x_theora_info.fps_numerator=x->x_framerate; x->x_theora_info.fps_denominator=1; ! x->x_theora_info.aspect_numerator=x->x_vwidth; ! x->x_theora_info.aspect_denominator=x->x_vheight; x->x_theora_info.colorspace=OC_CS_UNSPECIFIED; x->x_theora_info.target_bitrate=x->x_vkbps; --- 167,172 ---- x->x_theora_info.fps_numerator=x->x_framerate; x->x_theora_info.fps_denominator=1; ! x->x_theora_info.aspect_numerator=1; ! x->x_theora_info.aspect_denominator=1; x->x_theora_info.colorspace=OC_CS_UNSPECIFIED; x->x_theora_info.target_bitrate=x->x_vkbps; *************** *** 182,187 **** --- 182,189 ---- x->x_theora_info.keyframe_mindistance=8; x->x_theora_info.noise_sensitivity=1; + x->x_theora_info.sharpness=2;
theora_encode_init(&x->x_theora_state,&x->x_theora_info); + theora_info_clear (&x->x_theora_info);
vorbis_info_init(&x->x_vorbis_info); *************** *** 204,207 **** --- 206,210 ----
vorbis_comment_init(&x->x_vorbis_comment); + vorbis_comment_add_tag (&x->x_vorbis_comment, "ENCODER", "pdp_theorout~"); vorbis_analysis_init(&x->x_dsp_state,&x->x_vorbis_info); vorbis_block_init(&x->x_dsp_state,&x->x_vorbis_block); *************** *** 250,253 **** --- 253,257 ----
theora_comment_init(&x->x_theora_comment); + theora_comment_add_tag (&x->x_theora_comment, "ENCODER", "pdp_theorout~"); theora_encode_comment(&x->x_theora_comment, &x->x_ogg_packet); ogg_stream_packetin(&x->x_statet, &x->x_ogg_packet); *************** *** 533,536 **** --- 537,544 ---- t_float **vbuffer; double videotime, audiotime; + theora_info lti; + theora_comment ltc; + ogg_packet logp, logp2; +
if ( ( (int)(header->info.image.width) != x->x_vwidth ) || *************** *** 608,622 **** { // stream one packet ! theora_encode_packetout(&x->x_theora_state, 0, &x->x_ogg_packet); ! ogg_stream_packetin(&x->x_statet, &x->x_ogg_packet); // post( "pdp_theorout~ : new (theora) ogg packet : bytes:%ld, bos:%ld, eos:%ld, no:%lld", ! // x->x_ogg_packet.bytes, x->x_ogg_packet.b_o_s, ! // x->x_ogg_packet.e_o_s, x->x_ogg_packet.packetno );
while( ( ret = ogg_stream_pageout(&x->x_statet, &vpage) ) >0 ) { videotime = theora_granule_time(&x->x_theora_state, ogg_page_granulepos(&vpage)); ! x->x_vbytesout+=fwrite(vpage.header, 1, vpage.header_len, x->x_tfile ); ! x->x_vbytesout+=fwrite(vpage.body, 1, vpage.body_len, x->x_tfile ); } } --- 616,641 ---- { // stream one packet ! theora_encode_packetout(&x->x_theora_state, 0, &logp); ! ogg_stream_packetin(&x->x_statet, &logp); // post( "pdp_theorout~ : new (theora) ogg packet : bytes:%ld, bos:%ld, eos:%ld, no:%lld", ! // logp.bytes, logp.b_o_s, ! // logp.e_o_s, logp.packetno ); !
while( ( ret = ogg_stream_pageout(&x->x_statet, &vpage) ) >0 ) { videotime = theora_granule_time(&x->x_theora_state, ogg_page_granulepos(&vpage)); ! if ( ( ret = fwrite(vpage.header, 1, vpage.header_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_vbytesout+=ret; ! if ( ( ret = fwrite(vpage.body, 1, vpage.body_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_vbytesout+=ret; } } *************** *** 656,662 ****
// weld packets into the bitstream ! while(vorbis_bitrate_flushpacket( &x->x_dsp_state, &x->x_ogg_packet)) { ! ogg_stream_packetin( &x->x_statev, &x->x_ogg_packet); }
--- 675,681 ----
// weld packets into the bitstream ! while(vorbis_bitrate_flushpacket( &x->x_dsp_state, &logp2)) { ! ogg_stream_packetin( &x->x_statev, &logp2); }
*************** *** 666,671 **** { audiotime = vorbis_granule_time(&x->x_dsp_state, ogg_page_granulepos(&apage)); ! x->x_abytesout+=fwrite(apage.header, 1, apage.header_len, x->x_tfile ); ! x->x_abytesout+=fwrite(apage.body, 1, apage.body_len, x->x_tfile ); }
--- 685,700 ---- { audiotime = vorbis_granule_time(&x->x_dsp_state, ogg_page_granulepos(&apage)); ! if ( ( ret = fwrite(apage.header, 1, apage.header_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_abytesout+=ret; ! if ( ( ret = fwrite(apage.body, 1, apage.body_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_abytesout+=ret; }
*************** *** 694,705 **** { // stream one packet ! theora_encode_packetout(&x->x_theora_state, 1, &x->x_ogg_packet); ! ogg_stream_packetin( &x->x_statet, &x->x_ogg_packet);
while( ( ret = ogg_stream_pageout( &x->x_statet, &vpage) ) > 0 ) { videotime = theora_granule_time(&x->x_theora_state, ogg_page_granulepos(&vpage)); ! x->x_vbytesout+=fwrite(vpage.header, 1, vpage.header_len, x->x_tfile ); ! x->x_vbytesout+=fwrite(vpage.body, 1, vpage.body_len, x->x_tfile ); } } --- 723,744 ---- { // stream one packet ! theora_encode_packetout(&x->x_theora_state, 1, &logp); ! ogg_stream_packetin( &x->x_statet, &logp);
while( ( ret = ogg_stream_pageout( &x->x_statet, &vpage) ) > 0 ) { videotime = theora_granule_time(&x->x_theora_state, ogg_page_granulepos(&vpage)); ! if ( ( ret = fwrite(vpage.header, 1, vpage.header_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_vbytesout+=ret; ! if ( ( ret = fwrite(vpage.body, 1, vpage.body_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_vbytesout+=ret; } } *************** *** 715,721 ****
// weld packets into the bitstream ! while(vorbis_bitrate_flushpacket( &x->x_dsp_state, &x->x_ogg_packet)) { ! ogg_stream_packetin( &x->x_statev, &x->x_ogg_packet); } } --- 754,760 ----
// weld packets into the bitstream ! while(vorbis_bitrate_flushpacket( &x->x_dsp_state, &logp2)) { ! ogg_stream_packetin( &x->x_statev, &logp2); } } *************** *** 724,729 **** { audiotime = vorbis_granule_time(&x->x_dsp_state, ogg_page_granulepos(&apage)); ! x->x_abytesout+=fwrite(apage.header, 1, apage.header_len, x->x_tfile ); ! x->x_abytesout+=fwrite(apage.body, 1, apage.body_len, x->x_tfile ); }
--- 763,778 ---- { audiotime = vorbis_granule_time(&x->x_dsp_state, ogg_page_granulepos(&apage)); ! if ( ( ret = fwrite(apage.header, 1, apage.header_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_abytesout+=ret; ! if ( ( ret = fwrite(apage.body, 1, apage.body_len, x->x_tfile) ) <= 0 ) ! { ! post( "pdp_theorout~ : could not write headers (ret=%d).", ret ); ! perror( "fwrite" ); ! } ! x->x_abytesout+=ret; }
Index: pdp_ffmpeg~.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_ffmpeg~.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pdp_ffmpeg~.c 14 Nov 2004 22:52:21 -0000 1.5 --- pdp_ffmpeg~.c 2 Jan 2005 06:02:48 -0000 1.6 *************** *** 323,326 **** --- 323,327 ---- t_int owidth, oheight; short *pencbuf; + t_int framerate, atime, ttime;
/* allocate all ressources */ *************** *** 392,401 **** } } ! if ( x->x_secondcount[ svideoindex ] >= (x->x_avcontext->streams[i]->codec.frame_rate/10000) ) { - // 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; --- 393,402 ---- } } ! framerate = x->x_avcontext->streams[i]->codec.frame_rate/10000; ! ttime = ( ( x->x_nbframes + 1 ) % framerate ) * ( 1000 / framerate ); ! atime = ( etime.tv_usec / 1000 ); ! // post("pdp_theonice~ : actual : %d, theoretical : %d", atime, ttime ); ! if ( atime < ttime ) { x->x_nbframes_dropped++; continue;
--- NEW FILE: pdp_icedthe~.c --- /* * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ [...1330 lines suppressed...]
void pdp_icedthe_tilde_setup(void) { // post( pdp_icedthe_version ); pdp_icedthe_class = class_new(gensym("pdp_icedthe~"), (t_newmethod)pdp_icedthe_new, (t_method)pdp_icedthe_free, sizeof(t_pdp_icedthe), 0, A_NULL);
class_addmethod(pdp_icedthe_class, (t_method)pdp_icedthe_dsp, gensym("dsp"), A_NULL); class_addmethod(pdp_icedthe_class, (t_method)pdp_icedthe_connect, gensym("connect"), A_SYMBOL, A_NULL); class_addmethod(pdp_icedthe_class, (t_method)pdp_icedthe_disconnect, gensym("disconnect"), A_NULL); class_addmethod(pdp_icedthe_class, (t_method)pdp_icedthe_priority, gensym("priority"), A_FLOAT, A_NULL); class_addmethod(pdp_icedthe_class, (t_method)pdp_icedthe_audio, gensym("audio"), A_FLOAT, A_NULL); class_sethelpsymbol( pdp_icedthe_class, gensym("pdp_icedthe~.pd") );
}
#ifdef __cplusplus } #endif
Index: Makefile.in =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/Makefile.in,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile.in 14 Nov 2004 22:52:21 -0000 1.13 --- Makefile.in 2 Jan 2005 06:02:48 -0000 1.14 *************** *** 20,23 **** --- 20,24 ---- pdp_disintegration.o pdp_distance.o pdp_theorin~.o \ pdp_theorout~.o pdp_cropper.o pdp_background.o \ + pdp_mapper.o pdp_theonice~.o pdp_icedthe~.o\ @PDP_STREAMING_OBJECTS@ # pdp_xcanvas.o pdp_aa.o
--- NEW FILE: pdp_mapper.c --- /* * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */
/* This object is a pixels mapper enabling to do some cut and paste * Written by Yves Degoyon */
#include "pdp.h" #include <math.h>
static char *pdp_mapper_version = "pdp_mapper: version 0.1, a pixels mapper, written by Yves Degoyon (ydegoyon@free.fr)";
typedef struct pdp_mapper_struct { t_object x_obj; t_float x_f;
t_outlet *x_outlet0; t_int x_packet0; t_int x_packet1; t_int x_dropped; t_int x_queue_id;
t_int x_vwidth; t_int x_vheight; t_int x_vsize; unsigned int x_encoding; t_int *x_pixelmap;
} t_pdp_mapper;
static void pdp_mapper_copy(t_pdp_mapper *x, t_floatarg fromX, t_floatarg fromY, t_floatarg toX, t_floatarg toY) { if ( ( fromX >= 0 ) && ( fromX < x->x_vwidth ) && ( toX >= 0 ) && ( toX < x->x_vwidth ) && ( fromY >= 0 ) && ( fromY < x->x_vheight ) && ( toY >= 0 ) && ( toY < x->x_vheight ) ) { x->x_pixelmap[ (t_int)toY*x->x_vwidth+(t_int)toX ] = x->x_pixelmap[ (t_int)fromY*x->x_vwidth+(t_int)fromX ]; } }
static void pdp_mapper_reset(t_pdp_mapper *x) { t_int px, py;
if ( x->x_vsize > 0 ) { for ( py=0; py<x->x_vheight; py++ ) { for ( px=0; px<x->x_vwidth; px++ ) { x->x_pixelmap[py*x->x_vwidth+px] = py*x->x_vwidth+px; } } } }
static void pdp_mapper_swap(t_pdp_mapper *x, t_floatarg fromX, t_floatarg fromY, t_floatarg toX, t_floatarg toY) {
t_int tval;
if ( ( fromX >= 0 ) && ( fromX < x->x_vwidth ) && ( toX >= 0 ) && ( toX < x->x_vwidth ) && ( fromY >= 0 ) && ( fromY < x->x_vheight ) && ( toY >= 0 ) && ( toY < x->x_vheight ) ) { tval = x->x_pixelmap[ (t_int)toY*x->x_vwidth+(t_int)toX ]; x->x_pixelmap[ (t_int)toY*x->x_vwidth+(t_int)toX ] = x->x_pixelmap[ (t_int)fromY*x->x_vwidth+(t_int)fromX ]; x->x_pixelmap[ (t_int)fromY*x->x_vwidth+(t_int)fromX ] = tval; } }
static void pdp_mapper_allocate(t_pdp_mapper *x, t_int newsize) { int i, px, py;
if ( x->x_pixelmap != NULL ) { freebytes( x->x_pixelmap, x->x_vsize*sizeof(t_int) ); }
x->x_vsize = newsize; x->x_pixelmap = (t_int*) getbytes( x->x_vsize*sizeof(t_int) );
for ( py=0; py<x->x_vheight; py++ ) { for ( px=0; px<x->x_vwidth; px++ ) { x->x_pixelmap[py*x->x_vwidth+px] = py*x->x_vwidth+px; } } }
static void pdp_mapper_process_yv12(t_pdp_mapper *x) { t_pdp *header = pdp_packet_header(x->x_packet0); short int *data = (short int *)pdp_packet_data(x->x_packet0); t_pdp *newheader = pdp_packet_header(x->x_packet1); short int *newdata = (short int *)pdp_packet_data(x->x_packet1); int i;
t_int px, py, ppx, ppy, offset; short int *sy, *su, *sv, t; t_int *spy; short int *sny, *snu, *snv;
/* allocate all ressources */ if ( ((t_int)header->info.image.width != x->x_vwidth ) || ((t_int)header->info.image.height != x->x_vheight ) ) { x->x_vwidth = header->info.image.width; x->x_vheight = header->info.image.height; post( "pdp_mapper : reallocating buffers" ); pdp_mapper_allocate(x, header->info.image.width*header->info.image.height ); }
x->x_encoding = header->info.image.encoding;
newheader->info.image.encoding = x->x_encoding; newheader->info.image.width = x->x_vwidth; newheader->info.image.height = x->x_vheight;
/* copy images if necessary */ // memcpy( newdata, data, (( x->x_vsize + (x->x_vsize>>1))<<1));
sy = data; su = (data+x->x_vsize); sv = (data+x->x_vsize+(x->x_vsize>>2)); spy = x->x_pixelmap; sny = newdata; snu = (newdata+x->x_vsize); snv = (newdata+x->x_vsize+(x->x_vsize>>2));
for(py=1; py<x->x_vheight; py++) { for(px=0; px<x->x_vwidth; px++) { ppy = (*(spy)/x->x_vwidth); ppx = (*(spy)%x->x_vwidth); *(sny) = *(sy+ppy*x->x_vwidth+ppx); *(snu) = *(su+(ppy>>1)*(x->x_vwidth>>1)+(ppx>>1)); *(snv) = *(sv+(ppy>>1)*(x->x_vwidth>>1)+(ppx>>1)); sny++; spy++; if ( ( px%2 == 0 ) && ( py%2 == 0 ) ) { snu++; snv++; } } }
return; }
static void pdp_mapper_sendpacket(t_pdp_mapper *x) { /* release the packet */ pdp_packet_mark_unused(x->x_packet0); x->x_packet0 = -1;
/* unregister and propagate if valid dest packet */ pdp_packet_pass_if_valid(x->x_outlet0, &x->x_packet1); }
static void pdp_mapper_process(t_pdp_mapper *x) { int encoding; t_pdp *header = 0;
/* check if image data packets are compatible */ if ( (header = pdp_packet_header(x->x_packet0)) && (PDP_IMAGE == header->type)){
/* pdp_mapper_process inputs and write into active inlet */ switch(pdp_packet_header(x->x_packet0)->info.image.encoding){
case PDP_IMAGE_YV12: x->x_packet1 = pdp_packet_clone_rw(x->x_packet0); pdp_queue_add(x, pdp_mapper_process_yv12, pdp_mapper_sendpacket, &x->x_queue_id); break;
case PDP_IMAGE_GREY: // pdp_mapper_process_packet(x); break;
default: /* don't know the type, so dont pdp_mapper_process */ break; } } }
static void pdp_mapper_input_0(t_pdp_mapper *x, t_symbol *s, t_floatarg f) { /* if this is a register_ro message or register_rw message, register with packet factory */
if (s== gensym("register_rw")) { x->x_dropped = pdp_packet_convert_ro_or_drop(&x->x_packet0, (int)f, pdp_gensym("image/YCrCb/*") ); }
if ((s == gensym("process")) && (-1 != x->x_packet0) && (!x->x_dropped)) { /* add the process method and callback to the process queue */ pdp_mapper_process(x); } }
static void pdp_mapper_free(t_pdp_mapper *x) { int i;
pdp_queue_finish(x->x_queue_id); pdp_packet_mark_unused(x->x_packet0);
if ( x->x_pixelmap ) freebytes( x->x_pixelmap, x->x_vsize*sizeof(t_int) );
}
t_class *pdp_mapper_class;
void *pdp_mapper_new(void) { int i;
t_pdp_mapper *x = (t_pdp_mapper *)pd_new(pdp_mapper_class);
x->x_outlet0 = outlet_new(&x->x_obj, &s_anything);
x->x_packet0 = -1; x->x_packet1 = -1; x->x_queue_id = -1; x->x_vsize = -1;
return (void *)x; }
#ifdef __cplusplus extern "C" { #endif
void pdp_mapper_setup(void) { // post( pdp_mapper_version ); pdp_mapper_class = class_new(gensym("pdp_mapper"), (t_newmethod)pdp_mapper_new, (t_method)pdp_mapper_free, sizeof(t_pdp_mapper), 0, A_NULL);
class_addmethod(pdp_mapper_class, (t_method)pdp_mapper_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL); class_addmethod(pdp_mapper_class, (t_method)pdp_mapper_copy, gensym("copy"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_NULL); class_addmethod(pdp_mapper_class, (t_method)pdp_mapper_swap, gensym("swap"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_NULL); class_addmethod(pdp_mapper_class, (t_method)pdp_mapper_reset, gensym("reset"), A_NULL); class_sethelpsymbol( pdp_mapper_class, gensym("pdp_mapper.pd") );
}
#ifdef __cplusplus } #endif
Index: Makefile =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/Makefile,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** Makefile 14 Nov 2004 22:52:21 -0000 1.13 --- Makefile 2 Jan 2005 06:02:48 -0000 1.14 *************** *** 20,23 **** --- 20,24 ---- pdp_disintegration.o pdp_distance.o pdp_theorin~.o \ pdp_theorout~.o pdp_cropper.o pdp_background.o \ + pdp_mapper.o pdp_theonice~.o pdp_icedthe~.o\ pdp_live~.o pdp_ffmpeg~.o # pdp_xcanvas.o pdp_aa.o
Index: pdp_live~.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_live~.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pdp_live~.c 14 Nov 2004 22:52:21 -0000 1.4 --- pdp_live~.c 2 Jan 2005 06:02:49 -0000 1.5 *************** *** 84,87 **** --- 84,89 ---- pthread_t x_connectchild; // thread used for connecting to a stream pthread_t x_decodechild; // stream decoding thread + pthread_mutex_t x_audiolock; // audio mutex + pthread_mutex_t x_videolock; // video mutex t_int x_usethread; // flag to activate decoding in a thread t_int x_autoplay; // flag to autoplay the file ( default = true ) *************** *** 179,184 **** static void pdp_live_frame_cold(t_pdp_live *x, t_floatarg frameindex) { ! int frame = (int)frameindex; ! int ret; uint64_t newpts;
--- 181,186 ---- static void pdp_live_frame_cold(t_pdp_live *x, t_floatarg frameindex) { ! t_int frame = (int)frameindex; ! t_int ret, flags=0; uint64_t newpts;
*************** *** 197,201 **** return; } ! if ( ( ret = av_seek_frame(x->x_avcontext, x->x_videoindex, newpts) ) < 0 ) { post( "pdp_live~ : couldn't seek the requested frame (ret=%d)", ret ); --- 199,204 ---- return; } ! if ( frame < x->x_nbframes ) flags = AVSEEK_FLAG_BACKWARD; ! if ( ( ret = av_seek_frame(x->x_avcontext, x->x_videoindex, newpts, flags) ) < 0 ) { post( "pdp_live~ : couldn't seek the requested frame (ret=%d)", ret ); *************** *** 243,247 **** { post( "pdp_live~ : looping file reading..." ); ! if ( ( ret = av_seek_frame(x->x_avcontext, x->x_videoindex, 0) ) < 0 ) { post( "pdp_live~ : couldn't seek the requested frame (ret=%d)", ret ); --- 246,250 ---- { post( "pdp_live~ : looping file reading..." ); ! if ( ( ret = av_seek_frame(x->x_avcontext, x->x_videoindex, 0, 0) ) < 0 ) { post( "pdp_live~ : couldn't seek the requested frame (ret=%d)", ret ); *************** *** 302,305 **** --- 305,314 ---- }
+ if ( pthread_mutex_lock( &x->x_audiolock ) < 0 ) + { + post( "pdp_live~ : unable to lock audio mutex" ); + perror( "pthread_mutex_lock" ); + } + // resample received audio // post( "pdp_live~ : resampling from %dHz-%dch to %dHz-%dch (in position=%d)", *************** *** 337,340 **** --- 346,354 ---- // post( "pdp_live~ : audio on" ); } + if ( pthread_mutex_unlock( &x->x_audiolock ) < 0 ) + { + post( "pdp_live~ : unable to unlock audio mutex" ); + perror( "pthread_mutex_unlock" ); + } break;
*************** *** 384,387 **** --- 398,406 ---- else { + if ( pthread_mutex_lock( &x->x_videolock ) < 0 ) + { + post( "pdp_live~ : unable to lock video mutex" ); + perror( "pthread_mutex_lock" ); + } x->x_newpicture=1; x->x_vwidth = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.width; *************** *** 430,434 **** if ( gettimeofday(&ctime, NULL) == -1) { ! post("pdp_theorin~ : could not read time" ); }
--- 449,453 ---- if ( gettimeofday(&ctime, NULL) == -1) { ! post("pdp_live~ : could not read time" ); }
*************** *** 436,440 **** ( ctime.tv_usec-x->x_starttime.tv_usec )/1000; ttheoretical = ((x->x_nbframes)*1000 )/x->x_framerate; ! // post( "pdp-theorin~ : %d playing since : %lldms ( theory : %lldms )", // x->x_nbframes, tplaying, ttheoretical );
--- 455,459 ---- ( ctime.tv_usec-x->x_starttime.tv_usec )/1000; ttheoretical = ((x->x_nbframes)*1000 )/x->x_framerate; ! // post( "pdp_live~ : %d playing since : %lldms ( theory : %lldms )", // x->x_nbframes, tplaying, ttheoretical );
*************** *** 448,451 **** --- 467,475 ---- } } + if ( pthread_mutex_unlock( &x->x_videolock ) < 0 ) + { + post( "pdp_live~ : unable to unlock video mutex" ); + perror( "pthread_mutex_unlock" ); + } } break; *************** *** 474,478 **** if ( sched_setscheduler(0,SCHED_FIFO,&schedprio) == -1) { ! post("pdp_theorin~ : couldn't set priority for decoding thread."); }
--- 498,502 ---- if ( sched_setscheduler(0,SCHED_FIFO,&schedprio) == -1) { ! post("pdp_live~ : couldn't set priority for decoding thread."); }
*************** *** 765,768 **** --- 789,797 ---- if ( x->x_audioon ) { + if ( pthread_mutex_lock( &x->x_audiolock ) < 0 ) + { + post( "pdp_live~ : unable to lock audio mutex" ); + perror( "pthread_mutex_lock" ); + } sn=0; while (n--) *************** *** 790,793 **** --- 819,827 ---- // post( "pdp_live~ : audio off" ); } + if ( pthread_mutex_unlock( &x->x_audiolock ) < 0 ) + { + post( "pdp_live~ : unable to audio unlock mutex" ); + perror( "pthread_mutex_unlock" ); + } } else *************** *** 820,823 **** --- 854,862 ---- if ( x->x_newpicture ) { + if ( pthread_mutex_lock( &x->x_videolock ) < 0 ) + { + post( "pdp_live~ : unable to lock video mutex" ); + perror( "pthread_mutex_lock" ); + } pdp_packet_pass_if_valid(x->x_pdp_out, &x->x_packet0); x->x_newpicture = 0; *************** *** 827,830 **** --- 866,874 ---- x->x_secondcount++; outlet_float( x->x_outlet_nbframes, x->x_nbframes ); + if ( pthread_mutex_unlock( &x->x_videolock ) < 0 ) + { + post( "pdp_live~ : unable to unlock video mutex" ); + perror( "pthread_mutex_unlock" ); + } } outlet_float( x->x_outlet_streaming, x->x_streaming ); *************** *** 857,860 **** --- 901,915 ---- pdp_packet_mark_unused(x->x_packet0); av_free_static(); + + if ( pthread_mutex_destroy( &x->x_audiolock ) < 0 ) + { + post( "pdp_live~ : unable to destroy audio mutex" ); + perror( "pthread_mutex_destroy" ); + } + if ( pthread_mutex_destroy( &x->x_videolock ) < 0 ) + { + post( "pdp_live~ : unable to destroy video mutex" ); + perror( "pthread_mutex_destroy" ); + } }
*************** *** 908,911 **** --- 963,979 ---- x->x_firstpts = -1;
+ if ( pthread_mutex_init( &x->x_audiolock, NULL ) < 0 ) + { + post( "pdp_live~ : unable to initialize audio mutex" ); + perror( "pthread_mutex_init" ); + return NULL; + } + if ( pthread_mutex_init( &x->x_videolock, NULL ) < 0 ) + { + post( "pdp_live~ : unable to initialize video mutex" ); + perror( "pthread_mutex_init" ); + return NULL; + } + x->x_avcontext = av_mallocz(sizeof(AVFormatContext)); if ( !x->x_avcontext )
Index: pdp_binary.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_binary.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pdp_binary.c 14 Nov 2004 23:00:58 -0000 1.1 --- pdp_binary.c 2 Jan 2005 06:02:48 -0000 1.2 *************** *** 199,203 **** if ( x->x_colorY >= 0 ) { ! diff += abs(y-x->x_colorY ); } if ( x->x_colorV >= 0 ) --- 199,203 ---- if ( x->x_colorY >= 0 ) { ! diff = abs(y-x->x_colorY ); } if ( x->x_colorV >= 0 )
Index: pdp_i.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_i.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pdp_i.c 14 Nov 2004 22:52:21 -0000 1.4 --- pdp_i.c 2 Jan 2005 06:02:48 -0000 1.5 *************** *** 156,160 **** if ( x->x_ddata ) freebytes( x->x_ddata, x->x_psize ); if ( x->x_hdata ) freebytes( x->x_hdata, x->x_hsize ); ! if ( x->x_bdata ) freebytes( x->x_hdata, x->x_bsize ); }
--- 156,160 ---- if ( x->x_ddata ) freebytes( x->x_ddata, x->x_psize ); if ( x->x_hdata ) freebytes( x->x_hdata, x->x_hsize ); ! if ( x->x_bdata ) freebytes( x->x_bdata, x->x_bsize ); }
--- NEW FILE: pdp_theonice~.c --- /* * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ [...1294 lines suppressed...] class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_connect, gensym("connect"), A_SYMBOL, A_SYMBOL, A_DEFFLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_disconnect, gensym("disconnect"), A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_abitrate, gensym("audiobitrate"), A_FLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_vbitrate, gensym("videobitrate"), A_FLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_aquality, gensym("audioquality"), A_FLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_vquality, gensym("videoquality"), A_FLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_framerate, gensym("framerate"), A_FLOAT, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_passwd, gensym("passwd"), A_SYMBOL, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_title, gensym("title"), A_GIMME, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_artist, gensym("artist"), A_GIMME, A_NULL); class_addmethod(pdp_theonice_class, (t_method)pdp_theonice_url, gensym("url"), A_SYMBOL, A_NULL); 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); class_sethelpsymbol( pdp_theonice_class, gensym("pdp_theonice~.pd") );
}
#ifdef __cplusplus } #endif
Index: pdp_ascii.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_ascii.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** pdp_ascii.c 14 Nov 2004 22:52:21 -0000 1.4 --- pdp_ascii.c 2 Jan 2005 06:02:48 -0000 1.5 *************** *** 316,319 **** --- 316,320 ---- case '0': case '1': + // post( "pdp_ascii : read %c", charread ); *pdata++ = ( charread == '0' )?0:1; nbexpdata--;
Index: pdp_theorin~.c =================================================================== RCS file: /cvsroot/pure-data/externals/pidip/modules/pdp_theorin~.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pdp_theorin~.c 14 Nov 2004 23:00:58 -0000 1.1 --- pdp_theorin~.c 2 Jan 2005 06:02:49 -0000 1.2 *************** *** 43,47 **** #define VIDEO_BUFFER_SIZE (1024*1024) #define MAX_AUDIO_PACKET_SIZE (64 * 1024) ! #define MIN_AUDIO_SIZE (64*1024)
#define DEFAULT_CHANNELS 1 --- 43,47 ---- #define VIDEO_BUFFER_SIZE (1024*1024) #define MAX_AUDIO_PACKET_SIZE (64 * 1024) ! #define MIN_AUDIO_SIZE (128*1024)
#define DEFAULT_CHANNELS 1 *************** *** 53,56 **** --- 53,57 ---- #define DEFAULT_PRIORITY 1 #define MAX_PRIORITY 20 + #define NB_NOFRAMES_HIT 10
#define THEORA_NUM_HEADER_PACKETS 3 *************** *** 81,84 **** --- 82,87 ----
pthread_t x_decodechild; // file decoding thread + pthread_mutex_t x_audiolock; // audio mutex + pthread_mutex_t x_videolock; // video mutex t_int x_usethread; // flag to activate decoding in a thread t_int x_autoplay; // flag to autoplay the file ( default = true ) *************** *** 91,97 **** t_int x_theorainit; // flag for indicating that theora is initialized t_int x_videoready; // video ready flag t_int x_newpicture; // new picture flag t_int x_newpictureready;// new picture ready flag - t_int x_loop; // looping flag ( default = on ) t_int x_notpackets; // number of theora packets decoded t_int x_novpackets; // number of vorbis packets decoded --- 94,100 ---- t_int x_theorainit; // flag for indicating that theora is initialized t_int x_videoready; // video ready flag + t_int x_noframeshits; // number of tries without getting a frame t_int x_newpicture; // new picture flag t_int x_newpictureready;// new picture ready flag t_int x_notpackets; // number of theora packets decoded t_int x_novpackets; // number of vorbis packets decoded *************** *** 125,131 **** /* audio structures */ t_int x_audio; // flag to activate the decoding of audio ! t_float x_audio_inl[4*MAX_AUDIO_PACKET_SIZE]; /* buffer for float audio decoded from ogg */ ! t_float x_audio_inr[4*MAX_AUDIO_PACKET_SIZE]; /* buffer for float audio decoded from ogg */ ! t_int x_audioin_position; // writing position for incoming audio
} t_pdp_theorin; --- 128,135 ---- /* audio structures */ t_int x_audio; // flag to activate the decoding of audio ! t_float x_audio_inl[4*MAX_AUDIO_PACKET_SIZE]; // left buffer for pd ! t_float x_audio_inr[4*MAX_AUDIO_PACKET_SIZE]; // right buffer for pd ! t_int x_audioin_position;// writing position for incoming audio ! t_float **x_pcm; // buffer for vorbis decoding
} t_pdp_theorin; *************** *** 163,174 **** }
- static void pdp_theorin_loop(t_pdp_theorin *x, t_floatarg floop ) - { - if ( ( floop == 0. ) || ( floop == 1. ) ) - { - x->x_loop = (int)floop; - } - } - static void pdp_theorin_bang(t_pdp_theorin *x) { --- 167,170 ---- *************** *** 202,206 **** { int ret, count, maxsamples, samples, si=0, sj=0; - float **pcm; struct timespec mwait; struct timeval ctime; --- 198,201 ---- *************** *** 209,212 **** --- 204,208 ---- unsigned char *pY, *pU, *pV; unsigned char *psY, *psU, *psV; + t_float **lpcm; t_int px, py;
*************** *** 215,239 **** if ( !x->x_reading ) return -1;
! while ( x->x_novpackets && !x->x_audioon ) { /* if there's pending, decoded audio, grab it */ ! if((ret=vorbis_synthesis_pcmout(&x->x_dsp_state, &pcm))>0) { if (x->x_audio) { maxsamples=(3*MAX_AUDIO_PACKET_SIZE-x->x_audioin_position); samples=(ret<maxsamples)?ret:maxsamples;
! if ( x->x_audioin_position + samples*x->x_audiochannels < 3*MAX_AUDIO_PACKET_SIZE ) ! { ! memcpy( (void*)&x->x_audio_inl[x->x_audioin_position], pcm[0], samples*sizeof(t_float) ); ! memcpy( (void*)&x->x_audio_inr[x->x_audioin_position], pcm[1], samples*sizeof(t_float) ); ! x->x_audioin_position = ( x->x_audioin_position + samples ) % (4*MAX_AUDIO_PACKET_SIZE); ! } ! else ! { ! post( "pdp_theorin~ : audio overflow : packet ignored..."); ! x->x_audioin_position = 0; ! } if ( ( x->x_audioin_position > MIN_AUDIO_SIZE ) && (!x->x_audioon) ) { --- 211,234 ---- if ( !x->x_reading ) return -1;
! while ( x->x_novpackets ) { /* if there's pending, decoded audio, grab it */ ! x->x_pcm = NULL; ! if((ret=vorbis_synthesis_pcmout(&x->x_dsp_state, &x->x_pcm))>0) { if (x->x_audio) { + if ( pthread_mutex_lock( &x->x_audiolock ) < 0 ) + { + post( "pdp_theorin~ : unable to lock audio mutex" ); + perror( "pthread_mutex_lock" ); + } maxsamples=(3*MAX_AUDIO_PACKET_SIZE-x->x_audioin_position); samples=(ret<maxsamples)?ret:maxsamples;
! memcpy( (void*)&x->x_audio_inl[x->x_audioin_position], x->x_pcm[0], samples*sizeof(t_float) ); ! memcpy( (void*)&x->x_audio_inr[x->x_audioin_position], x->x_pcm[1], samples*sizeof(t_float) ); ! x->x_audioin_position = ( x->x_audioin_position + samples ) % (3*MAX_AUDIO_PACKET_SIZE); ! if ( ( x->x_audioin_position > MIN_AUDIO_SIZE ) && (!x->x_audioon) ) { *************** *** 244,247 **** --- 239,251 ---- // post( "pdp_theorin~ : got %d audio samples (audioin=%d)", samples, x->x_audioin_position ); vorbis_synthesis_read(&x->x_dsp_state, samples); + if((ret=vorbis_synthesis_lapout(&x->x_dsp_state, &x->x_pcm))>0) + { + // post( "pdp_theorin~ : supplemental samples (nb=%d)", ret ); + } + if ( pthread_mutex_unlock( &x->x_audiolock ) < 0 ) + { + post( "pdp_theorin~ : unable to audio unlock mutex" ); + perror( "pthread_mutex_unlock" ); + } } else *************** *** 277,301 **** // post( "pdp_theorin~ : got one video frame" ); x->x_videoready=1; } else { // post( "pdp_theorin~ : no more video frame (frames=%d)", x->x_nbframes ); ! if ( x->x_nbframes > 0 ) { - if ( !x->x_loop ) - { x->x_endoffile = 1; - } - else - { - // restart a new loop - if ( gettimeofday(&x->x_starttime, NULL) == -1) - { - post("pdp_theorin~ : could not set start time" ); - } - } - x->x_nbframes = 0; - x->x_audioin_position = 0; // reset audio - x->x_audioon = 0; } break; --- 281,293 ---- // post( "pdp_theorin~ : got one video frame" ); x->x_videoready=1; + x->x_noframeshits=0; } else { // post( "pdp_theorin~ : no more video frame (frames=%d)", x->x_nbframes ); ! x->x_noframeshits++; ! if ( x->x_nbframes > 0 && ( x->x_noframeshits > NB_NOFRAMES_HIT ) ) { x->x_endoffile = 1; } break; *************** *** 305,308 **** --- 297,305 ---- if ( x->x_videoready ) { + if ( pthread_mutex_lock( &x->x_videolock ) < 0 ) + { + post( "pdp_theorin~ : unable to lock video mutex" ); + perror( "pthread_mutex_lock" ); + } theora_decode_YUVout(&x->x_theora_state, &x->x_yuvbuffer);
*************** *** 351,354 **** --- 348,356 ---- x->x_newpictureready = 1; } + if ( pthread_mutex_unlock( &x->x_videolock ) < 0 ) + { + post( "pdp_theorin~ : unable to unlock video mutex" ); + perror( "pthread_mutex_unlock" ); + } } } *************** *** 364,368 **** ( ctime.tv_usec-x->x_starttime.tv_usec )/1000; ttheoretical = ((x->x_nbframes)*1000 )/x->x_framerate; ! // post( "pdp-theorin~ : %d playing since : %lldms ( theory : %lldms )", // x->x_nbframes, tplaying, ttheoretical );
--- 366,370 ---- ( ctime.tv_usec-x->x_starttime.tv_usec )/1000; ttheoretical = ((x->x_nbframes)*1000 )/x->x_framerate; ! // post( "pdp_theorin~ : %d playing since : %lldms ( theory : %lldms )", // x->x_nbframes, tplaying, ttheoretical );
*************** *** 375,391 **** }
- // check end of file - if(!x->x_videoready && feof(x->x_infile)) - { - if ( x->x_loop ) - { - if ( fseek( x->x_infile, 0x0, SEEK_SET ) < 0 ) - { - post( "pdp_theorin~ : could not reset file." ); - perror( "fseek" ); - } - } - } - // read more data in if( ( x->x_audioin_position < MIN_AUDIO_SIZE ) || ( !x->x_newpicture && !x->x_newpictureready ) ) --- 377,380 ---- *************** *** 413,417 ****
twait.tv_sec = 0; ! twait.tv_nsec = 5000000; // 5 ms
schedprio.sched_priority = sched_get_priority_min(SCHED_FIFO) + x->x_priority; --- 402,406 ----
twait.tv_sec = 0; ! twait.tv_nsec = 10000000; // 10 ms
schedprio.sched_priority = sched_get_priority_min(SCHED_FIFO) + x->x_priority; *************** *** 450,454 ****
twait.tv_sec = 0; ! twait.tv_nsec = 10000000; // 10 ms
if ( x->x_infile == NULL ) --- 439,443 ----
twait.tv_sec = 0; ! twait.tv_nsec = 100000000; // 100 ms
if ( x->x_infile == NULL ) *************** *** 461,466 **** { x->x_newpicture = 0; x->x_reading = 0; ! post("pdp_theorin~ : waiting end of decoding..." ); while ( x->x_decoding ) nanosleep( &twait, NULL );
--- 450,456 ---- { x->x_newpicture = 0; + x->x_newpictureready = 0; x->x_reading = 0; ! // post("pdp_theorin~ : waiting end of decoding..." ); while ( x->x_decoding ) nanosleep( &twait, NULL );
*************** *** 493,497 **** x->x_notpackets = 0; x->x_novpackets = 0; - x->x_endoffile = 0; x->x_nbframes = 0; x->x_decoding = 0; --- 483,486 ---- *************** *** 516,520 **** if ( x->x_infile != NULL ) { ! post("pdp_theorin~ : open request but a file is open ... closing" ); pdp_theorin_close(x); } --- 505,509 ---- if ( x->x_infile != NULL ) { ! // post("pdp_theorin~ : open request but a file is open ... closing" ); pdp_theorin_close(x); } *************** *** 523,527 **** x->x_filename = (char*) malloc( strlen( s->s_name ) + 1 ); strcpy( x->x_filename, s->s_name ); ! post( "pdp_theorin~ : opening file : %s", x->x_filename );
if ( ( x->x_infile = fopen(x->x_filename,"r") ) == NULL ) --- 512,517 ---- x->x_filename = (char*) malloc( strlen( s->s_name ) + 1 ); strcpy( x->x_filename, s->s_name ); ! // post( "pdp_theorin~ : opening file : %s", x->x_filename ); ! x->x_audio = 1;
if ( ( x->x_infile = fopen(x->x_filename,"r") ) == NULL ) *************** *** 636,640 **** } } ! post( "pdp_theorin~ : parsed headers ok." );
// initialize decoders --- 626,630 ---- } } ! // post( "pdp_theorin~ : parsed headers ok." );
// initialize decoders *************** *** 643,650 **** theora_decode_init(&x->x_theora_state, &x->x_theora_info); x->x_framerate = (t_int)x->x_theora_info.fps_numerator/x->x_theora_info.fps_denominator; ! post("pdp_theorin~ : stream %x is theora %dx%d %d fps video.", ! x->x_statet.serialno, ! x->x_theora_info.width,x->x_theora_info.height, ! x->x_framerate); if(x->x_theora_info.width!=x->x_theora_info.frame_width || x->x_theora_info.height!=x->x_theora_info.frame_height) --- 633,640 ---- theora_decode_init(&x->x_theora_state, &x->x_theora_info); x->x_framerate = (t_int)x->x_theora_info.fps_numerator/x->x_theora_info.fps_denominator; ! // post("pdp_theorin~ : stream %x is theora %dx%d %d fps video.", ! // x->x_statet.serialno, ! // x->x_theora_info.width,x->x_theora_info.height, ! // x->x_framerate); if(x->x_theora_info.width!=x->x_theora_info.frame_width || x->x_theora_info.height!=x->x_theora_info.frame_height) *************** *** 664,671 **** break;; case OC_CS_ITU_REC_470M: ! post("pdp_theorin~ : encoder specified ITU Rec 470M (NTSC) color."); break;; case OC_CS_ITU_REC_470BG: ! post("pdp_theorin~ : encoder specified ITU Rec 470BG (PAL) color."); break;; default: --- 654,661 ---- break;; case OC_CS_ITU_REC_470M: ! // post("pdp_theorin~ : encoder specified ITU Rec 470M (NTSC) color."); break;; case OC_CS_ITU_REC_470BG: ! // post("pdp_theorin~ : encoder specified ITU Rec 470BG (PAL) color."); break;; default: *************** *** 691,697 **** x->x_audiochannels = x->x_vorbis_info.channels; x->x_samplerate = x->x_vorbis_info.rate; ! post("pdp_theorin~ : ogg logical stream %x is vorbis %d channel %d Hz audio.", ! x->x_statev.serialno, ! x->x_audiochannels, x->x_samplerate); } else --- 681,687 ---- x->x_audiochannels = x->x_vorbis_info.channels; x->x_samplerate = x->x_vorbis_info.rate; ! // post("pdp_theorin~ : ogg logical stream %x is vorbis %d channel %d Hz audio.", ! // x->x_statev.serialno, ! // x->x_audiochannels, x->x_samplerate); } else *************** *** 789,794 ****
// just read the buffer ! if ( x->x_audioon ) { sn=0; while (n--) --- 779,789 ----
// just read the buffer ! if ( x->x_audioon && x->x_reading ) { + if ( pthread_mutex_lock( &x->x_audiolock ) < 0 ) + { + post( "pdp_theorin~ : unable to lock audio mutex" ); + perror( "pthread_mutex_lock" ); + } sn=0; while (n--) *************** *** 817,820 **** --- 812,820 ---- // x->x_audioin_position, x->x_audiochannels ); } + if ( pthread_mutex_unlock( &x->x_audiolock ) < 0 ) + { + post( "pdp_theorin~ : unable to unlock audio mutex" ); + perror( "pthread_mutex_unlock" ); + } } else *************** *** 828,831 **** --- 828,833 ---- }
+ if ( !x->x_reading ) return (w+5); + // check if the framerate has been exceeded if ( gettimeofday(&etime, NULL) == -1) *************** *** 843,846 **** --- 845,853 ---- if ( x->x_newpicture ) { + if ( pthread_mutex_lock( &x->x_videolock ) < 0 ) + { + post( "pdp_theorin~ : unable to lock video mutex" ); + perror( "pthread_mutex_lock" ); + } pdp_packet_pass_if_valid(x->x_pdp_out, &x->x_packet0); x->x_newpicture = 0; *************** *** 849,859 **** x->x_nbframes++; x->x_secondcount++; outlet_float( x->x_outlet_nbframes, x->x_nbframes ); ! } if ( x->x_endoffile == 1 ) // only once { outlet_float( x->x_outlet_endoffile, x->x_endoffile ); - x->x_endoffile = 0; } if ( x->x_endoffile == -1 ) // reset --- 856,870 ---- x->x_nbframes++; x->x_secondcount++; + // post( "pdp_theorin~ : frame #%d", x->x_nbframes ); outlet_float( x->x_outlet_nbframes, x->x_nbframes ); ! if ( pthread_mutex_unlock( &x->x_videolock ) < 0 ) ! { ! post( "pdp_theorin~ : unable to unlock video mutex" ); ! perror( "pthread_mutex_unlock" ); ! } } if ( x->x_endoffile == 1 ) // only once { outlet_float( x->x_outlet_endoffile, x->x_endoffile ); } if ( x->x_endoffile == -1 ) // reset *************** *** 884,889 **** pdp_theorin_close(x); }
! post( "pdp_theorin~ : freeing object" ); }
--- 895,911 ---- pdp_theorin_close(x); } + + if ( pthread_mutex_destroy( &x->x_audiolock ) < 0 ) + { + post( "pdp_theorin~ : unable to destroy audio mutex" ); + perror( "pthread_mutex_destroy" ); + } + if ( pthread_mutex_destroy( &x->x_videolock ) < 0 ) + { + post( "pdp_theorin~ : unable to destroy video mutex" ); + perror( "pthread_mutex_destroy" ); + }
! // post( "pdp_theorin~ : freeing object" ); }
*************** *** 910,913 **** --- 932,947 ---- x->x_packet0 = -1; x->x_decodechild = 0; + if ( pthread_mutex_init( &x->x_audiolock, NULL ) < 0 ) + { + post( "pdp_theorin~ : unable to initialize audio mutex" ); + perror( "pthread_mutex_init" ); + return NULL; + } + if ( pthread_mutex_init( &x->x_videolock, NULL ) < 0 ) + { + post( "pdp_theorin~ : unable to initialize video mutex" ); + perror( "pthread_mutex_init" ); + return NULL; + } x->x_decoding = 0; x->x_theorainit = 0; *************** *** 928,932 **** x->x_blocksize = MIN_AUDIO_SIZE; x->x_autoplay = 1; - x->x_loop = 1; x->x_nextimage = 0; x->x_infile = NULL; --- 962,965 ---- *************** *** 958,962 **** class_addmethod(pdp_theorin_class, (t_method)pdp_theorin_audio, gensym("audio"), A_FLOAT, A_NULL); class_addmethod(pdp_theorin_class, (t_method)pdp_theorin_autoplay, gensym("autoplay"), A_FLOAT, A_NULL); - class_addmethod(pdp_theorin_class, (t_method)pdp_theorin_loop, gensym("loop"), A_FLOAT, A_NULL); class_addmethod(pdp_theorin_class, (t_method)pdp_theorin_threadify, gensym("thread"), A_FLOAT, A_NULL); class_addmethod(pdp_theorin_class, (t_method)pdp_theorin_bang, gensym("bang"), A_NULL); --- 991,994 ----