summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
Commit message (Collapse)AuthorAgeFilesLines
* demux: remove relative seekingwm42016-02-281-20/+8
| | | | | | | | | | | | | | | | | | | Ever since a change in mplayer2 or so, relative seeks were translated to absolute seeks before sending them to the demuxer in most cases. The only exception in current mpv is DVD seeking. Remove the SEEK_ABSOLUTE flag; it's not the implied default. SEEK_FACTOR is kept, because it's sometimes slightly useful for seeking in things like transport streams. (And maybe mkv files without duration set?) DVD seeking is terrible because DVD and libdvdnav are terrible, but mostly because libdvdnav is terrible. libdvdnav does not expose seeking with seek tables. (Although I know xbmc/kodi use an undocumented API that is not declared in the headers by dladdr()ing it - I think the function is dvdnav_jump_to_sector_by_time().) With the current mpv policy if not giving a shit about DVD, just revert our half-working seek hacks and always use dvdnav_time_search(). Relative seeking might get stuck sometimes; in this case --hr-seek=always is recommended.
* demux: avoid lost wakeup on queue overflowwm42016-02-241-1/+6
| | | | | | | | | If a stream is marked as EOF (due to no packets found in reach), then we need to wakeup the decoder. This is important especially if no packets are found at the start of the file, so the A/V sync logic actually starts playback, instead of waiting for packets that will never come. (It would randomly start playback when running the playback loop due to arbitrary external events like user input.)
* demux_timeline: fix nested timelineswm42016-02-201-0/+3
| | | | | You can e.g. reference ordered chapters or other EDL files in EDLs. There were some bugs left which broke this in some cases.
* Rewrite ordered chapters and timeline stuffwm42016-02-151-2/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This uses a different method to piece segments together. The old approach basically changes to a new file (with a new start offset) any time a segment ends. This meant waiting for audio/video end on segment end, and then changing to the new segment all at once. It had a very weird impact on the playback core, and some things (like truly gapless segment transitions, or frame backstepping) just didn't work. The new approach adds the demux_timeline pseudo-demuxer, which presents an uniform packet stream from the many segments. This is pretty similar to how ordered chapters are implemented everywhere else. It also reminds of the FFmpeg concat pseudo-demuxer. The "pure" version of this approach doesn't work though. Segments can actually have different codec configurations (different extradata), and subtitles are most likely broken too. (Subtitles have multiple corner cases which break the pure stream-concatenation approach completely.) To counter this, we do two things: - Reinit the decoder with each segment. We go as far as allowing concatenating files with completely different codecs for the sake of EDL (which also uses the timeline infrastructure). A "lighter" approach would try to make use of decoder mechanism to update e.g. the extradata, but that seems fragile. - Clip decoded data to segment boundaries. This is equivalent to normal playback core mechanisms like hr-seek, but now the playback core doesn't need to care about these things. These two mechanisms are equivalent to what happened in the old implementation, except they don't happen in the playback core anymore. In other words, the playback core is completely relieved from timeline implementation details. (Which honestly is exactly what I'm trying to do here. I don't think ordered chapter behavior deserves improvement, even if it's bad - but I want to get it out from the playback core.) There is code duplication between audio and video decoder common code. This is awful and could be shareable - but this will happen later. Note that the audio path has some code to clip audio frames for the purpose of codec preroll/gapless handling, but it's not shared as sharing it would cause more pain than it would help.
* demux: reduce verbositywm42016-02-111-2/+3
| | | | Tired of seeing all these useless pseudo-demuxers in the log.
* demux: remove a minor difference between threaded/unthreaded modeswm42016-01-191-2/+2
| | | | This difference was unnecessary.
* demux: fix leaking closed captions packets with unselected sub streamwm42016-01-191-6/+6
| | | | | Calling demux_add_packet() unconditonally frees the packet if the stream is not selected.
* vd_lavc: feed A53_CC side data packets into the demuxer for eia_608 decodingAman Gupta2016-01-181-0/+25
|
* demux: disable stream cache if no tracks are selectedwm42016-01-181-0/+8
| | | | | | | | | Slightly helps with timeline stuff, like EDL. There is no need to keep network (or even just disk I/O) busy for all segments at the same time, because 1. the data won't be needed any time soon, and 2. will probably be discarded anyway if the stream is seeked when segment is resumed. Partially fixes #2692.
* demux: remove unused functionwm42016-01-181-13/+0
|
* demux: fix interleaved subtitle reading in unthreaded modewm42016-01-181-16/+17
| | | | | | Meh. Why are there even two code paths. This adds an additional check; the big function is only moved.
* demux: unify codepaths for threaded/unthreaded track switchingwm42016-01-181-10/+8
| | | | Well, not that the unthreaded case is important, or even works properly.
* demux: merge sh_video/sh_audio/sh_subwm42016-01-121-8/+7
| | | | | | | | | | This is mainly a refactor. I'm hoping it will make some things easier in the future due to cleanly separating codec metadata and stream metadata. Also, declare that the "codec" field can not be NULL anymore. demux.c will set it to "" if it's NULL when added. This gets rid of a corner case everything had to handle, but which rarely happened.
* mpv_talloc.h: rename from talloc.hDmitrij D. Czarkoff2016-01-111-1/+1
| | | | This change helps avoiding conflict with talloc.h from libtalloc.
* player: eliminate demux_get_next_pts()wm42016-01-111-16/+0
| | | | | | | | | | | | | | | | This slightly changes behavior when seeking with external audio/subtitle tracks if transport streams and mpeg files are played, as well as behavior when seeking with such external tracks. get_main_demux_pts() is evil because it always blocks on the demuxer (if there isn't already a packet queued). Thus it could lock up the player, which is a shame because all other possible causes have been removed. The reduced "precision" when seeking in the ts/mpeg cases (where SEEK_FACTOR is used, resulting in byte seeks instead of timestamp seeks) might lead to issues. We should probably drop this heuristic. (It was introduced because there is no other way to seek in files with PTS resets with libavformat, but its value is still questionable.)
* sub: change how subtitles are readwm42015-12-291-6/+28
| | | | | | | | Slightly change how it is decided when a new packet should be read. Switch to demux_read_packet_async(), and let the player "wait properly" until required subtitle packets arrive, instead of blocking everything. Move distinguishing the cases of passive and active reading into the demuxer, where it belongs.
* demux: remove weird tripple-buffering for the sh_stream listwm42015-12-231-67/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The demuxer infrastructure was originally single-threaded. To make it suitable for multithreading (specifically, demuxing and decoding on separate threads), some sort of tripple-buffering was introduced. There are separate "struct demuxer" allocations. The demuxer thread sets the state on d_thread. If anything changes, the state is copied to d_buffer (the copy is protected by a lock), and the decoder thread is notified. Then the decoder thread copies the state from d_buffer to d_user (again while holding a lock). This avoids the need for locking in the demuxer/decoder code itself (only demux.c needs an internal, "invisible" lock.) Remove the streams/num_streams fields from this tripple-buffering schema. Move them to the internal struct, and protect them with the internal lock. Use accessors for read access outside of demux.c. Other than replacing all field accesses with accessors, this separates allocating and adding sh_streams. This is needed to avoid race conditions. Before this change, this was awkwardly handled by first initializing the sh_stream, and then sending a stream change event. Now the stream is allocated, then initialized, and then declared as immutable and added (at which point it becomes visible to the decoder thread immediately). This change is useful for PR #2626. And eventually, we should probably get entirely of the tripple buffering, and this makes a nice first step.
* demux: check embedded cuesheet refers to only one fileKevin Mitchell2015-12-171-4/+9
| | | | | | If someone was "clever" enough to embed a cuesheet referencing multiple files, mpv would create a bunch of nonsense chapter markers.
* demux: remove old subtitle parserwm42015-12-101-3/+0
| | | | | | | | | All of these are supported by FFmpeg now. It was disabled by default too (with FFmpeg). If compiled against Libav, mpv will lose the ability to read some subtitle formats (but the most important ones, srt and ass, still should work).
* demux: fix seeking in .tswm42015-11-231-1/+1
| | | | | .ts files (and some other raw streams) are the only files that enable the SEEK_FACTOR code path, which was broken since commit 70df1608.
* player: handle rebasing start time differentlywm42015-11-161-1/+20
| | | | | | | | | | | | | | | | Most of this is explained in the DOCS additions. This gives us slightly more sanity, because there is less interaction between the various parts. The goal is getting rid of the video_offset entirely. The simplification extends to the user API. In particular, we don't need to fix missing parts in the API, such as the lack for a seek command that seeks relatively to the start time. All these things are now transparent. (If someone really wants to know the real timestamps/start time, new properties would have to be added.)
* demux_libass: remove this demuxerwm42015-11-111-4/+0
| | | | | | | | | This loaded external .ass files via libass. libavformat's .ass reader is now good enough, so use that instead. Apparently libavformat still doesn't support fonts embedded into text .ass files, but support for this has been accidentally broken in mpv for a while anyway. (And only 1 person complained.)
* command: do not return 0 for bitrates if unknownwm42015-10-231-2/+3
| | | | | | | | This makes the bitrate properties unavailable, instead of returning 0 when: 1. No track is selected, or 2. Not enough packets have been read to have a bitrate estimate yet
* demux: cosmetics: remove indirectionwm42015-10-221-4/+2
| | | | Let's not waste precious lines.
* demux: remove demux_add_packet() return valuewm42015-10-171-5/+3
|
* demux: don't attempt to open a demuxer after abort signal was givenwm42015-10-061-0/+3
| | | | | demux_open() kept trying to fallback to other demuxers when opening was cancelled. This was not really a problem, but it was stupid.
* cue: read more metadatawm42015-10-011-1/+2
| | | | | | | | | | | Make handling of metadata slightly more generic, and add reading of the "PERFORMER" fields. There are some more fields, but for now let's leave it at this. TRACK-specific PERFORMER fields have to be read from the per-chapter metadata (somewhat obscure). Fixes #2328.
* stream: provide a stream_get_size() convenience functionwm42015-08-181-2/+1
| | | | | 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.
* demux: remove redundant demux_chapter.name fieldwm42015-08-121-4/+1
| | | | | | | | | | Instead, force everyone to use the metadata struct and set a "title" field. This is only a problem for the timeline producers, which set up chapters manually. (They do this because a timeline is a separate struct.) This fixes the behavior of the chapter-metadata property, which never returned a "title" property for e.g. ordered chapters.
* demux: add options to control maximum queue sizewm42015-08-051-1/+5
| | | | | | | | | | | | | | Add --demuxer-max-packets and --demuxer-max-bytes, which control the maximum size of the packet queue. These can be helpful to avoid excessive memory usage. Memory usage is the reason why there's a limit in the first place. If a file is more or less broken, and audio and video don't line up, the decoders will fill up the packet queue trying to read more audio or video, and the maximum sizes are required to avoid unbounded memory allocation. Being able to override the maximum sizes is useful; either for restricting memory usage further, or enlarging the sizes when attempting to play various broken files.
* demux: remove options to control minimum packet queue sizewm42015-08-051-6/+0
| | | | | | | | Remove --demuxer-readahead-packets and --demuxer-readahead-bytes. These were a bit useless. They could force a minimum packet queue size, but controlling the queue size with --demuxer-readahead-secs is much nicer. It's fairly certain nobody ever used these options.
* player: use demux_open_url() to open main fileswm42015-08-041-3/+11
| | | | | | | | | | | | | | | | Instead of opening a stream and then a demuxer, do both at once with demux_open_url(). This requires some awkward additions to demuxer_params, because there are some weird features associated with opening the main file. E.g. the relatively useless --stream-capture features requires enabling capturing on the stream before the demuxer is opened, but on the other hand shouldn't be done on secondary files like external subtitles. Also relatively bad: since demux_open_url() returns just a demuxer pointer or NULL, additional error reporting is done via demuxer_params. Still, at least conceptually, it's ok, and simpler than before.
* player: remove higher-level remains of DVD/BD menu supportwm42015-08-031-17/+0
| | | | | | | | | | | | | | | Nobody wanted to restore this, so it gets the boot. If anyone still wants to volunteer to restore menu support, this would be welcome. (I might even try it myself if I feel masochistic and like wasting a lot of time for nothing.) But if it does get restored, it should be done differently. There were many stupid things about how it was done. For example, it somehow tried to pull mp_nav_events through all the layers (including needing to "buffer" them in the demuxer), which was needlessly complicated. It could be done simpler. This code was already inactive, so this commit actually changes nothing. Also keep in mind that normal DVD/BD playback still works.
* demux: handle Matroska-style replaygain tags as wellwm42015-07-121-0/+8
| | | | | | | Matroska doesn't follow the usual ReplayGain conventions, and doesn't distinguish between track/album values. Fixes #2128.
* demux: refactor replaygain tag handlingwm42015-07-121-17/+19
| | | | | For the following commit. Also print the replaygain values in verbose mode.
* player: disable seeking even if the cache is enabledwm42015-07-081-3/+2
| | | | | | | | | | | | | | Until now, if a stream wasn't seekable, but the stream cache was enabled (--cache), we've enabled seeking anyway. The idea was that at least short seeks would typically fall within the cache. And if not, the user was out of luck and terrible things happened. In other words, it was unreliable. Be stricter about it and remove this behavior. Effectively, this will for example disable seeking in piped data. Instead of trying to be clever, add an --force-seekable option, which will always enable seeking if the user really wants it.
* demux: get rid of some bstr thingswm42015-06-241-12/+10
| | | | | Change the demuxer_add_attachment() and demuxer_add_chapter() signatures to take char* instead of bstr, and everything which depends on it.
* player: add some debug output for seekingwm42015-06-181-0/+7
|
* demux: don't get stuck on some cases of timestamp resetswm42015-05-261-1/+2
| | | | | In this case, streaming ogg via mpd over icecast made it buffer infinitely on new tracks.
* demux: read cue sheets embedded in tagswm42015-05-191-2/+17
| | | | | | | | | This reads the "CUESHEET" tag, and attempts to parse it as .cue data. If any is found, the cue tracks are added as chapters. This reuses the parser written for demux_cue.c. Fixes #1957.
* demux_mkv: move global options to the demuxerwm42015-04-231-1/+1
| | | | | | | The options don't change, but they're now declared and used privately by demux_mkv.c. This also brings with it a minor refactor of the subpreroll seek handling - merge the code from playloop.c into demux_mkv.c. The change in demux.c is pretty much equivalent as well.
* demux: report correct cache state close to EOFwm42015-04-201-5/+4
| | | | | | | | | | | | | | | | | | | | | On EOF, this stopped reporting the actual cache duration, and just signalled unknown duration. Fix this and keep reporting whatever is left in the packet queue. This reverts commit 5438a8b3. The commit doesn't give a good explanation as to why it is needed, but I guess it was because the reporting was imperfect (it switched between unknown or 0, and the correct duration). This also removes a line added in commit 848546f2. The line is ds->active = false; The "active" flag basically says that data from this stream is actively needed, and it's used to calculate the minimum data that can actually be played (approximately). If this were ignored, a sparse subtitle stream would set the cache duration to 0s. The commit message adding the line says "actually does nothing, but in theory it's cleaner". Well, screw it.
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* demux: fix rar support for files containing DTS audio trackswm42015-03-241-0/+2
| | | | | | | | | | | | | | | | | With a recent cleanup, rar support was stuffed into demux_playlist.c (because "opening" rar files pretty much just lists archive contents and adds them to a playlist using a special rar:// protocol, which will actually access the rar file contents). Since demux_playlist.c is probed _after_ demux_lavf.c (and should/must be), libavformat was given the chance to detect DTS streams embedded within the rar file. This is not really what we want, and a regression what happened before rar listing was moved to demux_playlist.c. Fix it by moving the rar listing into its own pseudo-demuxer, and let ir probe before demux_lavf.c. (Yes, this feature still has users.)
* demux_mkv: check for playback abortswm42015-03-091-0/+5
| | | | | | | | | Check async abort notification. libavformat already do something equivalent. Before this commit, the demuxer could enter resync mode (and print silly warning messages) when the stream stopped returning data because of an abort.
* stream: remove stream filter conceptwm42015-02-271-1/+1
| | | | Unused since the previous commit. (Apparently it was a stupid idea.)
* demux: add a demux_open_url() functionwm42015-02-201-0/+20
| | | | | Often stream and a demuxer are opened at the same time. Provide a function for this and replace most of its uses.
* demux: change demux_open() signaturewm42015-02-201-4/+4
| | | | Fold the relatively obscure force_format parameter into demuxer_params.
* demux: add free_demuxer_and_stream() functionwm42015-02-201-0/+9
| | | | | Although their lifetimes are conceptually different, it happens often that a demuxer is destroyed together with its stream.
* player: enable cache and demuxer thread for subtitles toowm42015-02-181-0/+1
| | | | | | | | | Includes some logic for not starting the demuxer thread for fully read subtitles. (Well, the cache will still waste _lots_ of resources, and the cache always has to be created, because we don't know whether it'll be needed _before_ opening the file.) See #1597.
* demux, matroska: remove demuxer type fieldwm42015-02-171-1/+0
| | | | | | | | | | | | | The Matroska timeline code was the only thing which still used the demuxer.type field. This field explicitly identifies a demuxer implementation. The purpose of the Matroska timeline code was to reject files that are not Matroska. But it already forces the Matroska format, meaning loading will explicitly only use the Matroska demuxer. If the demuxer can't open the file, no other demuxer will be tried, and thus checking the field is redundant. The change in demux_mkv_timeline.c removes the if condition, and unindents the if body.
* demux: remove file_contents fieldwm42015-02-171-1/+0
| | | | | | | Only demux_cue and demux_edl used it. It's a weird field and doesn't help with anything anymore - by now, it only saves a priv context in the mentioned demuxers. Reducing the number of confusing things the demuxer struct has is more important than minimizing the code.
* demux: copy priv pointer toowm42015-02-171-0/+1
| | | | | Weird, but helps with the case a demuxer gets handed its own instance from outside.
* demux: chapters without metadata are allowedwm42015-02-171-2/+3
| | | | Makes some of the following commits slightly simpler. Also fix a typo.
* demux: fix dropped subtitle packets with the new stream swit