Libvlc function libvlc_new_callbacks
-
Hello i am trying to implement this function of libvlc version 3.0, libvlc_new_callbacks to read from a buffer array. Documentation
I got a function that use libusb to receive usb transfers from a device
static void procedimiento_de_llamada_leer_transferencia_usb(struct libusb_transfer *transferencia_usb_2) { if(transferencia_usb_2->status == LIBUSB_TRANSFER_COMPLETED) { std::cout<<"Transferencia completa"<<std::endl; } else std::cout<<"Error: "<<transferencia_usb_2->status<<std::endl; contador_evitar_basura++; if (contador_evitar_basura > 4) { apuntador_al_buffer_recepcion_BTS=transferencia_usb_2->buffer; variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer); } int respuesta_transferencia_llamada = libusb_submit_transfer(transferencia_usb_2); if(respuesta_transferencia_llamada != 0) std::cout<<"Error transferencia: "<<respuesta_transferencia_llamada<<std::endl; }
Actually the transfered bytes goes to a file and then open that file with libvlc as a media file to reproduce it, with this line instruction i write the bytes received to a file
variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
I can see the video in my program but the file is constantly growing, if a keep watching the video for a long time the file could get sizes of 10 Gb. I am trying to send the buffer that libusb received to the player without saving it in a file, i create a global variable that points to the buffer
unsigned char *apuntador_al_buffer_recepcion_BTS; apuntador_al_buffer_recepcion_BTS=transferencia_usb_2->buffer;
Then i am trying to implement the function of libvlc_new_call_backs:
I pass the pointer apuntador_al_buffer_recepcion_BTS to the function, and set the callbacks open and read, declare seek and close as a NULL, maybe is a wrong approach but i am thinking to read all the buffer at once so i don't need a seek function
void procedimiento_media_callbacks() { static libvlc_media_t *media = libvlc_media_new_callbacks( instancia_vlc, // vlc open_callback, //open media read_callback, //read media NULL, //NULL seak NULL, //NULL close apuntador_al_buffer_recepcion_BTS); //NULL libvlc_media_player_set_media(reproductor, media); libvlc_media_add_option(media, funcion_leer_id()); libvlc_media_player_set_media(reproductor, media); }
I am thinking in just using the open_callback function to points data to opaque(buffer) and set sizep to the size of the buffer,
int open_callback(void *opaque, void **datap, long unsigned int *sizep) { *sizep = 245760; *datap = opaque; return 0; }
In the read function i am not sure about this just return the size of data read it
long int read_callback(void *opaque, unsigned char *buf,long unsigned int len) { return 245760; }
But i can't get it work, i couldn't find a code that use this function.
Maybe if you know another way to read directly from the buffer, without creating a file, tell me please.
-
Hello i am trying to implement this function of libvlc version 3.0, libvlc_new_callbacks to read from a buffer array. Documentation
I got a function that use libusb to receive usb transfers from a device
static void procedimiento_de_llamada_leer_transferencia_usb(struct libusb_transfer *transferencia_usb_2) { if(transferencia_usb_2->status == LIBUSB_TRANSFER_COMPLETED) { std::cout<<"Transferencia completa"<<std::endl; } else std::cout<<"Error: "<<transferencia_usb_2->status<<std::endl; contador_evitar_basura++; if (contador_evitar_basura > 4) { apuntador_al_buffer_recepcion_BTS=transferencia_usb_2->buffer; variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer); } int respuesta_transferencia_llamada = libusb_submit_transfer(transferencia_usb_2); if(respuesta_transferencia_llamada != 0) std::cout<<"Error transferencia: "<<respuesta_transferencia_llamada<<std::endl; }
Actually the transfered bytes goes to a file and then open that file with libvlc as a media file to reproduce it, with this line instruction i write the bytes received to a file
variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
I can see the video in my program but the file is constantly growing, if a keep watching the video for a long time the file could get sizes of 10 Gb. I am trying to send the buffer that libusb received to the player without saving it in a file, i create a global variable that points to the buffer
unsigned char *apuntador_al_buffer_recepcion_BTS; apuntador_al_buffer_recepcion_BTS=transferencia_usb_2->buffer;
Then i am trying to implement the function of libvlc_new_call_backs:
I pass the pointer apuntador_al_buffer_recepcion_BTS to the function, and set the callbacks open and read, declare seek and close as a NULL, maybe is a wrong approach but i am thinking to read all the buffer at once so i don't need a seek function
void procedimiento_media_callbacks() { static libvlc_media_t *media = libvlc_media_new_callbacks( instancia_vlc, // vlc open_callback, //open media read_callback, //read media NULL, //NULL seak NULL, //NULL close apuntador_al_buffer_recepcion_BTS); //NULL libvlc_media_player_set_media(reproductor, media); libvlc_media_add_option(media, funcion_leer_id()); libvlc_media_player_set_media(reproductor, media); }
I am thinking in just using the open_callback function to points data to opaque(buffer) and set sizep to the size of the buffer,
int open_callback(void *opaque, void **datap, long unsigned int *sizep) { *sizep = 245760; *datap = opaque; return 0; }
In the read function i am not sure about this just return the size of data read it
long int read_callback(void *opaque, unsigned char *buf,long unsigned int len) { return 245760; }
But i can't get it work, i couldn't find a code that use this function.
Maybe if you know another way to read directly from the buffer, without creating a file, tell me please.
-
Pure speculation:
variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
looks like you are not cleaning the buffer after any call@VRonin said in Libvlc function libvlc_new_callbacks:
Pure speculation:
variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer);
looks like you are not cleaning the buffer after any callThank you
By the way i share the solution for other users, they could improve it
At this way you will read from a buffer that comes from libusb with transport stream video
int open_callback(void *opaque, void **datap, long unsigned int *sizep) { *sizep = 245760; *datap = opaque; return 0; } long int read_callback(void *opaque, unsigned char *buf,long unsigned int len) { procedimiento_retardo_milisegundos(60); //Delay waiting new data std::memcpy(buf,apuntador_al_buffer_recepcion_BTS, 245760); //Copy from archive return 245760; } void procedimiento_media_callbacks() { static libvlc_media_t *media = libvlc_media_new_callbacks( instancia_vlc, //Instancia vlc open_callback, //open media read_callback, //read media NULL, //NULL seak NULL, //NULL close apuntador_al_buffer_recepcion_BTS); //NULL libvlc_media_player_set_media(reproductor, 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 }
-
@jsulm if one cannot posts something about C++ and not directly related to Qt what is "General and Desktop" category of "Qt Development" for?
-
@_PIB You can ask but you should be aware that this is Qt forum.
"General and Desktop" - Qt in general and desktop related questions.@jsulm I mean, there is a development category which has "Qt" in it's name and a development category which does not have "Qt" in it's name. It would be natural to suggest that If it's the only difference then one can post things about C+++ and not necessarily about Qt here.
-
@jsulm I mean, there is a development category which has "Qt" in it's name and a development category which does not have "Qt" in it's name. It would be natural to suggest that If it's the only difference then one can post things about C+++ and not necessarily about Qt here.
@_PIB You should ask C++ questions here: https://forum.qt.io/category/34/c-gurus
It would be more natural to ask VLC related questions in a VLC forum/mailing list.