2014-08-27, 22:47
I've already been looking at your code, and something seems strange to me. It's about how you created a new bufferqueue to save a stack of sftp requests that you execute asynchronously. It seems like this means you are still using a separate buffer/cache in order to receive those requests (i also saw some memcpy and memmove stuff, not sure if that was related), but according to Memphiz a separate cache would not be accepted in xbmc. So if it would not be accepted, it doesn't seem like it would be a good solution. I could also be wrong about this, because i can't quite follow all of it.
As for the actual implementation of asynchronous read in xbmc, wouldn't it be possible to only change the CSFTPSession::Read() and CSFTPFile::Read method (based on the current code in xbmc master)? You would have to do the sftp_async_read_begin and a check for ssh_again, ssh_error and eof in CSFTPFile::Read() and the actual sftp_async_read in CSFTPSession::Read(). The queuing would be handled by CFileCache which is used whenever buffering in XBMC is enabled. It would keep asking for chunks to read until reaching the required XBMC buffer size. It also waits till each chunk is read before processing it. This seems like the easiest and most consistent way to enable asynchronous reads in XBMC. Of course, i'm assuming that the way CFileCache works is compatible with the way sftp does asynchronous reads and i'm assuming that the asynchronous reads would also still work without a buffer (albeit with stuttering in the video/audio when the bandwidth drops, which is to be expected when you don't have a buffer).
I couldn't quite work out if the above would actually be enough to make it work. Perhaps you've already tried it, then you could tell me what happened and why it didn't work. If not, I'd be glad to hear it too, then i might give it a try. I would also love for this to make it into the next xbmc/kodi release.
As for the actual implementation of asynchronous read in xbmc, wouldn't it be possible to only change the CSFTPSession::Read() and CSFTPFile::Read method (based on the current code in xbmc master)? You would have to do the sftp_async_read_begin and a check for ssh_again, ssh_error and eof in CSFTPFile::Read() and the actual sftp_async_read in CSFTPSession::Read(). The queuing would be handled by CFileCache which is used whenever buffering in XBMC is enabled. It would keep asking for chunks to read until reaching the required XBMC buffer size. It also waits till each chunk is read before processing it. This seems like the easiest and most consistent way to enable asynchronous reads in XBMC. Of course, i'm assuming that the way CFileCache works is compatible with the way sftp does asynchronous reads and i'm assuming that the asynchronous reads would also still work without a buffer (albeit with stuttering in the video/audio when the bandwidth drops, which is to be expected when you don't have a buffer).
I couldn't quite work out if the above would actually be enough to make it work. Perhaps you've already tried it, then you could tell me what happened and why it didn't work. If not, I'd be glad to hear it too, then i might give it a try. I would also love for this to make it into the next xbmc/kodi release.