[英]How to use win32 pipe on single application
I'm trying to write to a pipe I created locally (in the same application) 我正在尝试写入我在本地创建的管道(在同一应用程序中)
At the moment I have this: 目前,我有这个:
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
);
I don't know how to actually write data to it. 我不知道如何实际向其中写入数据。 I guess using WriteFile()
but is there more to it? 我猜想使用WriteFile()
但是还有更多吗? All examples I read seem to be using a client-server system and I don't need that. 我阅读的所有示例似乎都在使用客户端服务器系统,而我并不需要。 I just need to write data to the pipe (so ffmpeg picks it up, hopefully) 我只需要将数据写入管道(希望ffmpeg接管)
Based on comments, you are creating a named pipe that the command-line FFMPEG app will connect to. 基于注释,您正在创建命令行FFMPEG应用程序将连接到的命名管道。 In order for that to work, you need to do three things: 为了使其正常工作,您需要做三件事:
change your call to CreateNamedPipe()
to use PIPE_TYPE_BYTE
instead of PIPE_TYPE_MESSAGE
, as you will be streaming raw data live to FFMPEG, not messages. 将您对CreateNamedPipe()
调用更改为使用PIPE_TYPE_BYTE
而不是PIPE_TYPE_MESSAGE
,因为您将把原始数据实时流传输到FFMPEG,而不是消息。 That will allow FFMPEG to read data from the pipe using whatever arbitrary buffers, etc it wants, as if it were reading from a real file directly. 这将允许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 );
you need to call ConnectNamedPipe()
to accept a connection from FFMPEG before you can then write data to it. 您需要先调用ConnectNamedPipe()
以接受来自FFMPEG的连接,然后才能向其中写入数据。
ConnectNamedPipe(audioPipe, NULL);
when running FFMPEG, specify your pipe name as the input filename using the -i
parameter, eg: ffmpeg -i \\\\.\\pipe\\audioPipe
. 运行FFMPEG时,请使用-i
参数将管道名称指定为输入文件名,例如: ffmpeg -i \\\\.\\pipe\\audioPipe
。
There's nothing more to this than calling WriteFile
. 除了调用WriteFile
之外,没有什么比这更多的了。 You'll also need to call ConnectNamedPipe
before calling WriteFile
to wait for the client to connect. 在调用WriteFile
等待客户端连接之前,您还需要调用ConnectNamedPipe
。
The client reads from the pipe by opening a handle with CreateFile
and then reading using ReadFile
. 客户端通过使用CreateFile
打开句柄,然后使用ReadFile
读取管道中的内容。
For a stream of bytes you need PIPE_TYPE_BYTE
. 对于字节流,您需要PIPE_TYPE_BYTE
。 Are you sure you want to specify 0 for the buffer sizes? 您确定要将缓冲区大小指定为0吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.