summaryrefslogtreecommitdiffstats
path: root/demux/demux_lavf.c
Commit message (Collapse)AuthorAgeFilesLines
* demux: add per-track metadatawm42016-08-121-22/+15
| | | | | | | | | | | | | | | | | ...and ignore it. The main purpose is for retrieving per-track replaygain tags. Other than that per-track tags are not used or accessed by the playback core yet. The demuxer infrastructure is still not really good with that whole synchronization thing (at least in part due to being inherited from mplayer's single-threaded architecture). A convoluted mechanism is needed to transport the tags from demuxer thread to user thread. Two factors contribute to the complexity: tags can change during playback, and tracks (i.e. struct sh_stream) are not duplicated per thread. In particular, we update the way replaygain tags are retrieved. We first try to use per-track tags (common in Matroska) and global tags (effectively formats like mp3). This part fixes #3405.
* demux: make refresh seek handling more genericwm42016-08-061-1/+0
| | | | | | | | | | | | | | | | | Remove the explicit whitelisting of formats for refresh seeks. Instead, check whether the packet position is somewhat reliable during demuxing. If there are packets without position, or the packet position is not monotonically increasing, then do not use them for refresh seeks. This does not make sure of some requirements, such as deterministic seeks. If that happens, mpv will mess up a bit on stream switching. Also, add another method that uses DTS to identify packets, and prefer it to the packet position method. Even if there's a demuxer which randomizes packet positions, it hardly can do that with DTS. The DTS method is not always available either, though. Some formats do not have a DTS, and others are not always strictly monotonic (possibly due to libavformat codec parsing and timestamp determination issues).
* demux_lavf: remove subtitle seeking special-casewm42016-07-241-22/+7
| | | | | | | | It used not to work - but now it apparently does. Not sure when that got fixed in FFmpeg, but there's no longer a reason to keep this hack. This also gets rid of the check for the read_seek2 field, which is not part of the public API.
* demux_lavf: assume fully read files (subtitles) are always seekablewm42016-06-081-0/+1
| | | | | | | Since the libavformat API is crap, we have to apply tons of heuristics to check whether seeking will work. (No, checking it at seek time isn't going to work either, because if a seek fails, the demuxer will be in an undefined state. Because the libavformat API is crap.)
* demux_lavf: fix a minor memory leakwm42016-05-081-1/+5
|
* demux_lavf, ad_lavc, ad_spdif, vd_lavc: handle FFmpeg codecpar API changewm42016-03-311-2/+16
| | | | | | | | | AVFormatContext.codec is deprecated now, and you're supposed to use AVFormatContext.codecpar instead. Handle this for all of the normal playback code. Encoding mode isn't touched.
* demux_lavf: remove old MicroDVD frame timing guessingwm42016-03-311-6/+1
| | | | | | | | | | This was changed in 2014, so I suppose users will usually have a FFmpeg release which includes the corresponding upstream change. If not, well too bad for those MicroDVD-obsessed users. Also don't try to retrieve the default framerate as exported by the demuxer, and instead hardcode it and trust it won't ever change. this avoids that we have to deal with a larger mess in the codecpar commit.
* demux_lavf: remove some old framerate guessingwm42016-03-311-14/+1
| | | | | | I don't trust it one bit, and it's a bother with the codecpar change. If it turns out to be important for some file formats, it could be added back (or FFmpeg fixed).
* demux_lavf: don't copy cover art picturewm42016-03-031-2/+2
| | | | Use the AVPacket refcounting mechanism instead.
* demux: remove relative seekingwm42016-02-281-23/+11
| | | | | | | | | | | | | | | | | | | 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_lavf: adjust seeks by maximum codec delaywm42016-02-221-0/+8
| | | | | | | | | | | | | | | Fixes relative seeks. Without this, a seek back could skip so much data that the seek would effectively jump forward. (Or insert silence for files with video.) There's the question whether the frontend should do this instead (by using information from the decoders), but for now this seems more proper. demux_mkv.c does this already, sort of. libavformat doesn't for seeks in .ogg (aka .opus), but might be doing it for mkv. Seems to be a mess as well.
* sub: fix memory leakswm42016-01-181-0/+2
| | | | | | | | | demux_lavf.c leaked the complete subtitle data if it was put through iconv. lavc_conv.c leaked AVCodecContext.subtitle_header (set by libavcodec), which is fixed by using avcodec_free_context(). It also leaked the subtitle that was decoded last.
* demux_lavf: update metadata with information from AV_PROGRAM on switch.Oliver Freyermuth2016-01-141-0/+6
| | | | | | Need to trigger demux_changed() manually since metadata of tracks and streams is not changed, but demuxer-metadata is still changed on program switch.
* demux_lavf: fix charset conversion with UTF-16 subtitleswm42016-01-121-5/+6
| | | | | | | | | | | | | | | | | | | | UTF-16 subtitles are special in that they are usually read by libavformat directly, even though they are not in UTF-8. This is explicitly handled convert_charset() and skips conversion to UTF-8. There was a bug due to not resetting the file position: if conversion happens, the actual stream is replaced with a memory stream containing the converted data, but if conversion is skipped, the original stream with the wrong file position is kept. Fix by always opening a memory stream. (We _could_ seek back, but there is a slight possibility of additional failure due to unseekable streams.) Also, don't enter conversion if the subtitle is detected as UTF-8 either. Fixes #2700.
* demux: merge sh_video/sh_audio/sh_subwm42016-01-121-30/+27
| | | | | | | | | | 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.
* demux_lavf: re-enable codepage autodetection for .assfwr2016-01-041-2/+1
| | | | | | | | There are a lot of incorrectly encoded subtitles with .ass extension and non-ass subtitles (srt, ssa) with such extension, so we need to try codepage detection even for .ass. Signed-off-by: wm4 <wm4@nowhere>
* sub: do charset conversion in demux_lavf.cwm42015-12-281-13/+19
| | | | | | | | | | | | | Just so I can remove a few lines from dec_sub.c. This is slightly inelegant, as the whole subtitle file has to be read into memory, converted at once in memory, and then provided to libavformat in an awkward way by creating a memory stream instead of using demuxer->stream. It also won't be possible to force the charset on subtitles in binary container formats - but this wasn't exposed before, and we just hope this won't be ever needed. (One motivation was fixing broken files with non-UTF8 muxed.) It also won't be possible to change the charset on the fly, but this was not exposed either.
* demux_lavf: prepare for using wrapper stream instancewm42015-12-281-14/+20
| | | | Preparation for the next commit.
* demux: remove weird tripple-buffering for the sh_stream listwm42015-12-231-14/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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_lavf: rename to handle_new_stream to clarify intentAman Gupta2015-12-221-2/+2
|
* demux_lavf: make trace output for mp_seek easier to digestAman Gupta2015-12-211-1/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* video: switch from using display aspect to sample aspectwm42015-12-191-6/+2
| | | | | | | | | | | | | | | | MPlayer traditionally always used the display aspect ratio, e.g. 16:9, while FFmpeg uses the sample (aka pixel) aspect ratio. Both have a bunch of advantages and disadvantages. Actually, it seems using sample aspect ratio is generally nicer. The main reason for the change is making mpv closer to how FFmpeg works in order to make life easier. It's also nice that everything uses integer fractions instead of floats now (except --video-aspect option/property). Note that there is at least 1 user-visible change: vf_dsize now does not set the display size, only the display aspect ratio. This is because the image_params d_w/d_h fields did not just set the display aspect, but also the size (except in encoding mode).
* demux_lavf: minor cleanupswm42015-12-171-13/+5
|
* sub: detect charset in demuxerwm42015-12-171-8/+26
| | | | | | | | | | | | Slightly simpler, and removes the need to pre-read all subtitle packets. This still does the subtitle charset conversion on the packet level (instead converting when parsing the file), so in theory this still could provide a way to change the charset at runtime. But maybe even this should be removed, as FFmpeg is somewhat likely to get its own charset detection and conversion mechanism in the future. (Would have to keep the subtitle file in memory to allow changing the charset on the fly, I guess.)
* sub: remove sd_movtext.cwm42015-12-151-4/+12
| | | | | libavcodec's movtext-to-ass converter does the same and has more features. On Libav, this commit disables mp4 subtitle display.
* demux_lavf: mark ASS tracks as always UTF-8wm42015-11-111-0/+4
| | | | | Stops mpv from trying to run a subtitle charset detector on .ass files loaded by libavformat.
* Replace deprecated av_free_packet() callswm42015-10-281-4/+4
| | | | | | av_free_packet() got finally deprecated. Use av_packet_unref() instead, which has almost the same semantics, has existed for a while, and is available in all FFmpeg and Libav versions we support.
* demux_lavf: always copy codec headerswm42015-10-191-1/+8
| | | | | | If this is not done, libavformat could change the headers while demuxing, all while the decoder thread reads these fields during initialization.
* Take care of libavcodec convergence_duration deprecationwm42015-09-291-0/+2
| | | | | | This AVPacket field was a hack against the fact that the duration field was merely an int (too small for things like subtitle durations). Newer libavcodec drops this field and makes duration 64 bit.
* stream: provide a stream_get_size() convenience functionwm42015-08-181-4/+3
| | | | | And use it everywhere, instead of retrieving the size manually. Slight simplification.
* demux_lavf: check for NAN rotation angleswm42015-06-301-3/+5
| | | | Yep, the FFmpeg API can return this.
* demux: export forced flagwm42015-06-271-1/+3
| | | | | | At least Matroska files have a "forced" flag (in addition to the "default" flag). Export this flag. Treat it almost like the default flag, but with slightly higher priority.
* demux_lavf: fix chapter titleswm42015-06-241-1/+1
| | | | Obvious bug added earlier today.
* demux: get rid of some bstr thingswm42015-06-241-4/+3
| | | | | Change the demuxer_add_attachment() and demuxer_add_chapter() signatures to take char* instead of bstr, and everything which depends on it.
* demux: merge extradata fieldswm42015-06-211-3/+3
| | | | | | | MPlayer traditionally had completely separate sh_ structs for audio/video/subs, without a good way to share fields. This meant that fields shared across all these headers had to be duplicated. This commit deduplicates essentially the last remaining duplicated fields.
* demux: rename sh_stream.format to sh_stream.codec_tagwm42015-06-211-3/+1
| | | | | Why not. "format" sounds too misleading for the actual importance and meaning of this field.
* demux_lavf: fix wrong printf parameter type on 64 bit systemswm42015-06-021-1/+1
| | | | | "f.len - 4" is size_t, not int. Fix by using BSTR_P() (and a bstr function to adjust the length).
* demux_lavf: do a better job at guessing the vobsub .sub filenamewm42015-05-281-0/+40
| | | | | | | | | | | Vobsubs come as .idx/.sub pair of files. The .idx file is the one that should be opened, but the name of the .sub file is unknown. We can now make our own guess what the name of that file is. In particular, improve support with URLs (as these can have the file extension in the middle of the filename string if there are HTTP parameters). Note that this works only with newer ffmpeg versions, because the recently added sub_name demuxer option is used for this.
* demux_lavf: drop dead codewm42015-04-251-7/+1
| | | | stream.url can never be NULL, although it probably used to be.
* player: change video-bitrate and audio-bitrate propertieswm42015-04-201-4/+0
| | | | | | | | | | | | | | Remove the old implementation for these properties. It was never very good, often returned very innaccurate values or just 0, and was static even if the source was variable bitrate. Replace it with the implementation of "packet-video-bitrate". Mark the "packet-..." properties as deprecated. (The effective difference is different formatting, and returning the raw value in bits instead of kilobits.) Also extend the documentation a little. It appears at least some decoders (sipr?) need the AVCodecContext.bit_rate field set, so this one is still passed through.
* demuxer_lavf: add an option for disabling hackswm42015-04-171-0/+5
|
* Update license headersMarcin Kurczewski2015-04-131-5/+4
| | | | Signed-off-by: wm4 <wm4@nowhere>
* demux_lavf: use mimetype instead of codec type for embedded fontswm42015-04-051-9/+3
| | | | | | | We handle picking out font attachments by mime type ourselves in a higher level, so we really just want to use the mimetype. Also, Matroska is currently the only code in libavformat which uses the fonts at all, and we can drop use of the codec IDs completely.
* demux_lavf: print seek failures in verbose modewm42015-03-241-6/+12
| | | | | Don't bother with making these visible by default, because often they are bogus and/or useless.
* demux_lavf: assume h264/hevc raw streams have no timestampswm42015-03-201-4/+12
| | | | | There are obscure methods to add timestamps to such streams, but assume they're unused.
* player: better handling of video with no timestampswm42015-03-201-10/+3
| | | | | | | | | | | Trying to handle such video is almost worthless, but it was requested by at least 2 users. If there are no timestamps, enable byte seeking by setting ts_resets_possible. Use the video FPS (wherever it comes from) and the audio samplerate for timing. The latter was already done by making the first packet emit DTS=0; remove this again and do it "properly" in a higher level.
* sub: this isn't needed eitherwm42015-03-031-2/+0
|
* Revert "demux_lavf: workaround for broken libavformat subtitle seeking"wm42015-03-031-23/+4
| | | | | | | This reverts commit c8f49be919ffaf983bde77b63d75f96a593ec7a8. Not needed anymore; fixed in all supported FFmpeg releases. Though I could not test again, because all sample files are gone (oops).
* Remove some FFmpeg/Libav compatibility hackswm42015-03-031-33/+2
| | | | | | All of these are now in the supported FFmpeg and Libav versions. The 3 remaining API checks are for FFmpeg-only things.
* demux_lavf: use this for image formatswm42015-03-021-6/+13
| | | | | | | | | | | | | | | | | | Use the (relatively new) libavformat image format probing functionality, instead of letting demux_mf guess by file extension and MIME type. The libavformat support is weird, though. Traditionally, it uses an absolutely terrible hack to detect images by extension, _and_ (which is the horrible part) will randomly interpret parts of the filename as specifiers for matching by number. So something like '%03d' will be interpreted as placeholder for a frame number. The worst part is that such character sequences can be perfectly valid and common in http URLs. This is known as "image2" demuxer. The newer support, which probes by examining the file header, is split into several format-specific demuxers with names ending in "_pipe". So we check for such a name suffix. (At this point we're doing fine-grained hacking around ffmpeg weirdness, so a clean solution is impossible anyway until upstream changes.)
* demux_lavf: apply hacks even if format is forcedwm42015-02-201-27/+28
| | | | | | | | | | | | | Some of the hacks were not applied if the file format was forced. Commit 37a0c914 moved them to a table, which is checked with normal probing only. Fixes #1612 (DVD forces mpeg, which in turn has to export native stream IDs specifically). Do some code restructuring on the way. For example, the probescore can simply be set to the correct initial value, instead of checking whether it was set at all.
* demux_lavf: blacklist bintext fileswm42015-02-181-0/+3
| | | | | | Whatever the hell that is. FFmpeg tries to open any files with .bin file extension with this demuxer (unless it finds a better demuxer), and then reads the whole damn file, along with spamming dumb crap.
* player: enable cache and demuxer thread for subtitles toowm42015-02-181-0/+8
| | | | | | | | | 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_lavf: reorganize hackswm42015-02-181-67/+70
| | | | | | | | | | | An attempt to make format-specifics more declarative. (In my opinion, all of this should be either provided by libavformat, or should not be needed.) I'm still leaving many checks with matches_avinputformat_name(), because they're so specific. Also useful for the following commit.
* demux_lavf: set interrupt_callbackwm42015-02-181-0/+11
| | | | | | Helps with terminating the stream if e.g. HLS streams are stuck. (For other demuxers, the stream's interrupt callback already takes care of this.)
* demux_lavf: hack against hls showing "100%" positionwm42015-02-171-0/+6
| | | | | | | | | | | | | The HLs protocol consists of a "playlist" main file, which mpv downloads and passes to the HLS demuxer. The HLS demuxer actually requests segment files containing media data on its own. The packets read from the demuxer have a source file position set, but it's not from the main file. This leads to a strange effect: as a last fallback, the player will calculate the approximate playback position from the file position/size ratio, and since the main file is tiny, this will always show 100%. Fix this by resetting the packet file position. This doesn't affect the case when HLS actually reports a duration.
* demux: hack for instant stream switchingwm42015-02-131-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |