Differenze tra le versioni di "Riproduzione dell'audio di radio WEB con le funzioni esterne del API di GStreamer"

Da Gambas-it.org - Wikipedia.
Riga 61: Riga 61:
 
   
 
   
 
  '''End'''
 
  '''End'''
 +
 +
 +
===Uso della funzione ''gst_parse_launch( )'' e il plugin "''uridecodebin''"===
 +
Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.
 +
Private bo As Boolean
 +
 +
 +
Library "libgstreamer-1.0"
 +
 +
Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
 +
Private Const GST_FORMAT_TIME As Integer = 3
 +
 +
<FONT color=gray>' ''gst_init (int *argc, char **argv[])''
 +
' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font>
 +
Private Extern gst_init(argc As Pointer, argv As Pointer)
 +
 +
<FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
 +
' ''Create a new pipeline based on command line syntax.''</font>
 +
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer
 +
 +
<FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
 +
' ''Sets the state of the element.''</font>
 +
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer
 +
 +
<FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
 +
' ''Queries an element for the stream position in nanoseconds.''</font>
 +
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean
 +
 +
<FONT color=gray>' ''void gst_object_unref(gpointer object)
 +
' ''Decrements the reference count on object.''</font>
 +
Private Extern gst_object_unref(gobject As Pointer)
 +
 +
 +
'''Public''' Sub Main()
 +
 +
  Dim audio As Pointer
 +
  Dim pos As Long
 +
   
 +
  gst_init(0, 0)
 +
 
 +
  audio = gst_parse_launch("uridecodebin uri=<FONT color=gray>''http&#058;//indirizzo/della/radio/web/live''</font> ! autoaudiosink", 0)
 +
     
 +
<FONT color=gray>' ''Avviamo l'esecuzione audio della radio web:''</font>
 +
  gst_element_set_state(audio, GST_STATE_PLAYING)
 +
 
 +
  Repeat
 +
    gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
 +
    Write "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, pos / 1000000)
 +
    Wait 0.001
 +
  Until bo = True
 +
 
 +
  gst_object_unref(audio)
 +
 
 +
  Quit
 +
 
 +
'''End'''
 +
 +
 +
'''Public''' Sub Application_Read()
 +
 
 +
  Dim s As String
 +
 
 +
  Input s
 +
 
 +
  bo = True
 +
 
 +
'''End'''
 +
 +
 +
===Uso della funzione ''gst_parse_launch( )'' e i plugin "''souphttpsrc''" e "''decodebin''"===
 +
Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.
 +
Private bo As Boolean
 +
 +
 +
Library "libgstreamer-1.0"
 +
 +
Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
 +
Private Const GST_FORMAT_TIME As Integer = 3
 +
 +
<FONT color=gray>' ''gst_init (int *argc, char **argv[])''
 +
' ''Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.''</font>
 +
Private Extern gst_init(argc As Pointer, argv As Pointer)
 +
 +
<FONT color=gray>' ''GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
 +
' ''Create a new pipeline based on command line syntax.''</font>
 +
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer
 +
 +
<FONT color=gray>' ''GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
 +
' ''Sets the state of the element.''</font>
 +
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer
 +
 +
<FONT color=gray>' ''gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
 +
' ''Queries an element for the stream position in nanoseconds.''</font>
 +
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean
 +
 +
<FONT color=gray>' ''void gst_object_unref(gpointer object)
 +
' ''Decrements the reference count on object.''</font>
 +
Private Extern gst_object_unref(gobject As Pointer)
 +
 +
 +
'''Public''' Sub Main()
 +
 +
  Dim audio As Pointer
 +
  Dim pos As Long
 +
   
 +
  gst_init(0, 0)
 +
 
 +
  audio = gst_parse_launch("souphttpsrc location=<FONT color=gray>''http&#058;//indirizzo/della/radio/web/live''</font> ! decodebin ! autoaudiosink", 0)
 +
     
 +
<FONT color=gray>' ''Avviamo l'esecuzione audio della radio web:''</font>
 +
  gst_element_set_state(audio, GST_STATE_PLAYING)
 +
 
 +
  Repeat
 +
    gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
 +
    Write "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, pos / 1000000)
 +
    Wait 0.001
 +
  Until bo = True
 +
 
 +
  gst_object_unref(audio)
 +
 
 +
  Quit
 +
 
 +
'''End'''
 +
 +
 +
'''Public''' Sub Application_Read()
 +
 
 +
  Dim s As String
 +
 
 +
  Input s
 +
 
 +
  bo = True
 +
 
 +
'''End'''
 +
  
  

Versione delle 18:58, 3 ago 2019

Le stazioni radio via WEB possono essere ascoltate utilizzando le risorse del API di GStreamer.


Uso del plug-in playbin

Private play As Pointer

Library "libgstreamer-1.0"

Private Const GST_STATE_NULL As Integer = 1
Private Const GST_STATE_PLAYING As Integer = 4

' gst_init (&argc, &argv)
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Integer, argv As Pointer)

' GstElement * gst_element_factory_make(const gchar *factoryname, Const gchar * name)
' Create a new element of the type defined by the given element factory.
Private Extern gst_element_factory_make(factoryname As String, name As String) As Pointer

' void g_object_set(gpointer object, const gchar *first_property_name, ...)
' Sets properties on an object.
Private Extern g_object_set(gobject As Pointer, key As String, value As String, nl As String)

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstobject As Pointer, state As Integer) As Integer

' void gst_object_unref(gpointer object)
' Decrements the reference count on object .
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Form_Open()

Dim retI As Integer

 gst_init(0, 0)

 play = gst_element_factory_make("playbin", "play")

' Nel terzo argomento della seguente funzione va inserito
' l'indirizzo web del flusso di dati audio in tempo reale:
 g_object_set(play, "uri", "http://indirizzo/web/del/flusso/dati/della/radio4-web", Null)

' Avviamo la riproduzione audio della radio-web:
 retI = gst_element_set_state(play, GST_STATE_PLAYING)
 Print "Stato di cambiamento = "; retI

End


Public Sub Button1_Click()

Dim retI As Integer

' Arrestiamo la riproduzione audio:
 retI = gst_element_set_state(play, GST_STATE_NULL)
 Print "Stato di cambiamento = "; retI
  
 gst_object_unref(play)

End


Uso della funzione gst_parse_launch( ) e il plugin "uridecodebin"

Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.

Private bo As Boolean


Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()

 Dim audio As Pointer
 Dim pos As Long
    
  gst_init(0, 0)
  
  audio = gst_parse_launch("uridecodebin uri=http://indirizzo/della/radio/web/live ! autoaudiosink", 0)
      
' Avviamo l'esecuzione audio della radio web:
  gst_element_set_state(audio, GST_STATE_PLAYING)
  
  Repeat
   gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
   Write "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, pos / 1000000)
   Wait 0.001
 Until bo = True
 
 gst_object_unref(audio)
 
 Quit
 
End


Public Sub Application_Read()
 
 Dim s As String
 
 Input s
 
 bo = True
 
End


Uso della funzione gst_parse_launch( ) e i plugin "souphttpsrc" e "decodebin"

Nell'esempio, che segue, sarà sufficiente premere il tasto "Invio" per chiudere il programma.

Private bo As Boolean


Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()

 Dim audio As Pointer
 Dim pos As Long
    
  gst_init(0, 0)
  
  audio = gst_parse_launch("souphttpsrc location=http://indirizzo/della/radio/web/live ! decodebin ! autoaudiosink", 0)
      
' Avviamo l'esecuzione audio della radio web:
  gst_element_set_state(audio, GST_STATE_PLAYING)
  
  Repeat
   gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
   Write "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, pos / 1000000)
   Wait 0.001
 Until bo = True
 
 gst_object_unref(audio)
 
 Quit
 
End


Public Sub Application_Read()
 
 Dim s As String
 
 Input s
 
 bo = True
 
End


Uso della funzione gst_parse_launch( ) e del plugin jackaudiosink

Per l'esecuzione del seguente codice è necessario avviare preliminarmente il programma Jack.
Sarà sufficiente premere il tasto "Invio" per chiudere il programma.

Private bo As Boolean


Library "libgstreamer-1.0"

Private Enum GST_STATE_VOID_PENDING = 0, GST_STATE_NULL, GST_STATE_READY, GST_STATE_PAUSED, GST_STATE_PLAYING
Private Const GST_FORMAT_TIME As Integer = 3

' gst_init (int *argc, char **argv[])
' Initializes the GStreamer library, setting up internal path lists, registering built-in elements, and loading standard plugins.
Private Extern gst_init(argc As Pointer, argv As Pointer)

' GstElement * gst_parse_launch (const gchar *pipeline_description, GError **error)
' Create a new pipeline based on command line syntax.
Private Extern gst_parse_launch(description As String, GError As Pointer) As Pointer

' GstStateChangeReturn gst_element_set_state(GstElement *element, GstState state)
' Sets the state of the element.
Private Extern gst_element_set_state(gstelement As Pointer, state As Integer) As Integer

' gboolean gst_element_query_position (GstElement *element, GstFormat format, gint64 *cur)
' Queries an element for the stream position in nanoseconds.
Private Extern gst_element_query_position(gstelement As Pointer, gstformat As Pointer, cur As Pointer) As Boolean

' void gst_object_unref(gpointer object)
' Decrements the reference count on object.
Private Extern gst_object_unref(gobject As Pointer)


Public Sub Main()

 Dim audio As Pointer
 Dim pos As Long
    
  gst_init(0, 0)
  
  audio = gst_parse_launch("uridecodebin uri=http://indirizzo/della/radio/web/live ! audioconvert ! audioresample ! jackaudiosink", 0)
      
' Avviamo l'esecuzione audio della radio web:
  gst_element_set_state(audio, GST_STATE_PLAYING)
  
  Repeat
   gst_element_query_position(audio, GST_FORMAT_TIME, VarPtr(pos))
   Write "\rTempo trascorso: " & Date(0, 0, 0, 0, 0, 0, pos / 1000000)
   Wait 0.001
 Until bo = True
 
 gst_object_unref(audio)
 
 Quit
 
End


Public Sub Application_Read()
 
 Dim s As String
 
 Input s
 
 bo = True
 
End