summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
Commit message (Collapse)AuthorAgeFilesLines
* demux: remove gsh field from sh_audio/sh_video/sh_subwm42013-11-231-2/+2
| | | | | | | | | This used to be needed to access the generic stream header from the specific headers, which in turn was needed because the decoders had access only to the specific headers. This is not the case anymore, so this can finally be removed again. Also move the "format" field from the specific headers to sh_stream.
* demux: simplify handling of filepos fieldwm42013-11-161-3/+1
| | | | | | | | | | | | demuxer->filepos contains the byte offset of the last read packet. This is so that the player can estimate the current playback position, if no proper timestamps are available. Simplify it to use demux_packet->pos in the generic demuxer code, instead of bothering every demuxer implementation about it. (Note that this is still a bit incorrect: it relfects the position of the last packet read by the demuxer, not that returned to the user. But that was already broken, and is not that trivial to fix.)
* demux_lavf: remove broken and commented byte based seekswm42013-11-161-40/+0
| | | | | | | | | | | | | This was originally added for better seeking where libavformat's seek function won't work well: files with timestamp resets. In these cases, the code tried to calculate an average bitrate, and then do byte based seeks by multiplying the seek target time with the bitrate. Apparently this was unreliable enough that the code was just commented (and other parts became inactive). Get rid of it. Note that the player still does byte based seeks in these cases when doing percent-seeks.
* demux: make determining seek capability genericwm42013-11-031-5/+6
| | | | | | | | | | | | | | | | Instead of having each demuxer do it (only demux_mkv actually did...), let generic code determine whether the file is seekable. This requires adding exceptions to demuxers where the stream is not seekable, but the demuxer is. Sort-of try to improve handling of unseekable files in the player. Exit early if the file is determined to be unseekable, instead of resetting all decoders and then performing a pointless seek. Add an exception to allow seeking if the file is not seekable, but the stream cache is enabled. Print a warning in this case, because seeking outside the cache (which we can't prevent since the demuxer is not aware of this problem) still messes everything up.
* demux: remove movi_start/movi_end fieldswm42013-11-031-6/+6
| | | | | | | Pointless, using stream->start_pos/end_pos instead. demux_mf was the only place where this was used specially, but we can rely on timestamps instead for this case.
* Enable -Wshadowwm42013-11-011-1/+1
| | | | | | | | | This one really did bite me hard (see previous commit), so enable it by default. Fix some cases of shadowing throughout the codebase. None of these change behavior, and all of these were correct code, and just tripped up the warning.
* talloc: change talloc destructor signaturewm42013-10-131-2/+1
| | | | | | | | | | | | | Change talloc destructor so that they can never signal failure, and don't return a status code. This makes our talloc copy even more incompatible to upstream talloc, but on the other hand this is preparation for getting rid of talloc entirely. (The talloc replacement in the next commit won't allow the talloc_free equivalent to fail, and the destructor return value would be useless. But I don't want to change any mpv code either; the idea is that the talloc replacement commit can be reverted for some time in order to test whether the talloc replacement introduced a regression.)
* network: fix rtsp playbackwm42013-09-221-1/+22
| | | | | | | | | | | | | | By default, libavformat uses UDP for rtsp playback. This doesn't work very well. Apparently the reason is that the buffer sizes libavformat chooses for UDP are way too small, and switching to TCP gets rid of this issue entirely (thanks go to Reimar Döffinger for figuring this out). In theory, you can set buffer sizes as libavformat options, but that doesn't seem to help. Add an option to select the rtsp transport, and make TCP the default. Also remove an outdated comment from stream.c.
* demux: retrieve per-chapter metadatawm42013-09-081-1/+6
| | | | | | | | | | Retrieve per-chapter metadata, but don't do much with it. We just make the metadata of the _current_ chapter available as chapter-metadata property. Returning the full chapter list with metadata would be no problem, except that the property interface isn't really good with structured data, so it's not available for now. Not sure if it's worth it, but it was requested via github issue #201.
* demux_lavf: workaround for broken libavformat subtitle seekingwm42013-09-071-4/+23
| | | | | | | | | | | | | | The really funny thing about this commit is that this code is added on top of another work around. Basically, subtitle seeking in libavformat is completely broken. To make it useful, we have to add yet another workaround. The basic problem is that libavformat's subtitle seeking code always uses the stream time base, instead of AV_TIME_BASE if stream index -1 is passed to the avformat_seek_file() function. Fixes github issue #216. Hopefully this will be fixed in ffmpeg too at some point.
* demux: remove unused audio_delay parameter from demux_seek()wm42013-08-221-4/+3
| | | | Used to be needed by demux_avi.
* demux_lavf: blacklist "tty" libavformat demuxerv0.1.0wm42013-08-071-1/+16
| | | | | | | | | | This is completely useless, and in this particular case, it broke the fallback for MLP2 subtitles (stored as .txt files) to demux_subreader. (Yes, libavformat should be fixed to handle this, but for now this will _always_ break playback of subtitle files stored in .txt.) You can still force this demuxer, but by default we will just pretend that the "tty" demuxer does not exist.
* core: move contents to mpvcore (2/2)Stefano Pigozzi2013-08-061-6/+6
| | | | Followup commit. Fixes all the files references.
* demux_lavf: make avio buffer configurablewm42013-08-041-6/+8
| | | | | | Perhaps not very useful, but reserved for situations when a user reports awful latency and experimentation/debugging might be required to find out why or to fix it (happens often).
* demux_lavf: fix API usagewm42013-08-041-2/+10
| | | | | | | | | avio_alloc_context() is documented to require an av_malloc'ed buffer. It appears libavformat can even reallocate the buffer while it is probing, so passing a static buffer can in theory lead to crashes. I couldn't reproduce such a crash, but apparently it happened to mplayer-svn. This commit follows the mplayer fix in svn commit r36397.
* options: simplify --correct-pts handlingwm42013-07-261-1/+1
| | | | | | Remove the (now unused) code for determining correct-pts mode based on the demuxer in use. Change its description in the manpage to reflect what this option does now.
* demux_lavf: set keyframe flag on attached pictureswm42013-07-241-0/+1
| | | | | | | | | Gives really funky results with PNG attachments otherwise. The main problem is that avcodec_flush_buffers() does not fully reset the decoder, so passing multiple PNG packets without keyframe flags will attempt to combine the new picture with the previously decoded contents. (Makes no sense with proper PNG - maybe this codepath is intended for MNG or APNG.)
* demux_lavf: add terrible hack to make DVD playback just workwm42013-07-141-8/+85
| | | | | | | | | | | | | | | | | | DVD playback had some trouble with PTS resets: libavformat's genpts feature would try reading until EOF (worst case) to find a new usable PTS in case a packet's PTS is not set correctly. Especially with slow DVD access, this would make the player to appear frozen. Reimplement it partially in demux_lavf.c, and use that code in the DVD case. This is heavily "inspired" by the code in av_read_frame from libavformat/utils.c. The difference is that we stop reading if no PTS has been found after 50 packets (consider this a heuristic). Also, we don't bother with the PTS wrapping and last-frame-before-EOF handling. Even with normal PTS wraps, the player frontend will go to hell for the duration of a frame anyway, and should recover quickly after that. The terribleness of this commit is mostly that we duplicate libavformat functionality, and that we suddenly need a packet queue.
* demux: assume correct-pts mode by defaultwm42013-07-121-2/+0
| | | | | | | | All demuxers make a reasonable effort to set packet timestamps, and thus support correct-pts mode. This commit also implicitly switches demux_rawvideo to correct-pts mode. We still allow demuxers to disable correct-pts mode in theory.
* demux: remove useless author/comment fieldswm42013-07-121-4/+1
| | | | Same deal as with previous commit.
* demux: rewrite probing and demuxer initializationwm42013-07-121-9/+9
| | | | | | | | | | | | | | Get rid of the strange and messy reliance on DEMUXER_TYPE_ constants. Instead of having two open functions for the demuxer callbacks (which somehow are both optional, but you can also decide to implement both...), just have one function. This function takes a parameter that tells the demuxer how strictly it should check for the file headers. This is a nice simplification and allows more flexibility. Remove the file extension code. This literally did nothing (anymore). Change demux_lavf so that we check our other builtin demuxers first before libavformat tries to guess by file extension.
* demux: change signature of open functions, cleanupswm42013-07-111-24/+24
| | | | Preparation for redoing the open functions.
* core: completely change handling of attached picture pseudo videowm42013-07-111-5/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this commit, we tried to play along with libavformat and tried to pretend that attached pictures are video streams with a single frame, and that the frame magically appeared at the seek position when seeking. The playback core would then switch to a mode where the video has ended, and the "remaining" audio is played. This didn't work very well: - we needed a hack in demux.c, because we tried to read more packets in order to find the "next" video frame (libavformat doesn't tell us if a stream has ended) - switching the video stream didn't work, because we can't tell libavformat to send the packet again - seeking and resuming after was hacky (for some reason libavformat sets the returned packet's PTS to that of the previously returned audio packet in generic code not related to attached pictures, and this happened to work) - if the user did something stupid and e.g. inserted a deinterlacer by default, a picture was never displayed, only an inactive VO window) - same when using a command that reconfigured the VO (like switching aspect or video filters) - hr-seek didn't work For this reason, handle attached pictures as separate case with a separate video decoding function, which doesn't read packets. Also, do not synchronize audio to video start in this case.
* demux_lavf: do stream selection centrallywm42013-07-111-12/+13
| | | | Removes very minor code duplication for setting the st->discard flag.
* demux: improve DVD sub auto-selection hackwm42013-07-111-16/+4
| | | | | | | | | | | | | | | | | | | | | | | The code touched by this commit makes sure that DVD subtitle tracks known by libdvdread but not known by demux_lavf can be selected and displayed properly. These subtitle tracks have the first packet some time late in the packet stream, so that libavformat won't immediately recognize them, and will add the track as soon as the first packet is seen during normal demuxing. demux_mpg used to handle this elegantly: you just set the MPEG ID of the stream you wanted. demux_lavf couldn't do this, so it was emulated with a DEMUXER_CTRL. This commit changes it so that new streams are selected by default (if autoselect is enabled), and the playloop simply can take appropriate action before the lower layer throws away the first packet. This also changes the demux_lavf behavior that subtitle packets are always demuxed, even if not needed. (They were immediately thrown away, so there was no advantage to this.) Further, this adds the ability to demux.c to deal with demuxing more than one stream of a kind at once. (Though currently it's not useful.)
* demux_lavf: use AVDISCARD_DEFAULT instead of AVDISCARD_NONEwm42013-07-111-1/+1
| | | | | | AVDISCARD_DEFAULT is probably a bit better for normal decoding. AVDISCARD_NONE would (as by documentation) include "useless" packets too, while DEFAULT filters these.
* video: eliminate frametime variablewm42013-07-111-1/+0
|
* core: don't access demux_stream outside of demux.c, make it privatewm42013-07-111-1/+1
| | | | | | | | | | | | | | | | | | | Generally remove all accesses to demux_stream from all the code, except inside of demux.c. Make it completely private to demux.c. This simplifies the code because it removes an extra concept. In demux.c it is reduced to a simple packet queue. There were other uses of demux_stream, but they were removed or are removed with this commit. Remove the extra "ds" argument to demux fill_buffer callback. It was used by demux_avi and the TV pseudo-demuxer only. Remove usage of d_video->last_pts from the no-correct-pts code. This field contains the last PTS retrieved after a packet that is not NOPTS. We can easily get this value manually because we read the packets ourselves. Reuse sh_video->last_pts to store the packet PTS values. It was used only by the correct-pts code before, and like d_video->last_pts, it is reset on seek. The behavior should be exactly the same.
* demux_lavf: different hack for DVD sub autoselection hackwm42013-07-111-3/+2
| | | | | | | | | | | For now, we want to get rid of the demux->sub access, because this field will become private to demux.c in a later commit. So replace the current hack with another hack. The need for the hack will be removed sooner or later. (Instead of autoselecting a specific stream, all new streams will be enabled by default, so that no packets can get lost. The frontend will then be responsible to deselect unwanted streams.)
* demux: remove separate arrays for audio/video/sub streams, simplifywm42013-07-081-3/+3
| | | | | | | | | | | | These separate arrays were used by the old demuxers and are not needed anymore. We can simplify track switching as well. One interesting thing is that stream/tv.c (which is a demuxer) won't respect --no-audio anymore. It will probably work as expected, but it will still open an audio device etc. - this is because track selection is now always done with the runtime track switching mechanism. Maybe the TV code could be updated to do proper runtime switching, but I can't test this stuff.
* Remove old demuxerswm42013-07-071-1/+1
| | | | | | | | | | Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does better than them (except in rare corner cases), and the demuxers have a bad influence on the rest of the code. Often they don't output proper packets, and require additional audio and video parsing. Most work only in --no-correct-pts mode. Remove them to facilitate further cleanups.
* demux_lavf: add one more AAC mimetypewm42013-06-251-0/+1
|
* demux_lavf: use stream_peek() instead of read/unreadwm42013-06-251-6/+4
| | | | | | | Simpler, reduces the amount of copying. We still have to malloc+memcpy the probe buffer though, because padding with FF_INPUT_BUFFER_PADDING_SIZE is required by libavformat.
* Merge branch 'cache_new'wm42013-06-161-32/+33
|\
| * stream: remove stream_reset()wm42013-06-161-1/+0
| | | | | | | | | | | | | | | | | | 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.
| * demux_lavf: change probing, use stream_unread_buffer()wm42013-06-161-31/+33
| | | | | | | | | | This fixes a longstanding issue with demux_lavf probing. See previous commit.
* | demux_lavf: show metadata for OGG audio fileswm42013-06-151-5/+18
|/ | | | Whether this is a hack or not, I don't even know anymore.
* demux_lavf: always set packet durationwm42013-06-031-5/+2
| | | | | | | | | | | | | | Makes WebVTT actually work. Also simplify the logic for setting duration. Only the subtitle path uses the packet duration, so the checks for STREAM_SUB as well as the keyframe flag are redundant. Apparently duration and convergence_duration are the same thing, but convergence_duration was added as Matroska-specific hack to get a higher value range (int vs. int64_t) with high resolution Matroska timebases. For us it doesn't matter, because double floats are used for timestamps and durations.
* demuxer_lavf: use audio/mpeg mime type for mp3wm42013-05-271-0/+1
| | | | | Basically, add exactly the same hacks for mp3 as we did for AAC. Should make starting mp3 streams much faster.
* demux_lavf: minimal probing and reduced analyzeduration for AAC over HTTPwm42013-05-271-14/+43
| | | | | | | | | | | | | | | | | | | | | | | When AAC is streamed over HTTP, using libavformat defaults is pathetically slow. One solution for that is skipping probing and using the mimetype to identify that it's AAC instead. This is what we did before this commit (and ffmpeg does it too, but their logic is too "inaccessible" for mpv). This is still pretty fragile though. Make it a bit more robust by requiring minimal probing. A probescore of 25 is reached after feeding 2 KB to libavformat (instead of > 500 KB for the normal probescore), so use that. This is done only when streaming AAC from HTTP to reduce the possibility of weird breakages for other formats. Also reduce analyzeduration. The default analyzeduration will make libavformat read lots of data, which makes playback start slow. So we set analyzeduration to a low value. On the other hand, doing that for other formats is risky, because there are unspecified effects with certain "strange" formats (like transport streams). So we do this only if we're streaming AAC from HTTP as well. tl;dr libavformat is shit for media players
* options: add allow-mimetype suboption for demux_lavfwm42013-05-271-1/+2
| | | | | | | This can control whether demux_lavf should use the HTTP mime type to determine the format, instead of probing the data with the libavformat API. Do this to allow easier debugging in case the mimetype is incorrect. (This is done only for AAC streams right now.)
* demux_lavf: print how many bytes are read by avformat_find_stream_info()wm42013-05-261-0/+6
| | | | | | Can be helpful for debugging slow stream startup. Also add a comment about BIO_BUFFER_SIZE.
* demux_lavf: workaround minor ffmpeg memory leakwm42013-05-211-3/+1
| | | | | | | | | | | | The sequence of avcodec_alloc_context3() / avcodec_copy_context() / avcodec_close() / av_free() leaks some memory. So don't copy the context and use it directly. Originally avcodec_copy_context() was used to guarantee that libavformat can't update the fields of the context during demuxing in order to make things a little more robust, but it's not strictly needed, and ffmpeg/ffplay don't do this anyway. Still might make the situation worse should we move demuxing into a separate thread, though.
* Merge branch 'audio_changes'wm42013-05-121-1/+3
|\ | | | | | | | | Conflicts: audio/out/ao_lavc.c
| * core: use channel map on demuxer level toowm42013-05-121-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | demux_lavf: use demuxer ID for transport streamswm42013-05-051-1/+4
| | | | | | | | | | Might help mapping tracks correctly to stream_bluray, fixing the issue with the track language not being reported.
* | demux_lavf: fix DEMUXER_CTRL_RESYNCwm42013-05-051-1/+1
| | | | | | | | | | | | | | | | | | This used the libavformat current position, instead of the mp stream (which reflects current DVD/Bluray read position). This was broken, because libavformat won't update its position by calling the user's stream callbacks, negating the whole point of DEMUXER_CTRL_RESYNC. Now DVD playback with libavformat seems to work relatively well.
* | demux_lavf: set stream_ptswm42013-05-051-0/+6
| | | | | | | | | | | | | | | | demux_mpg did the same, and doing this in demux_lavf fixes DVD playback when using this demuxer. Additionally this might make bluray work better in the future (but for now, bluray playback doesn't change as it doesn't report stream PTS yet).
* | demux_lavf: fix subtitle seeking before start of the filewm42013-04-211-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to seek before the start of the file, which usually happens when using the arrow keys to seek to the start of the file, external libavformat demuxed subtitles will be invisible. This is because seeking in the external subtitle file fails, so the subtitle demuxer is left in a random state. This is actually similar to the normal seeking path, which has some fallback code to handle this situation. Add such code to the subtitle seeking path too. (Normally, all demuxer support av_seek_frame(), except subtitles, which support avformat_seek_file() only. The latter was meant to be the "new" seeking API, but this never really took off, and using it normally seems to cause worse seeking behavior. Or maybe we just use it incorrectly, nobody really knows.)
* | sub, demux: identify subtitle types with the codec namewm42013-04-201-21/+0
|