Created
January 13, 2012 04:01
-
-
Save j0sh/1604622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| From bffa7d14da4e008735a803c865568bec44c2d6af Mon Sep 17 00:00:00 2001 | |
| From: Josh Allmann <joshua.allmann@gmail.com> | |
| Date: Thu, 12 Jan 2012 20:01:03 -0800 | |
| Subject: [PATCH] -- RTMP: Allow application-selectable outfile streams. | |
| --- | |
| .../protocols/rtmp/basertmpappprotocolhandler.h | 12 +++++- | |
| .../protocols/rtmp/streaming/innetrtmpstream.h | 4 +- | |
| .../protocols/rtmp/basertmpappprotocolhandler.cpp | 43 +++++++++++++++----- | |
| .../protocols/rtmp/streaming/innetrtmpstream.cpp | 22 +--------- | |
| 4 files changed, 47 insertions(+), 34 deletions(-) | |
| diff --git a/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h b/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h | |
| index fa730fd..0bca06b 100644 | |
| --- a/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h | |
| +++ b/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h | |
| @@ -26,10 +26,12 @@ | |
| #include "protocols/rtmp/header.h" | |
| #include "protocols/rtmp/rtmpprotocolserializer.h" | |
| #include "protocols/rtmp/sharedobjects/somanager.h" | |
| -#include "basertmpprotocol.h" | |
| +#include "streaming/baseoutstream.h" | |
| +#include "streaming/baseoutfilestream.h" | |
| class OutboundRTMPProtocol; | |
| class BaseRTMPProtocol; | |
| +class BaseOutFileStream; | |
| class DLLEXP BaseRTMPAppProtocolHandler | |
| : public BaseAppProtocolHandler { | |
| @@ -233,6 +235,14 @@ public: | |
| * */ | |
| bool SendRTMPMessage(BaseRTMPProtocol *pTo, Variant message, | |
| bool trackResponse = false); | |
| + | |
| + /* | |
| + * Create a file stream for writing to disk. | |
| + * pFrom - The connection which wants to stream to disk | |
| + * meta - Stream metadata | |
| + * append - Whether to append this stream to an exiting file | |
| + * */ | |
| + virtual BaseOutFileStream *CreateOutFileStream(BaseRTMPProtocol *pFrom, Variant &meta, bool append); | |
| private: | |
| /* | |
| * Will transform stream names of type streamName?param1=value1¶m2=value2&... | |
| diff --git a/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h b/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h | |
| index 755c3ae..4e6f619 100644 | |
| --- a/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h | |
| +++ b/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h | |
| @@ -27,6 +27,7 @@ | |
| class BaseRTMPProtocol; | |
| class BaseOutStream; | |
| +class BaseOutFileStream; | |
| class DLLEXP InNetRTMPStream | |
| : public BaseInNetStream { | |
| @@ -70,8 +71,7 @@ public: | |
| virtual bool SendStreamMessage(string functionName, Variant ¶meters, | |
| bool persistent = true); | |
| bool SendOnStatusStreamPublished(); | |
| - bool RecordFLV(Variant &meta, bool append); | |
| - bool RecordMP4(Variant &meta); | |
| + bool Record(BaseOutFileStream* pOutFileStream); | |
| virtual void SignalOutStreamAttached(BaseOutStream *pOutStream); | |
| virtual void SignalOutStreamDetached(BaseOutStream *pOutStream); | |
| diff --git a/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp b/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| index 87576d8..676b8a2 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/basertmpappprotocolhandler.cpp | |
| @@ -28,6 +28,7 @@ | |
| #include "protocols/rtmp/streaming/baseoutnetrtmpstream.h" | |
| #include "protocols/rtmp/streaming/infilertmpstream.h" | |
| #include "protocols/rtmp/streaming/innetrtmpstream.h" | |
| +#include "protocols/rtmp/streaming/outfilertmpflvstream.h" | |
| #include "streaming/streamstypes.h" | |
| #include "streaming/baseinstream.h" | |
| #include "streaming/baseinnetstream.h" | |
| @@ -812,17 +813,10 @@ bool BaseRTMPAppProtocolHandler::ProcessInvokePublish(BaseRTMPProtocol *pFrom, | |
| if (recording || appending) { | |
| Variant meta = GetMetaData(streamName, false); | |
| - if ((meta[META_MEDIA_TYPE] == MEDIA_TYPE_LIVE_OR_FLV) || | |
| - (meta[META_MEDIA_TYPE] == MEDIA_TYPE_FLV)) { | |
| - if (!pInNetRTMPStream->RecordFLV(meta, appending)) { | |
| - FATAL("Unable to bind the recording stream"); | |
| - return false; | |
| - } | |
| - } else if (meta[META_MEDIA_TYPE] == MEDIA_TYPE_MP4) { | |
| - if (!pInNetRTMPStream->RecordMP4(meta)) { | |
| - FATAL("Unable to bind the recording stream"); | |
| - return false; | |
| - } | |
| + BaseOutFileStream *pOutFileStream = CreateOutFileStream(pFrom, meta, appending); | |
| + if (!pOutFileStream || !pInNetRTMPStream->Record(pOutFileStream)) { | |
| + FATAL("Unable to bind the recording stream"); | |
| + return false; | |
| } | |
| } | |
| @@ -1866,6 +1860,33 @@ bool BaseRTMPAppProtocolHandler::SendRTMPMessage(BaseRTMPProtocol *pTo, | |
| } | |
| } | |
| +BaseOutFileStream* BaseRTMPAppProtocolHandler::CreateOutFileStream( | |
| + BaseRTMPProtocol *pFrom, Variant &meta, bool append) | |
| +{ | |
| + //1. Compute the file name | |
| + string fileName = meta[META_SERVER_MEDIA_DIR]; | |
| + fileName += (string) meta[META_SERVER_FILE_NAME]; | |
| + FINEST("fileName: %s", STR(fileName)); | |
| + | |
| + //2. Delete the old file | |
| + if (append) { | |
| + WARN("append not supported yet. File will be overwritten"); | |
| + } | |
| + deleteFile(fileName); | |
| + | |
| + if ((meta[META_MEDIA_TYPE] == MEDIA_TYPE_LIVE_OR_FLV) || | |
| + (meta[META_MEDIA_TYPE] == MEDIA_TYPE_FLV)) { | |
| + return new OutFileRTMPFLVStream(pFrom, | |
| + GetApplication()->GetStreamsManager(), fileName); | |
| + } | |
| + if (meta[META_MEDIA_TYPE] == MEDIA_TYPE_MP4) { | |
| + FATAL("Streaming to MP4 file not supported"); | |
| + return NULL; | |
| + } | |
| + FATAL("Media type not supported"); | |
| + return NULL; | |
| +} | |
| + | |
| string NormalizeStreamName(string streamName) { | |
| replace(streamName, "-", "_"); | |
| replace(streamName, "?", "-"); | |
| diff --git a/sources/thelib/src/protocols/rtmp/streaming/innetrtmpstream.cpp b/sources/thelib/src/protocols/rtmp/streaming/innetrtmpstream.cpp | |
| index 7d3694c..7ac1d1a 100644 | |
| --- a/sources/thelib/src/protocols/rtmp/streaming/innetrtmpstream.cpp | |
| +++ b/sources/thelib/src/protocols/rtmp/streaming/innetrtmpstream.cpp | |
| @@ -187,30 +187,12 @@ bool InNetRTMPStream::SendOnStatusStreamPublished() { | |
| return true; | |
| } | |
| -bool InNetRTMPStream::RecordFLV(Variant &meta, bool append) { | |
| - //1. Compute the file name | |
| - string fileName = meta[META_SERVER_MEDIA_DIR]; | |
| - fileName += (string) meta[META_SERVER_FILE_NAME]; | |
| - FINEST("fileName: %s", STR(fileName)); | |
| - | |
| - //2. Delete the old file | |
| - if (append) { | |
| - WARN("append not supported yet. File will be overwritten"); | |
| - } | |
| - deleteFile(fileName); | |
| - | |
| - //3. Create the out file | |
| - _pOutFileRTMPFLVStream = new OutFileRTMPFLVStream(_pProtocol, | |
| - _pStreamsManager, fileName); | |
| +bool InNetRTMPStream::Record(BaseOutFileStream *pOutStream) { | |
| - //4. Link it | |
| + _pOutFileRTMPFLVStream = pOutStream; | |
| return _pOutFileRTMPFLVStream->Link(this); | |
| } | |
| -bool InNetRTMPStream::RecordMP4(Variant &meta) { | |
| - NYIR; | |
| -} | |
| - | |
| void InNetRTMPStream::SignalOutStreamAttached(BaseOutStream *pOutStream) { | |
| if (GETAVAILABLEBYTESCOUNT(_videoCodecInit) != 0) { | |
| if (!pOutStream->FeedData(GETIBPOINTER(_videoCodecInit), | |
| -- | |
| 1.7.5.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment