Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MPV test
- //
- // mpv stops responding after about 50 loadfile commands are written, however writefile can keep
- // writing even after mpv stops responding to commands
- // mpv starts responding after this program is forced to quit/the pipe disconnects
- // If you open pipe, write, then close pipe every command, this problem does not occur.
- //
- // You can validate this behavior by opening mpv in command line mode with -v and seeing
- // that the output stops after some time. MPV wil still respond to keyboard commands though
- #include <Windows.h>
- #include "stdio.h"
- int main()
- {
- //const char command[] = "loadfile sdfasdfsadfasdfasdfc.mp3\n"; //doesn't matter if file doesn't exist
- const char command[] = "loadfile test.mp3\n";
- //const char command[] = "loadfile movie.mpg\n";
- HANDLE hPipe = CreateFile(L"\\\\.\\pipe\\mpvsocket", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hPipe == INVALID_HANDLE_VALUE)
- {
- return 0; //exit if can't create pipe
- }
- unsigned int total_bytes_written = 0;
- for (int i = 0; i < 1000; i++)
- {
- DWORD dwWritten;
- BOOL fSuccess = WriteFile(hPipe, command, sizeof(command)-1, &dwWritten, NULL);
- if (!fSuccess)
- {
- break; //exit if write fails
- }
- total_bytes_written += dwWritten;
- printf("%d: wrote %d bytes, total: %d\n", i, dwWritten, total_bytes_written);
- //FlushFileBuffers(hPipe);
- Sleep(300); //timing doesn't seem to make any difference, just takes longer to cause the problem.
- }
- CloseHandle(hPipe);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement