Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Libvlc function libvlc_new_callbacks
QtWS25 Last Chance

Libvlc function libvlc_new_callbacks

Scheduled Pinned Locked Moved Solved C++ Gurus
8 Posts 4 Posters 4.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aurquiel
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • A aurquiel

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @aurquiel This is a Qt forum.
      How is your question related to Qt?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      _ 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        Pure speculation:

        variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer); looks like you are not cleaning the buffer after any call

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        A 1 Reply Last reply
        1
        • VRoninV VRonin

          Pure speculation:

          variable_archivo_TS.write( (char *)transferencia_usb_2->buffer, tamanio_buffer); looks like you are not cleaning the buffer after any call

          A Offline
          A Offline
          aurquiel
          wrote on last edited by
          #4

          @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 call

          Thank 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
          }
          
          1 Reply Last reply
          0
          • jsulmJ jsulm

            @aurquiel This is a Qt forum.
            How is your question related to Qt?

            _ Offline
            _ Offline
            _PIB
            wrote on last edited by
            #5

            @jsulm if one cannot posts something about C++ and not directly related to Qt what is "General and Desktop" category of "Qt Development" for?

            jsulmJ 1 Reply Last reply
            0
            • _ _PIB

              @jsulm if one cannot posts something about C++ and not directly related to Qt what is "General and Desktop" category of "Qt Development" for?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @_PIB You can ask but you should be aware that this is Qt forum.
              "General and Desktop" - Qt in general and desktop related questions.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              _ 1 Reply Last reply
              0
              • jsulmJ jsulm

                @_PIB You can ask but you should be aware that this is Qt forum.
                "General and Desktop" - Qt in general and desktop related questions.

                _ Offline
                _ Offline
                _PIB
                wrote on last edited by
                #7

                @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.

                jsulmJ 1 Reply Last reply
                0
                • _ _PIB

                  @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.

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @_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.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved