Copyright 2009 The Flvstreamer Team
http://rtmpdump.mplayerhq.hu/
+4 March 2010, v2.2
+- move RTMP code into library librtmp
+- relicense RTMP code under LGPL v2.1
+- add rtmpdump manpage
+- fix AMF_LONG_STRING handling
+- more FlashPlayer 10 handshake support
+- in rtmpsrv fix Play Start/Stop messages
+
20 February 2010, v2.1d
- extend .swfinfo file format, add --swfAge rtmpdump parameter
old file should be replaced or manually updated: copy the
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
-DEF=-DRTMPDUMP_VERSION=\"v2.1d\"
+DEF=-DRTMPDUMP_VERSION=\"v2.2\"
OPT=-O2
CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT)
LDFLAGS=-Wall $(XLDFLAGS)
LIBS=-lcrypto -lz
THREADLIB=-lpthread
+LIBRTMP=librtmp/librtmp.a
SLIBS=$(THREADLIB) $(LIBS)
EXT=
clean:
rm -f *.o *.a rtmpdump$(EXT) rtmpgw$(EXT) rtmpsrv$(EXT) rtmpsuck$(EXT)
-librtmp.a: rtmp.o log.o amf.o hashswf.o
- $(AR) rs $@ $?
+$(LIBRTMP):
+ @$(MAKE) -C librtmp $(MAKEFLAGS)
-rtmpdump: rtmpdump.o parseurl.o librtmp.a
+rtmpdump: rtmpdump.o parseurl.o $(LIBRTMP)
$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(LIBS)
-rtmpsrv: rtmpsrv.o thread.o librtmp.a
+rtmpsrv: rtmpsrv.o thread.o $(LIBRTMP)
$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
-rtmpsuck: rtmpsuck.o thread.o librtmp.a
+rtmpsuck: rtmpsuck.o thread.o $(LIBRTMP)
$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
-rtmpgw: rtmpgw.o parseurl.o thread.o librtmp.a
+rtmpgw: rtmpgw.o parseurl.o thread.o $(LIBRTMP)
$(CC) $(LDFLAGS) $^ -o $@$(EXT) $(SLIBS)
-log.o: log.c log.h Makefile
-parseurl.o: parseurl.c parseurl.h log.h Makefile
-rtmpgw.o: rtmpgw.c rtmp.h log.h hashswf.o Makefile
-rtmp.o: rtmp.c rtmp.h handshake.h dh.h log.h amf.h Makefile
-amf.o: amf.c amf.h bytes.h log.h Makefile
-rtmpdump.o: rtmpdump.c rtmp.h log.h amf.h Makefile
-rtmpsrv.o: rtmpsrv.c rtmp.h log.h amf.h Makefile
-hashswf.o: hashswf.c http.h
+parseurl.o: parseurl.c parseurl.h Makefile
+rtmpgw.o: rtmpgw.c librtmp/rtmp.h librtmp/log.h librtmp/amf.h Makefile
+rtmpdump.o: rtmpdump.c librtmp/rtmp.h librtmp/log.h librtmp/amf.h Makefile
+rtmpsrv.o: rtmpsrv.c librtmp/rtmp.h librtmp/log.h librtmp/amf.h Makefile
thread.o: thread.c thread.h
--- /dev/null
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL. It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+ This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+ When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+ To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+ For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+
+ We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+ To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+\f
+ Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+ Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+ When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+ We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+
+ For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+ In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+ Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+ The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+\f
+ GNU LESSER GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+ A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+ The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+ "Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+ Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+
+ 1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+ You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+ 2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) The modified work must itself be a software library.
+
+ b) You must cause the files modified to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ c) You must cause the whole of the work to be licensed at no
+ charge to all third parties under the terms of this License.
+
+ d) If a facility in the modified Library refers to a function or a
+ table of data to be supplied by an application program that uses
+ the facility, other than as an argument passed when the facility
+ is invoked, then you must make a good faith effort to ensure that,
+ in the event an application does not supply such function or
+ table, the facility still operates, and performs whatever part of
+ its purpose remains meaningful.
+
+ (For example, a function in a library to compute square roots has
+ a purpose that is entirely well-defined independent of the
+ application. Therefore, Subsection 2d requires that any
+ application-supplied function or table used by this function must
+ be optional: if the application does not supply it, the square
+ root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+\f
+ Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+ This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+ 4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+ If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+ However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+ When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+
+ If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+ Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+\f
+ 6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+
+ You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+
+ a) Accompany the work with the complete corresponding
+ machine-readable source code for the Library including whatever
+ changes were used in the work (which must be distributed under
+ Sections 1 and 2 above); and, if the work is an executable linked
+ with the Library, with the complete machine-readable "work that
+ uses the Library", as object code and/or source code, so that the
+ user can modify the Library and then relink to produce a modified
+ executable containing the modified Library. (It is understood
+ that the user who changes the contents of definitions files in the
+ Library will not necessarily be able to recompile the application
+ to use the modified definitions.)
+
+ b) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (1) uses at run time a
+ copy of the library already present on the user's computer system,
+ rather than copying library functions into the executable, and (2)
+ will operate properly with a modified version of the library, if
+ the user installs one, as long as the modified version is
+ interface-compatible with the version that the work was made with.
+
+ c) Accompany the work with a written offer, valid for at
+ least three years, to give the same user the materials
+ specified in Subsection 6a, above, for a charge no more
+ than the cost of performing this distribution.
+
+ d) If distribution of the work is made by offering access to copy
+ from a designated place, offer equivalent access to copy the above
+ specified materials from the same place.
+
+ e) Verify that the user has already received a copy of these
+ materials or that you have already sent this user a copy.
+
+ For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+
+ It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+distribute.
+\f
+ 7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+
+ a) Accompany the combined library with a copy of the same work
+ based on the Library, uncombined with any other library
+ facilities. This must be distributed under the terms of the
+ Sections above.
+
+ b) Give prominent notice with the combined library of the fact
+ that part of it is a work based on the Library, and explaining
+ where to find the accompanying uncombined form of the same work.
+
+ 8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+
+ 9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+
+ 10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+\f
+ 11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+
+ 13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser General Public License from time to time.
+Such new versions will be similar in spirit to the present version,
+but may differ in detail to address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+\f
+ 14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
+
+ NO WARRANTY
+
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+\f
+ How to Apply These Terms to Your New Libraries
+
+ If you develop a new library, and you want it to be of the greatest
+possible use to the public, we recommend making it free software that
+everyone can redistribute and change. You can do so by permitting
+redistribution under these terms (or, alternatively, under the terms of the
+ordinary General Public License).
+
+ To apply these terms, attach the following notices to the library. It is
+safest to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least the
+"copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+Also add information on how to contact you by electronic and paper mail.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the library, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
--- /dev/null
+CC=$(CROSS_COMPILE)gcc
+LD=$(CROSS_COMPILE)ld
+
+DEF=-DRTMPDUMP_VERSION=\"v2.2\"
+OPT=-O2
+CFLAGS=-Wall $(XCFLAGS) $(INC) $(DEF) $(OPT)
+
+all: librtmp.a
+
+clean:
+ rm -f *.o *.a
+
+librtmp.a: rtmp.o log.o amf.o hashswf.o
+ $(AR) rs $@ $?
+
+log.o: log.c log.h Makefile
+rtmp.o: rtmp.c rtmp.h handshake.h dh.h log.h amf.h Makefile
+amf.o: amf.c amf.h bytes.h log.h Makefile
+hashswf.o: hashswf.c http.h
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
* Copyright (C) 2008-2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
+ * Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <string.h>
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
* Copyright (C) 2008-2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
+ * Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdint.h>
* Copyright (C) 2005-2008 Team XBMC
* http://www.xbmc.org
* Copyright (C) 2008-2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
+ * Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#ifndef __BYTES_H__
/* RTMPDump - Diffie-Hellmann Key Exchange
* Copyright (C) 2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
+ * Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdint.h>
-/* RTMPDump - Diffie-Hellmann Key Exchange
+/* librtmp - Diffie-Hellmann Key Exchange
* Copyright (C) 2009 Andrej Stepanchuk
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
/* from RFC 3526, see http://www.ietf.org/rfc/rfc3526.txt */
* Copyright (C) 2009-2010 Howard Chu
* Copyright (C) 2010 2a665470ced7adb7156fcef47f8199a6371c117b8a79e399a2771e0b36384090
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
/* This file is #included in rtmp.c, it is not meant to be compiled alone */
/*
* Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdio.h>
* Copyright (C) 2010 Howard Chu
* Copyright (C) 2010 Antti Ajanki
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
typedef enum {
-/* RTMPDump
+/*
* Copyright (C) 2008-2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
+ * Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdio.h>
-/* RTMP Dump
+/*
* Copyright (C) 2008-2009 Andrej Stepanchuk
* Copyright (C) 2009 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#ifndef __LOG_H__
* Copyright (C) 2008-2009 Andrej Stepanchuk
* Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#include <stdint.h>
* Copyright (C) 2008-2009 Andrej Stepanchuk
* Copyright (C) 2009-2010 Howard Chu
*
- * 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, or (at your option)
- * any later version.
+ * This file is part of librtmp.
*
- * This Program is distributed in the hope that it will be useful,
+ * librtmp is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1,
+ * or (at your option) any later version.
+ *
+ * librtmp 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 RTMPDump; see the file COPYING. If not, write to
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with librtmp see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
+ * http://www.gnu.org/copyleft/lgpl.html
*/
#ifdef WIN32
#include <assert.h>
#include <ctype.h>
-#include "log.h"
+#include "librtmp/log.h"
#include "parseurl.h"
#define RTMP_PROTOCOL_UNDEFINED -1
#include <signal.h> // to catch Ctrl-C
#include <getopt.h>
-#include "rtmp.h"
-#include "log.h"
+#include "librtmp/rtmp.h"
+#include "librtmp/log.h"
#include "parseurl.h"
#ifdef WIN32
#include <assert.h>
-#include "rtmp.h"
+#include "librtmp/rtmp.h"
#include "parseurl.h"
#include "thread.h"
#include <assert.h>
-#include "rtmp.h"
+#include "librtmp/rtmp.h"
#include "parseurl.h"
#include "thread.h"
#include <assert.h>
-#include "rtmp.h"
+#include "librtmp/rtmp.h"
#include "parseurl.h"
#include "thread.h"
+++ /dev/null
-/* HTTP-RTMP Stream Server
- * Copyright (C) 2009 Andrej Stepanchuk
- * Copyright (C) 2009 Howard Chu
- *
- * 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, 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 RTMPDump; see the file COPYING. If not, write to
- * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include <signal.h>
-#include <getopt.h>
-
-#include <assert.h>
-
-#include "rtmp.h"
-#include "parseurl.h"
-
-#include "thread.h"
-
-#define RD_SUCCESS 0
-#define RD_FAILED 1
-#define RD_INCOMPLETE 2
-
-#define PACKET_SIZE 1024*1024
-
-#ifdef WIN32
-#define InitSockets() {\
- WORD version; \
- WSADATA wsaData; \
- \
- version = MAKEWORD(1,1); \
- WSAStartup(version, &wsaData); }
-
-#define CleanupSockets() WSACleanup()
-#else
-#define InitSockets()
-#define CleanupSockets()
-#endif
-
-enum
-{
- STREAMING_ACCEPTING,
- STREAMING_IN_PROGRESS,
- STREAMING_STOPPING,
- STREAMING_STOPPED
-};
-
-typedef struct
-{
- int socket;
- int state;
-
-} STREAMING_SERVER;
-
-STREAMING_SERVER *httpServer = 0; // server structure pointer
-
-STREAMING_SERVER *startStreaming(const char *address, int port);
-void stopStreaming(STREAMING_SERVER * server);
-
-typedef struct
-{
- uint32_t dSeek; // seek position in resume mode, 0 otherwise
-
- char *hostname;
- int rtmpport;
- int protocol;
- bool bLiveStream; // is it a live stream? then we can't seek/resume
-
- long int timeout; // timeout connection afte 300 seconds
- uint32_t bufferTime;
-
- char *rtmpurl;
- AVal playpath;
- AVal swfUrl;
- AVal tcUrl;
- AVal pageUrl;
- AVal app;
- AVal auth;
- AVal swfHash;
- AVal flashVer;
- AVal token;
- AVal subscribepath;
- AMFObject extras;
- int edepth;
- uint32_t swfSize;
- int swfAge;
- int swfVfy;
-
- uint32_t dStartOffset;
- uint32_t dStopOffset;
- uint32_t nTimeStamp;
-
- unsigned char hash[HASHLEN];
-} RTMP_REQUEST;
-
-#define STR2AVAL(av,str) av.av_val = str; av.av_len = strlen(av.av_val)
-
-int
-parseAMF(AMFObject *obj, const char *arg, int *depth)
-{
- AMFObjectProperty prop = {{0,0}};
- int i;
- char *p;
-
- if (arg[1] == ':')
- {
- p = (char *)arg+2;
- switch(arg[0])
- {
- case 'B':
- prop.p_type = AMF_BOOLEAN;
- prop.p_vu.p_number = atoi(p);
- break;
- case 'S':
- prop.p_type = AMF_STRING;
- STR2AVAL(prop.p_vu.p_aval,p);
- break;
- case 'N':
- prop.p_type = AMF_NUMBER;
- prop.p_vu.p_number = strtod(p, NULL);
- break;
- case 'Z':
- prop.p_type = AMF_NULL;
- break;
- case 'O':
- i = atoi(p);
- if (i)
- {
- prop.p_type = AMF_OBJECT;
- }
- else
- {
- (*depth)--;
- return 0;
- }
- break;
- default:
- return -1;
- }
- }
- else if (arg[2] == ':' && arg[0] == 'N')
- {
- p = strchr(arg+3, ':');
- if (!p || !*depth)
- return -1;
- prop.p_name.av_val = (char *)arg+3;
- prop.p_name.av_len = p - (arg+3);
-
- p++;
- switch(arg[1])
- {
- case 'B':
- prop.p_type = AMF_BOOLEAN;
- prop.p_vu.p_number = atoi(p);
- break;
- case 'S':
- prop.p_type = AMF_STRING;
- STR2AVAL(prop.p_vu.p_aval,p);
- break;
- case 'N':
- prop.p_type = AMF_NUMBER;
- prop.p_vu.p_number = strtod(p, NULL);
- break;
- case 'O':
- prop.p_type = AMF_OBJECT;
- break;
- default:
- return -1;
- }
- }
- else
- return -1;
-
- if (*depth)
- {
- AMFObject *o2;
- for (i=0; i<*depth; i++)
- {
- o2 = &obj->o_props[obj->o_num-1].p_vu.p_object;
- obj = o2;
- }
- }
- AMF_AddProp(obj, &prop);
- if (prop.p_type == AMF_OBJECT)
- (*depth)++;
- return 0;
-}
-
-/* this request is formed from the parameters and used to initialize a new request,
- * thus it is a default settings list. All settings can be overriden by specifying the
- * parameters in the GET request. */
-RTMP_REQUEST defaultRTMPRequest;
-
-bool ParseOption(char opt, char *arg, RTMP_REQUEST * req);
-
-char DEFAULT_FLASH_VER[] = "LNX 10,0,22,87";
-
-#ifdef _DEBUG
-uint32_t debugTS = 0;
-
-int pnum = 0;
-
-FILE *netstackdump = NULL;
-FILE *netstackdump_read = NULL;
-#endif
-
-/* inplace http unescape. This is possible .. strlen(unescaped_string) <= strlen(esacped_string) */
-void
-http_unescape(char *data)
-{
- char hex[3];
- char *stp;
- int src_x = 0;
- int dst_x = 0;
-
- int length = (int) strlen(data);
- hex[2] = 0;
-
- while (src_x < length)
- {
- if (strncmp(data + src_x, "%", 1) == 0 && src_x + 2 < length)
- {
- //
- // Since we encountered a '%' we know this is an escaped character
- //
- hex[0] = data[src_x + 1];
- hex[1] = data[src_x + 2];
- data[dst_x] = (char) strtol(hex, &stp, 16);
- dst_x += 1;
- src_x += 3;
- }
- else if (src_x != dst_x)
- {
- //
- // This doesn't need to be unescaped. If we didn't unescape anything previously
- // there is no need to copy the string either
- //
- data[dst_x] = data[src_x];
- src_x += 1;
- dst_x += 1;
- }
- else
- {
- //
- // This doesn't need to be unescaped, however we need to copy the string
- //
- src_x += 1;
- dst_x += 1;
- }
- }
- data[dst_x] = '\0';
-}
-
-int
-WriteHeader(char **buf, // target pointer, maybe preallocated
- unsigned int len // length of buffer if preallocated
- )
-{
- char flvHeader[] = { 'F', 'L', 'V', 0x01,
- 0x05, // video + audio, we finalize later if the value is different
- 0x00, 0x00, 0x00, 0x09,
- 0x00, 0x00, 0x00, 0x00 // first prevTagSize=0
- };
-
- unsigned int size = sizeof(flvHeader);
-
- if (size > len)
- {
- *buf = (char *) realloc(*buf, size);
- if (*buf == 0)
- {
- Log(LOGERROR, "Couldn't reallocate memory!");
- return -1; // fatal error
- }
- }
- memcpy(*buf, flvHeader, sizeof(flvHeader));
- return size;
-}
-
-int
-WriteStream(RTMP * rtmp, char **buf, // target pointer, maybe preallocated
- unsigned int len, // length of buffer if preallocated
- uint32_t * nTimeStamp)
-{
- uint32_t prevTagSize = 0;
- int rtnGetNextMediaPacket = 0, ret = -1;
- RTMPPacket packet = { 0 };
-
- rtnGetNextMediaPacket = RTMP_GetNextMediaPacket(rtmp, &packet);
- while (rtnGetNextMediaPacket)
- {
- char *packetBody = packet.m_body;
- unsigned int nPacketLen = packet.m_nBodySize;
-
- // skip video info/command packets
- if (packet.m_packetType == 0x09 &&
- nPacketLen == 2 && ((*packetBody & 0xf0) == 0x50))
- {
- ret = 0;
- break;
- }
-
- if (packet.m_packetType == 0x09 && nPacketLen <= 5)
- {
- Log(LOGWARNING, "ignoring too small video packet: size: %d",
- nPacketLen);
- ret = 0;
- break;
- }
- if (packet.m_packetType == 0x08 && nPacketLen <= 1)
- {
- Log(LOGWARNING, "ignoring too small audio packet: size: %d",
- nPacketLen);
- ret = 0;
- break;
- }
-#ifdef _DEBUG
- Log(LOGDEBUG, "type: %02X, size: %d, TS: %d ms", packet.m_packetType,
- nPacketLen, packet.m_nTimeStamp);
- if (packet.m_packetType == 0x09)
- Log(LOGDEBUG, "frametype: %02X", (*packetBody & 0xf0));
-#endif
-
- // calculate packet size and reallocate buffer if necessary
- unsigned int size = nPacketLen
- +
- ((packet.m_packetType == 0x08 || packet.m_packetType == 0x09
- || packet.m_packetType == 0x12) ? 11 : 0) + (packet.m_packetType !=
- 0x16 ? 4 : 0);
-
- if (size + 4 > len)
- { // the extra 4 is for the case of an FLV stream without a last prevTagSize (we need extra 4 bytes to append it)
- *buf = (char *) realloc(*buf, size + 4);
- if (*buf == 0)
- {
- Log(LOGERROR, "Couldn't reallocate memory!");
- ret = -1; // fatal error
- break;
- }
- }
- char *ptr = *buf, *pend = ptr + size+4;
-
- // audio (0x08), video (0x09) or metadata (0x12) packets :
- // construct 11 byte header then add rtmp packet's data
- if (packet.m_packetType == 0x08 || packet.m_packetType == 0x09
- || packet.m_packetType == 0x12)
- {
- // set data type
- //*dataType |= (((packet.m_packetType == 0x08)<<2)|(packet.m_packetType == 0x09));
-
- (*nTimeStamp) = packet.m_nTimeStamp;
- prevTagSize = 11 + nPacketLen;
-
- *ptr++ = packet.m_packetType;
- ptr = AMF_EncodeInt24(ptr, pend, nPacketLen);
- ptr = AMF_EncodeInt24(ptr, pend, *nTimeStamp);
- *ptr = (char) (((*nTimeStamp) & 0xFF000000) >> 24);
- ptr++;
-
- // stream id
- ptr = AMF_EncodeInt24(ptr, pend, 0);
- }
-
- memcpy(ptr, packetBody, nPacketLen);
- unsigned int len = nPacketLen;
-
- // correct tagSize and obtain timestamp if we have an FLV stream
- if (packet.m_packetType == 0x16)
- {
- unsigned int pos = 0;
-
- while (pos + 11 < nPacketLen)
- {
- uint32_t dataSize = AMF_DecodeInt24(packetBody + pos + 1); // size without header (11) and without prevTagSize (4)
- *nTimeStamp = AMF_DecodeInt24(packetBody + pos + 4);
- *nTimeStamp |= (packetBody[pos + 7] << 24);
-
- // set data type
- //*dataType |= (((*(packetBody+pos) == 0x08)<<2)|(*(packetBody+pos) == 0x09));
-
- if (pos + 11 + dataSize + 4 > nPacketLen)
- {
- if (pos + 11 + dataSize > nPacketLen)
- {
- Log(LOGERROR,
- "Wrong data size (%lu), stream corrupted, aborting!",
- dataSize);
- ret = -2;
- break;
- }
- Log(LOGWARNING, "No tagSize found, appending!");
-
- // we have to append a last tagSize!
- prevTagSize = dataSize + 11;
- AMF_EncodeInt32(ptr + pos + 11 + dataSize, pend, prevTagSize);
- size += 4;
- len += 4;
- }
- else
- {
- prevTagSize =
- AMF_DecodeInt32(packetBody + pos + 11 + dataSize);
-
-#ifdef _DEBUG
- Log(LOGDEBUG,
- "FLV Packet: type %02X, dataSize: %lu, tagSize: %lu, timeStamp: %lu ms",
- (unsigned char) packetBody[pos], dataSize, prevTagSize,
- *nTimeStamp);
-#endif
-
- if (prevTagSize != (dataSize + 11))
- {
-#ifdef _DEBUG
- Log(LOGWARNING,
- "Tag and data size are not consitent, writing tag size according to dataSize+11: %d",
- dataSize + 11);
-#endif
-
- prevTagSize = dataSize + 11;
- AMF_EncodeInt32(ptr + pos + 11 + dataSize, pend, prevTagSize);
- }
- }
-
- pos += prevTagSize + 4; //(11+dataSize+4);
- }
- }
- ptr += len;
-
- if (packet.m_packetType != 0x16)
- { // FLV tag packets contain their own prevTagSize
- AMF_EncodeInt32(ptr, pend, prevTagSize);
- //ptr += 4;
- }
-
- // Return 0 if this was completed nicely with invoke message Play.Stop or Play.Complete
- if (rtnGetNextMediaPacket == 2)
- {
- Log(LOGDEBUG,
- "Got Play.Complete or Play.Stop from server. Assuming stream is complete");
- ret = 0;
- break;
- }
-
- ret = size;
- break;
- }
-
- RTMPPacket_Free(&packet);
- return ret; // no more media packets
-}
-
-TFTYPE
-controlServerThread(void *unused)
-{
- char ich;
- while (1)
- {
- ich = getchar();
- switch (ich)
- {
- case 'q':
- LogPrintf("Exiting\n");
- stopStreaming(httpServer);
- exit(0);
- break;
- default:
- LogPrintf("Unknown command \'%c\', ignoring\n", ich);
- }
- }
- TFRET();
-}
-
-/*
-ssize_t readHTTPLine(int sockfd, char *buffer, size_t length)
-{
- size_t i=0;
-
- while(i < length-1) {
- char c;
- int n = read(sockfd, &c, 1);
-
- if(n == 0)
- break;
-
- buffer[i] = c;
- i++;
-
- if(c == '\n')
- break;
- }
- buffer[i]='\0';
- i++;
-
- return i;
-}
-
-bool isHTTPRequestEOF(char *line, size_t length)
-{
- if(length < 2)
- return true;
-
- if(line[0]=='\r' && line[1]=='\n')
- return true;
-
- return false;
-}
-*/
-
-void processTCPrequest(STREAMING_SERVER * server, // server socket and state (our listening socket)
- int sockfd // client connection socket
- )
-{
- char buf[512] = { 0 }; // answer buffer
- char header[2048] = { 0 }; // request header
- char *filename = NULL; // GET request: file name //512 not enuf
- char *buffer = NULL; // stream buffer
- char *ptr = NULL; // header pointer
-
- size_t nRead = 0;
-
- char srvhead[] =
- "\r\nServer:HTTP-RTMP Stream Server \r\nContent-Type: Video/MPEG \r\n\r\n";
-
- server->state = STREAMING_IN_PROGRESS;
-
- RTMP rtmp = { 0 };
- uint32_t dSeek = 0; // can be used to start from a later point in the stream
-
- // reset RTMP options to defaults specified upon invokation of streams
- RTMP_REQUEST req;
- memcpy(&req, &defaultRTMPRequest, sizeof(RTMP_REQUEST));
-
- // timeout for http requests
- fd_set fds;
- struct timeval tv;
-
- memset(&tv, 0, sizeof(struct timeval));
- tv.tv_sec = 5;
-
- // go through request lines
- //do {
- FD_ZERO(&fds);
- FD_SET(sockfd, &fds);
-
- if (select(sockfd + 1, &fds, NULL, NULL, &tv) <= 0)
- {
- Log(LOGERROR, "Request timeout/select failed, ignoring request");
- goto quit;
- }
- else
- {
- nRead = recv(sockfd, header, 2047, 0);
- header[2047] = '\0';
-
- Log(LOGDEBUG, "%s: header: %s", __FUNCTION__, header);
-
- if (strstr(header, "Range: bytes=") != 0)
- {
- // TODO check range starts from 0 and asking till the end.
- LogPrintf("%s, Range request not supported\n", __FUNCTION__);
- sprintf(buf, "HTTP/1.0 416 Requested Range Not Satisfiable%s",
- srvhead);
- send(sockfd, buf, (int) strlen(buf), 0);
- goto quit;
- }
-
- if (strncmp(header, "GET", 3) == 0 && nRead > 4)
- {
- filename = header + 4;
-
- // filter " HTTP/..." from end of request
- char *p = filename;
- while (*p != '\0')
- {
- if (*p == ' ')
- {
- *p = '\0';
- break;
- }
- p++;
- }
- }
- }
- //} while(!isHTTPRequestEOF(header, nRead));
-
- // if we got a filename from the GET method
- if (filename != NULL)
- {
- Log(LOGDEBUG, "%s: Request header: %s", __FUNCTION__, filename);
- if (filename[0] == '/')
- { // if its not empty, is it /?
- ptr = filename + 1;
-
- // parse parameters
- if (*ptr == '?')
- {
- ptr++;
- int len = strlen(ptr);
-
- while (len >= 2)
- {
- char ich = *ptr;
- ptr++;
- if (*ptr != '=')
- goto filenotfound; // long parameters not (yet) supported
-
- ptr++;
- len -= 2;
-
- // get position of the next '&'
- char *temp;
-
- unsigned int nArgLen = len;
- if ((temp = strstr(ptr, "&")) != 0)
- {
- nArgLen = temp - ptr;
- }
-
- char *arg = (char *) malloc((nArgLen + 1) * sizeof(char));
- memcpy(arg, ptr, nArgLen * sizeof(char));
- arg[nArgLen] = '\0';
-
- //Log(LOGDEBUG, "%s: unescaping parameter: %s", __FUNCTION__, arg);
- http_unescape(arg);
-
- Log(LOGDEBUG, "%s: parameter: %c, arg: %s", __FUNCTION__,
- ich, arg);
-
- ptr += nArgLen + 1;
- len -= nArgLen + 1;
-
- ParseOption(ich, arg, &req);
- }
- }
- }
- else
- {
- goto filenotfound;
- }
- }
- else
- {
- LogPrintf("%s: No request header received/unsupported method\n",
- __FUNCTION__);
- }
-
- // do necessary checks right here to make sure the combined request of default values and GET parameters is correct
- if (req.hostname == 0)
- {
- Log(LOGERROR,
- "You must specify a hostname (--host) or url (-r \"rtmp://host[:port]/playpath\") containing a hostname");
- goto filenotfound;
- }
- if (req.playpath.av_len == 0)
- {
- Log(LOGERROR,
- "You must specify a playpath (--playpath) or url (-r \"rtmp://host[:port]/playpath\") containing a playpath");
- goto filenotfound;;
- }
-
- if (req.rtmpport == -1)
- {
- Log(LOGWARNING,
- "You haven't specified a port (--port) or rtmp url (-r), using default port 1935");
- req.rtmpport = 1935;
- }
- if (req.protocol == RTMP_PROTOCOL_UNDEFINED)
- {
- Log(LOGWARNING,
- "You haven't specified a protocol (--protocol) or rtmp url (-r), using default protocol RTMP");
- req.protocol = RTMP_PROTOCOL_RTMP;
- }
-
- if (req.flashVer.av_len == 0)
- {
- STR2AVAL(req.flashVer, DEFAULT_FLASH_VER);
- }
-
- if (req.tcUrl.av_len == 0 && req.app.av_len != 0)
- {
- char str[512] = { 0 };
- snprintf(str, 511, "%s://%s/%s", RTMPProtocolStringsLower[req.protocol],
- req.hostname, req.app.av_val);
- req.tcUrl.av_len = strlen(str);
- req.tcUrl.av_val = (char *) malloc(req.tcUrl.av_len + 1);
- strcpy(req.tcUrl.av_val, str);
- }
-
- if (req.rtmpport == 0)
- req.rtmpport = 1935;
-
- if (req.swfVfy)
- {
- if (RTMP_HashSWF(req.swfUrl.av_val, &req.swfSize, req.hash, req.swfAge) == 0)
- {
- req.swfHash.av_val = (char *)req.hash;
- req.swfHash.av_len = HASHLEN;
- }
- }
-
- // after validation of the http request send response header
- sprintf(buf, "HTTP/1.0 200 OK%s", srvhead);
- send(sockfd, buf, (int) strlen(buf), 0);
-
- // send the packets
- buffer = (char *) calloc(PACKET_SIZE, 1);
-
- // User defined seek offset
- if (req.dStartOffset > 0)
- {
- if (req.bLiveStream)
- Log(LOGWARNING,
- "Can't seek in a live stream, ignoring --seek option");
- else
- dSeek += req.dStartOffset;
- }
-
- if (dSeek != 0)
- {
- LogPrintf("Starting at TS: %d ms\n", req.nTimeStamp);
- }
-
- Log(LOGDEBUG, "Setting buffer time to: %dms", req.bufferTime);
- RTMP_Init(&rtmp);
- RTMP_SetBufferMS(&rtmp, req.bufferTime);
- RTMP_SetupStream(&rtmp, req.protocol, req.hostname, req.rtmpport, NULL, // sockshost
- &req.playpath, &req.tcUrl, &req.swfUrl, &req.pageUrl, &req.app, &req.auth, &req.swfHash, req.swfSize, &req.flashVer, &req.subscribepath, dSeek, -1, // length
- req.bLiveStream, req.timeout);
- /* backward compatibility, we always sent this as true before */
- if (req.auth.av_len)
- rtmp.Link.authflag = true;
-
- rtmp.Link.extras = req.extras;
- rtmp.Link.token = req.token;
-
- LogPrintf("Connecting ... port: %d, app: %s\n", req.rtmpport, req.app);
- if (!RTMP_Connect(&rtmp, NULL))
- {
- LogPrintf("%s, failed to connect!\n", __FUNCTION__);
- }
- else
- {
- unsigned long size = 0;
- double percent = 0;
- double duration = 0.0;
-
- int nWritten = 0;
- int nRead = 0;
-
- // write FLV header first
- nRead = WriteHeader(&buffer, PACKET_SIZE);
- if (nRead > 0)
- {
- nWritten = send(sockfd, buffer, nRead, 0);
- if (nWritten < 0)
- {
- Log(LOGERROR, "%s, sending failed, error: %d", __FUNCTION__,
- GetSockError());
- goto cleanup; // we are in STREAMING_IN_PROGRESS, so we'll go to STREAMING_ACCEPTING
- }
-
- size += nRead;
- }
- else
- {
- Log(LOGERROR, "%s: Couldn't obtain FLV header, exiting!",
- __FUNCTION__);
- goto cleanup;
- }
-
- // get the rest of the stream
- do
- {
- nRead = WriteStream(&rtmp, &buffer, PACKET_SIZE, &req.nTimeStamp);
-
- if (nRead > 0)
- {
- nWritten = send(sockfd, buffer, nRead, 0);
- //Log(LOGDEBUG, "written: %d", nWritten);
- if (nWritten < 0)
- {
- Log(LOGERROR, "%s, sending failed, error: %d", __FUNCTION__,
- GetSockError());
- goto cleanup; // we are in STREAMING_IN_PROGRESS, so we'll go to STREAMING_ACCEPTING
- }
-
- size += nRead;
-
- //LogPrintf("write %dbytes (%.1f KB)\n", nRead, nRead/1024.0);
- if (duration <= 0) // if duration unknown try to get it from the stream (onMetaData)
- duration = RTMP_GetDuration(&rtmp);
-
- if (duration > 0)
- {
- percent =
- ((double) (dSeek + req.nTimeStamp)) / (duration *
- 1000.0) * 100.0;
- percent = ((double) (int) (percent * 10.0)) / 10.0;
- LogStatus("\r%.3f KB / %.2f sec (%.1f%%)",
- (double) size / 1024.0,
- (double) (req.nTimeStamp) / 1000.0, percent);
- }
- else
- {
- LogStatus("\r%.3f KB / %.2f sec", (double) size / 1024.0,
- (double) (req.nTimeStamp) / 1000.0);
- }
- }
-#ifdef _DEBUG
- else
- {
- Log(LOGDEBUG, "zero read!");
- }
-#endif
-
- // Force clean close if a specified stop offset is reached
- if (req.dStopOffset && req.nTimeStamp >= req.dStopOffset)
- {
- LogPrintf("\nStop offset has been reached at %.2f seconds\n",
- (double) req.dStopOffset / 1000.0);
- nRead = 0;
- RTMP_Close(&rtmp);
- }
-
- }
- while (server->state == STREAMING_IN_PROGRESS && nRead > -1
- && RTMP_IsConnected(&rtmp) && nWritten >= 0);
- }
-cleanup:
- LogPrintf("Closing connection... ");
- RTMP_Close(&rtmp);
- LogPrintf("done!\n\n");
-
-quit:
- if (buffer)
- {
- free(buffer);
- buffer = NULL;
- }
-
- if (sockfd)
- closesocket(sockfd);
-
- if (server->state == STREAMING_IN_PROGRESS)
- server->state = STREAMING_ACCEPTING;
-
- return;
-
-filenotfound:
- LogPrintf("%s, File not found, %s\n", __FUNCTION__, filename);
- sprintf(buf, "HTTP/1.0 404 File Not Found%s", srvhead);
- send(sockfd, buf, (int) strlen(buf), 0);
- goto quit;
-}
-
-TFTYPE
-serverThread(void *arg)
-{
- STREAMING_SERVER *server = arg;
- server->state = STREAMING_ACCEPTING;
-
- while (server->state == STREAMING_ACCEPTING)
- {
- struct sockaddr_in addr;
- socklen_t addrlen = sizeof(struct sockaddr_in);
- int sockfd =
- accept(server->socket, (struct sockaddr *) &addr, &addrlen);
-
- if (sockfd > 0)
- {
- // Create a new process and transfer the control to that
- Log(LOGDEBUG, "%s: accepted connection from %s\n", __FUNCTION__,
- inet_ntoa(addr.sin_addr));
- processTCPrequest(server, sockfd);
- Log(LOGDEBUG, "%s: processed request\n", __FUNCTION__);
- }
- else
- {
- Log(LOGERROR, "%s: accept failed", __FUNCTION__);
- }
- }
- server->state = STREAMING_STOPPED;
- TFRET();
-}
-
-STREAMING_SERVER *
-startStreaming(const char *address, int port)
-{
- struct sockaddr_in addr;
- int sockfd;
- STREAMING_SERVER *server;
-
- sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sockfd == -1)
- {
- Log(LOGERROR, "%s, couldn't create socket", __FUNCTION__);
- return 0;
- }
-
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = inet_addr(address); //htonl(INADDR_ANY);
- addr.sin_port = htons(port);
-
- if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) ==
- -1)
- {
- Log(LOGERROR, "%s, TCP bind failed for port number: %d", __FUNCTION__,
- port);
- return 0;
- }
-
- if (listen(sockfd, 10) == -1)
- {
- Log(LOGERROR, "%s, listen failed", __FUNCTION__);
- closesocket(sockfd);
- return 0;
- }
-
- server = (STREAMING_SERVER *) calloc(1, sizeof(STREAMING_SERVER));
- server->socket = sockfd;
-
- ThreadCreate(serverThread, server);
-
- return server;
-}
-
-void
-stopStreaming(STREAMING_SERVER * server)
-{
- assert(server);
-
- if (server->state != STREAMING_STOPPED)
- {
- if (server->state == STREAMING_IN_PROGRESS)
- {
- server->state = STREAMING_STOPPING;
-
- // wait for streaming threads to exit
- while (server->state != STREAMING_STOPPED)
- msleep(1);
- }
-
- if (closesocket(server->socket))
- Log(LOGERROR, "%s: Failed to close listening socket, error %d",
- GetSockError());
-
- server->state = STREAMING_STOPPED;
- }
-}
-
-
-void
-sigIntHandler(int sig)
-{
- RTMP_ctrlC = true;
- LogPrintf("Caught signal: %d, cleaning up, just a second...\n", sig);
- if (httpServer)
- stopStreaming(httpServer);
- signal(SIGINT, SIG_DFL);
-}
-
-// this will parse RTMP related options as needed
-// excludes the following options: h, d, g
-
-// Return values: true (option parsing ok)
-// false (option not parsed/invalid)
-bool
-ParseOption(char opt, char *arg, RTMP_REQUEST * req)
-{
- switch (opt)
- {
-#ifdef CRYPTO
- case 'w':
- {
- int res = hex2bin(arg, &req->swfHash.av_val);
- if (!res || res != HASHLEN)
- {
- req->swfHash.av_val = NULL;
- Log(LOGWARNING,
- "Couldn't parse swf hash hex string, not hexstring or not %d bytes, ignoring!", HASHLEN);
- }
- req->swfHash.av_len = HASHLEN;
- break;
- }
- case 'x':
- {
- int size = atoi(arg);
- if (size <= 0)
- {
- Log(LOGERROR, "SWF Size must be at least 1, ignoring\n");
- }
- else
- {
- req->swfSize = size;
- }
- break;
- }
- case 'W':
- {
- STR2AVAL(req->swfUrl, arg);
- req->swfVfy = 1;
- }
- break;
- case 'X':
- {
- int num = atoi(arg);
- if (num < 0)
- {
- Log(LOGERROR, "SWF Age must be non-negative, ignoring\n");
- }
- else
- {
- req->swfAge = num;
- }
- break;
- }
-#endif
- case 'b':
- {
- int32_t bt = atol(arg);
- if (bt < 0)
- {
- Log(LOGERROR,
- "Buffer time must be greater than zero, ignoring the specified value %d!",
- bt);
- }
- else
- {
- req->bufferTime = bt;
- }
- break;
- }
- case 'v':
- req->bLiveStream = true; // no seeking or resuming possible!
- break;
- case 'd':
- STR2AVAL(req->subscribepath, arg);
- break;
- case 'n':
- req->hostname = arg;
- break;
- case 'c':
- req->rtmpport = atoi(arg);
- break;
- case 'l':
- {
- int protocol = atoi(arg);
- if (protocol != RTMP_PROTOCOL_RTMP && protocol != RTMP_PROTOCOL_RTMPE)
- {
- Log(LOGERROR, "Unknown protocol specified: %d, using default",
- protocol);
- return false;
- }
- else
- {
- req->protocol = protocol;
- }
- break;
- }
- case 'y':
- STR2AVAL(req->playpath, arg);
- break;
- case 'r':
- {
- req->rtmpurl = arg;
-
- char *parsedHost = 0;
- unsigned int parsedPort = 0;
- char *parsedPlaypath = 0;
- char *parsedApp = 0;
- int parsedProtocol = RTMP_PROTOCOL_UNDEFINED;
-
- if (!ParseUrl
- (req->rtmpurl, &parsedProtocol, &parsedHost, &parsedPort,
- &parsedPlaypath, &parsedApp))
- {
- Log(LOGWARNING, "Couldn't parse the specified url (%s)!", arg);
- }
- else
- {
- if (req->hostname == 0)
- req->hostname = parsedHost;
- if (req->rtmpport == -1)
- req->rtmpport = parsedPort;
- if (req->playpath.av_len == 0 && parsedPlaypath)
- {
- STR2AVAL(req->playpath, parsedPlaypath);
- }
- if (req->protocol == RTMP_PROTOCOL_UNDEFINED)
- req->protocol = parsedProtocol;
- if (req->app.av_len == 0 && parsedApp)
- {
- STR2AVAL(req->app, parsedApp);
- }
- }
- break;
- }
- case 's':
- STR2AVAL(req->swfUrl, arg);
- break;
- case 't':
- STR2AVAL(req->tcUrl, arg);
- break;
- case 'p':
- STR2AVAL(req->pageUrl, arg);
- break;
- case 'a':
- STR2AVAL(req->app, arg);
- break;
- case 'f':
- STR2AVAL(req->flashVer, arg);
- break;
- case 'u':
- STR2AVAL(req->auth, arg);
- break;
- case 'C':
- parseAMF(&req->extras, optarg, &req->edepth);
- break;
- case 'm':
- req->timeout = atoi(arg);
- break;
- case 'A':
- req->dStartOffset = atoi(arg) * 1000;
- //printf("dStartOffset = %d\n", dStartOffset);
- break;
- case 'B':
- req->dStopOffset = atoi(arg) * 1000;
- //printf("dStartOffset = %d\n", dStartOffset);
- break;
- case 'T':
- STR2AVAL(req->token, arg);
- break;
- case 'q':
- debuglevel = LOGCRIT;
- break;
- case 'V':
- debuglevel = LOGDEBUG;
- break;
- case 'z':
- debuglevel = LOGALL;
- break;
- default:
- LogPrintf("unknown option: %c, arg: %s\n", opt, arg);
- break;
- }
- return true;
-}
-
-int
-main(int argc, char **argv)
-{
- int nStatus = RD_SUCCESS;
-
- // http streaming server
- char DEFAULT_HTTP_STREAMING_DEVICE[] = "0.0.0.0"; // 0.0.0.0 is any device
-
- char *httpStreamingDevice = DEFAULT_HTTP_STREAMING_DEVICE; // streaming device, default 0.0.0.0
- int nHttpStreamingPort = 80; // port
-
- LogPrintf("HTTP-RTMP Stream Server %s\n", RTMPDUMP_VERSION);
- LogPrintf("(c) 2010 Andrej Stepanchuk, Howard Chu; license: GPL\n\n");
-
- // init request
- memset(&defaultRTMPRequest, 0, sizeof(RTMP_REQUEST));
-
- defaultRTMPRequest.rtmpport = -1;
- defaultRTMPRequest.protocol = RTMP_PROTOCOL_UNDEFINED;
- defaultRTMPRequest.bLiveStream = false; // is it a live stream? then we can't seek/resume
-
- defaultRTMPRequest.timeout = 300; // timeout connection afte 300 seconds
- defaultRTMPRequest.bufferTime = 20 * 1000;
-
- defaultRTMPRequest.swfAge = 30;
-
- int opt;
- struct option longopts[] = {
- {"help", 0, NULL, 'h'},
- {"host", 1, NULL, 'n'},
- {"port", 1, NULL, 'c'},
- {"protocol", 1, NULL, 'l'},
- {"playpath", 1, NULL, 'y'},
- {"rtmp", 1, NULL, 'r'},
- {"swfUrl", 1, NULL, 's'},
- {"tcUrl", 1, NULL, 't'},
- {"pageUrl", 1, NULL, 'p'},
- {"app", 1, NULL, 'a'},
-#ifdef CRYPTO
- {"swfhash", 1, NULL, 'w'},
- {"swfsize", 1, NULL, 'x'},
- {"swfVfy", 1, NULL, 'W'},
- {"swfAge", 1, NULL, 'X'},
-#endif
- {"auth", 1, NULL, 'u'},
- {"conn", 1, NULL, 'C'},
- {"flashVer", 1, NULL, 'f'},
- {"live", 0, NULL, 'v'},
- //{"flv", 1, NULL, 'o'},
- //{"resume", 0, NULL, 'e'},
- {"timeout", 1, NULL, 'm'},
- {"buffer", 1, NULL, 'b'},
- //{"skip", 1, NULL, 'k'},
- {"device", 1, NULL, 'D'},
- {"sport", 1, NULL, 'g'},
- {"subscribe", 1, NULL, 'd'},
- {"start", 1, NULL, 'A'},
- {"stop", 1, NULL, 'B'},
- {"token", 1, NULL, 'T'},
- {"debug", 0, NULL, 'z'},
- {"quiet", 0, NULL, 'q'},
- {"verbose", 0, NULL, 'V'},
- {0, 0, 0, 0}
- };
-
- signal(SIGINT, sigIntHandler);
-#ifndef WIN32
- signal(SIGPIPE, SIG_IGN);
-#endif
-
- InitSockets();
-
- while ((opt =
- getopt_long(argc, argv,
- "hvqVzr:s:t:p:a:f:u:n:c:l:y:m:d:D:A:B:T:g:w:x:W:X:", longopts,
- NULL)) != -1)
- {
- switch (opt)
- {
- case 'h':
- LogPrintf
- ("\nThis program dumps the media content streamed over rtmp.\n\n");
- LogPrintf("--help|-h Prints this help screen.\n");
- LogPrintf
- ("--rtmp|-r url URL (e.g. rtmp//hotname[:port]/path)\n");
- LogPrintf
- ("--host|-n hostname Overrides the hostname in the rtmp url\n");
- LogPrintf
- ("--port|-c port Overrides the port in the rtmp url\n");
- LogPrintf
- ("--protocol|-l Overrides the protocol in the rtmp url (0 - RTMP, 3 - RTMPE)\n");
- LogPrintf
- ("--playpath|-y Overrides the playpath parsed from rtmp url\n");
- LogPrintf("--swfUrl|-s url URL to player swf file\n");
- LogPrintf
- ("--tcUrl|-t url URL to played stream (default: \"rtmp://host[:port]/app\")\n");
- LogPrintf("--pageUrl|-p url Web URL of played programme\n");
- LogPrintf("--app|-a app Name of player used\n");
-#ifdef CRYPTO
- LogPrintf
- ("--swfhash|-w hexstring SHA256 hash of the decompressed SWF file (32 bytes)\n");
- LogPrintf
- ("--swfsize|-x num Size of the decompressed SWF file, required for SWFVerification\n");
- LogPrintf
- ("--swfVfy|-W url URL to player swf file, compute hash/size automatically\n");
- LogPrintf
- ("--swfAge|-X days Number of days to use cached SWF hash before refreshing\n");
-#endif
- LogPrintf
- ("--auth|-u string Authentication string to be appended to the connect string\n");
- LogPrintf
- ("--conn|-C type:data Arbitrary AMF data to be appended to the connect string\n");
- LogPrintf
- (" B:boolean(0|1), S:string, N:number, O:object-flag(0|1),\n");
- LogPrintf
- (" Z:(null), NB:name:boolean, NS:name:string, NN:name:number\n");
- LogPrintf
- ("--flashVer|-f string Flash version string (default: \"%s\")\n",
- DEFAULT_FLASH_VER);
- LogPrintf
- ("--live|-v Get a live stream, no --resume (seeking) of live strems possible\n");
- LogPrintf
- ("--subscribe|-d string Stream name to subscribe to (otherwise defaults to playpath if live is specifed)\n");
- LogPrintf
- ("--timeout|-m num Timeout connection num seconds (default: %lu)\n",
- defaultRTMPRequest.timeout);
- LogPrintf
- ("--start|-A num Start at num seconds into stream (not valid when using --live)\n");
- LogPrintf
- ("--stop|-B num Stop at num seconds into stream\n");
- LogPrintf
- ("--token|-T key Key for SecureToken response\n");
- LogPrintf
- ("--buffer|-b Buffer time in milliseconds (default: %lu)\n\n",
- defaultRTMPRequest.bufferTime);
-
- LogPrintf
- ("--device|-D Streaming device ip address (default: %s)\n",
- DEFAULT_HTTP_STREAMING_DEVICE);
- LogPrintf
- ("--sport|-g Streaming port (default: %d)\n\n",
- nHttpStreamingPort);
- LogPrintf
- ("--quiet|-q Supresses all command output.\n");
- LogPrintf("--verbose|-x Verbose command output.\n");
- LogPrintf("--debug|-z Debug level command output.\n");
- LogPrintf
- ("If you don't pass parameters for swfUrl, pageUrl, app or auth these propertiews will not be included in the connect ");
- LogPrintf("packet.\n\n");
- return RD_SUCCESS;
- break;
- // streaming server specific options
- case 'D':
- if (inet_addr(optarg) == INADDR_NONE)
- {
- Log(LOGERROR,
- "Invalid binding address (requested address %s), ignoring",
- optarg);
- }
- else
- {
- httpStreamingDevice = optarg;
- }
- break;
- case 'g':
- {
- int port = atoi(optarg);
- if (port < 0 || port > 65535)
- {
- Log(LOGERROR,
- "Streaming port out of range (requested port %d), ignoring\n",
- port);
- }
- else
- {
- nHttpStreamingPort = port;
- }
- break;
- }
- default:
- //LogPrintf("unknown option: %c\n", opt);
- ParseOption(opt, optarg, &defaultRTMPRequest);
- break;
- }
- }
-
-#ifdef _DEBUG
- netstackdump = fopen("netstackdump", "wb");
- netstackdump_read = fopen("netstackdump_read", "wb");
-#endif
-
- // start text UI
- ThreadCreate(controlServerThread, 0);
-
- // start http streaming
- if ((httpServer =
- startStreaming(httpStreamingDevice, nHttpStreamingPort)) == 0)
- {
- Log(LOGERROR, "Failed to start HTTP server, exiting!");
- return RD_FAILED;
- }
- LogPrintf("Streaming on http://%s:%d\n", httpStreamingDevice,
- nHttpStreamingPort);
-
- while (httpServer->state != STREAMING_STOPPED)
- {
- sleep(1);
- }
- Log(LOGDEBUG, "Done, exiting...");
-
- CleanupSockets();
-
-#ifdef _DEBUG
- if (netstackdump != 0)
- fclose(netstackdump);
- if (netstackdump_read != 0)
- fclose(netstackdump_read);
-#endif
- return nStatus;
-}
*/
#include "thread.h"
-#include "log.h"
+#include "librtmp/log.h"
#ifdef WIN32