Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef RTMPSTREAMER_H
- #define RTMPSTREAMER_H
- #include "curl\curl.h"
- #include "curl\multi.h"
- #include <iostream>
- #include <WinSock2.h>
- #pragma comment(lib, "Ws2_32.lib")
- extern "C"
- {
- #include "librtmp/rtmp.h"
- #include "librtmp/log.h"
- }
- #include <string>
- #include <vector>
- #include <stdint.h>
- #include <inttypes.h>
- #define STR2AVAL(av,str) av.av_val = str; av.av_len = strlen(av.av_val)
- static void rtmp_log(int level, const char *fmt, va_list args)
- {
- std::cout<< fmt<< std::endl;
- }
- class RTMPStreamer
- {
- public:
- RTMPStreamer()
- {
- }
- WSADATA wsaData;
- RTMPStreamer(std::string url, bool writer)
- {
- RTMP_LogSetLevel(RTMP_LOGDEBUG);
- RTMP_LogSetCallback(rtmp_log);
- int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
- if (iResult != 0) {
- printf("WSAStartup failed: %d\n", iResult);
- }
- Connect(writer);
- //Example rtmp link
- //"rtmp://localhost:1935/live/desktop";
- }
- ~RTMPStreamer()
- {
- }
- bool RTMPStreamer::Connect(bool writer)
- {
- try
- {
- r = RTMP_Alloc();
- RTMP_Init(r);
- //This link works as rtmpdump as param -r
- char *uri = "rtmp://localhost:1935/flvplayback/bunny.flv";
- int retSetup = RTMP_SetupURL(r, uri);
- if(writer)
- {
- RTMP_EnableWrite(r);
- }
- int ver = RTMP_LibVersion();
- int pro = r->Link.protocol;
- int retVal = RTMP_Connect(r,NULL);
- retVal = RTMP_ConnectStream(r, 0);
- retVal = RTMP_IsConnected(r);
- //Return vals are all good here.
- return true;
- }
- catch(int e)
- {
- return false;
- }
- }
- void RTMPStreamer::Disconnect()
- {
- RTMP_Close(r);
- RTMP_Free(r);
- }
- int RTMPStreamer::Write(std::vector<unsigned char> data)
- {
- char *charArray = new char[data.size()+1];
- charArray = reinterpret_cast<char*> (&data[0]);
- return RTMP_Write(r,charArray,0);
- }
- std::vector<unsigned char> RTMPStreamer::Read()
- {
- bool packetComplete = false;
- char* buf = new char[4096];
- std::vector<unsigned char> bufVec;
- //Returns false
- int timedOut = RTMP_IsTimedout(r);
- //RETURNS 0.0000
- double duration = RTMP_GetDuration(r);
- // Returns 4, the bytes can be printed via cout and "FLV:)" where the :) is a single character. Seriously!?!
- int retVal = RTMP_Read(r,buf,sizeof(buf));
- return bufVec;
- }
- void RTMPStreamer::Pause()
- {
- RTMP_Pause(r,true);
- }
- void RTMPStreamer::Play()
- {
- RTMP_Pause(r,false);
- }
- void RTMPStreamer::Seek(int dTime)
- {
- RTMP_SendSeek(r,dTime);
- }
- private:
- RTMP *r;
- };
- #endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement