Changeset 54


Ignore:
Timestamp:
08/04/10 21:39:39 (18 months ago)
Author:
shiretu
Message:

-- added support for stream metadata gathered from flv metadata

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/builders/cmake/rtmpserver/rtmpserver.lua

    r53 r54  
    133133                                        ip="0.0.0.0", 
    134134                                        port=6666, 
    135                                         protocol="inboundLiveFlv" 
     135                                        protocol="inboundLiveFlv", 
     136                                        waitForMetadata=true, 
    136137                                }, 
    137138                                { 
  • trunk/sources/thelib/include/protocols/liveflv/inboundliveflvprotocol.h

    r2 r54  
    3131        InNetLiveFLVStream *_pStream; 
    3232        bool _headerParsed; 
     33        bool _waitForMetadata; 
    3334public: 
    3435        InboundLiveFLVProtocol(); 
     
    4142        virtual bool SignalInputData(IOBuffer &buffer); 
    4243private: 
    43         bool InitializeStream(); 
     44        bool InitializeStream(string streamName); 
    4445}; 
    4546 
  • trunk/sources/thelib/src/protocols/liveflv/inboundliveflvprotocol.cpp

    r2 r54  
    11/*  
    2 *  Copyright (c) 2010, 
    3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
    4  
    5 *  This file is part of crtmpserver. 
    6 *  crtmpserver is free software: you can redistribute it and/or modify 
    7 *  it under the terms of the GNU General Public License as published by 
    8 *  the Free Software Foundation, either version 3 of the License, or 
    9 *  (at your option) any later version. 
    10  
    11 *  crtmpserver is distributed in the hope that it will be useful, 
    12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    14 *  GNU General Public License for more details. 
    15  
    16 *  You should have received a copy of the GNU General Public License 
    17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
    18 */ 
     2 *  Copyright (c) 2010, 
     3 *  Gavriloaie Eugen-Andrei (shiretu@gmail.com) 
     4 * 
     5 *  This file is part of crtmpserver. 
     6 *  crtmpserver is free software: you can redistribute it and/or modify 
     7 *  it under the terms of the GNU General Public License as published by 
     8 *  the Free Software Foundation, either version 3 of the License, or 
     9 *  (at your option) any later version. 
     10 * 
     11 *  crtmpserver is distributed in the hope that it will be useful, 
     12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     14 *  GNU General Public License for more details. 
     15 * 
     16 *  You should have received a copy of the GNU General Public License 
     17 *  along with crtmpserver.  If not, see <http://www.gnu.org/licenses/>. 
     18 */ 
    1919 
    2020#ifdef HAS_PROTOCOL_LIVEFLV 
     
    3232        _pStream = NULL; 
    3333        _headerParsed = false; 
     34        _waitForMetadata = false; 
    3435} 
    3536 
     
    4243 
    4344bool InboundLiveFLVProtocol::Initialize(Variant &parameters) { 
     45        GetCustomParameters() = parameters; 
     46        FINEST("parameters:\n%s", STR(parameters.ToString())); 
     47        if (parameters.HasKey("waitForMetadata")) 
     48                _waitForMetadata = (bool)parameters["waitForMetadata"]; 
     49        else 
     50                _waitForMetadata = false; 
     51        FINEST("_waitForMetadata: %d", _waitForMetadata); 
    4452        return true; 
    4553} 
     
    6371        //1. Initialize the stream 
    6472        if (_pStream == NULL) { 
    65                 if (!InitializeStream()) { 
    66                         FATAL("Unable to initialize the stream"); 
    67                         return false; 
     73                if (!_waitForMetadata) { 
     74                        if (!InitializeStream("")) { 
     75                                FATAL("Unable to initialize the stream"); 
     76                                return false; 
     77                        } 
    6878                } 
    6979        } 
     
    113123                        { 
    114124                                //audio data 
    115                                 if (!_pStream->FeedData(GETIBPOINTER(buffer), length, 0, 
    116                                                 length, timestamp, true)) { 
    117                                         FATAL("Unable to feed audio"); 
    118                                         return false; 
     125                                if (_pStream != NULL) { 
     126                                        if (!_pStream->FeedData(GETIBPOINTER(buffer), length, 0, 
     127                                                        length, timestamp, true)) { 
     128                                                FATAL("Unable to feed audio"); 
     129                                                return false; 
     130                                        } 
    119131                                } 
    120132                                break; 
     
    123135                        { 
    124136                                //video data 
    125                                 if (!_pStream->FeedData(GETIBPOINTER(buffer), length, 0, 
    126                                                 length, timestamp, false)) { 
    127                                         FATAL("Unable to feed audio"); 
    128                                         return false; 
     137                                if (_pStream != NULL) { 
     138                                        if (!_pStream->FeedData(GETIBPOINTER(buffer), length, 0, 
     139                                                        length, timestamp, false)) { 
     140                                                FATAL("Unable to feed audio"); 
     141                                                return false; 
     142                                        } 
    129143                                } 
    130144                                break; 
     
    151165                                //3. Read the rest of the parameters 
    152166                                Variant parameters; 
     167                                string streamName = ""; 
    153168                                while (GETAVAILABLEBYTESCOUNT(metaBuffer) > 0) { 
    154169                                        Variant v; 
     
    157172                                                return false; 
    158173                                        } 
     174                                        if (v.HasKey("streamName")) { 
     175                                                if (v["streamName"] == V_STRING) { 
     176                                                        streamName = (string) v["streamName"]; 
     177                                                } 
     178                                        } 
    159179                                        parameters.PushToArray(v); 
    160180                                } 
    161181 
     182                                if (_pStream == NULL) { 
     183                                        if (!InitializeStream(streamName)) { 
     184                                                FATAL("Unable to initialize the stream"); 
     185                                                return false; 
     186                                        } 
     187                                } 
     188 
     189                                INFO("Stream metadata:\n%s", STR(parameters.ToString())); 
     190 
    162191                                //4. Send the notify 
    163                                 if (!_pStream->SendStreamMessage(notifyFunction, parameters, true)) { 
    164                                         FATAL("Unable to send the notify"); 
    165                                         return false; 
     192                                if (_pStream != NULL) { 
     193                                        if (!_pStream->SendStreamMessage(notifyFunction, parameters, true)) { 
     194                                                FATAL("Unable to send the notify"); 
     195                                                return false; 
     196                                        } 
    166197                                } 
    167198 
     
    183214} 
    184215 
    185 bool InboundLiveFLVProtocol::InitializeStream() { 
    186         //1. Compute a stream name based on the nature of the carrier (if any...) 
    187         string streamName = ""; 
    188         if (GetIOHandler() != NULL) { 
    189                 //we have a carrier 
    190                 if (GetIOHandler()->GetType() == IOHT_TCP_CARRIER) { 
    191                         //this is a tcp carrier 
    192                         streamName = format("%s_%d", 
    193                                         STR(((TCPCarrier *) GetIOHandler())->GetFarEndpointAddressIp()), 
    194                                         ((TCPCarrier *) GetIOHandler())->GetFarEndpointPort()); 
     216bool InboundLiveFLVProtocol::InitializeStream(string streamName) { 
     217        if (streamName == "") { 
     218                //1. Compute a stream name based on the nature of the carrier (if any...) 
     219                if (GetIOHandler() != NULL) { 
     220                        //we have a carrier 
     221                        if (GetIOHandler()->GetType() == IOHT_TCP_CARRIER) { 
     222                                //this is a tcp carrier 
     223                                streamName = format("%s_%d", 
     224                                                STR(((TCPCarrier *) GetIOHandler())->GetFarEndpointAddressIp()), 
     225                                                ((TCPCarrier *) GetIOHandler())->GetFarEndpointPort()); 
     226                        } else { 
     227                                //this is not a TCP carrier 
     228                                streamName = format("flv_%d", GetId()); 
     229                        } 
    195230                } else { 
    196                         //this is not a TCP carrier 
     231                        //we don't have a carrier. This protocl might be artificially fed 
    197232                        streamName = format("flv_%d", GetId()); 
    198233                } 
    199         } else { 
    200                 //we don't have a carrier. This protocl might be artificially fed 
    201                 streamName = format("flv_%d", GetId()); 
    202234        } 
    203235        FINEST("Stream name: %s", STR(streamName)); 
Note: See TracChangeset for help on using the changeset viewer.