Summary:ASTERISK-14451: [patch] [branch] RTMP support in Asterisk
Reporter:phsultan (phsultan)Labels:patch
Date Opened:2009-07-10 07:30:54Date Closed:
Versions:Frequency of
Environment:Attachments:( 0) deleolajide-chan_rtmp.c
( 1) jtodd-sip-debug.txt
Description:I created a new branch that implements Adobe's RTMP (Real Time Media Protocol).

It allows Asterisk to connect as a client to an RTMP media server like Red5 or FMS (Flash Media Server), and then publish or receive media streams from such server. I only tested the connection with Red5.

To install the branch, you'll need several libavcodec, included in FFMPEG version 0.6. Be careful to configure FFMPEG's sources with the --enable-shared option activated in the configure script.

Prior to install Asterisk, you need to have librtmp on your system. librtmp is part of the rtmpdump program : http://rtmpdump.mplayerhq.hu/

To install it :
# wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.2e.tar.gz [^]
# tar zxvf rtmpdump-2.2e.tar.gz
# cd rtmpdump-2.2e/
# make
# make install

To install Asterisk :
# svn co http://svn.digium.com/svn/asterisk/team/phsultan/rtmp-support asterisk-rtmp
# cd asterisk-rtmp
# ./configure
# make menuselect
[check here that chan_rtmp is eligible for installation]
# make
# make install


Audio packets only are supported for the moment.

A documentation file is available (doc/rtmp.txt), as well as a sample configuration file (configs/rtmp.conf.sample).
Comments:By: Olle Johansson (oej) 2009-07-12 03:15:46

This is going to be a lot of fun!

By: dlogan (dlogan) 2009-07-15 05:42:08

Can you advise where FFMPEG 0.0.5 src can be downloaded from - the site only seems to have links to V0.5 and trunk.

I have tried compiling against 0.5 - but there are warnings at compile time and Asterisk seg faults.

== Spawn extension (default, 500, 1) exited non-zero on 'SIP/snom-00d614d8'
 -- Executing [1002@default:1] Dial("SIP/snom-00d614d8", "RTMP/writestream/readstream") in new stack
Segmentation fault

This is a very exciting channel - I am very keen to get this built and working.

FYI I am attempting to connect to FMS 3.5.1

Finally - we are testing with trunk built on 64bit linux - could this be an issue with the FFMPEG environment.

By: phsultan (phsultan) 2009-07-15 06:17:54

The version of FFMPEG to use is indeed 0.5, I'll correct the ticket description.

Do you see any warning when compiling Asterisk, or only FFMPEG? You can also try to compile FFMPEG with the following options :
--disable-optimizations --disable-mmx

Also, can you provide a backtrace of the core file generated by Asterisk after the segfault?

Thanks for your testing!

By: dlogan (dlogan) 2009-07-15 06:18:52

More of a feature suggestion - but with flash 10 and Asterisk both supporting speex - could this remove the need for ffmpeg all together?

By: dlogan (dlogan) 2009-07-15 06:29:13

warnings from asterisk compile time

  [CC] chan_rtmp.c -> chan_rtmp.o
chan_rtmp.c:301: warning: initialisation from incompatible pointer type
chan_rtmp.c: In function â??rtmp_newâ??:
chan_rtmp.c:601: warning: passing argument 9 of â??__ast_channel_allocâ?? makes integer from pointer without a cast
chan_rtmp.c:601: warning: passing argument 13 of â??__ast_channel_allocâ?? makes pointer from integer without a cast
chan_rtmp.c:601: warning: format not a string literal and no format arguments
chan_rtmp.c: In function â??check_handshake_replyâ??:
chan_rtmp.c:958: warning: format â??%dâ?? expects type â??intâ??, but argument 6 has type â??size_tâ??
chan_rtmp.c: In function â??rtmp_set_stringâ??:
chan_rtmp.c:1882: warning: format â??%dâ?? expects type â??intâ??, but argument 7 has type â??size_tâ??
chan_rtmp.c:1882: warning: format â??%dâ?? expects type â??intâ??, but argument 8 has type â??size_tâ??
chan_rtmp.c: In function â??rtmp_set_numberâ??:
chan_rtmp.c:1902: warning: format â??%dâ?? expects type â??intâ??, but argument 6 has type â??long unsigned intâ??
chan_rtmp.c: In function â??rtmp_set_objectâ??:
chan_rtmp.c:1959: warning: format â??%dâ?? expects type â??intâ??, but argument 7 has type â??size_tâ??
chan_rtmp.c:1959: warning: format â??%dâ?? expects type â??intâ??, but argument 9 has type â??size_tâ??
chan_rtmp.c:1994: warning: format â??%dâ?? expects type â??intâ??, but argument 6 has type â??long intâ??
chan_rtmp.c: In function â??rtmp_send_messageâ??:
chan_rtmp.c:2074: warning: format â??%dâ?? expects type â??intâ??, but argument 9 has type â??size_tâ??
chan_rtmp.c: In function â??rtmp_handle_connection_messageâ??:
chan_rtmp.c:2475: warning: the address of â??levelâ?? will always evaluate as â??trueâ??
chan_rtmp.c:2476: warning: the address of â??codeâ?? will always evaluate as â??trueâ??
chan_rtmp.c:2477: warning: the address of â??descriptionâ?? will always evaluate as â??trueâ??
chan_rtmp.c: In function â??rtmp_handle_audio_packetâ??:
chan_rtmp.c:2626: warning: â??avcodec_decode_audio2â?? is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3194)

By: dlogan (dlogan) 2009-07-15 06:42:29


#0  0x00007f9c0298ffb1 in strncpy () from /lib/libc.so.6
(gdb) bt
#0  0x00007f9c0298ffb1 in strncpy () from /lib/libc.so.6
#1  0x00007f9bf0fa8d65 in rtmp_request (type=<value optimized out>, format=<value optimized out>, data=<value optimized out>, cause=<value optimized out>)
   at /usr/include/bits/string3.h:122
#2  0x000000000045389e in ast_request (type=0x7f9be33a9dc0 "RTMP", format=64, requestor=0xc6b528, data=0x7f9be33aa6d0, cause=0x7f9be33aa0b8) at channel.c:4406
#3  0x00007f9bf5b3dc8c in dial_exec_full (chan=0xc6b528, data=<value optimized out>, peerflags=0x7f9be33aa870, continue_exec=0x0) at app_dial.c:1879
#4  0x00007f9bf5b40d76 in dial_exec (chan=0xc4af94, data=0x0) at app_dial.c:2452
ASTERISK-1  0x00000000004c4ce0 in pbx_exec (c=0xc6b528, app=0x7f9bfc496a70, data=0x7f9be33acda0 "RTMP/writestream/readstream") at pbx.c:1369
ASTERISK-2  0x00000000004ce6a4 in pbx_extension_helper (c=0xc6b528, con=<value optimized out>, context=0xc6b900 "default", exten=0xc6b950 "1002", priority=1, label=0x0,
   callerid=0xbf3b10 "snom", action=E_SPAWN, found=0x7f9be33aef0c, combined_find_spawn=1) at pbx.c:4028
ASTERISK-3  0x00000000004d0719 in __ast_pbx_run (c=0xc6b528, args=0x0) at pbx.c:4507
ASTERISK-4  0x00000000004d1b8b in pbx_thread (data=0xc4af94) at pbx.c:4884
ASTERISK-5  0x0000000000508dfc in dummy_start (data=<value optimized out>) at utils.c:968
ASTERISK-6 0x00007f9c021993ba in start_thread () from /lib/libpthread.so.0
ASTERISK-7 0x00007f9c029f4fcd in clone () from /lib/libc.so.6
ASTERISK-8 0x0000000000000000 in ?? ()

By: dlogan (dlogan) 2009-07-15 07:15:14

I have also now installed red5 for testing - can you advise what app you are running on red5 for testing - any details about running a red5 test - then we can prove if it is an asterisk or fms issue. I will be available later to do more testing.

By: dlogan (dlogan) 2009-07-15 07:51:09

red5 update - i am seeing asterisk connect in the red5 logs when i start asterisk - i also see a ping on the asterisk console from red5.

but as soon as i try to call red5 i get the seg fault.

By: phsultan (phsultan) 2009-07-16 10:53:40

I've been testing the Publisher demo application from Red5 for my tests. You should set the Buffer value to 0 under the Server tag, and the Timeout value to 0 under the Audio tag. I think we can check why Asterisk does not connect to FMS later (I know there are subtle differences in the connection handling process between FMS and Red5).

After that you can play the stream Asterisk is publishing, and publish back a stream named of your choice that will be read by Asterisk.

I think the fact that you're running this code on a 64 bits computer might cause problems, and the endianness certainly will as well. Just for information, I'm running a 32 bits / little endian computer.

I've just committed code that should fix the Asterisk related warnings. However, I can't really explain why the deprecation message for the avcodec_decode_audio2 does not show up on my computer.

Also, I committed the configure file, so you won't need to run the bootstrap.sh script before configure.

Finally, you're right, if we properly implement Speex pass-through in this code, we won't need FFMPEG to resample or transcode the media packets. That's something we need to add!

Thanks a lot for your valuable input.

By: dlogan (dlogan) 2009-07-16 12:37:05

Thanks for the update - I will make a test environment using Fedora 32bit.

By: dlogan (dlogan) 2009-07-16 19:25:03

compile error:

chan_rtmp.c:2486: error: expected ‘:’ before ‘)’ token

simple , typo!

By: phsultan (phsultan) 2009-07-17 03:28:49

Oops, that's what you get when you commit code without running make first. Sorry, now fixed.

By: dlogan (dlogan) 2009-07-17 04:43:21

Update: I have built it and it is now working with red5 - so I will now try some tests against FMS - I will let you know how it goes.

One question - when you start asterisk it connects to red5 - is this connection essential at start up - as it results in asterisk being very tightly coupled to red5.  would it be possible to only connect when a calls are live - so that asterisk will run even if red5 is down (obviously it would not be able to place calls without the server being up).

Then another feature could be the ability to configure more than one red5 / fms server in the rtmp.conf

Exciting stuff - this is a great project.

By: dlogan (dlogan) 2009-07-17 05:07:44

just run a quick test on FMS 3.5

Asterisk started - so it seemed to connect although we did not see anything on the FMS console. We also did not see any pings back from FMS to Asterisk like we do from Red5.

We then tried to route a call - Asterisk thought it worked - but then dropped the call after a couple of mins - FMS did not see the RTMP.

I am very happy to help test here - do you have any suggestions / comments.  I am also going to run some tests on Wowza.

By: dlogan (dlogan) 2009-07-17 13:50:45

Is it possible to configure the codec settings in rtmp.conf - so we can set the sample bit rate etc for nelly or any other codecs that can be supported?

By: phsultan (phsultan) 2009-07-25 04:23:51

dlogan, just a note to let you know that I won't have much time to commit code for the upcoming couple of weeks.

Thanks for your suggestions to improve the code, we definitely need to handle Speex and connect to FMS.

I can give a hand when I'm back!

By: dlogan (dlogan) 2009-07-27 16:39:56

Let me know when you are back and I will resume testing.

By: Adam Lis (adamlis) 2009-09-11 03:51:26

I've done checkout of repo this week.

1st issue: configuration variable global->port is not used in connection - it is parsed and assigned to variable "port", but network connection is done to constant value not this variable "port"

2nd issue: I'm getting "Floating point exception" on below environment:

Debian GNU/Linux i386/i686 Lenny 5.0.2 + mixed packages from Debian Squeeze (testing).

Basically all environment and packages are taken from Debian Stable Lenny, but:

1) ffmpeg packages:

||/ Name                                   Version                                Description
ii  libavcodec-dev                         4:0.5+svn20090706-2                    development files for libavcodec
ii  libavcodec52                           4:0.5+svn20090706-2                    ffmpeg codec library
ii  libavutil-dev                          4:0.5+svn20090706-2                    development files for libavutil
ii  libavutil49                            4:0.5+svn20090706-2                    ffmpeg utility library
ii  libdirac-encoder0                      1.0.2-2                                open and royalty free high quality codec - encoder library
ii  libgsm1                                1.0.13-1                               Shared libraries for GSM speech compressor
ii  liboil0.3                              0.3.16-1                               Library of Optimized Inner Loops
ii  libopenjpeg2                           1.3+dfsg-4                             JPEG 2000 image compression/decompression library
ii  libschroedinger-1.0-0                  1.0.7-2                                library for encoding/decoding of Dirac video streams
ii  libspeex1                              1.2~rc1-1                              The Speex codec runtime library

2) speex packages:

ii  libspeex-dev                           1.2~rc1-1                              The Speex codec library development files
ii  libspeexdsp-dev                        1.2~rc1-1                              The Speex extended library development files
ii  libspeexdsp1                           1.2~rc1-1                              The Speex extended runtime library
ii  speex                                  1.2~rc1-1                              The Speex codec command line tools

Other stuff (gcc, g++, cpp) is taken from Debian Lenny stable.

Asterisk that has been taken from your SVN compile without errors nor warnings.

Modules chan_rtmp connects to my FMS2 server (Red5 too).

Asterisk is configured using "make samples" + rtmp.conf adjusted to our server location/port/application.

Then I'm trying to redirect simple exten do RTMP:

exten => 400,1,Answer
exten => 400,n(hihi),BackGround(demo-congrats)  ; Play a congratulatory message
exten => 400,n,Wait(5)
exten => 400,n,HangUp()

By calling from Asterisk CLI:
localhost*CLI> originate RTMP/NetStream/NetStream extension 400@greeting

I see channels are being registered on FMS2 site - there is kind of system log of FMS available.

Then output of this 'originate' command:

localhost*CLI> originate RTMP/NetStream/NetStream extension 400@greeting
Sending createStream request for stream with id 1.000000
Sending createStream request for stream with id 2.000000
[Sep 11 09:03:46] WARNING[11707]: chan_rtmp.c:2798 amf_get_type: Unknown type 0
Received RTMP message from server :
        result       : 1.000000
        level        : N/A
        code         : N/A
        description  : N/A
Sending publish request for stream with id 1 and name NetStream
[Sep 11 09:03:46] WARNING[11707]: chan_rtmp.c:2798 amf_get_type: Unknown type 0
Received RTMP message from server :
        result       : 2.000000
        level        : N/A
        code         : N/A
        description  : N/A
[Sep 11 09:03:46] NOTICE[11707]: chan_rtmp.c:2504 rtmp_handle_connection_message: readstream_index : -0
[Sep 11 09:03:46] NOTICE[11707]: chan_rtmp.c:2509 rtmp_handle_connection_message: readstream_name : NetStream
Sending play request for stream with id 2 and name NetStream
   -- Executing [400@greeting:1] Answer("RTMP/1", "") in new stack
   -- Executing [400@greeting:2] BackGround("RTMP/1", "demo-congrats") in new stack
   -- <RTMP/1> Playing 'demo-congrats.gsm' (language '')
Handling PING message (ping type = 0)
Handling CHUNKSIZE message. Chunk size changed from 128 to 128
Handling PING message (ping type = 0)
Handling CHUNKSIZE message. Chunk size changed from 128 to 441
localhost*CLI> sbin/safe_asterisk: line 152: 11693 Floating point exception(core dumped) nice -n $PRIORITY ${ASTSBINDIR}/asterisk -f ${CLIARGS} ${ASTARGS} > /dev/${TTY} 2>&1 < /dev/${TTY}
Asterisk ended with exit status 136
Asterisk exited on signal EXITSTATUS-128.

Disconnected from Asterisk server
Executing last minute cleanups
Asterisk ending (0).
o2oadmin@localhost:/srv/asterisk$ Automatically restarting Asterisk.

Well - seems it does not understand part of FMS2 messages - but same problem on Red5.

Could anyone help me investigating this problem?

By: vmanthei (vmanthei) 2009-11-06 13:48:38.000-0600

I get this message:
loader.c: Error loading module 'chan_rtmp.so': /usr/lib/asterisk/modules/chan_rtmp.so: undefined symbol: av_audio_resample_init

when starting asterisk although compiling the branch was successful and all linked libs are there. Why is that?

ldd /usr/lib/asterisk/modules/chan_rtmp.so
   linux-vdso.so.1 =>  (0x00007fff191ff000)
   libavcodec.so.51 => /usr/lib/libavcodec.so.51 (0x00007f2010732000)
   libpthread.so.0 => /lib/libpthread.so.0 (0x00007f2010516000)
   libc.so.6 => /lib/libc.so.6 (0x00007f20101c2000)
   libavutil.so.49 => /usr/lib/libavutil.so.49 (0x00007f200ffb5000)
   libz.so.1 => /usr/lib/libz.so.1 (0x00007f200fd9e000)
   libm.so.6 => /lib/libm.so.6 (0x00007f200fb1a000)
   libfaad.so.0 => /usr/lib/libfaad.so.0 (0x00007f200f8d9000)
   libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007f200f6cc000)
   libtheora.so.0 => /usr/lib/libtheora.so.0 (0x00007f200f489000)
   libvorbisenc.so.2 => /usr/lib/libvorbisenc.so.2 (0x00007f200f0b1000)
   libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0x00007f200ee86000)
   /lib64/ld-linux-x86-64.so.2 (0x00007f2011078000)
   libogg.so.0 => /usr/lib/libogg.so.0 (0x00007f200ec80000)

By: vmanthei (vmanthei) 2009-11-07 07:52:07.000-0600

Fixed, just a local ffmpeg linking problem.

By: Vaughn Hannon (vhannon) 2009-11-09 16:50:17.000-0600

When I run make after a successful configure I get the following errors:

chan_rtmp.c:536: error: incompatible types in assignment
chan_rtmp.c:553: error: incompatible types in assignment
chan_rtmp.c: In function ‘rtmp_write’:
chan_rtmp.c:575: error: invalid operands to binary & (have ‘union <anonymous>’ and ‘long long unsigned int’)
chan_rtmp.c:576: warning: format ‘%d’ expects type ‘int’, but argument 6 has type ‘union <anonymous>’
chan_rtmp.c: In function ‘rtmp_handle_audio_packet’:

I'm attempting to build this on Ubuntu Server 9.04 with the latest ffmpeg from their subversion repo.  Any help much appreciated.


By: nychip (nychip) 2009-11-12 02:54:25.000-0600

Try to add .integer after f.subclass . For example,
f.subclass= 0; ---> f.subclass.integer = 0;
Shall fix the problem.

By: Vaughn Hannon (vhannon) 2009-11-16 13:20:50.000-0600

Thank nychip.

Now that it compiles we're having a little issue connecting to the FMS server.  We get this error when we make a call.  

-- Executing [1234@Encode:2] Dial("SIP/voicepulse-primary-00000004", "RTMP/writestream/null") in new stack
[Nov 15 01:37:11] WARNING[9807]: chan_rtmp.c:682 rtmp_request: The RTMP driver requires a stream identifier to read
[Nov 15 01:37:11] WARNING[9807]: app_dial.c:1818 dial_exec_full: Unable to create channel of type 'RTMP' (cause 0 - Unknown)

The basic dialplan is to answer and forward to the extension that calls rtmp:
exten => _XX.,n,Answer
exten => _XX.,n,Playback(hello-world)
exten => _XX.,n,Goto(Encode,1234,1)

[Encode] ;Send call to FMS
exten => 1234,1,Playback(hello-world)
exten => 1234,n,Dial(RTMP/writestream/null)

(ftr, both Hello world audio files play)
Thanks for any help.

By: Greg Pulier (gpulier) 2009-11-20 11:30:02.000-0600


How did you fix your "local ffmpeg linking problem"?
I am also getting:
Error loading module 'chan_rtmp.so': /usr/lib/asterisk/modules/chan_rtmp.so: undefined symbol: av_audio_resample_init



By: vmanthei (vmanthei) 2009-11-20 11:43:04.000-0600

av_audio_resample_init requires libavcodec.so.52
Do a ldd chan_rtmp.so and see which version of libavcodec it references. In my case it was the antiquated libavcodec.so.51
Compile the current ffmpeg trunk and replace the linked library with libavcodec.so.52 if still necessary.

By: Greg Pulier (gpulier) 2009-11-20 12:38:20.000-0600

Thank you!  That solved my problem with ffmpeg...

Now I get:
[Nov 20 18:29:24] WARNING[7338]: chan_rtmp.c:682 rtmp_request: The RTMP driver requires a stream identifier to read
[Nov 20 18:29:24] WARNING[7338]: app_dial.c:1818 dial_exec_full: Unable to create channel of type 'RTMP' (cause 0 - Unknown)

in the Asterisk console when using the default rtmp.conf to a red5 server or FMS.

Any ideas?

By: phsultan (phsultan) 2009-11-21 06:18:31.000-0600

The code needs to be updated, at least to reflect changes in the core Asterisk API, as nychip spotted it in note #113710, and also to solve the inability to set up the socket to the RTMP server.

I'll review the code and adapt it by the end of next week. Also, I don't have any FMS platform here to test with, so I suggest we focus on making it work with Red5 first.

I was also thinking about an improvement that could allow us to stop using FFMPEG. I read somewhere that Flash clients (version 10 or higher) can use Speex. If that's the case, then we can make them talk directly with Asterisk's rather than transcode the audio packets (codec : Nellymoser ASAO) with FFMPEG. That needs to be investigated.

Thanks everybody for all the testing and feedback!

By: phsultan (phsultan) 2009-12-10 03:50:21.000-0600

I just updated the branch to fix various reported issues.

By: vmanthei (vmanthei) 2009-12-11 04:53:38.000-0600


Replace the following lines in the method rtmp_new:

i->encoder = avcodec_find_encoder(CODEC_ID_PCM_S16LE);
i->encoder = avcodec_find_encoder(CODEC_ID_ADPCM_SWF);


i->encoding_context = avcodec_alloc_context2(CODEC_ID_ADPCM_SWF);
i->encoding_context->channels = 1;
i->encoding_context->sample_rate = 11000;
i->encoding_context = avcodec_alloc_context2(CODEC_TYPE_AUDIO);
i->encoding_context->codec_id = CODEC_ID_ADPCM_SWF;
i->encoding_context->codec_type = CODEC_TYPE_AUDIO;
i->encoding_context->channels = 1;
i->encoding_context->sample_rate = 11025;

Works fine for me.

By: Greg Pulier (gpulier) 2009-12-17 14:56:32.000-0600

I fixed my FFMPEG and now things seem to work!
Thanks all!


By: shimasaki (shimasaki) 2010-01-05 04:50:40.000-0600

I'm testing this branch using CentOS 5.4 (I confirmed Wowza Media Server also works).
However, I encountered intermittent noise during calls.
I've write the patch to fix the problem of noise from Flash Player to Asterisk (with RTMP support).
It seems like the reason for the noise was that the "buf" variable was freed before returning rtmp_read.


By: shimasaki (shimasaki) 2010-01-05 04:50:59.000-0600

I wrote a patch that uses Speex instead of Nellymoser ASAO, buf it still depends libavcodec.
Tested on CentOS 5.4 (i386) using Wowza Media Server.

http://gist.github.com/269314 (1/19: merged 269310)

By: Alejandro Rios P. (alerios) 2010-03-07 17:58:41.000-0600

I've got the readstream(prueba1) working without noise using shimasaki patch, but I cannot hear the writestream(prueba2) on publisher.swf. I see no errors on CLI with debug level 3:

   -- Executing [456@real-out-alerios:2] Dial("SIP/alerios-00000001", "RTMP/prueba2/prueba1") in new stack
Sending createStream request for stream with id 1.000000
[100307-184112] WARNING[2958]: chan_rtmp.c:2796 amf_get_type: Unknown type 0
Received RTMP message from server :
        result       : 1.000000
        level        : N/A
        code         : N/A
        description  : N/A
Sending publish request for stream with id 1 and name prueba2
Sending createStream request for stream with id 2.000000
   -- Called prueba2/prueba1
   -- RTMP/1 answered SIP/alerios-00000001
[100307-184112] WARNING[2958]: chan_rtmp.c:2796 amf_get_type: Unknown type 0
Received RTMP message from server :
        result       : 2.000000
        level        : N/A
        code         : N/A
        description  : N/A
[100307-184112] NOTICE[2958]: chan_rtmp.c:2502 rtmp_handle_connection_message: readstream_index : -0
[100307-184112] NOTICE[2958]: chan_rtmp.c:2507 rtmp_handle_connection_message: readstream_name : prueba1
Sending play request for stream with id 2 and name prueba1
Handling PING message (ping type = 0)
Unknown system message with type 3
[100307-184117] NOTICE[2958]: chan_rtmp.c:2647 rtmp_handle_audio_packet: Changed incoming sample rate from 11000 Hz to 22000 Hz
Unknown system message with type 0
Unknown system message with type 0

The last messages keeps repeating during the whole call.

I'm using Red5 and debian/unstable:

ffmpeg               4:0.5.1-1
libavcodec52         4:0.5.1-1

By: phsultan (phsultan) 2010-06-25 08:04:17

A major update to the code has been published to the rtmp-support branch.

We now use librtmp instead of our own RTMP stack. That should make Asterisk connect to any RTMP server (Red5, Wowza, FMS, etc.), but means that you need to install librtmp.

To do so, install rtmpdump :
wget http://rtmpdump.mplayerhq.hu/download/rtmpdump-2.2e.tar.gz
tar zxvf rtmpdump-2.2e.tar.gz
cd rtmpdump-2.2e/
make install

Then, rebuild Asterisk dependencies checking program :
cd rtmp-support (the RTMP Asterisk code branch)
make install

The librtmp debug messages can be read in a file (see the configs/rtmp.conf sample file).

We still have no video in this channel, but more will come in a near future.

By: John Todd (jtodd) 2010-07-09 11:54:56

Also, I get this error when trying to compile, which may be my fault: (Ubuntu 9.04)

root@ubuntu:/home/jtodd/asterisk/asterisk-rtmp# make
CC="cc" CXX="" LD="" AR="" RANLIB="" CFLAGS="" make -C menuselect CONFIGURE_SILENT="--silent" makeopts
make[1]: Entering directory `/home/jtodd/asterisk/asterisk-rtmp/menuselect'
make[1]: `makeopts' is up to date.
make[1]: Leaving directory `/home/jtodd/asterisk/asterisk-rtmp/menuselect'
 [CC] chan_rtmp.c -> chan_rtmp.o
chan_rtmp.c: In function â??rtmp_readâ??:
chan_rtmp.c:310: warning: the address of â??bufâ?? will always evaluate as â??trueâ??
chan_rtmp.c: In function â??rtmp_send_audioâ??:
chan_rtmp.c:678: error: â??FALSEâ?? undeclared (first use in this function)
chan_rtmp.c:678: error: (Each undeclared identifier is reported only once
chan_rtmp.c:678: error: for each function it appears in.)
make[1]: *** [chan_rtmp.o] Error 1
make: *** [channels] Error 2

By: John Todd (jtodd) 2010-07-09 18:14:14

I updated to latest SVN of ffmpeg (and x264, and rtmpdump, and the million dependencies that this creates) and I seem to get past the compile problem.

By: John Todd (jtodd) 2010-07-15 13:13:08

Does anyone have an "open" RTMP server I could point to for testing with a video stream that is accessible?  I don't quite have the time to go through the installation process of a RED5 or FMS server, though I'm happy to test this branch if there's something I can point to...

By: John Todd (jtodd) 2010-07-21 14:17:19

Do I need rtmpdump any more?  I've updated to the latest branch code.

I've moved to ffmpeg 0.6, removed SVN versions of ffmpeg, and with your compile options(--enable-shared --enable-swscale --disable-mmx --disable-optimizations--enable-debug) on ffmpeg 0.6 I get the same errors.  I'm on Debian 9.04.

Here's the compile warnings:

  [CC] app_ffplayback.c -> app_ffplayback.o
app_ffplayback.c: In function â??ff_playstreamâ??:
app_ffplayback.c:195: warning: passing argument 2 of â??ast_rtp_instance_get_remote_addressâ?? from incompatible pointer type
app_ffplayback.c:196: warning: passing argument 2 of â??ast_rtp_instance_get_remote_addressâ?? from incompatible pointer type
app_ffplayback.c:215: warning: passing argument 2 of â??ast_rtp_instance_get_local_addressâ?? from incompatible pointer type
app_ffplayback.c: In function â??video_threadâ??:
app_ffplayback.c:454: warning: â??avcodec_decode_videoâ?? is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3452)
app_ffplayback.c:475: warning: passing argument 2 of â??sws_scaleâ?? from incompatible pointer type
app_ffplayback.c: In function â??audio_threadâ??:
app_ffplayback.c:577: warning: pointer targets in passing argument 2 of â??avcodec_decode_audio3â?? differ in signedness
app_ffplayback.c:578: warning: pointer targets in passing argument 2 of â??audio_resampleâ?? differ in signedness
app_ffplayback.c:578: warning: pointer targets in passing argument 3 of â??audio_resampleâ?? differ in signedness
app_ffplayback.c: In function â??video_threadâ??:
app_ffplayback.c:365: warning: â??frame_rgbâ?? may be used uninitialized in this function
  [LD] app_ffplayback.o -> app_ffplayback.so

Here's what the CLI shows:

 == Registered custom function 'CALENDAR_WRITE'
res_calendar.so => (Asterisk Calendar integration)
[Jul 20 14:22:50] WARNING[27615]: loader.c:387 load_dynamic_module: Error loading module 'app_ffplayback.so': /usr/local/lib/libavformat.so.52: symbol av_new_packet, version LIBAVCODEC_52 not defined in file libavcodec.so.52 with link time reference
[Jul 20 14:22:50] WARNING[27615]: loader.c:819 load_resource: Module 'app_ffplayback.so' could not be loaded.
 == Registered file format g729, extension(s) g729

By: John Todd (jtodd) 2010-07-21 15:17:30

OK, that was my fault, I had an older version of ffmpeg that didn't get de-installed and it was taking precedence.  It now compiles cleanly... starting tests...

By: John Todd (jtodd) 2010-07-21 15:44:30

OK, it's at least not ALWAYS crashing.  :-)

I am connecting with Eyebeam release 1104g build 54685 on the Mac.  The Asterisk system and my SIP softclient are on the same NAT'ed network, so they see each other directly (192.168.1.xxx) with no translation in between.  I am not using ICE or STUN.

I have patched ffmpeg as follows:

Info : in order for X-lite to accept the video stream, you will have
to patch your FFMPEG installation with the following hack :
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -78,7 +78,7 @@ static int rtp_write_header(AVFormatContext *s1)

   s->payload_type = ff_rtp_get_payload_type(st->codec);
   if (s->payload_type < 0)
-        s->payload_type = RTP_PT_PRIVATE + (st->codec->codec_type == AVMEDIA_TY
+        s->payload_type = 115;

   s->base_timestamp = ff_random_get_seed();
   s->timestamp = s->base_timestamp;

;**** Play a local file ****
;- download a file from ted.com stored in the RTMP server using rtmpdump :
;rtmpdump --playpath=talks/dynamic/MarianBantjes_2010-high -r
;-o /tmp/temp.flv
;- instruct to play the downloaded file from the dialplan :
exten => 1235,1,Answer
exten => 1235,n,FFPlayback(/tmp/temp.flv)
exten => 1235,n,Hangup

This works for audio only.  When I attempt to open the video tab on Eyebeam, Asterisk crashes with a core dump.  (core dump available if you want to see it)

*CLI>     -- Executing [1235@rtmp:1] Answer("SIP/9000-00000001", "") in new stack
   -- Executing [1235@rtmp:2] FFPlayback("SIP/9000-00000001", "/tmp/temp.flv") in new stack
[Jul 20 15:53:51] NOTICE[22539]: app_ffplayback.c:132 ffplayback_exec: url value is : /tmp/temp.flv
[Jul 20 15:53:51] NOTICE[22539]: app_ffplayback.c:198 ff_playstream: Audio RTP address : - port 55496
[Jul 20 15:53:51] NOTICE[22539]: app_ffplayback.c:199 ff_playstream: Video RTP address : - port 0
[Jul 20 15:53:51] NOTICE[22539]: app_ffplayback.c:216 ff_playstream: Local video RTP address : - port 11460
[Jul 20 15:53:51] NOTICE[22539]: res_rtp_asterisk.c:530 ast_rtp_destroy: Destroyed RTP struct in RTP instance.
[flv @ 0xc59e880]Estimating duration from bitrate, this may be inaccurate
[flv @ 0xc54dfe0]Estimating duration from bitrate, this may be inaccurate
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:252 ff_playstream: Playing stream at location /tmp/temp.flv
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:261 ff_playstream: Duration : 00:16:28.44
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:302 ff_playstream: Audio codec time base info : 0/1
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:303 ff_playstream: Audio stream time base info : 1/1000
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:304 ff_playstream: Audio stream frame rate info : 0/0
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:305 ff_playstream: Video codec time base info : 1/1000
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:306 ff_playstream: Video stream time base info : 1/1000
[Jul 20 15:53:52] NOTICE[22539]: app_ffplayback.c:307 ff_playstream: Video stream frame rate info : 24/1
[Jul 20 15:53:52] NOTICE[22540]: app_ffplayback.c:448 video_thread: Now reading video input...
[Jul 20 15:53:52] WARNING[22541]: app_ffplayback.c:549 audio_thread: Now reading audio input...
 [I open the video tab while listening to the audio....]
Segmentation fault (core dumped)

;*** Play a file stored in an RTMP server ****
;- instruct to play the file from the RTMP server :
exten => 1236,1,Answer
exten => 1236,n,FFPlayback(rtmp://streaming.ted.com/ondemand?_fcs_vhost=streaming.ted.com&akmfv=1.7/talks/dynamic/Maria
exten => 1236,n,Hangup

Does not work - outputs this CLI data.  Also note that "rtmp://streaming.ted" seems to be an incomplete URL in the output.

*CLI>     -- Executing [1236@rtmp:1] Answer("SIP/9000-00000000", "") in new stack
   -- Executing [1236@rtmp:2] FFPlayback("SIP/9000-00000000", "rtmp://streaming.ted.com/ondemand?_fcs_vhost=streaming.ted.com&akmfv=1.7/talks/dynamic/MarianBantjes_2010-high") in new stack
[Jul 20 15:54:39] NOTICE[22585]: app_ffplayback.c:132 ffplayback_exec: url value is : rtmp://streaming.ted.com/ondemand?_fcs_vhost=streaming.ted.com&akmfv=1.7/talks/dynamic/MarianBantjes_2010-high
[Jul 20 15:54:39] NOTICE[22585]: app_ffplayback.c:198 ff_playstream: Audio RTP address : - port 21642
[Jul 20 15:54:39] NOTICE[22585]: app_ffplayback.c:199 ff_playstream: Video RTP address : - port 56134
[Jul 20 15:54:39] NOTICE[22585]: app_ffplayback.c:216 ff_playstream: Local video RTP address : - port 17608
[Jul 20 15:54:39] NOTICE[22585]: res_rtp_asterisk.c:530 ast_rtp_destroy: Destroyed RTP struct in RTP instance.
Cannot open connection tcp://streaming.ted:1935
[Jul 20 15:54:40] WARNING[22585]: app_ffplayback.c:238 ff_playstream: Could not open stream at location rtmp://streaming.ted
 == Spawn extension (rtmp, 1236, 2) exited non-zero on 'SIP/9000-00000000'
   -- Executing [h@rtmp:1] Hangup("SIP/9000-00000000", "") in new stack
 == Spawn extension (rtmp, h, 1) exited non-zero on 'SIP/9000-00000000'


;*** Play a file stored in an HTTP server ****
;- instruct to play the file from the RTMP server :
exten => 1237,1,Answer
exten => 1237,n,FFPlayback(http://video.ted.com/talks/podcast/MarianBantjes_2010.mp4)
exten => 1237,n,Hangup

Fails also.  Here is the output:

*CLI>     -- Executing [1237@rtmp:1] Answer("SIP/9000-00000001", "") in new stack
   -- Executing [1237@rtmp:2] FFPlayback("SIP/9000-00000001", "http://video.ted.com/talks/podcast/MarianBantjes_2010.mp4") in new stack
[Jul 20 15:55:32] NOTICE[22586]: app_ffplayback.c:132 ffplayback_exec: url value is : http://video.ted.com/talks/podcast/MarianBantjes_2010.mp4
[Jul 20 15:55:32] NOTICE[22586]: app_ffplayback.c:198 ff_playstream: Audio RTP address : - port 13844
[Jul 20 15:55:32] NOTICE[22586]: app_ffplayback.c:199 ff_playstream: Video RTP address : - port 60908
[Jul 20 15:55:32] NOTICE[22586]: app_ffplayback.c:216 ff_playstream: Local video RTP address : - port 17730
[Jul 20 15:55:32] NOTICE[22586]: res_rtp_asterisk.c:530 ast_rtp_destroy: Destroyed RTP struct in RTP instance.
[Jul 20 15:55:33] WARNING[22586]: app_ffplayback.c:238 ff_playstream: Could not open stream at location http://video.ted.com
 == Spawn extension (rtmp, 1237, 2) exited non-zero on 'SIP/9000-00000001'
   -- Executing [h@rtmp:1] Hangup("SIP/9000-00000001", "") in new stack
 == Spawn extension (rtmp, h, 1) exited non-zero on 'SIP/9000-00000001'


By: John Todd (jtodd) 2010-07-22 10:17:33

Just to note again: on the two streaming methods, I'm getting no audio OR video, while for the file-based method I get audio but a core dump when I try to re-invite video.

Here is what happens from a network perspective when I dial the "1237" extension in the example I provided:

root@ubuntu:/home/jtodd/asterisk/asterisk-rtmp# tshark -n host and not port 22 and not host and not arp
Running as user "root" and group "root". This could be dangerous.
Capturing on eth1

 0.000000 -> DNS Standard query A video.ted.com\020
 0.019101 -> DNS Standard query response A

What's up with the escaped characters in there?  It looks like it's getting a valid reply on the first query but not recognizing it.  Similar weird characters show up in the query for 1236 but even MORE mangled (dropping the ".com"):

10.727124 -> DNS Standard query A streaming.ted\020
10.748420 -> DNS Standard query response, No such name
10.748568 -> DNS Standard query A streaming.ted\020.loligo.com
10.770444 -> DNS Standard query response, No such name

This is with SVN version 278621 of the RTMP branch.  These DNS problems may be unrelated to RTMP, but are preventing functionality.

By: phsultan (phsultan) 2010-07-23 09:05:09

I really can't explain the escaped characters into the URLs, sorry. On my side, video and audio are properly received, in all cases (file, HTTP, RTMP).

I just fixed the compile warnings and added coded to properly packetize the H.263 frames in RTP packets. The consequence is that you don't need to patch your FFMPEG 0.6 installation anymore. And, the app_ffplayback.c code is very light.

All my testing have been done with X-Lite and Zoiper. X-lite and Zoiper to test the video and audio playbaycks respectively. Why? In short, X-lite is buggy on my MAC and has no sound, while Zoiper can't handle video...

Also, the RTP payload for the H.263 codec has to be set to 115 for X-lite to accept those packets. And the video codec on X-lite is H.263+(1998).

Finally, the call has to be a video call from the beginning (this happens on X-lite at least, don't know on Eyebeam).

Can you post a SIP debug output from the Asterisk console? An RTP debug output would be helpful as well, but it seems like recent changes in the trunk made this functionnality not available anymore.


By: phsultan (phsultan) 2010-07-23 09:08:15

Some TODOS :

Make the video output codec configurable. We can encode to anything FFMPEG can (H.264, etc.).

Make the video output size configurable. It is set by default to 176x144.

By: phsultan (phsultan) 2010-07-23 10:31:00

John, I forgot to mention that you don't need rtmpdump to compile app_ffplayback.c.

By: John Todd (jtodd) 2010-07-23 10:51:30

After an SVN update and re-compile, I no longer have the DNS problems I was having earlier.  No idea what fixed this, but both stream methods now produce audio, but still no video.

I've added a file (jtodd-sip-debug.txt) to this ticket with both a SIP and RTP debugging session, playing media back from a stored file on disk.

For what it's worth, I have no packet filters or firewalls on either host, and they're on the same LAN segment.

By: phsultan (phsultan) 2010-07-23 12:44:32

Better results with X-Lite?

By: phsultan (phsultan) 2010-07-23 12:50:00

From the SIP debug, it appears that Eyebeam proposes H.263 and H.263-1998. What happens if you keep H.263-1998 only, and take H.263 off the advertized codec list?

By: John Todd (jtodd) 2010-07-23 13:26:14

OK!  When I remove all codecs from Eyebeam except for H.263-1998, it works.  I get video and audio!  But then eyebeam crashes.  :-)  But that's not your problem.   It needs to have the video window open at the start of the call, or it will not start video after the audio track has started.  Putting a video call on hold stops the audio and video, but only re-starts audio after un-holding (which I assume is related to the prior sentence.)

The audio frequently becomes un-synchronized with the video, and I know that's going to be a big problem... or is it?  Is there any way to use RTCP to know when video and audio streams are out of sync?  Could it be possible to artificially pause audio frames for a certain period of time until the video catches up?  Honestly, I don't know what RTCP feeds back in enough detail to say if this is possible.  I'd say not to worry about that right now, right?  :-)

Video quality is terrible. ;-)

I get these messages consistently on the file-based version, at the same spot (about 20? seconds in):
[h263 @ 0xd459ee0]encoded frame too large

...and sporadically on the stream-based versions.  On the file-based version, eyebeam crashes, every time, right after that error message appears on the Asterisk console.  On the stream-based versions, eyebeam only sporadically crashes after that message appears.  I have only experimented about 5 times, so this is not 100% certain.

Audio is a bit "clicky" and has a vibrating sound going through it.  This is quite distracting.  I've tried different codecs on eyebeam (G.711 A, G.711 U, and GSM) and it's the same result, and consistently in the same places in the soundtrack, which makes me think this is a systemic problem.  I am running both the Linux/Asterisk instance (VMWare) and Eyebeam on the same dual-core machine, so maybe that's the problem.

By: Rus Rus (harbour) 2010-07-25 12:59:28

Playing 8KHz speex files with FFPlayback succeeded with clear sound. But using Dial(RTMP/1/2) always core dumped, last line is :

Jul 25 20:47:28] NOTICE[6464]: chan_rtmp.c:626 rtmp_handle_apacket: Changed incoming sample rate from 11000 Hz to 8000 Hz
Floating point exception (core dumped)

Core was generated by `asterisk -dcv'.
Program terminated with signal 8, Arithmetic exception.
#0  0xb2dd24c1 in av_resample () from /usr/lib/libavcodec.so.52
(gdb) backtrace
#0  0xb2dd24c1 in av_resample () from /usr/lib/libavcodec.so.52
#1  0xffffdc00 in ?? ()
#2  0x00000000 in ?? ()

The RTMP server is Wowza 3.0.0, can provide working URL for testing if needed.

By: John Todd (jtodd) 2010-07-29 17:34:19

Here's a quick demo of the TED video on my Grandstream phone.  I had to tell the Grandstream to only support H.263+, but that was the only trick.  Looks pretty usable, actually, even with my miserable VMWare image running the conversion.  The audio is a bit "buzzy" as I noted previously, but certainly listen-able.  http://bit.ly/dfOZYC

By: John Todd (jtodd) 2010-08-04 15:07:48

I've tried with the newest video-capable versions of SIPDroid, but no video.  I assume this is because H.263+ is not the only codec it supports, and perhaps is syncing to the wrong codec.   Any idea what the issue is with sending or being compatible with clients that support H.264 or H.263?

By: John Todd (jtodd) 2010-08-04 15:50:48

Update: It seems that SIPDroid does not like the video being sent, since I can see the video with tshark.  It is being sent as h263-1998, but does not display on the SIPDroid client.  I don't know if this is a SIPDroid flaw or what, but since the other clients work, I'll assume that this is a SIPDroid issue or some protocol sutblety on the SIP side of the stack.

By: John Todd (jtodd) 2010-08-16 12:33:05

Any idea if other transcoding methods (something other than H.263+) work here?  Anyone have something to sample other than TED videos?   Is anyone else testing this actively?

By: Chris Mendes (cmendes0101) 2010-09-01 23:30:51

I'm following the the steps to install but I installed FFMPEG from SVN instead of the 0.6 release. I've been getting the errors below for the chan_rtmp during the make of asterisk. Couldn't find a solution so far to work but then saw a document that avcodec_decode_audio2 is depreciated (http://cekirdek.uludag.org.tr/~ismail/ffmpeg-docs/avcodec_8h.html#d8bc42dbb60426c9fd28cfbf1d7a3c35) but could not tell what version. I then installed the 0.6 version of FFMPEG but I am still receiving this error.

Generating embedded module rules ...
  [CC] astcanary.c -> astcanary.o
  [LD] astcanary.o -> astcanary
  [CC] chan_agent.c -> chan_agent.o
  [LD] chan_agent.o -> chan_agent.so
  [CC] chan_bridge.c -> chan_bridge.o
  [LD] chan_bridge.o -> chan_bridge.so
  [CC] chan_iax2.c -> chan_iax2.o
  [CC] iax2-parser.c -> iax2-parser.o
  [CC] iax2-provision.c -> iax2-provision.o
  [LD] chan_iax2.o iax2-parser.o iax2-provision.o -> chan_iax2.so
  [CC] chan_local.c -> chan_local.o
  [LD] chan_local.o -> chan_local.so
  [CC] chan_multicast_rtp.c -> chan_multicast_rtp.o
  [LD] chan_multicast_rtp.o -> chan_multicast_rtp.so
  [CC] chan_oss.c -> chan_oss.o
  [CC] console_video.c -> console_video.o
  [CC] vgrabbers.c -> vgrabbers.o
  [CC] console_board.c -> console_board.o
  [LD] chan_oss.o console_video.o vgrabbers.o console_board.o -> chan_oss.so
  [CC] chan_phone.c -> chan_phone.o
  [LD] chan_phone.o -> chan_phone.so
  [CC] chan_rtmp.c -> chan_rtmp.o
chan_rtmp.c: In function ârtmp_readâ:
chan_rtmp.c:310: warning: the address of âbufâ will always evaluate as âtrueâ
chan_rtmp.c: In function ârtmp_handle_apacketâ:
chan_rtmp.c:613: warning: âavcodec_decode_audio2â is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3390)
  [LD] chan_rtmp.o -> chan_rtmp.so
/usr/bin/ld: /usr/local/lib/librtmp.a(rtmp.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/librtmp.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [chan_rtmp.so] Error 1
make: *** [channels] Error 2

By: Chris Mendes (cmendes0101) 2010-09-07 13:34:55

Fixed my issue.

Not sure why but I matched all the version here and got that error. Had to upgrade rtmpdump from 2.2e to 2.3 and that solved the issue.

By: Les Green (devbatbaby) 2010-10-24 04:52:11

I have the rtmp branch working pretty well using red5 and the built in subscriber application.

I have tried to get it to work with FMS and all the publishing seems to be fine and media players (eg: jwplayer) seem to connect to the stream okay but there is no audio. (FMS works with live video streaming away from asterisk)

I have also not yet managed to get the jwplayer to play the red5 stream.

Is there something obvious which I have missed? .. Has someone a working configuration with FMS? or a working configuration with an external media player for red5?

Any help / information would be gratefully received!!

The working versions/environment I am using are:
CentOS release 5.5 (Final)
asterisk-rtmp branch Last Changed Rev: 284623
rtmpdump - version 2.3
FMS - version FMS_4_0_0_r1121
red5 - trunk revision 4149

By: John Todd (jtodd) 2010-10-29 15:16:29

FWIW, this was listed in the priority list for Asterisk 1.10 at the AstriDevCon.  We're hoping more people test this out.

By: Chris Mendes (cmendes0101) 2010-11-01 19:33:58

I'm still having trouble getting this to fully work. I tried rebuilding a couple times but still having the same issue.

exten => 500,1,Answer()
exten => 500,2,Dial(RTMP/writestream/readstream)

When I have the caller go into this context, I can use the Publisher demo app to publish audio(mic) to "readstream" and that works fine, but I cannot get the Publisher demo app to play audio from the writestream (audio from the caller).

The only thing that I do get during setup is this error:

  [CC] chan_rtmp.c -> chan_rtmp.o
chan_rtmp.c: In function ârtmp_readâ:
chan_rtmp.c:310: warning: the address of âbufâ will always evaluate as âtrueâ
chan_rtmp.c: In function ârtmp_handle_apacketâ:
chan_rtmp.c:613: warning: âavcodec_decode_audio2â is deprecated (declared at /usr/local/include/libavcodec/avcodec.h:3390)
  [LD] chan_rtmp.o -> chan_rtmp.so

Could this have to do with my audio problem?

I dont have a FMS but I'll see what I can do, just so I can eliminate if its red5 or not.

By: gabole (gabole) 2010-11-05 15:52:27

Hi there
working great with ubuntu 9.04 and wowzamedia 2. One question: how can we specify rtmp application instance name and stream name dynamically ?
i believe that several stream names can be specified in the extensions.conf file but what about application instance ?

thanks !

By: gabole (gabole) 2010-11-06 05:04:43

asterisk crashes when trying to play a stream that don't exist. Any clue about how to fix this ?

By: webdelic (webdelic) 2010-11-10 14:46:46.000-0600

Installed on clean debian 5.0 32bit on openvz - early testing but video seems to be working great with hardware videophones. Testing with UMEC UC722 with Vericall stack and getting no crashes at all. As of softphones, X-Lite and Linphone both work fine with proper STUN but produce frequent crashes in * for calls with one-way video RTP (where asterisk is sending out data and the UA is not they are almost guaranteed) Flaphone (flaphone.com) is producing the best results out of the box so far when sending and receiving. Trying to recompile ffmpeg on a clone to post proper dumps and captures of re-invites. Great Job! Looking forward news on the configurable codec and resolution.

By: Dele Olajide (deleolajide) 2010-11-11 18:21:13.000-0600


I had the same issue, but fixed it by modifying chan_rtmpc.c and adding a timestamp. I had the same problem in red5phone. Zero timestamps used to work in Flash player for live stream, but since version 10.x.x, correct timestamps are now required to work properly.

packet.m_nTimeStamp = (time(NULL) * 1000) -  p->timestamp;

I added timestamp to the rtmp_pvt structure and set it to start time

By: Chris Mendes (cmendes0101) 2010-11-12 02:33:23.000-0600


Does that mean something like this:
struct rtmp_pvt {
       struct ast_channel *owner;
       pthread_t thread;
       AVCodec *encoder;
       AVCodec *decoder;
       AVCodecContext *encoding_context;
       AVCodecContext *decoding_context;
       ReSampleContext *tortmp_resample_context;
       ReSampleContext *fromrtmp_resample_context;
       unsigned int rtmpinputrate;                     /* default : 11000 Hz */
       unsigned int astinputrate;                      /* default : 8000 Hz */

       char readstream[AST_MAX_EXTENSION];
       char writestream[AST_MAX_EXTENSION];

       /* two RTMP connections : one read a stream from the server, the other
        * to publish a stream */
       RTMP *rtmpin;
       RTMP *rtmpout;

       /* \brief Pipe file descriptor handles array.
        * Read from pipe[0], write to pipe[1]
       int pipe[2];
       packet.m_nTimeStamp = (time(NULL) * 1000) - p->timestamp;

With that I actually get a error during make that stops it.

By: alanbover (alanbover) 2010-11-12 04:40:26.000-0600

Hi, I have been trying to make it work on a ubuntu server 10.04 and red5. I get no errors, and it seems asterisk and red5 connect, but I just have been able to make audio works on the writestream.

When I connect, on the red5 server (using oflademo app) I get that error, even if connect with readstream and writestream:

[ERROR] [NioProcessor-1] org.red5.server.service.ServiceInvoker - Method FCSubscribe with parameters [readstream] not found in org.red5.demos.oflaDemo.Application@1eda64e

Then, if I talk through the phone I can hear it using the flash, but I cannot see any video.

In the other way, if I publish a video using flash, the phone cannot see it. If I publish audio using flash to the readstream, the conection works good but once I say something to the microphone, I get a segmentation fault in asterisk.

I'm really interested on having work audio and video on the writestream side. For hear the audio in the flash, I should put buffer = 0. Maybe I'm missing any configuration for the video? Cause I can see how the video is sended from the phone to the asterisk, but then, I cannot see any video on flash.



ubuntu 10.04 LTS
rtmpdump 2.2e

Phone: Grandstream

By: Dele Olajide (deleolajide) 2010-11-12 05:35:42.000-0600


I have uploaded my modified chan_rtmp.c file. Look for timestamp.
For your Flash application, make sure the NetStream bufferTime is 0 (default) otherwise your subscribed audio stream will be delayed accordingly.

I also found different behaviour with Flash players and Red5 versions. We are having the same problems in red5phone as well. My changes enable latest Flash Player 10 to work with latest red5 1.0 RC1 server.

Lower versions may not need this patch.


Video is not yet supported in the code. I also suggest you update your librtmp to latest SVN or 2.3. That may solve your seg fault. I am using SVN version with no problems. Also make sure you publish the read stream from your application first before caling Dial(RTMP/writestream/readstream)

By: Chris Mendes (cmendes0101) 2010-11-12 09:58:39.000-0600


Thanks for the help so far but I do not see the uploaded file. I see it in the issue history below that it was uploaded but on the attachments to this issue there is no file. Not sure if its because its needs to be made public or anything. Would you be able to use pastebin.org

EDIT: Nevermind I see it now. Thanks will try it out

By: phsultan (phsultan) 2010-11-15 10:14:59.000-0600

Dele: thanks a lot for the information regarding timestamps in recent Flash clients. I'll modify the source according to your suggestion during the week. I hope that will solve cmendes0101's issue. By the way, do you plan to integrate real-time video with red5phone? While FFPlayback behaves quite well within Asterisk, I'd love to have real time video packets handled too. I started to write code in this purpose, but wasn't able to get H.264 video frames from the Flash client (10.x) I tested. Any chance you could help?

gabole: Did you try to upgrade librtmp to the 2.3 version? Also, having the application configurable as a parameter seems to be feasible, though you can't have have Asterisk connect to more than one app.

Just for information, the code branch has just been resynchronized with Asterisk's trunk.

By: Jorg Bauer (murkhog) 2010-11-16 03:34:36.000-0600

phsultan wrote:
> Just for information, the code branch has just been resynchronized
> with Asterisk's trunk.

Great work - very useful branch. Is there any plan to move the RTMP code into the main trunk?

By: Jorg Bauer (murkhog) 2010-11-16 03:36:39.000-0600

The RTMP module sends the audio in PCM to the Flash server. We are using JW Player for playback and it doesn't support PCM. Is there any way to use a different encoding?

Or does anybody have experience with changing enconding on the Flash Media Server side?

By: Dele Olajide (deleolajide) 2010-11-16 10:07:43.000-0600


Thanks for getting this started. Nice !!
I am stuck with the same problem, H.264 decoding. I did do screenshare which uses the screen codec to encode RTMP video packets, but that is far as I got. We might be able pass the packets through to an H.264 SIP endpoint with no re-coding.

By: Chris Mendes (cmendes0101) 2010-11-16 13:10:21.000-0600

Yes, it fixed my issue and everything is working great. Thanks again deleolajide. I have it playing back with JWPlayer and its working good.

One thing I noticed is if you use an IAX trunk most of the time when trying to create the streams it will cause asterisk to totally crash. I switched to SIP trunk and it works perfect. Just thought I would bring up that experience in case  anyone else has that problem.

By: phsultan (phsultan) 2010-11-17 07:55:32.000-0600

gabole: I could reproduce the problem, now fixed in the new SVN version.

murkhog: it looks like cmendes0101 had the code working with JWPlayer. In the future though, we will certainly offer the ability to choose the encoding codec (see the commented code in chan_rtmp.c).

Dele: I just integrated your patch, thanks a lot!

By: Jorg Bauer (murkhog) 2010-11-17 09:58:50.000-0600

With the last patch JW player now works for me as well. Using a different codec is now less important. Thanks!

By: gabole (gabole) 2010-11-29 02:15:07.000-0600

Thanks for your work ! i tryed to update from the svn but apparently i still have the same revision version (552). is this the last rev version ?
how could i simply install the latest source (svn up didn't work)
thanks !

By: Chris Mendes (cmendes0101) 2010-12-09 15:37:57.000-0600

I switched from Red5 over to Wowza Server and not I can't get asterisk to read or publish a stream.

Asterisk hangs at:
Dial("SIP/rapidvox-00000000", "RTMP/writestream/readstream")

Then in Wowza it just says:
INFO stream create - -

Nothing appears in the Wowza, Asterisk or that RTMP log from rtmp.conf.
Is there any way to trigger more detailed log or screen to see why it just lockes up in those applications. I have to stop the Wowza server then that causes asterisk to spit this out:

[Dec  9 12:58:52] ERROR[4103]: chan_rtmp.c:166 rtmp_call: Could not establish stream.
   -- Couldn't call writestream/readstream

If I dont do that then asterisk just hangs there forever.

EDIT: I just noticed the rtmp.conf log file has a level, so I switched it to 6. Is there anything noticable in here? http://pastebin.com/hPCVg9B7
I didnt notice the create stream with the name writestream, is anything missing?

By: Jorg Bauer (murkhog) 2011-03-08 16:25:03.000-0600

Some feature ideas that have come up while working with this branch:

* Ability to leave writestream or readstream empty. A use case: we are streaming telephone conference calls. This is a broadcast and there is no RTMP stream coming back into Asterisk.

I've tried setting the readstream to an unknown stream id ('none') and this causes a time-out after 5 minutes. The RTMP channel is bridged to a SIP call to an external provider that connects us to the PSTN. chan_rtmp does not send any RTP packets for the 'none' stream and I suspect our provider have the default setting of rtpholdtimeout=300 kick in.

Anybody know how to send silence from within the chan_rtmp (i. e. how would the sample data look I write to buffer, how often would I need to do this)?

* I'd really like to be able to specify different FMS server, or application for writestream and readstream. Would it make sense to have this as part of the channel specification: I. e. RTMP/server,app,writestream/server,app,readstream. The current settings in rtmp.conf could still serve as defaults.

By: gabole (gabole) 2011-03-08 23:10:50.000-0600

yep i'm in the same case as murkhog and theses features are mandatory to me...i would be ready to contribute financialy to have such feature

By: dlogan (dlogan) 2011-04-06 06:00:01

We would also be happy to sponsor the streaming feature - the ability to create a call between a streaming server / CDN and Asterisk. One way audio - this is to broadcast audio (like ICES) not to build flash telephones etc.

If this is supported then please advise and I will resume testing.

By: Jorg Bauer (murkhog) 2011-04-06 06:53:56

Just as follow up to the one-way broadcasting of phone calls (for dlogan and gabole):

We now have a set-up that works for us. The outgoing stream goes to our streaming server (FMS) and we read a silent stream from a seperate Wowza server to avoid the time-outs.

We use Wowza because it supports scheduling of playlists (as live stream). We schedule a silent FLV to start in the past (so it starts right away) and then loop it. Asterisk can use this as incoming stream whenever a call is established with chan_rtmp.

More information on the Wowza playlist configuration is here: http://www.wowzamedia.com/forums/content.php?145-Stream-class-example-with-playlists-and-schedules-set-in-smil-file

I've also uploaded our SMIL playlist and silent FLV: http://jbauer.es/asterisk/

Note that I had to hack the chan_rtmp.c code. We are using different streaming servers for incoming and outgoing streams. I hard-coded the incoming streaming URL to our wowza server. If I find a bit of time, I'll try to create a patch for chan_rtmp.c to allow the configuration of different streaming servers and application.

By: Leif Madsen (lmadsen) 2011-04-06 12:22:39

Just curious if phsultan will be looking at this in the near future?

By: dlogan (dlogan) 2011-04-13 15:11:04

Thanks murkhog - I will give this a test.

By: Bandol (bandol) 2011-07-05 14:35:16.179-0500

Hello all, Thank you very much for the work done on this branch.

I've been able to test and install this, and worked some on it to add native speex16 support so that libavcodec is no longer a hard requirement. It was not all that hard, just #ifdef HAVE_AVCODEC all of the avcodec calls and changing the RTMP packet header byte to 0xb2. As part of that I do have a question maybe someone can help with:
- What do I return in rtmp_read for number samples? Right now I just return 320 (20ms) but that is not necessarily true.

As part of this work I'd like to share some bugs I found and fixed:

- I had many garbled sound issues, then I noticed the RTMP spec released by Adobe mentioned the timestamp for each RTMP packet should be based on the current time and increase monotonically. So, instead of using the 1 second timer I used ast_now() and got a milli-second timestamp (so each packet has a different timestamp at least). That made all the garbled sound go away.
   p->timestamp = (now.tv_sec*1000)+(now.tv_usec/1000);

- The return code of rtmp_write was 0 on error and 1 on success. Not sure why or how, but the dialplan playback() application seems to want to have 0 for success. So I just changed that to 'return 0' and it worked.

By: Kevin Reeves (superkvn) 2011-07-19 14:41:14.226-0500

I'm currently running chan_rtmp in 1.8.2

phsultan: I've made some changes to chan_rtmp.c that allows you to specify your connection parameters via channel settings allowing you to do things like this:


If you'd like to take a look at the changes, let me know.

Also, I've updated the configure script for 1.8.2 to allow it to be built in that release.  If you'd like to have a copy, I'd be happy to share.

By: tatiana (tatianita_) 2011-08-25 20:51:29.027-0500

Hi, I am testing this channel with red 5 server and with eyebeam
I get to see a movie that is in oflademo application from eyebeam , with this in extensions
exten => 201,n,FFPlayback(rtmp://localhost:1935/oflaDemo/avatar)

But now, I want to see the live stream that I publish with demo Publisher on the eyebeam with this url rmp://localhost:1935/oflaDemo/publisher/

but I can't..!! I think the url is wrong but I make some testing and  I don't know what is the correct url

Could someone help me please? I am new on this.

By: Grzegorz Kocyk (kkocyk) 2011-09-20 03:59:26.424-0500

Sound works great with Dial to rtmp channel, but is it possible to handle video also?

By: Chris Mendes (cmendes0101) 2011-11-14 12:14:17.579-0600

@Grzegorz Kocyk: Its currently audio only I believe. It was mentioned earlier in the thread.

I'm having an issue when using the RTMP channel. The connections never seem to close. I have been running live streams for the weekend and had about 7000 calls come through in the rtmp channel. Started having an issue with asterisk not being able to open any more connections. I had to do: ulimit -n 65000 since by default its 1024. I have not had any other issues so far except for needing to increase that.

I can view the open of connections at the moment with:  ls -l /proc/<PID of Asterisk>/fd | wc -l
Its showing about 3000 and thats about how many streams were started since asterisk started. Is there something that is not closing properly, or any suggestions on what to look into? Increasing the connection limits would only be a temporary fix. I'm using FMS and that seems to be closing the streams on that side.

By: Lorenzo Miniero (lminiero) 2012-01-30 04:39:55.125-0600

I get segfaults both trying to originate a call using chan_rtmp and using FFplayback, in both cases after a few seconds. Is the FFmpeg version the only plausible cause for this? I also have librtmp 2.4 which is higher than the suggested version (2.3), I don't know if this may be related.

By: Juan Carlos Castro y Castro (jccyc) 2012-05-10 16:29:21.621-0500

I want to implement server functionality so RTMP clients can authenticate against us. Does librtmp have support for that?