Created
January 11, 2012 22:54
-
-
Save j0sh/1597284 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
| diff --git a/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h b/sources/thelib/include/protocols/rtmp/basertmpappprotocolhandler.h | |
| index fa730fd..3a26899 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,11 @@ public: | |
| * */ | |
| bool SendRTMPMessage(BaseRTMPProtocol *pTo, Variant message, | |
| bool trackResponse = false); | |
| + | |
| + /* | |
| + * Create a file stream for writing to disk. | |
| + * */ | |
| + 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..d245ef8 100644 | |
| --- a/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h | |
| +++ b/sources/thelib/include/protocols/rtmp/streaming/innetrtmpstream.h | |
| @@ -70,8 +70,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(BaseOutStream* 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..4e77eb4 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..18cadbb 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(BaseOutStream *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), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment