summaryrefslogtreecommitdiffstats
path: root/stream
Commit message (Collapse)AuthorAgeFilesLines
* stream: never let read functions return values < 0wm42013-06-251-3/+5
| | | | | | | | | | stream_read_unbuffered() can sometimes return negative values on error. Change that to return 0 - the negative values are nowhere used anyway. If distinguishing errors and EOF is really needed, a flag could be added instead. This also fixes the stream_read_partial() call in cache.c, which assumes the return values is always >= 0.
* stream: readd memory streamswm42013-06-252-5/+21
|
* stream: remove padding parameter from stream_read_complete()wm42013-06-232-18/+17
| | | | | | | | Seems like a completely unnecessary complication. Instead, always add a 1 byte padding (could be extended if a caller needs it), and clear it. Also add some documentation. There was some, but it was outdated and incomplete.
* cache: fix build on OSX (again)wm42013-06-161-0/+7
| | | | | | | | | | | | | OSX doesn't support the POSIX API we were using. We check for _POSIX_TIMERS. 0 or -1 means unsupported. See: http://pubs.opengroup.org/onlinepubs/009696699/functions/clock_getres.html http://pubs.opengroup.org/onlinepubs/009696699/basedefs/unistd.h.html The workaround of using gettimeofday() is suggested by Apple: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/pthread_cond_timedwait.3.html Thanks to AStorm for providing help here.
* cache: fix compilation on Libavwm42013-06-161-1/+8
| | | | Appears Libav doesn't have av_clip64(). So implement our own.
* cache: use correct header for clock_gettimewm42013-06-161-0/+1
| | | | Fixes compilation on OSX.
* stream: don't set sector size on cachewm42013-06-161-3/+1
| | | | | | | | | This is useless on the cache side. The sector is needed only to deal with stream implementations which are not byte addressable, and the cache is always byte addressable. Also set a default read_chunk value. (This value is never used unless you chain multiple caches, but it's cleaner.)
* cache: attempt to improve slow cache warningwm42013-06-161-26/+35
| | | | | Still sucks. The old cache behavior (before removing the fork code) wasn't great either, though.
* cache: report more precise stream timewm42013-06-161-9/+39
| | | | | | | | | | | | | | | | | | | | | | | | DVD and bluray packet streams carry (essentially) random timestamps, which don't start at 0, can wrap, etc. libdvdread and libbluray provide a linear timestamp additionally. This timestamp can be retrieved with STREAM_CTRL_GET_CURRENT_TIME. The problem is that this timestamp is bound to the current raw file position, and the stream cache can be ahead of playback by an arbitrary amount. This is a big problem for the user, because the displayed playback time and actual time don't match (depending on cache size), and relative seeking is broken completely. Attempt to fix this by saving the linear timestamp all N bytes (where N = BYTE_META_CHUNK_SIZE = 16 KB). This is a rather crappy hack, but also very effective. A proper solution would probably try to offset the playback time with the packet PTS, but that would require at least knowing how the PTS can wrap (e.g. how many bits is the PTS comprised of, and what are the maximum and reset values). Another solution would be putting the cache between libdvdread and the filesystem/DVD device, but that can't be done currently. (Also isn't that the operating system's responsibility?)
* stream: don't align stream position if not neededwm42013-06-161-3/+1
| | | | | This is pointless, and just increases latency on seeking. For streams that have a sector size set, this is still needed, though.
* stream: don't adjust stream position if seek succeeds, but read failswm42013-06-161-3/+2
| | | | | | | This was probably done this way to ensure that after a successful seek, the reported stream position is the same as the requested seek position. But it doesn't make too much sense, since both stream->pos and the stream implementation's internal position will go out of sync.
* stream: fix some aspects of EOF handlingwm42013-06-161-10/+22
| | | | | | | | | | | | | The stream EOF flag should only be set when trying to read past the end of the file (relatively similar to unix files). Always clear the EOF flag on seeking. Trying to set it "properly" (depending whether data is available at seek destination or not) might be an ok idea, but would require attention to too many special cases. I suspect before this commit (and in MPlayer etc. too), the EOF flag wasn't handled consistently when the stream position was at the end of the file. Fix one special case in ebml.c and stream_skip(): this function couldn't distinguish between at-EOF and past-EOF either.
* stream: don't set EOF flag in stream implementationswm42013-06-167-13/+1
| | | | | | | | | | EOF should be set when reading more data fails. The stream implementations have nothing to say here and should behave correctly when trying to read when EOF was actually read. Even when seeking, a correct EOF flag should be guaranteed. stream_seek() (or actually stream_seek_long()) calls stream_fill_buffer() at least once, which also updates the EOF flag.
* stream: remove stream_reset()wm42013-06-162-12/+3
| | | | | | | | | This function was called in various places. Most time, it was used before a seek. In other cases, the purpose was apparently resetting the EOF flag. As far as I can see, this makes no sense anymore. At least the stream_reset() calls paired with stream_seek() are completely pointless. A seek will either seek inside the buffer (and reset the EOF flag), or do an actual seek and reset all state.
* stream: check for interruption when trying to reconnect streamwm42013-06-161-3/+3
| | | | | | | This happens with something like "mpv https://www.youtube.com/watch". The URL is obviously not valid, but the stream layer tries to reconnect. This commit at least allows to use the terminal to abort gracefully. (Other than killing the process.)
* stream: cosmeticswm42013-06-162-26/+12
|
* stream: reset buffer even on EOF/errorwm42013-06-161-4/+2
| | | | This probably didn't matter anywhere, but it's more proper.
* cache: use threads instead of fork()wm42013-06-163-542/+403
| | | | | | | | | | | | | | | | | | | Basically rewrite all the code supporting the cache (i.e. anything other than the ringbuffer logic). The underlying design is untouched. Note that the old cache2.c (on which this code is based) already had a threading implementation. This was mostly unused on Linux, and had some problems, such as using shared volatile variables for communication and uninterruptible timeouts, instead of using locks for synchronization. This commit does use proper locking, while still retaining the way the old cache worked. It's basically a big refactor. Simplify the code too. Since we don't need to copy stream ctrl args anymore (we're always guaranteed a shared address space now), lots of annoying code just goes away. Likewise, we don't need to care about sector sizes. The cache uses the high-level stream API to read from other streams, and sector sizes are handled transparently.
* stream: add partial read functionwm42013-06-162-17/+28
| | | | | This is a nice way to avoid an additional copy of the data when reading with stream_read().
* stream: add stream_unread_buffer()wm42013-06-162-4/+33
| | | | | | | | | | | | | | | | | | | | | | demux_lavf probes up to 2 MB of data in the worst case. When the ffmpeg demuxer is actually opened, the stream is seeked back to 0, and the previously read data is thrown away. This wasn't a problem for playback of local files, but it's less than ideal for playing from slow media (like web streams), and breaks completely if the media is not seekable (pipes, some web streams). This new function is intended to allow fixing this. demux_lavf will use it to put the read probe data back into the buffer. The simplest way of implementing this function is by making it transparently extend the normal stream buffer. This makes sure no existing code is broken by new weird special cases. For simplicity and to avoid possible performance loss due to extra dereferencing when accessing the buffer, we just extend the static buffer from 8 KB to 2 MB. Normally, most of these 2 MB will stay uncommitted, so there's no associated waste of memory. If demux_lavf really reads all 2 MB, the memory will be committed and stay unused, though.
* cache: make the stream cache a proper stream that wraps other streamswm42013-06-165-331/+220
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, the cache was franken-hacked on top of the stream API. You had to use special functions (like cache_stream_fill_buffer() instead of stream_fill_buffer()), which would access the stream in a cached manner. The whole idea about the previous design was that the cache runs in a thread or in a forked process, while the cache awa functions made sure the stream instance looked consistent to the user. If you used the normal functions instead of the special ones while the cache was running, you were out of luck. Make it a bit more reasonable by turning the cache into a stream on its own. This makes it behave exactly like a normal stream. The stream callbacks call into the original (uncached) stream to do work. No special cache functions or redirections are needed. The only different thing about cache streams is that they are created by special functions, instead of being part of the auto_open_streams[] array. To make things simpler, remove the threading implementation, which was messed into the code. The threading code could perhaps be kept, but I don't really want to have to worry about this special case. A proper threaded implementation will be added later. Remove the cache enabling code from stream_radio.c. Since enabling the cache involves replacing the old stream with a new one, the code as-is can't be kept. It would be easily possible to enable the cache by requesting a cache size (which is also much simpler). But nobody uses stream_radio.c and I can't even test this thing, and the cache is probably not really important for it either.
* stream: remove pointless checkwm42013-06-091-7/+3
|
* stream: remove unused functionwm42013-06-091-9/+0
|
* stream: move VCD specific stuff to stream_vcdwm42013-06-093-5/+4
| | | | I don't even know what VCDs are. A prehistoric version of the DVD or so.
* stream_cdda, stream_vcd: check read buffer sizewm42013-06-092-0/+5
| | | | | | | | These assumed that the buffer provided with fill_buffer() was at least sector sized, instead of checking the size parameter. This is just a cleanup, since every caller made sure to align everything on sector sizes, if a stream has the sector size set.
* stream_dvd: remove some deadly insane codewm42013-06-091-15/+0
| | | | | | Of course all of stream_dvd.c (as well as libdvdread) is completely insane, but at least this hack for ancient broken compilers on really obscure platforms should be safe to remove.
* stream: misleading statementwm42013-06-091-1/+1
|
* core: use STREAM_CTRL instead of accessing stream_dvd internalswm42013-06-093-0/+24
| | | | | | | | | | | | Some code in mplayer.c did stuff like accessing (dvd_priv_t *)st->priv. Do this indirectly by introducing STREAM_CTRL_GET_DVD_INFO. This is extremely specific to DVD, so it's not worth abstracting this further. This is a preparation for turning the cache into an actual stream, which simply wraps the cached stream. There are other streams which are accessed in the way DVD was, at least TV/radio/DVB. We assume these can't be used with the cache. The code doesn't look thread-safe or fork aware.
* stream: rename cache2.c to cache.cwm42013-06-091-0/+0
| | | | | | | I never found cache1.c (whatever it was named, if it ever existed). cache2.h will be deleted later, so don't go through the trouble of renaming it.
* cache2: uncrustifywm42013-06-091-452/+521
|
* demux: fix "-demuxer mpegps", don't force demuxer in stream_dvdwm42013-06-021-1/+0
| | | | | | | | | | Internally, stream_dvd.c returned DEMUXER_TYPE_MPEG_PS, and the same value was hardcoded to enforced usage of demux_lavf in demux.c. But "-demuxer mpegps" basically did the same, so that switch was broken for this format. Undo this and don't request a demuxer in stream_dvd.c. demux_lavf.c is (probably) good enough to probe correctly with DVD. Otherwise, we'd actually have to do something completely different to force the libavformat demuxer.
* stream: kill STREAM_CTRL_RESETwm42013-05-262-4/+0
| | | | Was unused.
* stream: kill memory streamswm42013-05-262-23/+3
| | | | | These are unused by now, and it relied on some assumptions that have been broken by now.
* stream: de-inline some larger functionswm42013-05-262-70/+73
| | | | | | | | | | | | | | | | Tests with demux_mkv show that the speed doesn't change (or actually, it seems to be faster after this change). In any case, there is not the slightest reason why these should be inline. Functions for which this will (probably) actually matter, like stream_read_char, are still left inline. This was tested with demux_mkv's indexing. For broken files without index, demux_mkv creates an on-the-fly index. If you seek to a later part of the file, all data has to be read and parsed until the wanted position is found. This means demux_mkv will do mostly I/O, calling stream_read_char() and stream_read(). This should be the most I/O intensive non-deprecated part of mpv that uses the stream interface. (demux_lavf has its own buffering.)
* Replace calls to usec_sleep()wm42013-05-262-4/+4
| | | | | | This is just dumb sed replacement to mp_sleep_us(). Also remove the now unused usec_sleep() wrapper.
* Replace all calls to GetTimer()/GetTimerMS()wm42013-05-262-4/+4
| | | | | | | | | | | | | | | | | | | | | | GetTimer() is generally replaced with mp_time_us(). Both calls return microseconds, but the latter uses int64_t, us defined to never wrap, and never returns 0 or negative values. GetTimerMS() has no direct replacement. Instead the other functions are used. For some code, switch to mp_time_sec(), which returns the time as double float value in seconds. The returned time is offset to program start time, so there is enough precision left to deliver microsecond resolution for at least 100 years. Unless it's casted to a float (or the CPU reduces precision), which is why we still use mp_time_us() out of paranoia in places where precision is clearly needed. Always switch to the correct time. The whole point of the new timer calls is that they don't wrap, and storing microseconds in unsigned int variables would negate this. In some cases, remove wrap-around handling for time values.
* Silence some compiler warningswm42013-05-211-8/+7
| | | | None of these were actual issues.
* core: add --stream-capturewm42013-05-123-0/+41
| | | | | | This is a partial revert of commit 7059c15, and basically re-adds --capture, just with different option names and slightly different semantics.
* Merge branch 'audio_changes'wm42013-05-121-4/+6
|\ | | | | | | | | Conflicts: audio/out/ao_lavc.c
| * core: use channel map on demuxer level toowm42013-05-121-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This helps passing the channel layout correctly from decoder to audio filter chain. (Because that part "reuses" the demuxer level codec parameters, which is very disgusting.) Note that ffmpeg stuff already passed the channel layout via mp_copy_lav_codec_headers(). So other than easier dealing with the demuxer/decoder parameters mess, there's no real advantage to doing this. Make the --channels option accept a channel map. Since simple numbers map to standard layouts with the given number of channels, this is downwards compatible. Likewise for demux_rawaudio.
* | stream_bluray: report chapter timeswm42013-05-091-0/+21
| | | | | | | | This was forgotten in commit 7294303.
* | stream_bluray: general timeline supportwm42013-05-091-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | Uses the same mechanisms as stream_dvd to report the virtual playback time as known by libdvdread/libbluray, instead of the raw demuxer output. This should solve many problems with BD playback, like correct display of playback time and duration. On the other hand, this causes some new problems. For example, the reported stream time has a rather low resolution (1-2 seconds), so doing precise seeking on it is near impossible.
* | stream_bluray: make code a bit more obviouswm42013-05-091-4/+4
| |
* | stream: report chapter times, use time seeks for DVD chapterswm42013-05-063-6/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow the stream layer to report chapter times. Extend stream_dvd to do this. I'm not 100% sure whether the re-used code is bug-free (because it was used for slave-mode and/or debugging only). MAke the frontend do time-based seeks when switching DVD chapters. I'm not sure if there's a real reason STREAM_CTRL_SEEK_TO_CHAPTER exists (maybe/hopefully not), but we will see. Note that querying chapter times in demuxer_chapter_time() with the new STREAM_CTRL_GET_CHAPTER_TIME could be excessively slow, especially with the cache enabled. The frontend likes to query chapter times very often. Additionally, stream_dvd uses some sort of quadratic algorithm to list times for all chapters. For this reason, we try to query all chapters on start (after the demuxer is opened), and add the chapters to the demuxer chapter list. demuxer_chapter_time() will get the time from that list, instead of asking the stream layer over and over again. This assumes stream_dvd knows the list of chapters at the start, and also that the list of chapters never changes during playback. This seems to be true, and the only exception, switching DVD titles, is not supported at runtime (and doesn't need to be supported).
* | Fix some cppcheck / scan-build warningswm42013-05-065-32/+5
| | | | | | | | | | | | | | | | These were found by the cppcheck and scan-build static analyzers. Most of these aren't interesting (the 2 previous commits fix some interesting cases found by these analyzers), and they don't nearly fix all warnings. (Most of the unfixed warnings are spam, things MPlayer never cared about, or false positives.)
* | stream: fix bad cache behavior introduced by recent commitwm42013-05-051-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Commit 4d14a42, a seemingly harmless change, introduced very bad cache behavior when the cache isn't forked, such as on Windows, where it uses threads. Apparently the cache code was designed for forking, and an unknown obscure condition causes severe performance degradation if a STREAM_CTRL is sent to the cache on every frame. Since the cache code is literally insane (uses shared memory + fork(), and has hacks to make it work with threads, is messed into the stream code in extra-hacky ways), we just fix it by caching the STREAM_CTRL in question. This is also done for some other STREAM_CTRLs that are called on each frame, such as playback duration. This indicates that the cache code has some inherent problem with answering such requests in a timely matter, and that there's no easy way around this. (Even if the cache is eventually rewritten, these things will probably have to be cached, otherwise you'd have to forcibly block until the stream implementation is done with a blocking read. The real question is why it worked fine with the forked cache, though.)
* | stream: add start time reportingwm42013-05-053-0/+9
| | | | | | | | | | | | Will be needed to override the demuxer's start time reporting. We could be lazy and special-case it since the result is always 0 for the streams that care, but doing it properly is better.
* | core: don't report byte-based playback position with dvdwm42013-05-054-0/+17
| | | | | | | | | | | | | | | | | | | | DVD playback uses a demuxer that signals to the frontend that timestamp resets are possible. This made the frontend calculate the OSD playback position based on the byte position and the total size of the stream. This actually broke DVD playback position display. Since DVD reports a a linear playback position, we don't have to rely on the demuxer reported position, so disable this functionality in case of DVD playback. This reverts the OSD behavior with DVD to the old behavior.
* | stream: remove unused new_ds_stream()wm42013-05-032-13/+0
| |
* | stream_bluray: remove the broken -bluray-chapter optionreimar2013-04-272-16/+2
| | | | | | | | | | | | | | | | | | | | Remove the broken -bluray-chapter option. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36175 b3059339-0415-0410-9bf9-f77b7e298cf2 Conflicts: DOCS/man/en/mplayer.1 cfg-common.h
* | stream_bluray: fix querying current chapterreimar2013-04-271-3/+1
| | | | | | | | | | | | | | | | | | br://: Fix querying current chapter. This also fixes specifying an end chapter via -chapter. Based on patch by Olivier Rolland [billl users.sourceforge.net] git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@36173 b3059339-0415-0410-9bf9-f77b7e298cf2
* | options: untangle track range parsing for stream_cddawm42013-04-211-17/+14
|/ | | | | | |