Audio/video stream recording forums (http://stream-recorder.com/forum/index.php)
-   rtmpdump (http://stream-recorder.com/forum/forumdisplay.php?f=54)
-   -  

Customized rtmpdump binaries with patch file

(http://stream-recorder.com/forum/showthread.php?t=16103)

KSV 04-18-2013 07:50 AM

Re: Customized rtmpdump binaries with patch file


 
for the time being try with openssl and fresh copy of repo without any modifications.

mkucharski 04-18-2013 12:28 PM

Re: Customized rtmpdump binaries with patch file


 
KSV, would you consider forking rtmpdump on github (or any other source code hosting service) and integrate your patches there? Or have you considered to push your changes upstream?

RedPenguin 04-18-2013 12:58 PM

Re: Customized rtmpdump binaries with patch file


 
Quote:

Originally Posted by KSV (Post 61689)
for the time being try with openssl and fresh copy of repo without any modifications.

Doing this produces a rtmpdump that works also.

KSV 04-18-2013 01:09 PM

Re: Customized rtmpdump binaries with patch file


 
can you add my latest patch file to the openssl mix and try. also try with fresh repo + polarssl only.

RedPenguin 04-18-2013 02:26 PM

Re: Customized rtmpdump binaries with patch file


 
Adding your patch to openssl blend breaks and so does with polarssl no other changes.

EDIT: As a test I upgraded to PolarSSL 1.2.7 from 1.0.0 and with fresh code that actually does download but again the minute your patch is added, broken again :(.

KSV 04-19-2013 11:12 AM

Re: Customized rtmpdump binaries with patch file


 
Quote:

Originally Posted by RedPenguin (Post 61697)
Adding your patch to openssl blend breaks and so does with polarssl no other changes.

EDIT: As a test I upgraded to PolarSSL 1.2.7 from 1.0.0 and with fresh code that actually does download but again the minute your patch is added, broken again :(.

hmmm so then something in patch is causing this particular problem. in absence of test case you have to debug it yourself. i can only suggest how to do that if you are interested.

1. first create two fresh repos and apply patch to only one of them.

2. copy rtmp.c, rtmp.h and rtmp_sys.h from patched repo to non-patched one.

3. compile it and check if problem reoccurs. if yes then we can leave out changes in other files as possible culprit.

4. now the hard part, if the problem is with changes of rtmp.c then you have to remove the code added by patch, block by block and figure out the offending code.

RedPenguin 04-19-2013 06:38 PM

Re: Customized rtmpdump binaries with patch file


 
Well so far it appears it's definitely those files but to even get rtmpdump to compile I had to copy over the patched rtmpdump.c but it still fails on rtmpgw but that's not needed right now.

I also tried with only rtmp_sys.h only so that looks like it's not the problem.

Will update once I get further.

RedPenguin 04-19-2013 10:13 PM

Re: Customized rtmpdump binaries with patch file


 
I have found almost the exact problem, it is definitely changes to the rtmp.c that break it.

The code you place in at the very bottom is doing it:

I can't seem to pinpoint the exact part of the code but once I removed all of this said code plus some small pieces above referencing it, it immediately worked.

Code:

+static int
+ConnectSocket(RTMP *r)
+{
+  int on = 1;
+  struct sockaddr_in service;
+  if (!r->Link.hostname.av_len)
+    return FALSE;
+
+  memset(&service, 0, sizeof (struct sockaddr_in));
+  service.sin_family = AF_INET;
+
+  if (r->Link.socksport)
+    {
+      /* Connect via SOCKS */
+      if (!add_addr_info(&service, &r->Link.sockshost, r->Link.socksport))
+        return FALSE;
+    }
+  else
+    {
+      /* Connect directly */
+      if (!add_addr_info(&service, &r->Link.hostname, r->Link.port))
+        return FALSE;
+    }
+
+  r->m_sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+  if (r->m_sb.sb_socket != -1)
+    {
+      if (connect(r->m_sb.sb_socket, (struct sockaddr *) &service, sizeof (struct sockaddr)) < 0)
+        {
+          int err = GetSockError();
+          RTMP_Log(RTMP_LOGERROR, "%s, failed to connect socket. %d (%s)",
+                  __FUNCTION__, err, strerror(err));
+          RTMP_Close(r);
+          return FALSE;
+        }
+
+      if (r->Link.socksport)
+        {
+          RTMP_Log(RTMP_LOGDEBUG, "%s ... SOCKS negotiation", __FUNCTION__);
+          if (!SocksNegotiate(r))
+            {
+              RTMP_Log(RTMP_LOGERROR, "%s, SOCKS negotiation failed.", __FUNCTION__);
+              RTMP_Close(r);
+              return FALSE;
+            }
+        }
+    }
+  else
+    {
+      RTMP_Log(RTMP_LOGERROR, "%s, failed to create socket. Error: %d",
+              __FUNCTION__, GetSockError());
+      return FALSE;
+    }
+
+  /* set timeout */
+  SET_RCVTIMEO(tv, r->Link.timeout);
+  if (setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *) &tv, sizeof (tv)))
+    {
+      RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %d failed!",
+              __FUNCTION__, r->Link.timeout);
+    }
+
+  setsockopt(r->m_sb.sb_socket, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof (on));
+  if (r->Link.protocol & RTMP_FEATURE_HTTP)
+    setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_KEEPALIVE, (char *) &on, sizeof (on));
+
+  return TRUE;
+}
+
+static int
+SendCommand(RTMP *r, char *method, int queue)
+{
+  char pbuf[256], *pend = pbuf + sizeof (pbuf), *enc;
+  AVal av_command, methodName;
+
+  enc = pbuf;
+  methodName.av_val = method;
+  methodName.av_len = strlen(method);
+  enc = AMF_EncodeString(enc, pend, &methodName);
+  enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes);
+  *enc++ = AMF_NULL;
+  av_command.av_val = pbuf;
+  av_command.av_len = enc - pbuf;
+
+  return SendInvoke(r, &av_command, queue);
+}
+
+static int
+SendGetStreamLength(RTMP *r)
+{
+  char pbuf[256], *pend = pbuf + sizeof (pbuf), *enc;
+  AVal av_Command;
+
+  enc = pbuf;
+  enc = AMF_EncodeString(enc, pend, &av_getStreamLength);
+  enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes);
+  *enc++ = AMF_NULL;
+  enc = AMF_EncodeString(enc, pend, &r->Link.playpath);
+  av_Command.av_val = pbuf;
+  av_Command.av_len = enc - pbuf;
+
+  return SendInvoke(r, &av_Command, TRUE);
+}
+
+static int
+SendInvoke(RTMP *r, AVal *command, int queue)
+{
+  RTMPPacket packet;
+  char pbuf[512], *enc;
+
+  packet.m_nChannel = 0x03; /* control channel (invoke) */
+  packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM;
+  packet.m_packetType = RTMP_PACKET_TYPE_INVOKE;
+  packet.m_nTimeStamp = 0;
+  packet.m_nInfoField2 = 0;
+  packet.m_hasAbsTimestamp = 0;
+  packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE;
+
+  enc = packet.m_body;
+  if (command->av_len)
+    {
+      memcpy(enc, command->av_val, command->av_len);
+      enc += command->av_len;
+    }
+  else
+    return FALSE;
+  packet.m_nBodySize = enc - packet.m_body;
+
+  return RTMP_SendPacket(r, &packet, queue);
+}
+
+static int
+strsplit(char *src, int srclen, char delim, char ***params)
+{
+  char *sptr, *srcbeg, *srcend, *dstr;
+  int count = 1, i = 0, len = 0;
+
+  if (src == NULL)
+    return 0;
+  if (!srclen)
+    srclen = strlen(src);
+  srcbeg = src;
+  srcend = srcbeg + srclen;
+  sptr = srcbeg;
+
+  /* count the delimiters */
+  while (sptr < srcend)
+    {
+      if (*sptr++ == delim)
+        count++;
+    }
+  sptr = srcbeg;
+  *params = calloc(count, sizeof (size_t));
+  char **param = *params;
+
+  for (i = 0; i < (count - 1); i++)
+    {
+      dstr = strchr(sptr, delim);
+      len = dstr - sptr;
+      param[i] = calloc(len + 1, sizeof (char));
+      strncpy(param[i], sptr, len);
+      sptr += len + 1;
+    }
+
+  /* copy the last string */
+  if (sptr <= srcend)
+    {
+      len = srclen - (sptr - srcbeg);
+      param[i] = calloc(len + 1, sizeof (char));
+      strncpy(param[i], sptr, len);
+    }
+  return count;
+}


