Jump to content

LibRTMP in autoit


Recommended Posts

Hi 1st post and i have a question can LibRTMP from the rtmpdump package and used in software like xbmc be used in autoit ?

I found some vb code to do it but i thought it would be cool if autit could do it also.

Here is the vb code:

Form:

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

LibRTMP class:

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

Note: you need to initialize winsock before calling RTMP_Connect.

More info on LibRTMP and RTMPDump here: http://rtmpdump.mplayerhq.hu/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...