Commit Graph

409 Commits

Author SHA1 Message Date
Uoti Urpala 0ece360eea demux_mkv: skip files faster in ordered chapter file search
Ordered chapter code tries opening files to find those matching the
SegmentUID values specified in the timeline. Previously this scan did
a full initialization of the Matroska demuxer for each file, then
checked whether the UID value in the demuxer was a match. Make the
scan code instead provide a list of searched-for UIDs to the demuxer
open code, and make that do a comparison against the list as soon as
it sees the UID in the file, aborting if there is no match.

Also fix units used in "Merging timeline part" verbose message.
2011-08-04 08:38:39 +03:00
Uoti Urpala f1bb6fde32 core: audio: if audio pts is missing return MP_NOPTS_VALUE
Change written_audio_pts() and playing_audio_pts() to return
MP_NOPTS_VALUE if no reasonable pts estimate is available. Before they
returned some incorrect value typically around zero (but not
necessarily exactly that).
2011-07-30 21:05:59 +03:00
Uoti Urpala 0958620591 bstr: rename BSTR() -> bstr()
Rename the BSTR() function to bstr(). The former caused a conflict
with some Windows OS name, and it's no longer a macro so uppercase
naming is less appropriate.
2011-07-27 08:38:12 +03:00
Uoti Urpala a4f4130819 cleanup: do libav* initialization on startup
Do the global initialization of libavcodec and libavformat
(avcodec_register_all(), av_register_all()) immediately on program
startup and remove the initialization calls from various individual
modules that use libavcodec/libavformat functionality.
2011-07-18 00:57:05 +03:00
Uoti Urpala c5364305be commands: change property mechanism to use talloc strings 2011-07-03 20:04:21 +03:00
Uoti Urpala 1a8384401b demux: use talloc for sh_* structs and "lang" field 2011-07-03 15:01:24 +03:00
Clément Bœsch 480f3fb8d0 cleanup: fix mp_dbg() format string warnings 2011-07-01 03:37:34 +03:00
Uoti Urpala 38b55f8cef demux: pad even 0-size demux packet data (fixes sd_ass crash)
sd_ass relies on there being a zero byte after packet data. However
the packet allocation routines special-cased data length 0 and left
the data pointer as NULL in that case. This could cause a crash in
sd_ass if there was an empty subtitle packet. Change the allocation
routines to stop special-casing empty data and always allocate
padding. Empty packets are not so common that special casing them
would be a worthwhile optimization.

Also fix resize_demux_packet() to use MP_INPUT_BUFFER_PADDING SIZE as
the padding size, instead of a hardcoded value of 8.
2011-06-18 20:02:39 +03:00
Uoti Urpala 7e65428712 Merge branch 'mplayer1_changes' 2011-05-02 00:46:03 +03:00
Clément Bœsch 59fff90d94 options: change -alang and -slang to use string list type
There is no reason to use manual language list splitting when an
automatic split function is already available.

Some types change from "unsigned char" to "char", but this shouldn't
cause issues since [as]lang settings are unlikely to have characters
above 127.
2011-04-20 04:22:42 +03:00
reimar 7a3fd839ef audio: do not run the AC-3 parser on byte-swapped AC-3
Libavcodec has no parser that would work on byte-swapped AC3, but at
least don't run the normal AC-3 one which would only break things.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33026 b3059339-0415-0410-9bf9-f77b7e298cf2

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33027 b3059339-0415-0410-9bf9-f77b7e298cf2
2011-04-13 03:10:33 +03:00
Uoti Urpala 9ef15ac4fc Merge branch 'edl'
* edl:
  core: support timeline with audio-only files
  core: wake up a bit less often for audio-only files
  core: audio: cut audio writes at end of timeline part
  EDL: add support for new EDL file format
  stream.[ch], ass_mp: new stream function for whole-file reads
  tl_matroska.c: move the find_files() function here
  bstr.[ch], path.[ch]: add string and path handling functions
  core: ordered chapters: move timeline creation to timeline/
  options: drop support for numeric -demuxer values
  cleanup: demuxer.[ch]: remove unused code, make functions static
  cleanup: reindent demuxer.h, use struct names for types
2011-04-08 22:50:06 +03:00
Uoti Urpala 968154ba77 EDL: add support for new EDL file format
The timeline code previously added to support Matroska ordered
chapters allows constructing a playback timeline from segments picked
from multiple source files. Add support for a new EDL format to make
this machinery available for use with file formats other than Matroska
and in a manner easier to use than creating files with ordered
chapters.

Unlike the old -edl option which specifies an additional file with
edits to apply to the video file given as the main argument, the new
EDL format is used by giving only the EDL file as the file to play;
that file then contains the filename(s) to use as source files where
actual video segments come from. Filename paths in the EDL file are
ignored. Currently the source files are only searched for in the
directory of the EDL file; support for a search path option will
likely be added in the future.

Format of the EDL files

The first line in the file must be "mplayer EDL file, version 2".
The rest of the lines belong to one of these classes:
1) lines specifying source files
2) empty lines
3) lines specifying timeline segments.

Lines beginning with '<' specify source files. These lines first
contain an identifier used to refer to the source file later, then the
filename separated by whitespace. The identifier must start with a
letter. Filenames that start or end with whitespace or contain
newlines are not supported.

On other lines '#' characters delimit comments. Lines that contain
only whitespace after comments have been removed are ignored.

Timeline segments must appear in the file in chronological order. Each
segment has the following information associated with it:
- duration
- output start time
- output end time (= output start time + duration)
- source id (specifies the file the content of the segment comes from)
- source start time (timestamp in the source file)
- source end time (= source start time + duration)
The output timestamps must form a continuous timeline from 0 to the
end of the last segment, such that each new segment starts from the
time the previous one ends at. Source files and times may change
arbitrarily between segments.

The general format for lines specifying timeline segments is
[output time info] source_id [source time info]
source_id must be an identifier defined on a '<' line. Both the time
info parts consists of zero or more of the following elements:
1) timestamp
2) -timestamp
3) +duration
4) *
5) -*
, where "timestamp" and "duration" are decimal numbers (computations
are done with nanosecond precision). Whitespace around "+" and "-" is
optional. 1) and 2) specify start and end time of the segment on
output or source side. 3) specifies duration; the semantics are the
same whether this appears on output or source side. 4) and 5) are
ignored on the output side (they're always implicitly assumed). On the
source side 4) specifies that the segment starts where the previous
segment _using this source_ ended; if there was no previous segment
time 0 is used. 5) specifies that the segment ends where the next
segment using this source starts.

Redundant information may be omitted. It will be filled in using the
following rules:
- output start for first segment is 0
- two of [output start, output end, duration] imply third
- two of [source start, source end, duration] imply third
- output start = output end of previous segment
- output end = output start of next segment
- if "*", source start = source end of earlier segment
- if "-*", source end = source start of a later segment

As a special rule, a last zero-duration segment without a source
specification may appear. This will produce no corresponding segment
in the resulting timeline, but can be used as syntax to specify the
end time of the timeline (with effect equal to adding -time on the
previous line).

Examples:
----- begin -----
mplayer EDL file, version 2
< id1 filename

  0 id1 123
100 id1 456
200 id1 789
300
-----  end  -----
All segments come from the source file "filename". First segment
(output time 0-100) comes from time 123-223, second 456-556, third
789-889.

----- begin -----
mplayer EDL file, version 2
< f filename
f  60-120
f 600-660
f  30- 90
-----  end  -----
Play first seconds 60-120 from the file, then 600-660, then 30-90.

----- begin -----
mplayer EDL file, version 2
< id1 filename1
< id2 filename2

+10 id1 *
+10 id2 *
+10 id1 *
+10 id2 *
+10 id1 *
+10 id2 *
-----  end  -----
This plays time 0-10 from filename1, then 0-10 from filename1, then
10-20 from filename1, then 10-20 from filename2, then 20-30 from
filename1, then 20-30 from filename2.

----- begin -----
mplayer EDL file, version 2
< t1 filename1
< t2 filename2

t1 * +2            # segment 1
+2 t2 100          # segment 2
t1 *               # segment 3
t2 *-*             # segment 4
t1 3 -*            # segment 5
+0.111111 t2 102.5 # segment 6
7.37 t1 5 +1       # segment 7
-----  end  -----
This rather pathological example illustrates the rules for filling in
implied data. All the values can be determined by recursively applying
the rules given above, and the full end result is this:
+2         0-2                 t1  0-2              # segment 1
+2         2-4                 t2  100-102          # segment 2
+0.758889  4-4.758889          t1  2-2.758889       # segment 3
+0.5       4.4758889-5.258889  t2  102-102.5        # segment 4
+2         5.258889-7.258889   t1  3-5              # segment 5
+0.111111  7.258889-7.37       t2  102.5-102.611111 # segment 6
+1         7.37-8.37           t1  5-6              # segment 7
2011-04-05 06:26:17 +03:00
Uoti Urpala df31b077b4 core, demux: fix video index handling in stream switching
Fix bugs in the handling of stream index values in video stream
switching. This is similar to what commit 90bedd0b87
did for audio.

Also clean up the corresponding audio code a little bit.
2011-03-31 00:13:36 +03:00
Uoti Urpala f7643ddde6 options: drop support for numeric -demuxer values
Drop support for specifying demuxer types by numeric ID (options
-demuxer, -audio-demuxer and -sub-demuxer). Stop printing the numeric
values in "-demuxer help" output. Convert the list of DEMUXER_TYPE_XXX
defines to "enum demuxer_type".
2011-02-22 15:16:41 +02:00
Uoti Urpala 5177b24b25 cleanup: demuxer.[ch]: remove unused code, make functions static
Remove some unused lines from demuxer.h. Make some demuxer.c functions
static. Move new_ds_stream() declaration from demuxer.h to stream.h
(the function is defined in stream.c). Clean up some code in mplayer.c
that had commented-out free_demuxer_stream() calls.
2011-02-22 15:16:41 +02:00
Uoti Urpala f50f34245e Merge branch 'sub'
* sub:
  sub/OSD: move some related files to sub/
  subtitles: options: enable -ass by default
  subtitles: change default libass rendering style
  demux_mkv, chapters: change millisecond arithmetic to ns
  cleanup: rename ass_* functions to mp_ass_*
  subs: use correct font aspect ratio for libass + converted subs
  cleanup: some random minor code simplification and cleanup
  vf_vo: fix EOSD change detection bug
  sd_ass: remove subreader use, support plaintext markup
  subtitles: style support for common SubRip tags and MicroDVD
  core: ordered chapters: fix bad subtitle parameter
  subs/demux: don't try to enable sub track when creating it
  subtitles/demux: store duration instead of endpts in demux packets
  subtitles: add framework for subtitle decoders
  options: add special -leak-report option
  subtitles: remove code trying to handle text subs with libavcodec
  cleanup: move MP_NOPTS_VALUE definition to mpcommon.h
  subtitles: move global ass_track to struct osd_state
  core: move most mpcommon.c contents to mplayer.c
  core: move global "subdata" and "vo_sub_last" to mpctx
  subtitles: remove sub_last_pts hack
  options: move -noconfig to option struct, simplify
2011-01-26 20:42:15 +02:00
Uoti Urpala 304cafd31d demux_mkv, chapters: change millisecond arithmetic to ns
demux_mkv kept various integer timestamps in millisecond units.
Matroska timestamp arithmetic is however specified in nanoseconds
(even though files typically use 1 ms precision), and using ms units
instead of that only made things more complex. Based on the demux_mkv
example the general demuxer-level chapter structure also used ms
units. Change the demux_mkv arithmetic and demuxer chapter structures
to use nanoseconds instead. This also fixes a seeking problem in
demux_mkv with files using a TimecodeScale other than the usual
1000000 (confusion between ms and TimecodeScale*ns units).
2011-01-26 20:39:04 +02:00
Uoti Urpala b86c9e5922 subs/demux: don't try to enable sub track when creating it
demuxer.c new_sh_sub_sid() tried to immediately select the created sub
track for playback if its id matched the "-sid" option value. This was
buggy, as more initialization is needed to properly enable subtitles.
Normally the correct track to play is selected after the demuxer has
been created. It's possible that some DVD use case or such depended on
the removed code to make -sid work with a subtitle track that's not
found at start and only added later (vobsubs probably would start
playing without separate initialization); if so then that needs to be
fixed later in a different way.
2011-01-18 14:58:09 +02:00
Uoti Urpala e990fb2ffe subtitles: add framework for subtitle decoders
Add a framework for subtitle decoder modules that work more like
audio/video decoders do, and change libass rendering of demuxed
subtitles to use the new framework.

The old subtitle code is messy, with details specific to handling
particular subtitle types spread over high-level code. This should
make it easier to clean things up and fix some bugs/limitations.
2011-01-18 14:58:09 +02:00
Uoti Urpala 757e43c3f8 demux: add sanity checks to packet allocation functions
Change new_demux_packet() and resize_demux_packet() length parameter
type from int to size_t and add a check to abort() if the size is over
1 GB. This should make integer overflow problems leading to memory
corruption in demuxers less likely; and aborting should be no worse
than insane memory consumption. Also make the functions abort() if the
actual allocation fails instead of trying to continue with a
zero-sized buffer.
2011-01-17 16:16:39 +02:00
Uoti Urpala e342a81d6f cleanup: move demux packet functions from demuxer.h to demuxer.c
There's no reason why the demux packet functions would need to be
inlined, so move them from the header to the .c file.
2011-01-17 15:47:57 +02:00
Uoti Urpala 4a26b4c024 cosmetics: remove unused code, small formatting tweaks 2010-12-20 06:42:04 +02:00
Uoti Urpala cc2d748b73 audio: FLAC: support new libavcodec parser, use lavf to demux
Parse FLAC data with new libavcodec parser if needed. Use libavformat
demuxer for raw FLAC files by default.
2010-12-09 02:50:17 +02:00
Uoti Urpala b82f82fe08 demux: fix initial subtitle track selection
Commit 3c2cfee488 ("demux: improve -alang / -slang track choosing
logic") had a copy/paste error which left the subtitle code using
audio variables and broke initial subtitle track selection. Fix.

I actually realized soon after creating the original commit that I'd
forgotten to change the variables and went back to fix it, but then
somehow thought that it was already OK and didn't change it...
2010-11-16 10:49:23 +02:00
Uoti Urpala 642ce15ef7 core: give pts as parameter to demuxer_get_current_chapter()
demuxer_get_current_chapter() accessed sh_video/sh_audio pts fields to
determine playback position. demux layer shouldn't access those and
the values used weren't quite correct anyway. Give the playback
position as a parameter to the demux layer function instead. Also
change the top-level get_current_chapter() to use get_current_time()
in the timeline case where it didn't refer to demux layer.
2010-11-13 16:48:31 +02:00
Clément Bœsch e7d3e63a3f options: move -cache-min and cache-seek-min to option struct 2010-11-11 17:53:44 +02:00
Clément Bœsch 449484179f options: move [no]hr-mp3-seek to option struct 2010-11-11 17:51:03 +02:00
Clément Bœsch 6526bee39b options: move some demux options to option struct
Following options were moved: audiofile, audiofile-cache, subfile,
demuxer, audio-demuxer, sub-demuxer, [no]extbased.
2010-11-11 16:31:46 +02:00
Uoti Urpala 523a48d8a9 demux: change "%s file format detected" message
"libavformat file format detected" wasn't a very useful message due to
the many file formats supported to libavformat. Change the message so
that for demux_lavf it says something like
"Detected file format: QuickTime/MPEG-4/Motion JPEG 2000 format (libavformat)"
(using long name from FFmpeg), and for non-lavf something like
"Detected file format: Matroska".
2010-11-10 15:38:36 +02:00
Uoti Urpala b98821de7c demuxer.c: clean up demux_open_stream()
Refactor the code to avoid duplication. Behavior should be mostly the
same as before.
2010-11-10 15:34:13 +02:00
Uoti Urpala 7b076f79a9 demux: error out if given invalid -demuxer option
The code choosing the demuxer to use only printed an error if given an
unknown demuxer name, then continued with default demuxer selection.
Change it to abort instead. This feels like more sensible behavior.
Also there's no fallback to autodetection in the case where the
demuxer name is recognized but the demuxer fails to open the file
either.
2010-11-10 09:49:39 +02:00
Uoti Urpala 3c2cfee488 demux: improve -alang / -slang track choosing logic
When -alang / -slang was specified the numerically first matching
track (if any) was always chosen. This meant that specifying "-alang
eng" could change the track choice even if all tracks were in English,
because now the default flag of tracks was ignored. Change the logic
to take the default flag into account as a secondary sorting key.

The code also accepted prefix matches, so that "-slang g" would match
track language "ger". I think that was not intentional. Change it to
require exact matches.
2010-11-08 18:05:12 +02:00
Uoti Urpala 9a663ffec6 core: move video pos/length query functions from demux to core
Move functions to query current playback position, percentage position
and total video length from from the demuxer layer to top level. The
functions need access to playback state that doesn't belong on the
demuxing level. Make the new functions more capable and simplify some
code that can now rely on them. This fixes some errors in displayed in
OSD and slave mode information when using timeline (ordered chapters).
2010-11-08 18:05:12 +02:00
Uoti Urpala 3628a903f4 demux: fix -correct-pts autoselection with -audiofile
Make demuxer-based -correct-pts autoselection base the decision on the
video demuxer in case several are being used, such as with
-audiofile.
2010-11-08 18:05:12 +02:00
cehoyos 458350350b demuxer.c: add missing parser list fourccs
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32596 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-08 18:05:12 +02:00
cehoyos 9bb304898b demuxer.c: fix parser list fourcc typo: 'MPE '->'MP3 '
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32595 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-08 18:05:11 +02:00
reimar e666e3ce91 demuxer.c: Add support for parsing LATM
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32582 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-08 18:03:35 +02:00
Uoti Urpala c5e462b33d build: enable/disable all FFmpeg libraries together
Enable all of libavcodec, libavformat, libswscale, and libpostproc
together (libavutil is always required).

based on svn commit by diego:

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32226 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-02 04:16:55 +02:00
diego f2899d96ee Add central init_avcodec() to avoid duplicated libavcodec init code
Patch by Vlad Seryakov, vseryakov gmail com

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32043 b3059339-0415-0410-9bf9-f77b7e298cf2

Refactor more instances of avcodec_initialized handling into init_avcodec().
This is a leftover from the previous commit.

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32044 b3059339-0415-0410-9bf9-f77b7e298cf2

Add missing #include for vd_ffmpeg.h; fixes the warning:
libmpcodecs/vf_zrmjpeg.c:472: warning: implicit declaration of function 'init_avcodec'

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32176 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-02 04:15:51 +02:00
reimar 415b948f2e demuxer.c: reset subtitle EOF on seeking
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32031 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-02 04:15:49 +02:00
reimar 0e82595632 demux_lavf: print subtitle type in more cases
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32006 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-11-02 04:15:49 +02:00
Uoti Urpala 7d17b5e254 demuxer.c: add new_sh_sub_sid_lang
Allocates a new sh_sub and specifies language at the same time. I
don't think this is a particularly good API but add it for easier
compatibility with some svn changes.
2010-11-02 04:14:44 +02:00
reimar c1b0498c1f demuxer.c: Make ds_get_next_pts work for the first packet of a stream
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@31338 b3059339-0415-0410-9bf9-f77b7e298cf2
2010-10-27 20:30:30 +03:00
Uoti Urpala 90bedd0b87 Make audio stream index handling saner in stream switching
The handling of audio stream numbering was handled in the stream
selection property was a total mess. The most important issue was
confusion between values used as index for demuxer->audio_streams[]
array (consistently stored in demuxer->audio->id) and values stored
in sh_audio->aid and used as "-aid N" option values. Now demuxer audio
switch control functions and demuxer_switch_audio() are supposed to
return the new value for the "-aid" option (internal MPEG demuxers
still don't; the demuxer requirement could perhaps be dropped as it
can be easily calculated afterwards). That is also the value
returned for the "switch_audio" property. The main changes are:

 - Make command.c mp_property_audio() consistently use and return the
   "-aid" values. Before it used that as input but the array index as
   output, with extra mess related to demuxer_switch_audio() return
   value. Don't modify the audio_id option field any more.

 - Make demuxer_switch_audio() always return "-aid" values (like it
   takes as input). There are two changes for this: picking this
   return value in case the demuxer doesn't support switching, and
   overriding demuxer return value (for internal MPEG demuxers).

 - Make demux_lavf return "-aid" values from DEMUXER_CTRL_SWITCH_AUDIO
   code. This isn't actually necessary because of the override part
   above.

Here's some history of the relevant behavior that I looked up:
* For most demuxers array index and "-aid" values are the same. At
  least demux_mkv, (some of?) the internal MPEG demuxers and demux_ogg
  have differed for a long time. demux_ogg doesn't matter because it
  doesn't support stream switching.
* Old code seemed to assume that demuxer_switch_audio() return value was
  array index, but this wasn't true at least for demux_mkv.
* In svn r19951 reimar mostly removed use of the return value.
* In r20162 ptt added mp_property_audio(). This set the global
  audio_id variable (-aid option value) to the return value of
  demuxer_switch_audio() and treated the global as the persistent
  value of the property, apparently assuming that it would be set to
  the "-aid" value, not array index. This was false for internal
  MPEG.
* In r30124 reimar changed the property code so that even though it
  still modified the option value it didn't use that as the value of
  the property any more; instead it incorrectly used the array index.
  This meant that for demux_mkv the return value didn't match -aid any
  more (though input still did, so setting the property and querying
  it didn't match as they used different value systems).
* In r31129 aurel made demux_lavf changes that resulted in its -aid
  and array index values no longer matching either. He didn't change
  the return value from audio switch when changing -aid, so it now
  matched array index only. The latter part didn't cause additional
  problems from r20162 though because either choice would have been
  broken anyway after r30124 as long as they weren't the same value.
2010-05-22 10:11:25 +03:00
Uoti Urpala de5566f0b5 stream.h: remove bad EOF check in stream_seek()
Also remove a redundant stream->eof = 0 in demuxer.c.
2010-05-22 06:40:34 +03:00
Anton Khirnov bc072fb7dc demux: use bstr arguments for demuxer_add_attachment() and demuxer_add_chapter() 2010-05-22 06:40:28 +03:00
Anton Khirnov 9f508dab97 demuxer.c: add demux_info_add_bstr(), use talloc for info field
demux_info_add() is now a wrapper around demux_info_add_bstr().
2010-05-21 00:06:26 +03:00
Uoti Urpala 05ae9dbd0d Fix chapter handling with first chapter not at beginning of file
Before "-chapter 1" did nothing even if the first chapter didn't start
at the beginning of file. Fix it.
Before all chapter property commands (including chapter seek keys)
failed if the current playback position was before the start of the
first chapter. Now they'll work. Relative chapter seeks will go to the
first chapter (even if that's in the wrong direction for backward
seeks).
2010-04-25 22:48:10 +03:00
Uoti Urpala 19907b8fbc demuxer.c: clean up stream-seek code
Only try to use the dvd/dvdnav stream seek hack with those stream
types. Generally demuxers can not be expected to cope with the stream
suddenly seeking under them. In principle it would be more correct to
make the test demuxer-based (instead of assuming that using stream
seeks in this manner is OK with whatever demuxer that will be used
with these streams), but that'd be more work.
2010-04-23 21:01:21 +03:00