RTP - LIB - Datenschreiben ?



  • Hallo,
    ich will die http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib folgende lib benutzen um eine MJPEG zu streamen, das Beispiel habe ich soweit verstanden und nochmal etwas ausführlicher dokumentiert und erweitert. Jedenfalls die Methode SendPacket http://research.edm.uhasselt.be/jori/jrtplib/documentation/classjrtplib_1_1RTPSession.html erwartet neben den Einstellungen einen data Pointer. Hier beginnt meine Frage, wie genau soll ich jetzt ein MJPEG mit dieser Methode verschicken?

    Die Frage ist, was muss ich mit nem MJPEG machen damit ich es mit SendPacket() verschicken kann.

    Danke 🙂

    #include "rtpsession.h"
    #include "rtpudpv4transmitter.h"
    #include "rtpipv4address.h"
    #include "rtpsessionparams.h"
    #include "rtperrors.h"
    #include "rtprawpacket.h" //Abgeleitete Klasse RTPMJPEG
    #ifndef WIN32
    	#include <netinet/in.h>
    	#include <arpa/inet.h>
    #else
    	#include <winsock2.h>
    #endif // WIN32
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <string>
    
    //DEFINES//
    #define PAYLOADTYPE 26		//Payloadtype for MJPEG "26" found in RFC2435
    #define MARK false			//Marker ?
    #define TIMESTAMPINC 3000   //Increment of the timestamp 30fps = 3000; 25fps = 3600
    
    using namespace jrtplib;
    
    //
    // This function checks if there was a RTP error. If so, it displays an error
    // message and exists.
    //
    
    void checkerror(int rtperr)
    {
    	if (rtperr < 0)
    	{
    		std::cout << "ERROR: " << RTPGetErrorString(rtperr) << std::endl;
    		exit(-1);
    	}
    }
    
    //
    // The main routine
    //
    
    int main(void)
    {
    #ifdef WIN32
    	WSADATA dat;
    	WSAStartup(MAKEWORD(2,2),&dat);
    #endif // WIN32
    
    	RTPSession sess;													  // $$ Create a session object
    
    	uint16_t portbase,destport;
    	uint32_t destip;
    	std::string ipstr;
    	int status,i,num;
    
            // First, we'll ask for the necessary information
    
    	std::cout << "Enter local portbase:" << std::endl;
    	std::cin >> portbase;
    	std::cout << std::endl;
    
    	std::cout << "Enter the destination IP address" << std::endl;
    	std::cin >> ipstr;
    	destip = inet_addr(ipstr.c_str());
    	if (destip == INADDR_NONE)
    	{
    		std::cerr << "Bad IP address specified" << std::endl;
    		return -1;
    	}
    
    	// The inet_addr function returns a value in network byte order, but
    	// we need the IP address in host byte order, so we use a call to
    	// ntohl
    	destip = ntohl(destip);
    
    	std::cout << "Enter the destination port" << std::endl;
    	std::cin >> destport;
    
    	std::cout << std::endl;
    	std::cout << "Number of packets you wish to be sent:" << std::endl;
    	std::cin >> num;
    
    	// Now, we'll create a RTP session, set the destination, send some
    	// packets and poll for incoming data.
    
    	RTPUDPv4TransmissionParams transparams;								 // $$ Object for the transmition parameters 
    	RTPSessionParams sessparams;										 //	$$ Object for the sessionparameters
    
    	// IMPORTANT: The local timestamp unit MUST be set, otherwise
    	//            RTCP Sender Report info will be calculated wrong
    	// In this case, we'll be sending 10 samples each second, so we'll
    	// put the timestamp unit to (1.0/10.0)
    	sessparams.SetOwnTimestampUnit(1.0/90000.0);						// $$ Setting Timestamp - 90000Hz sample Rate for MJPEG
    	sessparams.SetAcceptOwnPackets(true);								// $$ ???
    	transparams.SetPortbase(portbase);									// $$ Setting local port 
    
    	sessparams.SetUsePollThread(false);									// $$ NOT using a background thread for polling the incoming data, no automatic response (RTCP packets) 
    	///////////////////////////////////////////
    
    	status = sess.Create(sessparams,&transparams);					   	// $$ Creating a session Create awaits (const RTPSessionParams &sessparams, RTPTransmitter *transmitter)
    	checkerror(status);
    
    	RTPIPv4Address addr(destip,destport);								// $$ Building the IP address/Port via constructur object: addr
    
    	status = sess.AddDestination(addr);									// $$ Set Destination, needs an object containing the IP address port (see above)
    	checkerror(status);
    
    	//DEFAULT RTP PACKAGE Parameters//
    	sess.SetDefaultMark(MARK);
    	sess.SetDefaultPayloadType(PAYLOADTYPE);							// §§ (M)JPEG = 26
    	sess.SetDefaultTimestampIncrement(TIMESTAMPINC);
    	//END - OF SETTING//
    
    	for (i = 1 ; i <= num ; i++)
    	{
    		printf("\nSending packet %d/%d\n",i,num);
    
    		// send the packet
    		status = sess.SendPacket((void *)"1234567890",10);              // $$ Sending package ||HERE DATA!!??||
    		checkerror(status);
    
    		// INCOMING DATA PROCESSING // 
    		sess.BeginDataAccess();											// $$ From BeginDataAccess to EndDataAccess: "The processing of incoming data"
    
    		// check incoming packets
    		if (sess.GotoFirstSourceWithData())								// $$ 
    		{
    			do
    			{
    				RTPPacket *pack;
    
    				while ((pack = sess.GetNextPacket()) != NULL)
    				{
    					// You can examine the data here
    					printf("Got packet !\n");
    																		// $$ Here we can do whatever we want with the received package
    					// we don't longer need the packet, so
    					// we'll delete it
    					sess.DeletePacket(pack);
    				}
    			} while (sess.GotoNextSourceWithData());
    		}
    
    		sess.EndDataAccess();
    		//END OF INCOMING DATA PROCESSING //
    
    #ifndef RTP_SUPPORT_THREAD
    		status = sess.Poll();
    		checkerror(status);
    #endif // RTP_SUPPORT_THREAD
    
    		RTPTime::Wait(RTPTime(1,0));
    	}
    
    	sess.BYEDestroy(RTPTime(10,0),0,0);									// $$ Informing other particapants of our depature and cleanup the RTPSession class
    
    #ifdef WIN32
    	WSACleanup();
    #endif // WIN32
    	return 0;
    }
    


  • Hi 🙂 niemand ein Tipp ?


Anmelden zum Antworten