How to use ibvlc_media_new_callbacks
Posted: 15 Mar 2017 16:09
Hello
I was searching around the internet but there are not good examples about using libvlc_media_new_callbacks from stream from an array of data
I am developing a software to play packets form an USB Device on Linux. I actually get to play the data but saving in a file that constantly grows up, that's the problem the file could consume the hard drive if you are reproducing it for a long time, for 48 min of Video i got a file of 10GB, the packets are TS (transport stream packets) so in a single frequency i have 6 programs ID, I just saying in that file of 10GB i have 6 different channels.
Lets see the callback function of the code USB receiving, in that callback function i get the buffer with the data. (I am using Libusb, this function is doing by a thread just receive data, the play is doing in the main thread application)
//This line of the code is where a write to the file.
In the frontend to play it i wait 1.5 seconds to fill the file, serach the directory and path to the file, add the media and play the file
The question is i could use this function
LIBVLC_API libvlc_media_t* libvlc_media_new_callbacks ( libvlc_instance_t * instance,
libvlc_media_open_cb open_cb,
libvlc_media_read_cb read_cb,
libvlc_media_seek_cb seek_cb,
libvlc_media_close_cb close_cb,
void * opaque
)
In the callback read pass the buffer of 1024bytes incoming through the usb transfer rather than write it to a file
But i can find any code how to implement it. I just find this https://forum.videolan.org/viewtopic.php?t=127796
The source code of my project is here https://github.com/aurquiel/TDA_Linux
I was searching around the internet but there are not good examples about using libvlc_media_new_callbacks from stream from an array of data
I am developing a software to play packets form an USB Device on Linux. I actually get to play the data but saving in a file that constantly grows up, that's the problem the file could consume the hard drive if you are reproducing it for a long time, for 48 min of Video i got a file of 10GB, the packets are TS (transport stream packets) so in a single frequency i have 6 programs ID, I just saying in that file of 10GB i have 6 different channels.
Lets see the callback function of the code USB receiving, in that callback function i get the buffer with the data. (I am using Libusb, this function is doing by a thread just receive data, the play is doing in the main thread application)
Code: Select all
//Global variables
std::ofstream variable_archivo_TS ("data.ts"); //File to write the BTS frame
const int tamanio_buffer=1024; //Size of the buffer 240Kb 245760
unsigned char MPEG2_TS[tamanio_buffer]; //Buffer to receive
int contador_evitar_basura=0;
static void funcion_de_llamda_leer_transferencia_usb(struct libusb_transfer *transferencia_usb_2)
{
int res;
if(transferencia_usb_2->status ==LIBUSB_TRANSFER_COMPLETED)
{
std::cout<<"Transferencia completa"<<std::endl; //Mostar la siguiente advertencia
}
else
{
std::cout<<"Error: "<<transferencia_usb_2->status<<std::endl; //Mostar la siguiente advertencia
}
contador_evitar_basura++; //Incrementar contador_evitar_basura
//If glbal_counter > 2 write to a file, this to avoid the trash in the first transmissions
if (contador_evitar_basura>2) variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
res = libusb_submit_transfer(transferencia_usb_2); //Realizar unanueva transferencia
if(res !=0)
{
std::cout<<"submitting. error code: "<<res<<std::endl; //Mostar la siguiente advertencia
}
}
Code: Select all
if (contador_evitar_basura>2) variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
Code: Select all
SemcoSleep(1500); //Esperar 1,5 segundo para llenar un poco el archivo .TS
//Obteniendo el directorio donde se encuentra el archivo a reproducir Comienzo
char directorio_actual_de_trabajo[200000]; //TamaƱo del buffer donde guardar el directorio
getcwd(directorio_actual_de_trabajo, sizeof(directorio_actual_de_trabajo)); //Rellena el buffer con el directorio actual de trabajo
std::string direccion_archivo_vlc=directorio_actual_de_trabajo; //Se guarda en un string
direccion_archivo_vlc="file://"+direccion_archivo_vlc+"/data.ts"; //Se modifica el string para hacerlo compatible con la direccion tomada por libvlc
//Obteniendo el directorio donde se encuentra el archivo a reproducir Fin
libvlc_media_t *media; //Se crea la variable media
media = libvlc_media_new_location(instancia_vlc, &direccion_archivo_vlc[0u]); //fill media
libvlc_media_add_option(media,funcion_leer_id()); //Se coloca el Id del canal deseado a reproducir
libvlc_media_player_set_media(reproductor, media); //Se coloca el medio media en el reporductor
libvlc_media_player_play(reproductor); //Reproducir
LIBVLC_API libvlc_media_t* libvlc_media_new_callbacks ( libvlc_instance_t * instance,
libvlc_media_open_cb open_cb,
libvlc_media_read_cb read_cb,
libvlc_media_seek_cb seek_cb,
libvlc_media_close_cb close_cb,
void * opaque
)
In the callback read pass the buffer of 1024bytes incoming through the usb transfer rather than write it to a file
But i can find any code how to implement it. I just find this https://forum.videolan.org/viewtopic.php?t=127796
The source code of my project is here https://github.com/aurquiel/TDA_Linux