KSV 04-20-2013 01:04 AM

Re: Customized rtmpdump binaries with patch file


 
Quote:

Originally Posted by RedPenguin (Post 61731)
I can't seem to pinpoint the exact part of the code but once I removed all of this said code plus some small pieces above referencing it, it immediately worked.

Those functions can't be the real culprit. they aren't even being used as per your log file. keep all the patch except following change. revert
Code:

  else if (AVMATCH(&method, &av__onbwcheck) || AVMATCH(&method, &av_onBWCheck))
to original
Code:

  else if (AVMATCH(&method, &av__onbwcheck))

RedPenguin 04-20-2013 01:07 AM

Re: Customized rtmpdump binaries with patch file


 
Quote:

Originally Posted by KSV (Post 61732)
Those functions can't be the real culprit. they aren't even being used as per your log file. keep all the patch except following change. revert
Code:

  else if (AVMATCH(&method, &av__onbwcheck) || AVMATCH(&method, &av_onBWCheck))
to original
Code:

  else if (AVMATCH(&method, &av__onbwcheck))

Yea that's what I figured, because I swear I made those changes, compiled and it worked, but when I tried to reproduce it, it failed.

EDIT: Damn KSV are you good! I made this single change only and it worked immediately! Also just to double verify, I deleted the dir and reused git, made same change, and works again. :)

Though as far as you know, this should not break anything else in the patch?


All times are GMT -6. The time now is 05:47 PM.