summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* demux, stream: ignore packets and errors on forced exitwm42018-03-261-1/+2
| | | | | | | | | | When this happens, network calls are forcibly aborted (more or less), but demuxers might keep going, as most of them do not check for forced exits properly. This can possibly lead to broken packets being added. Also do not attempt to read more packets in this situation. Also do not print a stream open failed message if opening was aborted anyway.
* stream: use native libavformat reconnection featurewm42018-01-041-35/+0
| | | | | | | | | | | | | | | | | | Remove our own hacky reconnection code, and use libavformat's feature for that. It's disabled by default, and until recently it did not work too well. This has been fixed in recent ffmpeg git master[1], so there's no reason to keep our own code. [1] FFmpeg/FFmpeg@8a108bdea06fac43af9f44b6d2538f357451167a We set "reconnect_delay_max" to 7, which limits the maximum time it waits. Since libavformat doubles the wait time on each reconnect attempt (starting with 1), and stops trying to reconnect once the wait time is over the reconnect_delay_max value, this allows for 4 reconnection attempts which should add to 11 seconds maximum wait time. The default is 120, which seems too high for normal playback use. (The user can still override these parameters with --stream-lavf-o.)
* stream_lavf: minor fixes to HTTP reconnection supportwm42018-01-021-2/+1
| | | | | | | | | | | | | Don't drop the stream buffers, because the read call (that must have been failing) might try to extend an existing read buffer in the first place. Just move the messy seek logic to stream_lavf.c. (In theory, stream_lavf should probably make libavformat connect at the correct offset instead of using a seek to reconnect it again. This patch doesn't fix it, but at least it's a good argument to have the messing with the position not in the generic code.) Also update the comment about avio not supporting reconnecting. It has that feature now. Maybe we should use it, but only after it gets fixed.
* msg: reinterpret a bunch of message levelsNiklas Haas2017-12-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | I've decided that MP_TRACE means “noisy spam per frame”, whereas MP_DBG just means “more verbose debugging messages than MSGL_V”. Basically, MSGL_DBG shouldn't create spam per frame like it currently does, and MSGL_V should make sense to the end-user and provide mostly additional informational output. MP_DBG is basically what I want to make the new default for --log-file, so the cut-off point for MP_DBG is if we probably want to know if for debugging purposes but the user most likely doesn't care about on the terminal. Also, the debug callbacks for libass and ffmpeg got bumped in their verbosity levels slightly, because being external components they're a bit less relevant to mpv debugging, and a bit too over-eager in what they consider to be relevant information. I exclusively used the "try it on my machine and remove messages from MSGL_* until it does what I want it to" approach of refactoring, so YMMV.
* stream: add an assert() to an obscure seek casewm42017-08-171-0/+1
| | | | | | | | This affects small seeks backwards while within the buffer. Demuxers usually avoid this, so it's probably not triggered very often. (Although demux_mkv.c potentially triggers it often, and it uses stream_peek() to explicitly guarantee that it can use this code to seek back.) The condition is complex enough to warrant an assertion.
* Avoid calling close(-1)wm42017-06-291-2/+4
| | | | | | | | | | While this is perfectly OK on Unix, it causes annoying valgrind warnings, and might be otherwise confusing to others. On Windows, the runtime can actually abort the process if this is called. push.c part taken from a patch by Pedro Pombeiro.
* stream: change license to LGPLwm42017-06-191-21/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | All relevant authors have agreed. There are two exceptions, patches by authors who could not be reached. This commit tries to remove their copyright. a0f08fbe: messes with the seeking code corner cases. The EOF flag logic was changed at some point, and always had a flaky history (see e.g. 347cf972 50274ca3 70411f27 5999efb9 0d5e6084 ff08d0c3 2e2f77e3 de5566f0 9554a844, all which happened after that patch, MPlayer ones without that patch). I claim that all of the copyright the patch might have added is gone. Except the message in stream_seek(), which this commit removes. The other code removed/changed in stream_seek() is probably not from that patch, but it doesn't hurt to be sure, and also makes it more readable. (It might change the behavior so that sometimes the eof flag is set after a seek, but it doesn't matter here.) 2aa6acd9: it looks like the seek_forward() modified by this patch was later moved to stream.c and renamed to stream_skip_read() in a790f2133. (Looking closer at it, it was actually modified again a bunch of times, fixing the logic.) I rewrote it in this commit. The code ended up rather similar, which probably could lead to doubts whether this was done properly, but I guess the reader of this will just have to believe me. I knew what stream_skip_read() was supposed to do (which was reinforced when I tried to replace it on the caller side), without reading the pre-existing code in detail. I had to "relearn" the logic how buf_pos and bug_len work - it was actually easy to see from stream_read_char() how to skip the data, essentially by generalizing its logic from 1 byte to N bytes. From the old code I only "used" the fact that it's obviously a while(len>0) look, that has to call stream_fill_buffer repeatedly to make progress. At first I actually didn't use stream_fill_buffer_by(), but the variant without _by, but readded it when I checked why the old code used it (see cd7ec016e7). This has to be good enough. In the end, it's hard to argue that this could be implemented in a way not using such a loop. Other than this, I could add the usual remarks about how this code was not modularized in the past, and how stream.c contained DVD code, and how this was later modularized, moving the copyright to other files, and so on. Also, if someone wrote a stream module, and was not asked about LGPL relicensing, we don't consider the entry in stream_list[] copyrightable.
* stream: rewrite url escaping/unescaping functionswm42017-06-131-36/+48
| | | | | | | | | | | | | | | | | | | | | | | | | The original functions come from 24c6f11c8b8, which says that these functions were copied from another project. This other project is GPL and was written by an unknown author, so there is no hope to relicense them to LGPL. Replace the existing functions with code written by Avi Halachmi. He did not see the old code, but wrote it based on the function signature and an extended description of what they should do (http://sprunge.us/edia). Some additional help was provided by me (in particular the function of the "ok" parameter and how to implement it - not in the original ASFRecorder code). Some of the code is hilariously similar, but these are coincidences. The name of the variable "c" probably "leaked" from me, but "o" is a true coincidence. The code was integrated by me - my only change is changing the function names to the old ones, moving the order of the top-level declarations, and changing "default_ok" to "url_default_ok", and changing the strings from char* to char[]. The author of the new code is Avi Halachmi.
* wscript: decouple dvdnav check from dvdreadRicardo Constantino2017-03-311-1/+1
| | | | | | | | | Reallows enabling dvdnav without enabling dvdread which was broken in 77cbb3543 when they were both disabled by default. Since dvdnav requires dvdread, we can enable dvdread:// even if --enable-dvdread isn't passed. Fixes #4290
* stream: get rid of streamtype enumwm42017-02-021-3/+2
| | | | | | | | | Because it's kind of dumb. (But not sure if it was worth the trouble.) For stream_file.c, we add new explicit fields. The rest are rather special uses and can be killed by comparing the stream impl. name. The changes to DVD/BD/CD/TV are entirely untested.
* stream: better method signal caching, rename weird uncached_stream fieldwm42017-02-021-6/+7
| | | | | | | | "uncached_stream" is a pretty bad name. It could be mistaken for a boolean, and then its meaning would be inverted. Rename it. Also add a "caching" field, which signals that the stream is a cache or reads from a cache. This is easier to understand and more flexible.
* stream: minor cleanup to previous commitwm42017-01-271-12/+7
| | | | | | | This is almost cosmetic, but removes the duplicated EOF-setting. Somewhat oddly, this will enter the reconnect path and exit it immediately again - should be fine.
* stream: set EOF if stream is canceledwm42017-01-261-1/+3
| | | | | | | | | Commit 7be495b3 added the cancellation test, but forgot to set the eof flag. This could lead to demux_mkv.c not terminating if the stream was cancelled in some code paths. This function is what is supposed to set the EOF flag in the first place, so just add the missing code.
* stream: check for playback aborts on reading toowm42017-01-241-0/+2
| | | | | | | | | Benefits demux_mkv.c, or demux_lavf.c during probing. In particular demux_lavf.c can sometimes get "stuck" when reading from a slow/blocking source, and if probing needs more than a few iterations. Since this is a read of an atomic variable with relaxed semantics, this should have no impact on reading speed at all, not even theoretically.
* player: remove --stream-capture option/propertywm42017-01-211-34/+0
| | | | | | | | | | | | | | | This was excessively useless, and I want my time back that was needed to explain users why they don't want to use it. It captured the byte stream only, and even for types of streams it was designed for (like transport streams), it was rather questionable. As part of the removal, un-inline demux_run_on_thread() (which has only 1 call-site now), and sort of reimplement --stream-dump to write the data directly instead of using the removed capture code. (--stream-dump is also very useless, and I struggled coming up with an explanation for it in the manpage.)
* demux, stream: add option to prevent opening referenced fileswm42016-12-041-0/+6
| | | | Quite irresponsibly hacked together. Sue me.
* stream_cb: don't add "*://" to protocol listwm42016-09-101-4/+1
| | | | | | | | | --list-protocol was printing a *:// entry, which looked strange at best. The "*" protocol was used to always match everything, so stream_cb.c could hook in custom protocols with a prefix chosen by the API user. Change it instead so that an empty protocol list means "match all", which also gets rid of the special-cased "*" entry.
* stream, demux, config: remove some dead/unneeded option-related codewm42016-09-091-79/+0
| | | | | | | | | | This has all been made unnecessary recently. The change not to copy the global option struct in particular can be made because now nothing accesses the global options anymore in the demux and stream layers. Some code that was accidentally added/changed in commit 5e30e7a0 is also removed, because it was simply committed accidentally, and was never used.
* stream_dvd, stream_dvdnav: remove weird option parsing stuffwm42016-09-081-7/+11
| | | | | | Same deal as with stream_bluray. Untested because I don't give a fuck about your shitty DVDs.
* osdep: rename atomics.h to atomic.hwm42016-09-071-1/+1
| | | | | The standard header is stdatomic.h, so the extra "s" freaks me out every time I look at it.
* demux: do not access global optionswm42016-09-061-1/+15
| | | | | | | | | | | | | | | | | Don't access MPOpts directly, and always use the new m_config.h functions for accessing them in a thread-safe way. The goal is eventually removing the mpv_global.opts field, and the demuxer/stream-layer specific hack that copies MPOpts to deal with thread-safety issues. This moves around a lot of options. For one, we often change the physical storage location of options to make them more localized, but these changes are not user-visible (or should not be). For shared options on the other hand it's better to do messy direct access, which is worrying as in that somehow renaming an option or changing its type would break code reading them manually, without causing a compilation error.
* stream: fix double-free if cache init failswm42016-08-081-1/+3
| | | | | | | | | | | | If the normal stream cache init fails, and a file cache was initialized before, we free the file cache as well. But since the file cache is chained to the real stream, the real stream will also be freed. This has to be prevented by clearing the pointer to the original stream in the uncached_stream field. This could in particular be triggered by using --cache-initial=1000 and aborting playback during loading. (Without that option, stream cache init failure is far less likely.)
* client API: add stream_cb API for user-defined stream implementationsAman Gupta2016-08-071-0/+19
| | | | | | Based on #2630. Some heavy changes by committer. Signed-off-by: wm4 <wm4@nowhere>
* build: silence -Wunused-resultNiklas Haas2016-06-071-1/+1
| | | | | | | | For clang, it's enough to just put (void) around usages we are intentionally ignoring the result of. Since GCC does not seem to want to respect this decision, we are forced to disable the warning globally.
* stream: separate posix/win32 cancellation codewm42016-05-201-27/+55
| | | | | | | | | This code evolved into an ifdef mess as support for cancellation on Windows was added. Make the Windows-specific code completely separate. It looks cleaner, and it also means that some of the posix code is not uselessly enabled on Windows. The latter made msvcrt.dll output warnings because it does not like -1 passed as FD to read/write. (The same would be harmless on POSIX.)
* stream: stream_read_complete() reads from current pos, not 0wm42016-01-121-1/+1
| | | | (Well, I hope no caller really relied on this anyway.)
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* Fix some typos in code commentsAman Gupta2015-12-211-1/+1
| | | | Signed-off-by: wm4 <wm4@nowhere>
* stream: drop PVR supportwm42015-12-101-4/+0
| | | | | | | | | This is only for specific Hauppage cards. According to the comments in who is actively using this feature. Get it out of the way. Anyone who still wants to use this should complain. Keeping this code would not cause terribly much additional work, and it could be restored again. (But not if the request comes months later.)
* stream: minor cleanup to verbose loggingwm42015-09-301-2/+4
| | | | | | Don't print the URL that is opened twice. stream.c and stream_lavf.c each printed it once. Remove the logging from stream_lavf.c, and move the log call to a more interesting point.
* stream: provide a stream_get_size() convenience functionwm42015-08-181-4/+11
| | | | | And use it everywhere, instead of retrieving the size manually. Slight simplification.
* stream: libarchive wrapper for reading compressed archiveswm42015-08-171-0/+4
| | | | | | | | | | | | | | | | | | | | This works similar to the existing .rar support, but uses libarchive. libarchive supports a number of formats, including zip and (most of) rar. Unfortunately, seeking does not work too well. Most libarchive readers do not support seeking, so it's emulated by skipping data until the target position. On backwards seek, the file is reopened. This works fine on a local machine (and if the file is not too large), but will perform not so well over network connection. This is disabled by default for now. One reason is that we try libarchive on every file we open, before trying libavformat, and I'm not sure if I trust libarchive that much yet. Another reason is that this breaks multivolume rar support. While libarchive supports seeking in rar, and (probably) supports multivolume archive, our support of libarchive (probably) does not. I don't care about multivolume rar, but vocal users do.
* vo_opengl: add support for custom shadersNiklas Haas2015-05-271-0/+14
|
* command: add protocol-list propertywm42015-05-231-6/+21
| | | | Fixes #1972.
* stream: don't print reconnection message if no stream supportwm42015-04-291-3/+5
| | | | | | | This code does not know whether the stream supports reconnecting until STREAM_CTRL_RECONNECT is called. So the message should be printed after it. To avoid that reconnects that succeed on the first try go unnoticed, print a warning on success.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* options: introduce --cache=yes choicewm42015-03-121-0/+2
| | | | | | I think this is what I alwass missed ever since I found the MPlayer cache options: a way to enable the cache on local files with the default settings, whatever they are.
* stream: use relaxed atomic loads for checking playback abortswm42015-03-091-1/+1
| | | | | | | Seems appropriate, and will probably avoid performance surprises with scary architectures which don't have trivial implementations for atomic loads. (Consider that demux_mkv calls this very often now, and libavformat demuxers and streams did this for a while now.)
* player: refine rar:// playlist-safety handlingwm42015-03-021-1/+0
| | | | | | | | | | | | It was possible to make the player play local files by putting rar:// links into remote playlists, and some other potentially unsafe things. Redo the handling of it. Now the rar-redirector (the thing in demux_playlist.c) sets disable_safety, which makes the player open any playlist entries returned. This is fine, because it redirects to the same file anyway (just with different selection/interpretation of the contents). On the other hand, rar:// itself is now considered fully unsafe, which means that it is ignored if found in normal playlists.
* stream: remove stream filter conceptwm42015-02-271-33/+11
| | | | Unused since the previous commit. (Apparently it was a stupid idea.)
* stream_rar: treat rar files as playlistswm42015-02-271-4/+2
| | | | | | | | | | | | Refactors an older hack, which for some reason used a more complicated way. This generates the playlist representing the contents of the rar file in demux_playlist.c. The pseudo-demuxer could easily be separate from the the playlist parsers (and in fact there's almost no shared code), but I don't think this obscure feature deserves a separate file. Sample files created with: rar a -v20000k -m0 files.rar file1.mkv file1.mkv
* stream: get rid of remaining uses of the end_pos fieldwm42015-02-061-16/+2
| | | | | | | | Most things stopped using this field for better support of growing files. Go through the trouble to repalce the remaining uses, so it can be removed. Also move the "streaming" field; saves 4 bytes (wow!).
* stream: minor cleanupswm42015-02-061-82/+59
| | | | | | | | | | | | | | | | Fix return types and return values to make them more consistent. Some reformatting and making code more concise. In stream_reconnect(), avoid the additional mp_cancel_test() call by moving the "connection lost" message below the mp_cancel_wait() call, which effectively leads to the same behavior when the stream was already canceled. (The goal is not to show the message in this case.) Merge stream_seek_long() into stream_seek(). It was the only caller. Always clear the eof flag on seeks. Reduce access to stream internals in cache.c and stream_lavf.c.
* stream: slightly improve reconnect behaviorwm42015-02-061-18/+28
| | | | | Wait for a longer time between reconnects. Introdeuce and use mp_cancel_wait(), so that quitting is still immediate.
* stream: reject overly long URLswm42015-01-211-0/+4
|
* stream_lavf: escape disallowed characters in http URLswm42015-01-211-2/+2
| | | | | | | | | | | | | | | | | In my opinion, libavformat should be doing this. But a patch handling a very safe case rejected, so I suppose we have to do it manually. (This patch was only escaping spaces, which can never work because they break the basic syntax of the HTTP protocol.) This commit attempts to do 2 things: - Try to guess whether libavformat will use the URL for http. This is not always trivial, because some protocols will recursively pass part of the user URL to http in some way. - Try to fix invalid URLs. We fix only the simplest case: only characters that are never valid are escaped. This excludes invalid escape codes, which happen with freestanding '%' characters. Fixes #1495.
* stream: always make stream dumping/capturing append to output filewm42014-12-271-1/+1
| | | | Partially fixes #1393 (but not really).
* stream: always disable cache for pseudo-streamswm42014-12-241-0/+3
| | | | | Streams which don't have a full_buffer function never return any actual data. Slight improvement over commit 5640c195.
* Do not call strerror()wm42014-11-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | ...because everything is terrible. strerror() is not documented as having to be thread-safe by POSIX and C11. (Which is pretty much bullshit, because both mandate threads and some form of thread-local storage - so there's no excuse why implementation couldn't implement this in a thread-safe way. Especially with C11 this is ridiculous, because there is no way to use threads and convert error numbers to strings at the same time!) Since we heavily use threads now, we should avoid unsafe functions like strerror(). strerror_r() is in POSIX, but GNU/glibc deliberately fucks it up and gives the function different semantics than the POSIX one. It's a bit of work to convince this piece of shit to expose the POSIX standard function, and not the messed up GNU one. strerror_l() is also in POSIX, but only since the 2008 standard, and thus is not widespread. The solution is using avlibc (libavutil, by its official name), which handles the unportable details for us, mostly. We avoid some pain.
* stream: fix endian swappingwm42014-11-211-2/+2
| | | | | | | | | | In addition to the messed-up expression, the endianness was also inverted. The code reads big endian by default. It "worked" by coincidence, but for little endian, codepoints outside of latin1 were broken. The broken expression was found by Coverity.
* stream: reduce ifdeffery for win32 somewhatwm42014-11-181-12/+7
| | | | Remove the ones which are not strictly needed.
* stream: signal a Windows event object on cancelJames Ross-Gowan2014-11-181-0/+31
| | | | | This will be used in the following commit to cancel subprocesses started by Lua.
* stream: fix --stream-dump dropping the file headerwm42014-10-251-10/+12
|