Audio/video stream recording forums

Attention Visitor:
You may have to register or log in before you can post:
  • Click the register link to sign up.
  • Registered members please fill in the form below and click the "Log in" button.
To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Audio/video stream recording forums > Streaming media recording forum > rtmpdump
Register FAQ Members List Calendar Mark Forums Read

Reply Post New Thread
 
Thread Tools Display Modes
  #1  
Old 02-14-2012, 09:12 AM
Elgero Elgero is offline
Senior Member
 
Join Date: Feb 2012
Posts: 177
Elgero is on a distinguished road
Default

Using LibRTMP in VB or C# application


Hello, I'm trying to use LibRTMP in my VB application, but I can't get it to work. No matter what rtmp stream I use, it always fails to connect (RTMP_Connect). Using RTMPDump with the same rtmp stream works fine.

Does anybody have any idea what's wrong?

In the immediate window I always get either this message:

Code:
Parsing...
Parsed protocol: 0
Parsed host    : rtmp.website.com
Parsed app     : play
Problem accessing the DNS. (addr: rtmp.website.com)
or this message:

Code:
Parsing...
Parsed protocol: 0
Parsed host    : rtmp.website.com
Parsed app     : play
RTMP_Connect0, failed to create socket. Error: 10093
This is my form code.

Code:
Imports System.Runtime.InteropServices
Imports System.IO

Public Class Form1

    Private m_LogCallback As New LibRTMP.LogCallback(AddressOf LogCallback)

    Private Sub LogCallback(ByVal level As LibRTMP.LogLevel, ByVal message As String)
        Debug.Print(message)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim b(1023) As Byte
        Dim bytes_read As Integer
        Dim r As IntPtr

        LibRTMP.RTMP_LogSetLevel(LibRTMP.LogLevel.ALL)
        LibRTMP.SetLogCallback(m_LogCallback)

        r = LibRTMP.RTMP_Alloc

        If r = IntPtr.Zero Then
            MessageBox.Show("failed rtmp_alloc")
            Return
        End If

        LibRTMP.RTMP_Init(r)

        LibRTMP.RTMP_SetupURL(r, Marshal.StringToHGlobalAnsi("rtmp://whatever-stream.com"))

        '// Always fails to connect here
        If LibRTMP.RTMP_Connect(r, IntPtr.Zero) = 0 Then
            MessageBox.Show("failed to establish RTMP connection")
            Return
        End If

        If LibRTMP.RTMP_ConnectStream(r, 0) = 0 Then
            MessageBox.Show("failed to establish RTMP session")
            Return
        End If

        Using FS As New FileStream("C:\teststream.flv", FileMode.Create, FileAccess.Write)
            Do
                bytes_read = LibRTMP.RTMP_Read(r, b, b.Length)
                If (bytes_read = 0) Then Exit Do
                FS.Write(b, 0, bytes_read)
            Loop
        End Using

        LibRTMP.RTMP_Close(r)
        LibRTMP.RTMP_Free(r)
    End Sub
End Class
This is my LibRTMP class.

Code:
Imports System.Runtime.InteropServices

Public Class LibRTMP

    Public Enum LogLevel
        CRIT = 0
        [ERROR]
        WARNING
        INFO
        DEBUG
        DEBUG2
        ALL
    End Enum

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_LibVersion() As Integer
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_Alloc() As IntPtr
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub RTMP_Free(ByVal rtmp As IntPtr)
    End Sub

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub RTMP_Init(ByVal rtmp As IntPtr)
    End Sub

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub RTMP_Close(ByVal rtmp As IntPtr)
    End Sub

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub RTMP_EnableWrite(ByVal rtmp As IntPtr)
    End Sub

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_SetupURL(ByVal rtmp As IntPtr, ByVal url As IntPtr) As Integer
    End Function
    'Intptr, because memory must remain valid so use StringToHGlobalAnsi

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub RTMP_LogSetLevel(ByVal lvl As Integer)
    End Sub

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_Connect(ByVal rtmp As IntPtr, ByVal cp As IntPtr) As Integer
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_ConnectStream(ByVal rtmp As IntPtr, ByVal seekTime As Integer) As Integer
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_Read(ByVal rtmp As IntPtr, ByVal buffer() As Byte, ByVal size As Integer) As Integer
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_Pause(ByVal rtmp As IntPtr, ByVal DoPause As Integer) As Integer
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_IsConnected(ByVal rtmp As IntPtr) As Boolean
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_IsTimedout(ByVal rtmp As IntPtr) As Boolean
    End Function

    <DllImport("librtmp.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function RTMP_HashSWF(ByVal url As String, <System.Runtime.InteropServices.Out()> ByRef size As Integer, ByVal hash() As Byte, ByVal age As Integer) As Boolean
    End Function

    <DllImport("logstub.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Function InitSockets() As Integer
    End Function

    <DllImport("logstub.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub CleanupSockets()
    End Sub

    <DllImport("logstub.dll", CallingConvention:=CallingConvention.Cdecl)>
    Public Shared Sub SetLogCallback(ByVal cb As LogCallback)
    End Sub

    Public Delegate Sub LogCallback(ByVal level As LogLevel, ByVal message As String)
End Class
Reply With Quote
  #2  
Old 02-14-2012, 11:28 AM
KSV KSV is offline
Senior Member
 
Join Date: Apr 2011
Posts: 853
KSV is on a distinguished road
Cool

Re: Using LibRTMP in VB or C# application


you need to initialize winsock before calling RTMP_Connect. first error is due to invalid rtmp url and second error is due to non initialized winsock.
Reply With Quote
  #3  
Old 02-14-2012, 12:45 PM
Elgero Elgero is offline
Senior Member
 
Join Date: Feb 2012
Posts: 177
Elgero is on a distinguished road
Default

Re: Using LibRTMP in VB or C# application


Thank you very much. It works fine now.
Reply With Quote
  #4  
Old 04-28-2012, 07:34 AM
Student Student is offline
Junior Member
 
Join Date: Aug 2011
Posts: 1
Student is on a distinguished road
Default

Re: Using LibRTMP in VB or C# application


Quote:
Originally Posted by Elgero View Post
Thank you very much. It works fine now.
Hi,

I´m trying to get this done too (in VB 6.0) and am right now not so good at it.
Would it be possible to get your Code (or a HowTo)?

Would be great if you could help me.
Thank you very much in advance.

Student
Reply With Quote
  #5  
Old 04-29-2012, 05:45 AM
evol evol is offline
Senior Member
 
Join Date: Jun 2011
Posts: 228
evol is on a distinguished road
Default

Re: Using LibRTMP in VB or C# application


Quote:
Originally Posted by Student View Post
Hi,

I´m trying to get this done too (in VB 6.0) and am right now not so good at it.
Would it be possible to get your Code (or a HowTo)?

Would be great if you could help me.
Thank you very much in advance.

Student
The code wont work on VB 6.0 his using VB.NET.

Get a copy its free VISUAL BASIC 2010 EXPRESS
Reply With Quote
  #6  
Old 06-16-2013, 06:02 AM
lorus lorus is offline
Junior Member
 
Join Date: Apr 2013
Posts: 7
lorus is on a distinguished road
Default

Re: Using LibRTMP in VB or C# application


Hi Elgero,

can you please post the code that was finally working for you?


cheerz lorus
Reply With Quote
Reply Post New Thread
Tags:



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 11:54 AM.


Powered by All-streaming-media.com; 2006-2011
vB forum hacked with Zoints add-ons