summaryrefslogtreecommitdiffstats
path: root/stream/stream.c
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'sub_mess2'wm42013-06-251-38/+73
|\ | | | | | | ...the return.
| * stream: remove stream_unread_buffer()wm42013-06-251-20/+0
| | | | | | | | Replaced with stream_peek().
| * stream: add stream_peek functionwm42013-06-251-0/+34
| | | | | | | | | | Makes probing easier, and this is perhaps a simpler interface than stream_unread_buffer().
| * 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-251-5/+20
| |
| * stream: remove padding parameter from stream_read_complete()wm42013-06-231-11/+15
| | | | | | | | | | | | | | | | 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.
* | osdep: remove shmem wrapperwm42013-06-181-1/+0
|/ | | | This is unused now that the cache is always threaded.
* 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.)
* 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-161-2/+0
| | | | | | | | | | 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-161-11/+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-161-16/+6
|
* 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-161-11/+19
| | | | | | | | | | | | | | | | | | | 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-161-17/+27
| | | | | 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-161-1/+26
| | | | | | | | | | | | | | | | | | | | | | 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-161-27/+86
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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: move VCD specific stuff to stream_vcdwm42013-06-091-1/+0
| | | | I don't even know what VCDs are. A prehistoric version of the DVD or so.
* stream: misleading statementwm42013-06-091-1/+1
|
* stream: kill STREAM_CTRL_RESETwm42013-05-261-3/+0
| | | | Was unused.
* stream: kill memory streamswm42013-05-261-20/+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-261-0/+70
| | | | | | | | | | | | | | | | 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-261-2/+2
| | | | | | This is just dumb sed replacement to mp_sleep_us(). Also remove the now unused usec_sleep() wrapper.
* core: add --stream-capturewm42013-05-121-0/+34
| | | | | | This is a partial revert of commit 7059c15, and basically re-adds --capture, just with different option names and slightly different semantics.
* core: don't report byte-based playback position with dvdwm42013-05-051-0/+5
| | | | | | | | | | 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-031-11/+0
|
* stream: silence clang empty statement warningswm42013-03-191-12/+8
| | | | | | | | | | clang printed warnings like: stream/stream.c:692:65: warning: if statement has empty body [-Wempty-body] GET_UTF16(c, src < end - 1 ? get_le16_inc(&src) : 0,; This macro expands to "if(cond) ;". Replace it with an empty statement that doesn't lead to a clang warning.
* stream: fix reconnecting on broken network connectionswm42013-01-241-10/+19
| | | | | | | | | | | | | | | | This didn't work properly for HTTP with libavformat. The builtin HTTP implementation reconnects automatically on its own, while libavformat doesn't. Fix this by adding explicit reconnection support to stream_lavf.c, which simply destroys and recreates the AVIO context. It mostly works, though sometimes it mysteriously fails, spamming crap all over the terminal and feeding broken data to the decoders. This is probably due to itneractions with the cache. Also, reconnecting to unseekable HTTP streams will make it read the entire stream until the previous playback position is reached again. It's not known whether this change makes behavior with "strange" protocols like RTP better or worse.
* stream: uncrustify stream.c/.hwm42013-01-241-409/+461
| | | | The formatting almost made me break out in tears.
* Remove netstream supportwm42013-01-131-2/+0
| | | | | | | | | | | | | | | | | | | | | | This allowed to move the input stream layer across the network, allowing the user to play anything that mplayer could play remotely. For example, playing a DVD related on a remote server (say, with the host name "remotehost1") could be done by starting the netstream server on that remote server, and then running: mplayer mpst://remotehost1/dvd:// This would open the DVD on the remote host, and transfer the raw DVD sector reads over network. It works the same for other protocols, and all accesses to the stream layer are marshaled over network. It's comparable to the way the cache layer (--cache) works. It has questionable use and most likely was barely used at all. There's lots of potential for breakage, because it doesn't translate the stream CTRLs to network packets. Just get rid of it. The server used to be in TOOLS/netstream.c, and was accidentally removed earlier.
* stream_lavf/demux_lavf: export/use HTTP MIME typewm42012-12-111-12/+6
| | | | | | | | | | | | | | | | | This is a fix for web radio streams that send raw AAC [1]. libavformat's AAC demuxer probe is picky enough to request hundreds of KBs data, which makes for a slow startup. To speed up stream startup, try use the HTTP MIME type to identify the format. The webstream in question sends an AAC specific MIME type, for which demux_lavf will force the AAC demuxer, without probing anything. ffmpeg/ffplay do the same thing. Note that as of ffmpeg commit 76d851b, av_probe_input_buffer() does the mapping from MIME type to demuxer. The actual mapping is not publicly accessible, and can only be used by calling that function. This will hopefully be rectified, and ideally ffmpeg would provide a function like find_demuxer_from_mime_type(). [1] http://lr2mp0.latvijasradio.lv:8000
* cache: simplify furtherwm42012-12-031-7/+3
| | | | | | | | | | | | This commit is separate from the previous one to separate our own changes from changes merged from mplayer2 (as far as that was possible). Make it easier for stream implementations to request being cached. Set a default cache size in stream.c, and remove them from various stream implementations. Only MS streaming support sets a meaningful cache size. Make querying cache size saner. This reduces the amount of #ifdefs needed.
* cache: refactor how cache enabling is doneUoti Urpala2012-12-031-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | Code enabling the cache by default for network streams did that by modifying the value of the "cache" option. This wasn't sane, as multiple streams may be created and all share the same options. Change the code to not modify options but store data in the stream instance instead. Conflicts: core/mplayer.c demux/demux.c stream/cache2.c stream/network.c stream/network.h stream/pnm.c stream/stream.c stream/stream_rtp.c Merged from mplayer2 commit e26070. Note that this doesn't solve any actual bug, as the playlist crashing bug has been fixed before. Since the global cache size option value is not overwritten anymore, the option doesn't need to be restored on end of playback (M_OPT_LOCAL).
* demux_lavf: add support for libavdevicewm42012-12-031-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libavdevice supports various "special" video and audio inputs, such as screen-capture or libavfilter filter graphs. libavdevice inputs are implemented as demuxers. They don't use the custom stream callbacks (in AVFormatContext.pb). Instead, input parameters are passed as filename. This means the mpv stream layer has to be disabled. Do this by adding the pseudo stream handler avdevice://, whose only purpose is passing the filename to demux_lavf, without actually doing anything. Change the logic how the filename is passed to libavformat. Remove handling of the filename from demux_open_lavf() and move it to lavf_check_file(). (This also fixes a possible bug when skipping the "lavf://" prefix.) libavdevice now can be invoked by specifying demuxer and args as in: mpv avdevice://demuxer:args The args are passed as filename to libavformat. When using libavdevice demuxers, their actual meaning is highly implementation specific. They don't refer to actual filenames. Note: libavdevice is disabled by default. There is one problem: libavdevice pulls in libavfilter, which in turn causes symbol clashes with mpv internals. The problem is that libavfilter includes a mplayer filter bridge, which is used to interface with a set of nearly unmodified mplayer filters copied into libavfilter. This filter bridge uses the same symbol names as mplayer/mpv's filter chain, which results in symbol clashes at link-time. This can be prevented by building ffmpeg with --disable-filter=mp, but unfortunately this is not the default. This means linking to libavdevice (which in turn forces linking with libavfilter by default) must be disabled. We try doing this by compiling a test file that defines one of the clashing symbols (vf_mpi_clear). To enable libavdevice input, ffmpeg should be built with the options: --disable-filter=mp and mpv with: --enable-libavdevice Originally, I tried to auto-detect it. But the resulting complications in configure did't seem worth the trouble.
* stream, demux_lavf: minor cleanup for stream size codewm42012-11-201-0/+9
|
* stream, demux: replace off_t with int64_twm42012-11-201-5/+5
| | | | | | On reasonable systems, these types were the same anyway. Even on unreasonable systems (seriously, which?), this may reduce potential breakage.
* Rename directories, move files (step 2 of 2)wm42012-11-121-4/+4
| | | | | | | | | | | | Finish renaming directories and moving files. Adjust all include statements to make the previous commit compile. The two commits are separate, because git is bad at tracking renames and content changes at the same time. Also take this as an opportunity to remove the separation between "common" and "mplayer" sources in the Makefile. ("common" used to be shared between mplayer and mencoder.)
* stream: open_stream_plugin() should set error code on failurewm42012-11-011-0/+1
| | | | | clang analyzer complained about *ret (&r) containing garbage in open_stream_full(). This should fix it.
* stream_ffmpeg: handle rtsp:// URLs by default, add lavf://Uoti Urpala2012-10-281-1/+1
| | | | | | | | | | | Make stream_ffmpeg handle rtsp:// URLs by default, without requiring ffmpeg://rtsp://. Previously (after removal of other rtsp implementations) rtsp:// fell back to using HTTP, which was unlikely to work. Also add lavf:// as an alternative to ffmpeg:// to force the stream implementation. Since libavformat can come from Libav rather than FFmpeg, using the ffmpeg name in the prefix is misleading.
* stream: remove NULL checks for open callswm42012-10-141-13/+3
| | | | | | | open_stream() and open_output_stream() checked for filename==NULL, and if true, printed an error message asking to report this as bug. Internal logic errors should just crash. Use assert() instead.
* core: show quvi page title in window title, clean up libquvi handlingwm42012-10-141-0/+24
| | | | | | | | | | | | | | | | | Clean up handling of libquvi (which resolves URLs of streaming sites into URLs to the actual media playable by mpv). Move the code out of open.c to quvi.c, and invoke it explicitly from mplayer.c, instead of trying to resolve every filename passed to open_stream(). This allows easily passing metadata from the quvi context to the frontend. Expose QUVIPROP_PAGETITLE as "media-title" property, and use that instead of "filename" for the mplayer window title. (For YouTube, this is the video title.) It's cleaner too. Handle a potential reliability issue: check quvi_getprop return values. Since open.c contains barely anything but the open_stream() stub, move that to stream.c and delete open.c.
* Remove support for libnemesi RTSP streamingwm42012-08-201-4/+0
| | | | | Removed due to being a maintainance burden. Support for FFmpeg is available.
* Remove support for LIVE555 RTSP streamingwm42012-08-201-6/+0
| | | | | | | | | | | | The main excuse for removing this is that LIVE555 deprecated the API the mplayer implementation was using. The old API still seems to be somewhat supported, but must be explicitly enabled at LIVE555 compilation, so mplayer won't always work on any user installation. The implementation was also very messy, in C++, and FFmpeg support is available as alternative. Remove it completely.
* Remove dvdnav support (DVD menus)wm42012-08-161-8/+0
| | | | | | | | | | | | | | | | When the internal mplayer MPEG demuxer was removed (commit 1fde09db), the default demuxer when using dvdnav was set to libavformat. Now it turns out that this doesn't work with libavformat. It will terminate playback right after the audio runs out (instead of looping it like the video, or whatever it's supposed to do). I'm not sure what exactly the problem is, but since 1. even mplayer-svn can't handle DVD menus directly (missing highlights), 2. DVD menus are essentially worthless, and 3. I don't directly watch DVDs, don't bother with it and remove it. For basic playback, there's still libdvdread support. Also, use pkg-config for libdvdread, and drop support for in-tree libdvdread. Remove support for in-tree libdvdcss as well.
* options: get rid of ambiguous option parsingwm42012-08-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Options parsing used to be ambiguous, as in the splitting into option and values pairs was ambiguous. Example: -option -something It wasn't clear whether -option actually takes an argument or not. The string "-something" could either be a separate option, or an argument to "-option". The code had to call the option specific parser function to resolve this. This made everything complicated and didn't even have a real use. There was only one case where this was actually used: string lists (m_option_type_string_list) and options based on it. That is because this option type actually turns a single option into a proxy for several real arguments, e.g. "vf*" can handle "-vf-add" and "-vf-clr". Options suffixed with "-clr" are the only options of this group which take no arguments. This is ambiguous only with the "old syntax" (as shown above). The "new" option syntax always puts option name and value into same argument. (E.g. "--option=--something" or "--option" "--something".) Simplify the code by making it statically known whether an option takes a parameter or not with the flag M_OPT_TYPE_OLD_SYNTAX_NO_PARAM. If it's set, the option parser assumes the option takes no argument. The only real ambiguity left, string list options that end on "-clr", are special cased in the parser. Remove some duplicatio