Attribute VB_Name = "Emisor"
Option Explicit
Public DireccionIP As String
Public CmdMOrigen As String
Public EmitiendoAhora As Byte
Public FormatoEmision As String

Public Sub InicializarEmisor(Origen As String)
Dim FormsStates() As Boolean, i As Integer, EnEjecucion As Boolean
ReDim FormsStates(0 To Forms.Count - 1)
For i = 0 To Forms.Count - 1
FormsStates(i) = Forms(i).Visible
Forms(i).Visible = False
Next

CmdMOrigen = Origen
Load Form15
Form15.Show
Form15.Refresh
Call ObtenerIP
Form15.Frame1.Visible = False

EnEjecucion = True
While EnEjecucion = True
DoEvents
EnEjecucion = False
For i = 0 To Forms.Count - 1
If Forms(i) Is Form15 Then
EnEjecucion = True
Exit For
End If
Next
Wend

CmdMOrigen = ""

For i = 0 To Forms.Count - 1
Forms(i).Visible = FormsStates(i)
Next
End Sub

Public Sub ObtenerIP()
Dim Comandos As String, BufferConsola As String, Posicion1 As Long, Posicion2 As Long
Dim Ret As String, RetSplit() As String
On Error GoTo Salir
Comandos = "cmd.exe /C ipconfig"
Call CaptureConsole.ExecAndCapture(Comandos, , , , , , , BufferConsola)
If BufferConsola = "" Then Exit Sub
Posicion1 = InStr(1, BufferConsola, "IP.")
If Posicion1 = 0 Then Posicion1 = InStr(1, BufferConsola, "IPv4.")
If Posicion1 = 0 Then Exit Sub
Posicion1 = InStr(Posicion1, BufferConsola, ": ")
If Posicion1 = 0 Then Exit Sub
Posicion1 = Posicion1 + 1
Posicion2 = InStr(Posicion1, BufferConsola, vbCrLf)
If Posicion2 = 0 Then Exit Sub
Ret = Mid(BufferConsola, Posicion1, Posicion2 - Posicion1)
If Ret = "" Then Exit Sub
RetSplit = Split(Ret, ".")
If UBound(RetSplit) - LBound(RetSplit) + 1 <> 4 Then Exit Sub
Ret = Val(RetSplit(LBound(RetSplit))) & "." & Val(RetSplit(LBound(RetSplit) + 1)) & "." & Val(RetSplit(LBound(RetSplit) + 2)) & "." & Val(RetSplit(LBound(RetSplit) + 3))
DireccionIP = Ret
If DireccionIP <> "" Then
Form15.Combo1.AddItem "udp://" & Emisor.DireccionIP & ":8080"
Form15.Combo1.AddItem "rtp://" & Emisor.DireccionIP & ":8080"
Form15.Combo1.Text = "udp://" & Emisor.DireccionIP & ":8080"
End If
Salir:
End Sub

Public Sub EmpezarEmision()
Dim Comandos As String, NumArchivo As Integer
Dim ComandosF As Convertidor.FormatoCmdL, BufError As Byte
Dim LoopCmd As String, BufferConsola As String
Dim OutCmdError As Long
If ffmpeg.ComprobarExistenciaFFmpeg = False Then Exit Sub
With Form15
If .Combo1.Text = "" Then
Lang.Emisor_Msg_DirectionNotFound
Exit Sub
End If
If .Check1.Value = 1 Then
If (IsNumeric(.Combo4.Text) = False And .Combo4.Text <> .Combo4.List(0)) Or InStr(1, .Combo4.Text, ".") > 0 Or InStr(1, .Combo4.Text, ",") > 0 Or InStr(1, .Combo4.Text, "-") > 0 Then
Lang.Emisor_Msg_RepitNumNoValid
Exit Sub
Else
If .Combo4.Text = .Combo4.List(0) Then LoopCmd = "-loop 0" Else LoopCmd = "-loop " & .Combo4.Text
End If
End If

If FormatoEmision = "" Then
Comandos = Chr(34) & ffmpeg.ffmpegPath & Chr(34)
Comandos = Comandos & " " & LoopCmd & " -re " & CmdMOrigen & " " & ffmpeg.FFmpegParametros.Contenedor & _
" mpegts " & ffmpeg.FFmpegParametros.CodecVideo & " libx264 " & ffmpeg.FFmpegParametros.CodecAudio & _
" libmp3lame " & ffmpeg.FFmpegParametros.BitrateAudio & " 24k " & ffmpeg.FFmpegParametros.SampleRate & _
" 22050 " & ffmpeg.FFmpegParametros.BitrateMaxVideo & _
" 750k -preset ultrafast -tune zerolatency -async 1 -bsf:v h264_mp4toannexb -bufsize 3000k " & _
.Combo1.Text
End If

If FormatoEmision <> "" Then
ComandosF = Convertidor.InterpretarPFormato(FormatoEmision, BufError)
If ComandosF.ECANombre <> "" Or ComandosF.ECVNombre <> "" Then
Lang.Grabador_Msg_FormatoNoValido
Exit Sub
End If
Select Case BufError
Case Is = 1: Lang.Convert_Error_GenerarCmdL_FormatoNotFound
Case Is = 2: Lang.Convert_Error_GenerarCmdL_LeerFmt
End Select
If BufError > 0 Then Exit Sub

Comandos = Chr(34) & ffmpeg.ffmpegPath & Chr(34) & " " & LoopCmd & _
" " & ComandosF.InCmdL & " " & CmdMOrigen & " " & ComandosF.OutCmdL & " " & ComandosF.CmdLA & " " & _
ComandosF.CmdLS & " " & ComandosF.CmdLV & " " & ComandosF.RelAspect & " " & ComandosF.TamanoVideo & _
" " & ComandosF.EliminarA & " " & ComandosF.EliminarS & " " & ComandosF.EliminarV
Comandos = Comandos & " " & .Combo1.Text
End If
EmitiendoAhora = 1
.Command2.Enabled = True
.Command3.Enabled = True
.Command7.Enabled = True
.Picture2.Visible = True
.Picture1.Visible = True
.Text3.Text = .Combo1.Text
.Text4.Text = ""
Call CaptureConsole.ExecAndCapture(Comandos, , , , .Text4, , 3, BufferConsola, 1024, OutCmdError)
If OutCmdError > 0 Then .Text4.Text = BufferConsola
.Command2.Enabled = False
.Command3.Enabled = False
.Command7.Enabled = False
.Text4.Text = .Text4.Text & vbCrLf & Lang.Convert_Str_ProcesoTermino
.Text4.SelStart = Len(.Text4.Text)
EmitiendoAhora = 0
End With
End Sub

Public Sub EmitirInFilesList()
Dim RutaConcat As String
If Aplicacion.InFilesCount = 0 Then
Lang.Convert_AddFiles2List
Exit Sub
End If
RutaConcat = Convertidor.GenerarListaConcat
If RutaConcat = "" Then Exit Sub
RutaConcat = ScriptObj.Archivo_RutaCorta(RutaConcat)
Call InicializarEmisor(ffmpeg.FFmpegParametros.Contenedor & " concat -safe 0 -i " & Chr(34) & RutaConcat & Chr(34))
Call ScriptObj.BorrarCarpeta(ScriptObj.DirectorioPadre(RutaConcat), True)
End Sub
