aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/help-pdp_distance.pd2
-rw-r--r--doc/help-pdp_rec~.pd2
-rw-r--r--doc/help-pdp_text.pd18
-rw-r--r--doc/rs_pdp_theonice~.pd103
-rw-r--r--modules/Makefile2
-rw-r--r--modules/pdp_ffmpeg~.c272
-rw-r--r--modules/pdp_live~.c97
7 files changed, 413 insertions, 83 deletions
diff --git a/doc/help-pdp_distance.pd b/doc/help-pdp_distance.pd
index 3451c85..cad3668 100644
--- a/doc/help-pdp_distance.pd
+++ b/doc/help-pdp_distance.pd
@@ -2,7 +2,7 @@
#X obj 341 20 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
-1;
#X msg 196 92 loop \$1;
-#X obj 197 70 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 1 1
+#X obj 197 70 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 1
;
#X msg 453 93 open \$1;
#X obj 452 69 openpanel;
diff --git a/doc/help-pdp_rec~.pd b/doc/help-pdp_rec~.pd
index 89b1e64..ffbf1b7 100644
--- a/doc/help-pdp_rec~.pd
+++ b/doc/help-pdp_rec~.pd
@@ -2,7 +2,7 @@
#X obj 255 34 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
-1;
#X msg 117 65 loop \$1;
-#X obj 117 40 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 1 1
+#X obj 117 40 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 1
;
#X msg 280 33 open \$1;
#X obj 342 33 openpanel;
diff --git a/doc/help-pdp_text.pd b/doc/help-pdp_text.pd
index 0b51dda..4bd5346 100644
--- a/doc/help-pdp_text.pd
+++ b/doc/help-pdp_text.pd
@@ -2,8 +2,8 @@
#X obj 152 627 pdp_xv;
#X obj 268 64 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
-1;
-#X msg 123 136 loop \$1;
-#X obj 124 114 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 1
+#X msg 158 123 loop \$1;
+#X obj 159 101 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0
1;
#X msg 370 44 open \$1;
#X obj 369 20 openpanel;
@@ -73,14 +73,6 @@
#X obj 380 594 hsl 128 15 0 1 0 0 empty empty empty -2 -6 0 8 -262144
-1 -1 0 1;
#X text 517 594 Alpha ( global );
-#X floatatom 73 91 5 0 0 0 - - -;
-#X floatatom 48 115 5 0 0 0 - - -;
-#X floatatom 21 150 5 0 0 0 - - -;
-#X obj 55 31 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
--1;
-#X obj 44 66 time;
-#X symbolatom 24 244 20 0 0 0 - - -;
-#X obj 24 213 makefilename %s:%s:%s;
#X connect 1 0 10 0;
#X connect 2 0 16 0;
#X connect 3 0 2 0;
@@ -128,9 +120,3 @@
#X connect 61 0 51 0;
#X connect 62 0 51 8;
#X connect 64 0 51 9;
-#X connect 68 0 72 0;
-#X connect 69 0 70 0;
-#X connect 70 0 68 0;
-#X connect 70 1 67 0;
-#X connect 70 2 66 0;
-#X connect 72 0 71 0;
diff --git a/doc/rs_pdp_theonice~.pd b/doc/rs_pdp_theonice~.pd
index 31602de..94d160b 100644
--- a/doc/rs_pdp_theonice~.pd
+++ b/doc/rs_pdp_theonice~.pd
@@ -2,7 +2,7 @@
#X obj 255 34 bng 15 250 50 0 empty empty empty 20 8 0 8 -262144 -1
-1;
#X msg 117 65 loop \$1;
-#X obj 117 40 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 1 1
+#X obj 117 40 tgl 15 0 empty empty empty 20 8 0 8 -262144 -1 -1 0 1
;
#X msg 278 48 open \$1;
#X obj 278 24 openpanel;
@@ -54,11 +54,9 @@
#X text 647 39 (patched) icecast server;
#X text 648 66 http://mediacast1.com/~karl;
#X text 647 53 the icecast server can be found here :;
-#X msg 384 237 passwd letmein;
#X text 579 585 before connecting;
#X msg 384 210 disconnect;
#X text 494 237 Setting up the password;
-#X text 627 184 Connect to an icecast server;
#X text 466 212 Disconnect;
#X text 577 598 ( or reconnect to the server );
#X msg 384 263 title the aesthetics of our anger;
@@ -66,7 +64,6 @@
#X msg 383 335 description images from infowar;
#X msg 384 309 url http://www.indymedia.org;
#X msg 384 285 artist recuerdos de luchas;
-#X msg 384 182 connect localhost theora.ogg 8000;
#X obj 356 98 pdp_theorin~;
#X floatatom 41 530 5 0 0 0 - - -;
#X text 83 531 Streaming status;
@@ -77,7 +74,7 @@
#X floatatom 124 594 5 0 0 0 - - -;
#X text 168 593 Emission framerate;
#X obj 23 304 pdp_spigot;
-#X obj 94 282 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
+#X obj 94 282 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
;
#X text 556 433 Video quality : [0 \, 63] \, default 2!;
#X floatatom 502 406 5 0 0 0 - - -;
@@ -101,6 +98,8 @@
#X obj 216 366 inlet~;
#X text 556 406 Framerate : [1 \, 100] \, default 7;
#X obj 159 490 pdp_theonice~;
+#X msg 384 182 connect localhost pula.ogg 8000;
+#X msg 384 237 passwd letmein;
#X connect 0 0 8 0;
#X connect 1 0 15 0;
#X connect 2 0 1 0;
@@ -115,61 +114,61 @@
#X connect 11 0 10 0;
#X connect 12 0 10 0;
#X connect 13 0 9 0;
-#X connect 15 0 76 0;
-#X connect 15 4 82 0;
-#X connect 15 4 93 0;
-#X connect 15 5 82 0;
-#X connect 15 5 93 1;
+#X connect 15 0 73 0;
+#X connect 15 4 79 0;
+#X connect 15 4 90 0;
+#X connect 15 5 79 0;
+#X connect 15 5 90 1;
#X connect 16 0 18 0;
#X connect 17 0 20 0;
#X connect 18 0 17 0;
#X connect 20 0 19 0;
-#X connect 26 0 76 0;
+#X connect 26 0 73 0;
#X connect 27 0 26 1;
#X connect 28 0 30 0;
-#X connect 29 0 62 0;
+#X connect 29 0 59 0;
#X connect 30 0 29 0;
-#X connect 30 0 86 1;
-#X connect 32 0 93 0;
-#X connect 33 0 93 0;
-#X connect 36 0 93 0;
-#X connect 37 0 93 0;
+#X connect 30 0 83 1;
+#X connect 32 0 90 0;
+#X connect 33 0 90 0;
+#X connect 36 0 90 0;
+#X connect 37 0 90 0;
#X connect 41 0 32 0;
#X connect 42 0 33 0;
#X connect 43 0 36 0;
#X connect 44 0 37 0;
-#X connect 49 0 93 0;
-#X connect 51 0 93 0;
-#X connect 56 0 93 0;
-#X connect 57 0 93 0;
-#X connect 58 0 93 0;
-#X connect 59 0 93 0;
-#X connect 60 0 93 0;
-#X connect 61 0 93 0;
-#X connect 62 0 93 0;
-#X connect 62 1 82 0;
-#X connect 62 1 93 0;
-#X connect 62 2 82 0;
-#X connect 62 2 93 1;
-#X connect 62 5 84 0;
-#X connect 71 1 25 0;
-#X connect 72 0 71 1;
-#X connect 74 0 75 0;
-#X connect 75 0 93 0;
-#X connect 76 0 71 0;
-#X connect 76 0 93 0;
-#X connect 81 0 25 0;
-#X connect 82 1 88 0;
-#X connect 82 1 87 0;
-#X connect 83 0 82 1;
-#X connect 84 0 85 0;
-#X connect 85 0 86 0;
-#X connect 86 0 29 0;
-#X connect 90 0 93 0;
-#X connect 91 0 93 1;
-#X connect 93 0 63 0;
-#X connect 93 1 65 0;
-#X connect 93 2 67 0;
-#X connect 93 3 69 0;
-#X connect 93 4 77 0;
-#X connect 93 5 79 0;
+#X connect 50 0 90 0;
+#X connect 54 0 90 0;
+#X connect 55 0 90 0;
+#X connect 56 0 90 0;
+#X connect 57 0 90 0;
+#X connect 58 0 90 0;
+#X connect 59 0 90 0;
+#X connect 59 1 79 0;
+#X connect 59 1 90 0;
+#X connect 59 2 79 0;
+#X connect 59 2 90 1;
+#X connect 59 5 81 0;
+#X connect 68 1 25 0;
+#X connect 69 0 68 1;
+#X connect 71 0 72 0;
+#X connect 72 0 90 0;
+#X connect 73 0 68 0;
+#X connect 73 0 90 0;
+#X connect 78 0 25 0;
+#X connect 79 1 85 0;
+#X connect 79 1 84 0;
+#X connect 80 0 79 1;
+#X connect 81 0 82 0;
+#X connect 82 0 83 0;
+#X connect 83 0 29 0;
+#X connect 87 0 90 0;
+#X connect 88 0 90 1;
+#X connect 90 0 60 0;
+#X connect 90 1 62 0;
+#X connect 90 2 64 0;
+#X connect 90 3 66 0;
+#X connect 90 4 74 0;
+#X connect 90 5 76 0;
+#X connect 91 0 90 0;
+#X connect 92 0 90 0;
diff --git a/modules/Makefile b/modules/Makefile
index bc263e7..a00c7d3 100644
--- a/modules/Makefile
+++ b/modules/Makefile
@@ -21,6 +21,6 @@ OBJECTS = pdp_intrusion.o pdp_yqt.o pdp_simura.o pdp_underwatch.o \
pdp_theorout~.o pdp_cropper.o pdp_background.o \
pdp_mapper.o pdp_theonice~.o pdp_icedthe~.o\
pdp_fdiff.o pdp_hue.o \
- # pdp_xcanvas.o pdp_aa.o
+ pdp_live~.o pdp_ffmpeg~.o # pdp_xcanvas.o pdp_aa.o
all_modules: $(OBJECTS)
diff --git a/modules/pdp_ffmpeg~.c b/modules/pdp_ffmpeg~.c
index fec1c35..f573a9a 100644
--- a/modules/pdp_ffmpeg~.c
+++ b/modules/pdp_ffmpeg~.c
@@ -112,6 +112,28 @@ static int pdp_ffmpeg_read_ffserver_streams(t_pdp_ffmpeg *x)
memcpy(st, ic->streams[i], sizeof(AVStream));
x->x_avcontext->streams[i] = st;
+#if FFMPEG_VERSION_INT >= 0x000409
+ if ( ic->streams[i]->codec->codec_type == CODEC_TYPE_UNKNOWN )
+ {
+ post( "pdp_ffmpeg~ : stream #%d # type : unknown", i );
+ }
+ if ( ic->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO )
+ {
+ post( "pdp_ffmpeg~ : stream #%d # type : audio # id : %d # bitrate : %d",
+ i, ic->streams[i]->codec->codec_id, ic->streams[i]->codec->bit_rate );
+ post( "pdp_ffmpeg~ : sample rate : %d # channels : %d",
+ ic->streams[i]->codec->sample_rate, ic->streams[i]->codec->channels );
+ x->x_nbaudiostreams++;
+ }
+ if ( ic->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
+ {
+ post( "pdp_ffmpeg~ : stream #%d # type : video # id : %d # bitrate : %d",
+ i, ic->streams[i]->codec->codec_id, ic->streams[i]->codec->bit_rate );
+ post( "pdp_ffmpeg~ : framerate : %d # width : %d # height : %d",
+ av_q2d( ic->streams[i]->r_frame_rate ), ic->streams[i]->codec->width, ic->streams[i]->codec->height );
+ x->x_nbvideostreams++;
+ }
+#else
if ( ic->streams[i]->codec.codec_type == CODEC_TYPE_UNKNOWN )
{
post( "pdp_ffmpeg~ : stream #%d # type : unknown", i );
@@ -132,6 +154,7 @@ static int pdp_ffmpeg_read_ffserver_streams(t_pdp_ffmpeg *x)
ic->streams[i]->codec.frame_rate/10000, ic->streams[i]->codec.width, ic->streams[i]->codec.height );
x->x_nbvideostreams++;
}
+#endif
}
if ( x->x_secondcount ) free( x->x_secondcount );
@@ -188,7 +211,11 @@ static void pdp_ffmpeg_starve(t_pdp_ffmpeg *x)
for(i=0;i<x->x_avcontext->nb_streams;i++)
{
+#if FFMPEG_VERSION_INT >= 0x000409
+ avcodec_close( x->x_avcontext->streams[i]->codec );
+#else
avcodec_close( &x->x_avcontext->streams[i]->codec );
+#endif
av_free( x->x_avcontext->streams[i] );
}
@@ -247,7 +274,11 @@ static void pdp_ffmpeg_feed(t_pdp_ffmpeg *x, t_symbol *s)
for(i=0;i<x->x_avcontext->nb_streams;i++)
{
AVCodec *codec;
+#if FFMPEG_VERSION_INT >= 0x000409
+ codec = avcodec_find_encoder(x->x_avcontext->streams[i]->codec->codec_id);
+#else
codec = avcodec_find_encoder(x->x_avcontext->streams[i]->codec.codec_id);
+#endif
if (!codec)
{
post("pdp_ffmpeg~ : unsupported codec for output stream #%d\n", i );
@@ -255,7 +286,11 @@ static void pdp_ffmpeg_feed(t_pdp_ffmpeg *x, t_symbol *s)
outlet_float( x->x_outlet_streaming, x->x_streaming );
return;
}
+#if FFMPEG_VERSION_INT >= 0x000409
+ if (avcodec_open(x->x_avcontext->streams[i]->codec, codec) < 0)
+#else
if (avcodec_open(&x->x_avcontext->streams[i]->codec, codec) < 0)
+#endif
{
post("pdp_ffmpeg~ : error while opening codec for stream #%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", i);
x->x_streaming = 0;
@@ -371,8 +406,240 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x)
// output all video streams
svideoindex=0;
saudioindex=0;
- for (i=0; i<x->x_avcontext->nb_streams; i++)
- {
+#if FFMPEG_VERSION_INT >= 0x000409
+ for (i=0; i<x->x_avcontext->nb_streams; i++)
+ {
+ /* convert pixel format and size if needed */
+ if ( x->x_avcontext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
+ {
+ t_int size;
+
+ // check if the framerate has been exceeded
+ if ( gettimeofday(&etime, NULL) == -1)
+ {
+ post("pdp_ffmpeg~ : could not read time" );
+ }
+ if ( etime.tv_sec != x->x_cursec )
+ {
+ x->x_cursec = etime.tv_sec;
+ outlet_float( x->x_outlet_framerate, x->x_secondcount[ svideoindex ] );
+ for (j=0; j<x->x_nbvideostreams; j++)
+ {
+ x->x_secondcount[ j ] = 0;
+ }
+ }
+ framerate = av_q2d( x->x_avcontext->streams[i]->r_frame_rate );
+ 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;
+ }
+
+ if ( x->x_avcontext->streams[i]->codec->pix_fmt != PIX_FMT_YUV420P )
+ {
+ /* create temporary picture */
+ size = avpicture_get_size(x->x_avcontext->streams[i]->codec->pix_fmt,
+ x->x_vwidth, x->x_vheight );
+ if (!x->x_buf1) x->x_buf1 = (uint8_t*) malloc(size);
+ if (!x->x_buf1)
+ {
+ post ("pdp_ffmpeg~ : severe error : could not allocate image buffer" );
+ return;
+ }
+ x->x_formatted_picture = &x->x_picture_format;
+ avpicture_fill(x->x_formatted_picture, x->x_buf1,
+ x->x_avcontext->streams[i]->codec->pix_fmt,
+ x->x_vwidth, x->x_vheight );
+
+ if (img_convert(x->x_formatted_picture,
+ x->x_avcontext->streams[i]->codec->pix_fmt,
+ &pdppict, PIX_FMT_YUV420P,
+ x->x_vwidth, x->x_vheight ) < 0)
+ {
+ post ("pdp_ffmpeg~ : error : image conversion failed" );
+ }
+ }
+ else
+ {
+ x->x_formatted_picture = &pdppict;
+ }
+
+ // post ( "pdp_ffmpeg~ : resampling [%d,%d] -> [%d,%d]",
+ // x->x_vwidth, x->x_vheight,
+ // x->x_avcontext->streams[i]->codec->width,
+ // x->x_avcontext->streams[i]->codec->height );
+ if ( ( x->x_avcontext->streams[i]->codec->width < x->x_vwidth ) &&
+ ( x->x_avcontext->streams[i]->codec->height < x->x_vheight ) )
+ {
+ owidth = x->x_avcontext->streams[i]->codec->width;
+ oheight = x->x_avcontext->streams[i]->codec->height;
+
+ if (x->x_img_resample_ctx) img_resample_close(x->x_img_resample_ctx);
+
+#if LIBAVCODEC_BUILD > 4715
+ x->x_img_resample_ctx = img_resample_full_init(
+ owidth, oheight,
+ x->x_vwidth, x->x_vheight,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0);
+#else
+ x->x_img_resample_ctx = img_resample_full_init(
+ owidth, oheight,
+ x->x_vwidth, x->x_vheight, 0, 0, 0, 0);
+#endif
+
+ size = avpicture_get_size(x->x_avcontext->streams[i]->codec->pix_fmt,
+ owidth, oheight );
+ if ( !x->x_buf2 )
+ {
+ x->x_buf2 = (uint8_t*) malloc(size);
+ }
+ if (!x->x_buf2)
+ {
+ post ("pdp_ffmpeg~ : severe error : could not allocate image buffer" );
+ return;
+ }
+ x->x_final_picture = &x->x_picture_final;
+ avpicture_fill(x->x_final_picture, x->x_buf2,
+ x->x_avcontext->streams[i]->codec->pix_fmt,
+ owidth, oheight );
+
+ img_resample(x->x_img_resample_ctx, x->x_final_picture, x->x_formatted_picture);
+
+ }
+ else
+ {
+ x->x_final_picture = x->x_formatted_picture;
+ }
+
+ // encode and send the picture
+ {
+ AVFrame aframe;
+#if LIBAVCODEC_BUILD > 4715
+ AVPacket vpkt;
+#endif
+ 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,
+ x->x_video_buffer, VIDEO_BUFFER_SIZE,
+ &aframe);
+
+#if LIBAVCODEC_BUILD > 4715
+ av_init_packet(&vpkt);
+
+ vpkt.pts = aframe.pts;
+ if(x->x_avcontext->streams[i]->codec->coded_frame->key_frame)
+ vpkt.flags |= PKT_FLAG_KEY;
+ vpkt.stream_index= i;
+ vpkt.data= (uint8_t *)x->x_video_buffer;
+ vpkt.size= fsize;
+
+ if ( ( ret = av_write_frame( x->x_avcontext, &vpkt) ) < 0 )
+#else
+ if ( ( ret = av_write_frame( x->x_avcontext, i, x->x_video_buffer, fsize) ) < 0 )
+#endif
+ {
+ post ("pdp_ffmpeg~ : error : could not send frame : (ret=%d)", ret );
+ return;
+ }
+ else
+ {
+ x->x_nbframes++;
+ x->x_secondcount[ svideoindex ]++;
+ // post ("pdp_ffmpeg~ : index=%d count=%d", svideoindex, x->x_secondcount[ svideoindex ] );
+ svideoindex++;
+ }
+ }
+ }
+
+ /* convert and stream audio data */
+ if ( x->x_avcontext->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO )
+ {
+ // we assume audio is synchronized on next video stream
+ if ( ( (i+1) < x->x_avcontext->nb_streams ) &&
+ ( x->x_avcontext->streams[i+1]->codec->codec_type == CODEC_TYPE_VIDEO ) )
+ {
+ x->x_audio_per_frame =
+ // 2*( (int) sys_getsr() ) / av_q2d( x->x_avcontext->streams[i+1]->r_frame_rate ) ;
+ AUDIO_PACKET_SIZE;
+ // post ("pdp_ffmpeg~ : transmit %d samples", x->x_audio_per_frame );
+ }
+ else
+ {
+ post ("pdp_ffmpeg~ : can't stream audio : video stream is not found" );
+ continue;
+ }
+
+ if ( x->x_audioin_position > x->x_audio_per_frame )
+ {
+ size = x->x_audioin_position;
+ if ( ( x->x_avcontext->streams[i]->codec->sample_rate != (int)sys_getsr() ) ||
+ ( x->x_avcontext->streams[i]->codec->channels != 2 ) )
+ {
+ if (x->x_audio_resample_ctx) audio_resample_close(x->x_audio_resample_ctx);
+ x->x_audio_resample_ctx =
+ audio_resample_init(x->x_avcontext->streams[i]->codec->channels, 2,
+ x->x_avcontext->streams[i]->codec->sample_rate,
+ (int)sys_getsr());
+ sizeout = audio_resample(x->x_audio_resample_ctx,
+ x->x_audio_enc_buf,
+ x->x_audio_buf,
+ size / (x->x_avcontext->streams[i]->codec->channels * 2));
+ pencbuf = (short*) &x->x_audio_enc_buf;
+ sizeout = sizeout * x->x_avcontext->streams[i]->codec->channels * 2;
+ }
+ else
+ {
+ pencbuf = (short*) &x->x_audio_buf;
+ sizeout = size;
+ }
+
+ /* output resampled raw samples */
+ fifo_write(&x->x_audio_fifo[saudioindex], (uint8_t*)pencbuf, sizeout,
+ &x->x_audio_fifo[saudioindex].wptr);
+
+ framebytes = x->x_avcontext->streams[i]->codec->frame_size * 2 *
+ x->x_avcontext->streams[i]->codec->channels;
+
+ while (fifo_read(&x->x_audio_fifo[saudioindex], (uint8_t*)pencbuf, framebytes,
+ &x->x_audio_fifo[saudioindex].rptr) == 0)
+ {
+#if LIBAVCODEC_BUILD > 4715
+ AVPacket apkt;
+#endif
+ encsize = avcodec_encode_audio(x->x_avcontext->streams[i]->codec,
+ (uint8_t*)&x->x_audio_out, sizeof(x->x_audio_out),
+ (short *)pencbuf);
+#if LIBAVCODEC_BUILD > 4715
+ av_init_packet(&apkt);
+
+ apkt.pts = etime.tv_sec*1000000 + etime.tv_usec;
+ if(x->x_avcontext->streams[i]->codec->coded_frame->key_frame)
+ apkt.flags |= PKT_FLAG_KEY;
+ apkt.stream_index= i;
+ apkt.data= (uint8_t *)x->x_audio_out;
+ apkt.size= encsize;
+
+ av_write_frame(x->x_avcontext, &apkt);
+#else
+ av_write_frame(x->x_avcontext, i, x->x_audio_out, encsize);
+#endif
+ }
+ saudioindex++;
+ }
+ }
+ }
+#else
+ for (i=0; i<x->x_avcontext->nb_streams; i++)
+ {
/* convert pixel format and size if needed */
if ( x->x_avcontext->streams[i]->codec.codec_type == CODEC_TYPE_VIDEO )
{
@@ -601,6 +868,7 @@ static void pdp_ffmpeg_process_yv12(t_pdp_ffmpeg *x)
}
}
}
+#endif
x->x_audioin_position=0;
}
return;
diff --git a/modules/pdp_live~.c b/modules/pdp_live~.c
index 2404aba..8b5e69d 100644
--- a/modules/pdp_live~.c
+++ b/modules/pdp_live~.c
@@ -276,7 +276,11 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
while (length > 0)
{
if ( !x->x_streaming ) break;
+#if FFMPEG_VERSION_INT >= 0x000409
+ switch(x->x_avcontext->streams[x->x_pkt.stream_index]->codec->codec_type)
+#else
switch(x->x_avcontext->streams[x->x_pkt.stream_index]->codec.codec_type)
+#endif
{
case CODEC_TYPE_AUDIO:
if ( !x->x_audio )
@@ -284,7 +288,11 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
av_free_packet(&x->x_pkt);
return 0;
}
+#if FFMPEG_VERSION_INT >= 0x000409
+ chunksize = avcodec_decode_audio(x->x_avcontext->streams[x->x_pkt.stream_index]->codec,
+#else
chunksize = avcodec_decode_audio(&x->x_avcontext->streams[x->x_pkt.stream_index]->codec,
+#endif
&x->x_audio_buf[0], &audiosize,
pcktptr, length);
if (chunksize < 0)
@@ -316,6 +324,21 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
// x->x_avcontext->streams[x->x_pkt.stream_index]->codec.channels,
// (int)sys_getsr(), 2, x->x_audioin_position );
+#if FFMPEG_VERSION_INT >= 0x000409
+ x->x_audiochannels = x->x_avcontext->streams[x->x_pkt.stream_index]->codec->channels;
+ x->x_samplerate = x->x_avcontext->streams[x->x_pkt.stream_index]->codec->sample_rate;
+ if (x->x_audio_resample_ctx) audio_resample_close(x->x_audio_resample_ctx);
+ x->x_audio_resample_ctx =
+ audio_resample_init(DEFAULT_CHANNELS,
+ x->x_avcontext->streams[x->x_pkt.stream_index]->codec->channels,
+ (int)sys_getsr(),
+ x->x_avcontext->streams[x->x_pkt.stream_index]->codec->sample_rate);
+
+ sizeout = audio_resample(x->x_audio_resample_ctx,
+ &x->x_audio_in[x->x_audioin_position],
+ &x->x_audio_buf[0],
+ audiosize/(x->x_avcontext->streams[x->x_pkt.stream_index]->codec->channels * sizeof(short)));
+#else
x->x_audiochannels = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.channels;
x->x_samplerate = x->x_avcontext->streams[x->x_pkt.stream_index]->codec.sample_rate;
if (x->x_audio_resample_ctx) audio_resample_close(x->x_audio_resample_ctx);
@@ -329,6 +352,7 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
&x->x_audio_in[x->x_audioin_position],
&x->x_audio_buf[0],
audiosize/(x->x_avcontext->streams[x->x_pkt.stream_index]->codec.channels * sizeof(short)));
+#endif
sizeout = sizeout * DEFAULT_CHANNELS;
if ( ( x->x_audioin_position + sizeout ) < 3*MAX_AUDIO_PACKET_SIZE )
@@ -354,6 +378,25 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
case CODEC_TYPE_VIDEO:
+#if FFMPEG_VERSION_INT >= 0x000409
+ 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
+
+ x->x_framerate = ( t_int ) av_q2d( x->x_avcontext->streams[x->x_pkt.stream_index]->r_frame_rate );
+ if ( x->x_framerate == 0 ) x->x_framerate = DEFAULT_FRAME_RATE;
+ x->x_videoindex = x->x_pkt.stream_index;
+
+ chunksize = avcodec_decode_video(
+ x->x_avcontext->streams[x->x_pkt.stream_index]->codec,
+ &frame, &pictureok,
+ pcktptr, length);
+ if ( x->x_avcontext->streams[x->x_pkt.stream_index]->codec->pix_fmt != PIX_FMT_YUV420P )
+ {
+ post( "pdp_live~ : unsupported image format : %d",
+ x->x_avcontext->streams[x->x_pkt.stream_index]->codec->pix_fmt );
+ pictureok = 0;
+ }
+#else
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
@@ -371,15 +414,7 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
x->x_avcontext->streams[x->x_pkt.stream_index]->codec.pix_fmt );
pictureok = 0;
}
- // post( "pdp_live~ : decoded new frame : type=%d format=%d (w=%d) (h=%d) (linesizes=%d,%d,%d,%d)",
- // frame.pict_type,
- // x->x_avcontext->streams[x->x_pkt.stream_index]->codec.pix_fmt,
- // x->x_avcontext->streams[x->x_pkt.stream_index]->codec.width,
- // x->x_avcontext->streams[x->x_pkt.stream_index]->codec.height,
- // frame.linesize[0],
- // frame.linesize[1],
- // frame.linesize[2],
- // frame.linesize[3] );
+#endif
x->x_picture_decoded = *(AVPicture*)&frame;
x->x_avcontext->streams[x->x_pkt.stream_index]->quality= frame.quality;
if (chunksize < 0)
@@ -403,8 +438,13 @@ static t_int pdp_live_decode_packet(t_pdp_live *x)
perror( "pthread_mutex_lock" );
}
x->x_newpicture=1;
+#if FFMPEG_VERSION_INT >= 0x000409
+ 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;
+#else
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;
+#endif
x->x_vsize = x->x_vwidth*x->x_vheight;
// create a new pdp packet from BITMAP YV12 image format
@@ -543,7 +583,6 @@ static void *pdp_live_connect_to_url(void *tdata)
memset(&x->x_avparameters, 0, sizeof(AVFormatParameters));
x->x_avparameters.sample_rate = sys_getsr();
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;
@@ -584,6 +623,31 @@ static void *pdp_live_connect_to_url(void *tdata)
{
AVStream *st;
+#if FFMPEG_VERSION_INT >= 0x000409
+ if ( x->x_avcontext->streams[i]->codec->codec_type == CODEC_TYPE_UNKNOWN )
+ {
+ post( "pdp_live~ : stream #%d # type : unknown", i );
+ }
+ if ( x->x_avcontext->streams[i]->codec->codec_type == CODEC_TYPE_AUDIO )
+ {
+ post( "pdp_live~ : stream #%d # type : audio # id : %d # bitrate : %d",
+ i, x->x_avcontext->streams[i]->codec->codec_id, x->x_avcontext->streams[i]->codec->bit_rate );
+ post( "pdp_live~ : sample rate : %d # channels : %d",
+ x->x_avcontext->streams[i]->codec->sample_rate, x->x_avcontext->streams[i]->codec->channels );
+ x->x_nbaudiostreams++;
+ }
+ if ( x->x_avcontext->streams[i]->codec->codec_type == CODEC_TYPE_VIDEO )
+ {
+ post( "pdp_live~ : stream #%d # type : video # id : %d # bitrate : %d",
+ i, x->x_avcontext->streams[i]->codec->codec_id,
+ x->x_avcontext->streams[i]->codec->bit_rate );
+ post( "pdp_live~ : framerate : %d # width : %d # height : %d",
+ av_q2d( x->x_avcontext->streams[i]->r_frame_rate )/10000,
+ x->x_avcontext->streams[i]->codec->width,
+ x->x_avcontext->streams[i]->codec->height );
+ x->x_nbvideostreams++;
+ }
+#else
if ( x->x_avcontext->streams[i]->codec.codec_type == CODEC_TYPE_UNKNOWN )
{
post( "pdp_live~ : stream #%d # type : unknown", i );
@@ -607,6 +671,7 @@ static void *pdp_live_connect_to_url(void *tdata)
x->x_avcontext->streams[i]->codec.height );
x->x_nbvideostreams++;
}
+#endif
}
/* open each decoder */
@@ -614,7 +679,11 @@ static void *pdp_live_connect_to_url(void *tdata)
{
AVCodec *codec;
post("pdp_live~ : opening decoder for stream #%d", i);
+#if FFMPEG_VERSION_INT >= 0x000409
+ codec = avcodec_find_decoder(x->x_avcontext->streams[i]->codec->codec_id);
+#else
codec = avcodec_find_decoder(x->x_avcontext->streams[i]->codec.codec_id);
+#endif
if (!codec)
{
post("pdp_live~ : unsupported codec for output stream #%d\n", i );
@@ -624,7 +693,11 @@ static void *pdp_live_connect_to_url(void *tdata)
x->x_avcontext = av_mallocz(sizeof(AVFormatContext));
pthread_exit(NULL);
}
+#if FFMPEG_VERSION_INT >= 0x000409
+ if (avcodec_open(x->x_avcontext->streams[i]->codec, codec) < 0)
+#else
if (avcodec_open(&x->x_avcontext->streams[i]->codec, codec) < 0)
+#endif
{
post("pdp_live~ : error while opening codec for stream #%d - maybe incorrect parameters such as bit_rate, rate, width or height\n", i);
x->x_streaming = 0;
@@ -703,7 +776,11 @@ static void pdp_live_disconnect(t_pdp_live *x)
/* close each decoder */
for(i=0;i<x->x_avcontext->nb_streams;i++)
{
+#if FFMPEG_VERSION_INT >= 0x000409
+ if (avcodec_close(x->x_avcontext->streams[i]->codec) < 0)
+#else
if (avcodec_close(&x->x_avcontext->streams[i]->codec) < 0)
+#endif
{
post("pdp_live~ : error while closing codec for stream #%d", i);
}