【问题标题】:LibVLC streaming to memory p_audio_dataLibVLC 流式传输到内存 p_audio_data
【发布时间】:2015-04-02 21:22:57
【问题描述】:

我一直在使用 LibVLC 将音频文件流式传输到内存,以便可以通过 UDP 套接字逐段发送。

我在这里学习教程:https://wiki.videolan.org/Stream_to_memory_%28smem%29_tutorial/

这是我的代码:

   void handleStream(void* p_audio_data, uint8_t* p_pcm_buffer, unsigned int channels,
            unsigned int rate, unsigned int nb_samples, unsigned int bits_per_sample, size_t size, int64_t pts)
        {
        char *buffer;
        int dataSize = size;
        int messageSize;
    int dataSent = 0;

    //cout << p_pcm_buffer << endl;

    // While we have data to write
    while (dataSize > 0)
    {
        // Set the size of the next message to send
        if (dataSize > MESSAGE_SIZE)
        {
            messageSize = MESSAGE_SIZE;
        }
        else
        {
            messageSize = dataSize;
        }

        // Write the data to the socket
        buffer = new char[dataSize];
        memcpy(buffer, p_pcm_buffer + dataSent, messageSize);

        sendto(multicastSocket, buffer, MESSAGE_SIZE, 0, (struct sockaddr *) &multicastDestInfo, sizeof(multicastDestInfo));

        dataSize -= messageSize;
        dataSent += messageSize;

        delete[] buffer;
    }

    // Free the temporary stream buffer
    free(p_pcm_buffer);
}

我遇到的问题是我需要在handleStream 回调中指定要将数据发送到哪个套接字。 LibVLC 教程暗示我可以指定通过

传入的对象
void* p_audio_data

但我找不到任何关于如何实际设置它的资源。

任何帮助将不胜感激!

【问题讨论】:

    标签: c++ sockets memory stream libvlc


    【解决方案1】:

    您可以为需要发送的参数定义结构或类。

    struct Myparam{
        //your socket param
        struct SocketStruct socket;
        //other params
    }
    ..
    Myparam* pUserData = new Myparam();
    param->socket = multicastSocket;
    
    ..
    
    sprintf(smem_options
      , "#transcode{vcodec=h264}:smem{"
         "video-prerender-callback=%lld,"
         "video-postrender-callback=%lld,"
         "video-data=%lld,"
         "no-time-sync},"
      , (long long int)(intptr_t)(void*)&cbVideoPrerender
      , (long long int)(intptr_t)(void*)&cbVideoPostrender 
      , (long long int)(intptr_t)(void*)pUserData
      );
    

    【讨论】:

      猜你喜欢
      • 2017-06-07
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多