繁体   English   中英

如何在单个应用程序上使用Win32管道

[英]How to use win32 pipe on single application

我正在尝试写入我在本地创建的管道(在同一应用程序中)
目前,我有这个:

audioPipe = CreateNamedPipe(
    L"\\\\.\\pipe\\audioPipe", // name of the pipe
    PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only
    PIPE_TYPE_MESSAGE, // send data as a byte stream
    1, // only allow 1 instance of this pipe
    0, // no outbound buffer
    0, // no inbound buffer
    0, // use default wait time
    NULL // use default security attributes
);

我不知道如何实际向其中写入数据。 我猜想使用WriteFile()但是还有更多吗? 我阅读的所有示例似乎都在使用客户端服务器系统,而我并不需要。 我只需要将数据写入管道(希望ffmpeg接管)

基于注释,您正在创建命令行FFMPEG应用程序将连接到的命名管道。 为了使其正常工作,您需要做三件事:

  1. 将您对CreateNamedPipe()调用更改为使用PIPE_TYPE_BYTE而不是PIPE_TYPE_MESSAGE ,因为您将把原始数据实时流传输到FFMPEG,而不是消息。 这将允许FFMPEG使用它想要的任何任意缓冲区等从管道读取数据,就好像它是直接从真实文件中读取一样。

     audioPipe = CreateNamedPipe( L"\\\\\\\\.\\\\pipe\\\\audioPipe", // name of the pipe PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only PIPE_TYPE_BYTE, // send data as a byte stream 1, // only allow 1 instance of this pipe 0, // no outbound buffer 0, // no inbound buffer 0, // use default wait time NULL // use default security attributes ); 
  2. 您需要先调用ConnectNamedPipe()以接受来自FFMPEG的连接,然后才能向其中写入数据。

     ConnectNamedPipe(audioPipe, NULL); 
  3. 运行FFMPEG时,请使用-i参数将管道名称指定为输入文件名,例如: ffmpeg -i \\\\.\\pipe\\audioPipe

除了调用WriteFile之外,没有什么比这更多的了。 在调用WriteFile等待客户端连接之前,您还需要调用ConnectNamedPipe

客户端通过使用CreateFile打开句柄,然后使用ReadFile读取管道中的内容。

对于字节流,您需要PIPE_TYPE_BYTE 您确定要将缓冲区大小指定为0吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM