简体   繁体   中英

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

Based on comments, you are creating a named pipe that the command-line FFMPEG app will connect to. In order for that to work, you need to do three things:

  1. 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. 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.

     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. you need to call ConnectNamedPipe() to accept a connection from FFMPEG before you can then write data to it.

     ConnectNamedPipe(audioPipe, NULL); 
  3. when running FFMPEG, specify your pipe name as the input filename using the -i parameter, eg: ffmpeg -i \\\\.\\pipe\\audioPipe .

There's nothing more to this than calling WriteFile . You'll also need to call ConnectNamedPipe before calling WriteFile to wait for the client to connect.

The client reads from the pipe by opening a handle with CreateFile and then reading using ReadFile .

For a stream of bytes you need PIPE_TYPE_BYTE . Are you sure you want to specify 0 for the buffer sizes?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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