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回调中指定将数据发送到哪个套接字
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
);
相关文章:
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- 'string.assign(string.data(), 5)' 是明确定义的还是 UB?
- 收到错误"invalid use of non-static data member 'stu::n' "
- C++ 初始化 .data 部分中的变量
- 模式"allocate memory or use existing data"
- boost::asio data owning `ConstBufferSequence`
- Python to C++ Data structure API
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- protobuf C++ SQLite handle blob data
- 错误:字段'dateOfBirth'的类型不完整'Poco::Data::Date'
- 为什么构造函数 Message(const T&data) 与 Message(T&& data) 冲突,当 T = int&时?
- "thread-safe data"与"thread-safe code/functions"的区别
- 如何找到目标文件 *.o 的 ram rom 使用情况(.bss .text .rodata .data)?
- 这在C++ "It does not own the underlying data, and so is cheap to copy or assign"中意味着什么
- 使用 .data() 将字符数组转换为 std::string 不会转换整个数组
- *(int*)&data[18]在这段代码中实际上做了什么?
- 避免在使用WinAPI(Windows Core Audio)时无效的指针
- 出现这种错误的原因是什么"invalid use of non-static data member "
- 构造中错误:未在此范围中声明"data"
- 我可以在初始化之前使用 std::array 成员变量中的 data() 指针吗?发出警告