Advertisement
drojf

mpv_ipc_issue.c

Aug 15th, 2016
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // MPV test
  2. //
  3. // mpv stops responding after about 50 loadfile commands are written, however writefile can keep
  4. // writing even after mpv stops responding to commands
  5. // mpv starts responding after this program is forced to quit/the pipe disconnects
  6. // If you open pipe, write, then close pipe every command, this problem does not occur.
  7. //
  8. // You can validate this behavior by opening mpv in command line mode with -v and seeing
  9. // that the output stops after some time. MPV wil still respond to keyboard commands though
  10.  
  11. #include <Windows.h>
  12. #include "stdio.h"
  13.  
  14. int main()
  15. {
  16.     //const char command[] = "loadfile sdfasdfsadfasdfasdfc.mp3\n";     //doesn't matter if file doesn't exist
  17.     const char command[] = "loadfile test.mp3\n";
  18.     //const char command[] = "loadfile movie.mpg\n";
  19.  
  20.     HANDLE hPipe = CreateFile(L"\\\\.\\pipe\\mpvsocket", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  21.     if (hPipe == INVALID_HANDLE_VALUE)
  22.     {
  23.         return 0;   //exit if can't create pipe
  24.     }
  25.  
  26.     unsigned int total_bytes_written = 0;
  27.  
  28.     for (int i = 0; i < 1000; i++)
  29.     {
  30.         DWORD dwWritten;
  31.         BOOL fSuccess = WriteFile(hPipe, command, sizeof(command)-1, &dwWritten, NULL);
  32.         if (!fSuccess)
  33.         {
  34.             break; //exit if write fails
  35.         }
  36.  
  37.         total_bytes_written += dwWritten;
  38.         printf("%d: wrote %d bytes, total: %d\n", i, dwWritten, total_bytes_written);
  39.        
  40.         //FlushFileBuffers(hPipe);
  41.         Sleep(300); //timing doesn't seem to make any difference, just takes longer to cause the problem.
  42.     }
  43.  
  44.     CloseHandle(hPipe);
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement