summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
Commit message (Collapse)AuthorAgeFilesLines
* demux: remove facility for partial packet readswm42013-07-111-117/+61
| | | | | | | | | | | | | | | | | | Partial packet reads were needed because the video/audio parsers were working on top of them. So it could happen that a parser read a part of a packet, and returned that to the decoder. With libavformat/libavcodec, packets are already parsed, and everything is much simpler. Most of the simplifications in ad_spdif could have been done earlier. Remove some other stuff as well, like the questionable slave mode start time reporting (could be replaced by proper code, but we don't bother). Remove the unused skip_audio_frame() functionality as well (it was used by old demuxers). Some functions become private to demux.c, like demux_fill_buffer(). Introduce new packet read functions, which have simpler semantics. Packets returned from them are owned by the caller, and all packets in the demux.c packet queue are considered unread. Remove special code that dropped subtitle packets with size 0. This used to be needed because it caused special cases in the old code.
* demux: remove ds_read_packet()wm42013-07-101-13/+0
|
* demux: remove some more minor unused thingswm42013-07-101-8/+0
|
* Merge branch 'master' into remove_old_demuxerswm42013-07-081-0/+2
|\ | | | | | | | | | | Conflicts: DOCS/man/en/changes.rst DOCS/man/en/options.rst
| * Fix building with --disable-libasswm42013-07-081-0/+2
| | | | | | | | Obscure corner case, but in theory we support this.
* | demux: simplify demux_open() callswm42013-07-081-18/+9
| | | | | | | | | | | | The demux_open as well as demux_open_withparams calls don't use the stream selection parameters anymore, so remove them everywhere. Completes the previous commit.
* | demux: remove separate arrays for audio/video/sub streams, simplifywm42013-07-081-70/+24
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | demux: merge functionswm42013-07-081-17/+9
| |
* | demux: remove some old stream header functionswm42013-07-081-36/+0
| |
* | demux: remove audio parserwm42013-07-081-70/+0
| | | | | | | | | | | | | | | | | | | | | | The audio parser was needed only by the "old" demuxers, and demux_rawaudio. All other demuxers output already parsed packets. demux_rawaudio is usually for raw audio, so using a parser with it doesn't usually make sense. But you can also force it to read compressed formats with fixed packet sizes, in which case the parser would have been used. This use case is probably broken now, but you will be able to do the same thing with libavformat demuxers.
* | Remove old demuxerswm42013-07-071-138/+2
|/ | | | | | | | | | 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.
* core: update metadata during playback, allow streams to export metadatawm42013-07-021-0/+13
| | | | | | | STREAM_CTRL_GET_METADATA will be used to poll for streamcast metadata. Also add DEMUXER_CTRL_UPDATE_INFO, which could in theory be used by demux_lavf.c. (Unfortunately, libavformat is too crappy to read metadata mid-stream for mp3 or ogg, so we don't implement it.)
* sub: add demux_libass wrapper, drop old hackswm42013-06-251-15/+2
| | | | | | | | | | | | demux_libass.c allows us to make subtitle format detection part of the normal file loading process. libass has no probe function, but trying to load the start of a file (the first 4 KB) is good enough. Hope that libass can even handle random binary input gracefully without printing stupid log messages, and that the libass parser doesn't accept too many non-ASS files as input. This doesn't handle the -subcp option correctly yet. This will be fixed later.
* core: don't set correct-pts mode randomlywm42013-06-251-5/+0
| | | | | | The default correct-pts mode depended on which demuxer was opened last. Often this is the subtitle demuxer. The correct-pts mode should be decided on the demuxer for video instead.
* subreader: turn into actual demuxerwm42013-06-251-0/+2
| | | | | | | | | | | | | | | | subreader.c (before this commit renamed to demux_subreader.c) was special cased to the -sub option. The plan is using the normal demuxer codepath for all subtitle formats (so we can prefer libavformat demuxers for most formats). There are some subtle changes. The probe size is restricted to 32 KB (instead of unlimitted + giving up after 100 lines of input). For formats like MicroDVD, the video FPS isn't used anymore, because it's not available on the subtitle demuxer level. Instead, hardcode it to 23.976 FPS (libavformat seems to do the same). The user can probably still use -sub-fps to fix the timing. Checking the file extension for ".utf"/".utf8"/".utf-8" is simply removed (seems worthless, was in the way, and I've never seen this anywhere).
* demux: add utility functions for preloading demuxerswm42013-06-251-3/+72
| | | | | These will be needed by subtitle demuxers, which read all data on initialization.
* sub: preload external text subtitleswm42013-06-231-1/+37
| | | | | | | | If a subtitle is external, read it completely and add all subtitle events in advance when the subtitle track is selected. This is done for text subtitles only. (Note that subreader.c and subtitles loaded with libass are different and don't have anything to do with this commit.)
* demux: don't require fill_buffer callbackwm42013-06-231-1/+1
|
* Merge branch 'sub_mess'wm42013-06-041-11/+26
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | This branch heavily refactors the subtitle code (both loading and rendering), and adds support for a few new formats through FFmpeg. We don't remove any of the old code yet. There are still some subtleties related to subreader.c to be resolved: code page detection & conversion, timing post-processing, UTF-16 subtitle support, support for the -subfps option. Also, SRT reading and loading ASS via libass should be turned into proper demuxers. (SRT is needed because Libav's is gravely broken, and we want ASS loading via libass to cover full libass format support. Both should be demuxers which are probed _before_ libavformat, so that all subtitles can be loaded through the demuxer infrastructure, and libavformat subtitles don't need to be treated in a special way.)
| * sub: pass subtitle packets directlywm42013-06-031-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | Before this, subtitle packets were returned as data ptr/len pairs, and mplayer.c got the rest (pts and duration) directly from the demuxer data structures. Then mplayer.c reassembled the packet data structure again. Pass packets directly instead. The mplayer.c side stays a bit awkward, because the (now by default unused) DVD path keeps getting in the way. In demux.c there's lots of weird stuff (3 functions that read packets, really?), but we want to keep the code equivalent for now to avoid hitting weird issues and corner cases.
| * core: add demux_sub pseudo demuxerwm42013-06-011-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Subtitle files are opened in mplayer.c, not using the demuxer infrastructure in general. Pretend that this is not the case (outside of the loading code) by opening a pseudo demuxer that does nothing. One advantage is that the initialization code is now the same, and there's no confusion about what the difference between track->stream, track->sh_sub and mpctx->sh_sub is supposed to be. This is a bit stupid, and it would be much better if there were proper subtitle demuxers (there are many in recent FFmpeg, but not Libav). So for now this is just a transition to a more proper architecture. Look at demux_sub like an artifical limb: it's ugly, but don't hate it - it helps you to get on with your life.
* | demux: fix "-demuxer mpegps", don't force demuxer in stream_dvdwm42013-06-021-1/+1
|/ | | | | | | | | | 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.
* core: avoid deselecting and reselecting stream needlesslywm42013-05-291-0/+4
| | | | | | | | | The core deselected all streams on initialization, and then selected the streams it actually wanted. This was no problem for demux_mkv/demux_lavf, but old demuxers (like demux_asf) could lose some packets. The problem is that these demuxers can buffer some data on initialization, which then is flushed on track switching. Fix this by explicitly avoiding deselecting a wanted stream.
* demux_asf: fix after commit 5165e19wm42013-05-291-2/+1
| | | | | This demuxer reallocated packets on its own, instead of using the demux.c functions, which clashed with a recent change.
* demux_lavf: workaround minor ffmpeg memory leakwm42013-05-211-4/+0
| | | | | | | | | | | | 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.
* demux: workaround for -demuxer mpegts -correct-ptswm42013-05-211-8/+15
| | | | | | | | | | | | | | | | | | | | | | Using -demuxer mpegts -correct-pts triggered the assertion in ds_get_packet2(). This is not surprising, because the correct-pts code was changed to accept _complete_ packets, while all the old demuxers (including the mpegts demuxer) require you to use "partial" packet reads, together with the video_read_frame(). (That function actually parses video frames, so fragments of the original "packets" can be fed to the decoder.) However, it returns out demux_ts packet's are mostly useable. demux_ts still adds an offset (i.e. ds->buffer_pos != 0) to the packets when calling internal parser functions, such as in parse_es.c. While this is unclean design due to mplayer's old video demuxing/decoding path, it can be easily be made work by modifying the packet as returned by ds_get_packet2(). We also have to change the packet freeing code, as demux_packet->buffer doesn't have to point to the start of the memory allocation anymore. MPlayer handles this "correctly" because it doesn't have a function that reads a complete packet.
* demux: restructure chapter seeking codewm42013-05-091-8/+8
| | | | | | Arrange the code such that commenting the first if will allow doing stream chapter seeks instead of time chapter seeks again, if both are possible.
* demux: don't name unknown chapters "unknown"wm42013-05-061-2/+1
| | | | The frontend's fallback for missing chapter names is better.
* stream: report chapter times, use time seeks for DVD chapterswm42013-05-061-0/+17
| | | | | | | | | | | | | | | | | | | | | | | | 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).
* demux: remove retrieval of chapter end timewm42013-05-061-3/+1
| | | | | | | The frontend doesn't use this. Also use double for returning the chapter times. Everything uses double for times, and there's no reason to use float here.
* demux: use talloc for packetswm42013-05-051-15/+19
| | | | No functional change.
* core: ignore backstep command if demuxer is not capablewm42013-05-051-0/+2
| | | | | | Also, mark demuxer as not capable if DVD playback is done. The problem with DVD is that playback time (stream_pts) is not reported frame-exact, and the time is a "guess" at best.
* demux: use demux_lavf instead of demux_mpg for DVD playbackwm42013-05-051-1/+1
| | | | | | | | | | With the commit "demux_lavf: fix DEMUXER_CTRL_RESYNC", DVD playback seems to work nicely with demux_lavf, and maybe works even better than with demux_mpg. The old demuxer can be forced with: --demuxer=mpegps If no regressions surface, demux_mpg.c will be deleted later.
* demux: report stream time info instead of demuxer info if possiblewm42013-05-051-4/+7
| | | | | Needed for bluray and dvd. demux_mpg (used for dvd playback) did this manually for the time length.
* core: move demuxer time reporting to demuxerwm42013-05-051-0/+18
|
* core: don't report byte-based playback position with dvdwm42013-05-051-1/+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.
* demux: simplify stream ID business, fix issue with cover artwm42013-04-291-13/+6
| | | | | | | | | | | The stream ID handling as it was changed in commit 654c34f was still a little bit insane, and caused a regression with the cover art hack (the stream set in demux->video->sh was incorrect for demux_lavf). Simplify by always using stream_index for demux_stream->id, and getting rid of that tid thing. It turns out that the id for subtitles isn't special either (maybe demux_ts.c was the only thing left that required this).
* demux: get rid of sh_common_twm42013-04-201-11/+10
| | | | | | The only reason this existed was the parsing code. Even though it could have been used for video, it's audio-only, so just move this to sh_audio_t.
* sub, demux: identify subtitle types with the codec namewm42013-04-201-15/+0
| | | | | | | | | Get rid of the 1-char subtitle type field. Use sh_stream->codec instead just like audio and video do. Use codec names as defined by libavcodec for simplicity, even if they're somewhat verbose and annoying. Note that ffmpeg might switch to "ass" as codec name for ASS, so we don't bother with the current silly "ssa" name.
* demux: remove useless vid/aid/sid fieldswm42013-04-201-3/+0
| | | | | Only demux_ts.c used sid in one case, replace that by reading the same value from another location.
* demux: fix clearing of input paddingwm42013-04-201-2/+2
| | | | | | MP_INPUT_BUFFER_PADDING_SIZE and FF_INPUT_BUFFER_PADDING_SIZE are both 16. The doxygen for FF_INPUT_BUFFER_PADDING_SIZE says only the first 23 bits must to be 0, but this is probably a lie.
* demux_mkv: introduce new_demux_packet_from() and use itwm42013-04-201-1/+8
|
* demux: remove some unused thingswm42013-04-201-42/+4
|
* demux: add functions to simplify demuxerswm42013-04-201-7/+42
| | | | | | | | | | | | | | Some preparations to simplify demux_mkv and demux_lavf. struct demux_stream manages state for each stream type that is being demuxed (audio/video/sub). demux_stream is rather annoying, especially the id and sh members, which are often used by the demuxers to determine current stream and so on. Demuxers don't really have to access this, except for testing whether a stream is selected and to add packets. Add a new_sh_stream(), which allows creating streams without having the caller specify any kind of stream ID. Demuxers should just use sh_stream pointers, instead of multiple kinds of IDs and indexes.
* demux: simpler way to notify demuxers about track switcheswm42013-04-201-2/+9
| | | | This interfaces assumes track switching is always successful.
* demux: simplify chapter appending codewm42013-04-121-14/+8
| | | | | This pre-allocation looked tricky and awkward. Use MP_TARRAY_APPEND(), which makes the code simpler. This even keeps the pre-allocation.
* demux: always sort chapterswm42013-04-121-8/+5
| | | | | | | | | | | The condition that checked whether the chapters are out of order and should be sorted was inverted. This likely wasn't noticed in testing, because even if the chapters are unsorted, if the last two chapters were sorted, the rest got sorted too. Instead of doing this silly check, always sort the chapters after demuxer initialization. Also make sure the sort order is stable in case chapter start times are the same (original_index check).
* demux: fix a specific gcc 4.8 warning that may hint to mis-optimized codeRudolf Polzer2013-04-091-0/+3
| | | | | | | | CC demux/demux.o demux/demux.c: In function 'demuxer_switch_track': demux/demux.c:1241:29: warning: array subscript is above array bounds [-Warray-bounds] int new_id = demuxer->ds[type]->id; ^
* demux: fix regressions by restricting cover art hack furtherwm42013-03-191-3/+3
| | | | | | | | | | | | | | | | | | | | The code modified by this commit is supposed to prevent demuxing the whole file when cover art is present. (The problem with cover art is that the ffmpeg libavformat API doesn't signal video EOF correctly - so we try to read more packets to find the next video frame, which results in demuxing and queuing the whole audio stream.) This caused regressions for files with extremely high audio offset (see github issue #46). MY conclusion is that this cover art crap doesn't work, and this is just another case of completely insane ffmpeg/libav API. Disable the hack in all cases, unless a cover art video track is selected. Maybe I'll handle cover art directly in the frontend later, so that we don't have to rely on whatever libavformat does. Unfortunately, this also makes behavior with equally insane mp4 files with sparse video tracks worse, but this issue takes priority.
* Prefix CODEC_ID_ with AV_wm42013-03-131-10/+10
| | | | | | | | | The old names have been deprecated a while ago, but were needed for supporting older ffmpeg/libav versions. The deprecated identifiers have been removed from recent Libav and FFmpeg git. This change breaks compatibility with Libav 0.8.x and equivalent FFmpeg releases.
* demux: apply sparse video hack only to demux_lavf and demux_mkvwm42013-02-141-10/+8
| | | | | | | | | | | | | | | | | Apparently this cuases trouble for legacy demuxers. demux_mpg stopped doing PCM audio. (The problem was probably that it read a bunch of video packets on detection, and then the sparse video hack prevented audio packets from being read, because it looked like there were no more audio packets. With sparse video, this normally helps not reading too many audio packets.) Since the legacy demuxers do not need this hack, enable it for demux_lavf and demux_mkv only. Some additional hacks that were needed to handle legacy demuxers can be removed, making the code simpler. Also see commit 4a40eed.
* demux: restructure code that warns about packet buffer overflowswm42013-02-141-34/+32
| | | | | | | | | There should be no functional changes, except that way how avoiding spamming the terminal with the overflow warning is handled changes a bit. The removed check for ds->eof looks suspicious, but it should be redundant now.
* demux_lavf, ad_lavc, vd_lavc: pass codec header data directlywm42013-02-101-3/+11
| | | | | | | | | | | |