簡體   English   中英

LibVLC流式傳輸到內存p_audio_data

[英]LibVLC streaming to memory p_audio_data

我一直在使用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

但是我找不到有關如何進行實際設置的任何資源。

任何幫助將不勝感激!

您可以為需要發送的參數定義結構或類。

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
  );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM