2013-10-29 21:38:29 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2013-10-29 21:38:29 +00:00
|
|
|
*
|
player: change license of most core files to LGPL
These files have all in common that they were fully or mostly taken from
mplayer.c. (mplayer.c was a huge file that contains almost all of the
playback core, until it was split into multiple parts.) This was
probably the hardest part to relicense, because so much code was moved
around all the time.
player/audio.c still does not compile. We'll have to redo audio
filtering. Once that is done, we can probably actually provide an
actual LGPL configure switch.
Here is a relatively detailed list of potential issues:
8d190244: author did not reply, parts were made GPL-only in a previous
commit.
7882ea9b: author could not be reached, but the code is gone. wscript
still has --datadir switch, but I don't think this is relevant to
copyright.
f197efd5: unclear origin, but I consider the code gone anyway (replaced
with generic OSD mechanisms).
8337d9c2: author did not reply, but only the option still exists (under
a different name), other code was removed.
d8fd7131: did not reply. Disabled in a previous commit.
05258251: same author as above. Both fields actually seem to have
vanished (even when tracking renames), so no action taken.
d459e644, 268b2c1a: author did not reply, but we reuse only the options
(with different names and slightly or fully different semantics, and
completely different implementations), so I don't think this is relevant
for copyright.
09e742fe, 17c39c4e: same as above.
e8a173de, bff4b3ee: author could not be reached. The commands were
reworked to properties, and the code outside of the TV code were moved
back to the TV code. So I don't think copyright applies to the current
command.c parts (mp_property_tv_color, mp_property_tv_freq,
mp_property_tv_scan). The TV parts remain GPL.
0810e427: could not be reached. Disabled in a previous commit.
43744a2d: unknown author, but this was replaced by dynamic alloc (if the
change is even copyrightable).
116ca0c7: unknown author; reasoning see input.c relicensing commit.
e7e4d1d8: these semantics still exist, but as generic code, and this
code was fully removed.
f1175cd9: the author of the cited patch is unknown, and upon inspection
it turns out that I was only using the idea to pause the player on EOF,
so I claim it's not copyright relevant.
25affdcc: author could not be reached (yet) - but it's only a function
rename, not copyrightable.
5728504c was committed by Arpi (who agreed), but hints that it might be
by a different author. In fact it seems to be mostly this patch:
http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2001-November/002041.html
The author did not respond, but it all seems to have been removed later.
It's a terrible mess though. Arpi reverted the A-V sync code at first,
but left the RTC code for a while. The following commits remove these
changes 100%: 14b35442, 7181a091, 31482783, 614f8475, df58e822.
cehoyos did explicitly not agree to LGPL, but was involved in the
following changes:
c99d8fc8: applied a patch and didn't modify it, the original author
agreed.
40ac0d31: author could not be reached, but all code is gone anyway. The
"af" command has a similar function, but works completely different and
actually reuses a mechanism older than this patch.
54350436: applied a patch, but didn't modify it, except for adding a
German translation, which was removed later.
a2dda036: same situation as above
240b743e: this was made GPL-only in a previous commit
7b25afd7: same as above (for now)
kirijua could not be reached, but was a regular patch contributor:
c2c997fd: video equalizer code move; probably not copyrightable. Is GPL
due to Nick anyway.
be54f481: technically, this became the audio track property later. But
all what is left is the fact that you pass a track ID to it, so consider
the original coypright non-relevant.
2f376d1b: this was rewritten in b7052b43, but for now we can afford to
be careful, so this was marked as GPL only in a previous commit.
43844d09: remaining parts in main.c were reverted in a previous commit.
anders has mostly disagreed with the LGPL relicensing. Does not want
libaf to become LGPL, but made some concessions. In particular, he
granted us permission to relicense 4943e9c52c and 242aa6ebd4. We also
consider some of his changes remaining in mpv not relevant for copyright
(such as 735de602 - we won't remove the this option completely). We will
completely remove his other contributions, including the entire audio
filter chain. For now, this stuff is marked as GPL only. The remaining
question is how much code in player/audio.c (based on the former
mplayer.c and dec_audio.c) is under his copyright. I made claims about
this in a previous commit.
Nick(ols) Kurshev, svn username "nick" and "nickols_k", could not be
reached. He had a lot of changes in early MPlayer. It seems all of that
was removed, at least in mpv. His main work, like VIDIX or libswscale
work, does not exist in mpv anymore, but the changes to mplayer.c and
other core parts still deserve attention:
a4119f6b, fb927549, ad3529b8, e11b23dc, 5f2178be, 93c371d5: removed in
b43d67e0, d1628d12, 24ed01fe, df58e822.
0a83c6ec, 104c125e, 4e067f62, aec5dcc8, b587a3d6, f3de6e6b: DR, VAA, and
"tune" stuff was fully removed later on or replaced with other
mechanisms.
340183b0: screenshots were redone later (the VOCTRL was even removed,
with an independent implementation using the same VOCTRL a few years
later), so not relevant anymore. Basically only the 's' shortcut remains
(but not its implementation).
92c5c274, bffd4007, 555c6766: for now marked as GPL only in a previous
commit.
Might contain some trace amounts of "michael"'s copyright, who agreed to
LGPL only once the core is relicensed. This will still be respected, but
I don't think it matters at this in this case. (Some code touched by him
was merged into mplayer.c, and then disappeared after heavy
refactoring.)
I tried to be as careful and as complete as possible. It can't be
excluded that amends to this will be made later.
This does not make the player LGPL yet.
2017-06-23 13:53:41 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2013-10-29 21:38:29 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2013-10-29 21:38:29 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
player: change license of most core files to LGPL
These files have all in common that they were fully or mostly taken from
mplayer.c. (mplayer.c was a huge file that contains almost all of the
playback core, until it was split into multiple parts.) This was
probably the hardest part to relicense, because so much code was moved
around all the time.
player/audio.c still does not compile. We'll have to redo audio
filtering. Once that is done, we can probably actually provide an
actual LGPL configure switch.
Here is a relatively detailed list of potential issues:
8d190244: author did not reply, parts were made GPL-only in a previous
commit.
7882ea9b: author could not be reached, but the code is gone. wscript
still has --datadir switch, but I don't think this is relevant to
copyright.
f197efd5: unclear origin, but I consider the code gone anyway (replaced
with generic OSD mechanisms).
8337d9c2: author did not reply, but only the option still exists (under
a different name), other code was removed.
d8fd7131: did not reply. Disabled in a previous commit.
05258251: same author as above. Both fields actually seem to have
vanished (even when tracking renames), so no action taken.
d459e644, 268b2c1a: author did not reply, but we reuse only the options
(with different names and slightly or fully different semantics, and
completely different implementations), so I don't think this is relevant
for copyright.
09e742fe, 17c39c4e: same as above.
e8a173de, bff4b3ee: author could not be reached. The commands were
reworked to properties, and the code outside of the TV code were moved
back to the TV code. So I don't think copyright applies to the current
command.c parts (mp_property_tv_color, mp_property_tv_freq,
mp_property_tv_scan). The TV parts remain GPL.
0810e427: could not be reached. Disabled in a previous commit.
43744a2d: unknown author, but this was replaced by dynamic alloc (if the
change is even copyrightable).
116ca0c7: unknown author; reasoning see input.c relicensing commit.
e7e4d1d8: these semantics still exist, but as generic code, and this
code was fully removed.
f1175cd9: the author of the cited patch is unknown, and upon inspection
it turns out that I was only using the idea to pause the player on EOF,
so I claim it's not copyright relevant.
25affdcc: author could not be reached (yet) - but it's only a function
rename, not copyrightable.
5728504c was committed by Arpi (who agreed), but hints that it might be
by a different author. In fact it seems to be mostly this patch:
http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2001-November/002041.html
The author did not respond, but it all seems to have been removed later.
It's a terrible mess though. Arpi reverted the A-V sync code at first,
but left the RTC code for a while. The following commits remove these
changes 100%: 14b35442, 7181a091, 31482783, 614f8475, df58e822.
cehoyos did explicitly not agree to LGPL, but was involved in the
following changes:
c99d8fc8: applied a patch and didn't modify it, the original author
agreed.
40ac0d31: author could not be reached, but all code is gone anyway. The
"af" command has a similar function, but works completely different and
actually reuses a mechanism older than this patch.
54350436: applied a patch, but didn't modify it, except for adding a
German translation, which was removed later.
a2dda036: same situation as above
240b743e: this was made GPL-only in a previous commit
7b25afd7: same as above (for now)
kirijua could not be reached, but was a regular patch contributor:
c2c997fd: video equalizer code move; probably not copyrightable. Is GPL
due to Nick anyway.
be54f481: technically, this became the audio track property later. But
all what is left is the fact that you pass a track ID to it, so consider
the original coypright non-relevant.
2f376d1b: this was rewritten in b7052b43, but for now we can afford to
be careful, so this was marked as GPL only in a previous commit.
43844d09: remaining parts in main.c were reverted in a previous commit.
anders has mostly disagreed with the LGPL relicensing. Does not want
libaf to become LGPL, but made some concessions. In particular, he
granted us permission to relicense 4943e9c52c and 242aa6ebd4. We also
consider some of his changes remaining in mpv not relevant for copyright
(such as 735de602 - we won't remove the this option completely). We will
completely remove his other contributions, including the entire audio
filter chain. For now, this stuff is marked as GPL only. The remaining
question is how much code in player/audio.c (based on the former
mplayer.c and dec_audio.c) is under his copyright. I made claims about
this in a previous commit.
Nick(ols) Kurshev, svn username "nick" and "nickols_k", could not be
reached. He had a lot of changes in early MPlayer. It seems all of that
was removed, at least in mpv. His main work, like VIDIX or libswscale
work, does not exist in mpv anymore, but the changes to mplayer.c and
other core parts still deserve attention:
a4119f6b, fb927549, ad3529b8, e11b23dc, 5f2178be, 93c371d5: removed in
b43d67e0, d1628d12, 24ed01fe, df58e822.
0a83c6ec, 104c125e, 4e067f62, aec5dcc8, b587a3d6, f3de6e6b: DR, VAA, and
"tune" stuff was fully removed later on or replaced with other
mechanisms.
340183b0: screenshots were redone later (the VOCTRL was even removed,
with an independent implementation using the same VOCTRL a few years
later), so not relevant anymore. Basically only the 's' shortcut remains
(but not its implementation).
92c5c274, bffd4007, 555c6766: for now marked as GPL only in a previous
commit.
Might contain some trace amounts of "michael"'s copyright, who agreed to
LGPL only once the core is relicensed. This will still be respected, but
I don't think it matters at this in this case. (Some code touched by him
was merged into mplayer.c, and then disappeared after heavy
refactoring.)
I tried to be as careful and as complete as possible. It can't be
excluded that amends to this will be made later.
This does not make the player LGPL yet.
2017-06-23 13:53:41 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-10-29 21:38:29 +00:00
|
|
|
*
|
player: change license of most core files to LGPL
These files have all in common that they were fully or mostly taken from
mplayer.c. (mplayer.c was a huge file that contains almost all of the
playback core, until it was split into multiple parts.) This was
probably the hardest part to relicense, because so much code was moved
around all the time.
player/audio.c still does not compile. We'll have to redo audio
filtering. Once that is done, we can probably actually provide an
actual LGPL configure switch.
Here is a relatively detailed list of potential issues:
8d190244: author did not reply, parts were made GPL-only in a previous
commit.
7882ea9b: author could not be reached, but the code is gone. wscript
still has --datadir switch, but I don't think this is relevant to
copyright.
f197efd5: unclear origin, but I consider the code gone anyway (replaced
with generic OSD mechanisms).
8337d9c2: author did not reply, but only the option still exists (under
a different name), other code was removed.
d8fd7131: did not reply. Disabled in a previous commit.
05258251: same author as above. Both fields actually seem to have
vanished (even when tracking renames), so no action taken.
d459e644, 268b2c1a: author did not reply, but we reuse only the options
(with different names and slightly or fully different semantics, and
completely different implementations), so I don't think this is relevant
for copyright.
09e742fe, 17c39c4e: same as above.
e8a173de, bff4b3ee: author could not be reached. The commands were
reworked to properties, and the code outside of the TV code were moved
back to the TV code. So I don't think copyright applies to the current
command.c parts (mp_property_tv_color, mp_property_tv_freq,
mp_property_tv_scan). The TV parts remain GPL.
0810e427: could not be reached. Disabled in a previous commit.
43744a2d: unknown author, but this was replaced by dynamic alloc (if the
change is even copyrightable).
116ca0c7: unknown author; reasoning see input.c relicensing commit.
e7e4d1d8: these semantics still exist, but as generic code, and this
code was fully removed.
f1175cd9: the author of the cited patch is unknown, and upon inspection
it turns out that I was only using the idea to pause the player on EOF,
so I claim it's not copyright relevant.
25affdcc: author could not be reached (yet) - but it's only a function
rename, not copyrightable.
5728504c was committed by Arpi (who agreed), but hints that it might be
by a different author. In fact it seems to be mostly this patch:
http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2001-November/002041.html
The author did not respond, but it all seems to have been removed later.
It's a terrible mess though. Arpi reverted the A-V sync code at first,
but left the RTC code for a while. The following commits remove these
changes 100%: 14b35442, 7181a091, 31482783, 614f8475, df58e822.
cehoyos did explicitly not agree to LGPL, but was involved in the
following changes:
c99d8fc8: applied a patch and didn't modify it, the original author
agreed.
40ac0d31: author could not be reached, but all code is gone anyway. The
"af" command has a similar function, but works completely different and
actually reuses a mechanism older than this patch.
54350436: applied a patch, but didn't modify it, except for adding a
German translation, which was removed later.
a2dda036: same situation as above
240b743e: this was made GPL-only in a previous commit
7b25afd7: same as above (for now)
kirijua could not be reached, but was a regular patch contributor:
c2c997fd: video equalizer code move; probably not copyrightable. Is GPL
due to Nick anyway.
be54f481: technically, this became the audio track property later. But
all what is left is the fact that you pass a track ID to it, so consider
the original coypright non-relevant.
2f376d1b: this was rewritten in b7052b43, but for now we can afford to
be careful, so this was marked as GPL only in a previous commit.
43844d09: remaining parts in main.c were reverted in a previous commit.
anders has mostly disagreed with the LGPL relicensing. Does not want
libaf to become LGPL, but made some concessions. In particular, he
granted us permission to relicense 4943e9c52c and 242aa6ebd4. We also
consider some of his changes remaining in mpv not relevant for copyright
(such as 735de602 - we won't remove the this option completely). We will
completely remove his other contributions, including the entire audio
filter chain. For now, this stuff is marked as GPL only. The remaining
question is how much code in player/audio.c (based on the former
mplayer.c and dec_audio.c) is under his copyright. I made claims about
this in a previous commit.
Nick(ols) Kurshev, svn username "nick" and "nickols_k", could not be
reached. He had a lot of changes in early MPlayer. It seems all of that
was removed, at least in mpv. His main work, like VIDIX or libswscale
work, does not exist in mpv anymore, but the changes to mplayer.c and
other core parts still deserve attention:
a4119f6b, fb927549, ad3529b8, e11b23dc, 5f2178be, 93c371d5: removed in
b43d67e0, d1628d12, 24ed01fe, df58e822.
0a83c6ec, 104c125e, 4e067f62, aec5dcc8, b587a3d6, f3de6e6b: DR, VAA, and
"tune" stuff was fully removed later on or replaced with other
mechanisms.
340183b0: screenshots were redone later (the VOCTRL was even removed,
with an independent implementation using the same VOCTRL a few years
later), so not relevant anymore. Basically only the 's' shortcut remains
(but not its implementation).
92c5c274, bffd4007, 555c6766: for now marked as GPL only in a previous
commit.
Might contain some trace amounts of "michael"'s copyright, who agreed to
LGPL only once the core is relicensed. This will still be respected, but
I don't think it matters at this in this case. (Some code touched by him
was merged into mplayer.c, and then disappeared after heavy
refactoring.)
I tried to be as careful and as complete as possible. It can't be
excluded that amends to this will be made later.
This does not make the player LGPL yet.
2017-06-23 13:53:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2013-10-29 21:38:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2014-06-07 13:08:45 +00:00
|
|
|
#include <pthread.h>
|
2018-03-09 03:10:28 +00:00
|
|
|
#include <locale.h>
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-04-23 18:37:57 +00:00
|
|
|
#include "misc/dispatch.h"
|
2018-05-06 16:27:18 +00:00
|
|
|
#include "misc/thread_pool.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "osdep/io.h"
|
2013-12-19 20:31:27 +00:00
|
|
|
#include "osdep/terminal.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "osdep/timer.h"
|
2015-05-02 16:47:57 +00:00
|
|
|
#include "osdep/main-fn.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/av_log.h"
|
|
|
|
#include "common/codecs.h"
|
|
|
|
#include "common/encode.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_config.h"
|
|
|
|
#include "options/m_option.h"
|
|
|
|
#include "options/m_property.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
2014-01-16 20:24:39 +00:00
|
|
|
#include "common/msg_control.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/global.h"
|
video: make decoder wrapper a filter
Move dec_video.c to filters/f_decoder_wrapper.c. It essentially becomes
a source filter. vd.h mostly disappears, because mp_filter takes care of
the dataflow, but its remains are in struct mp_decoder_fns.
One goal is to simplify dataflow by letting the filter framework handle
it (or more accurately, using its conventions). One result is that the
decode calls disappear from video.c, because we simply connect the
decoder wrapper and the filter chain with mp_pin_connect().
Another goal is to eventually remove the code duplication between the
audio and video paths for this. This commit prepares for this by trying
to make f_decoder_wrapper.c extensible, so it can be used for audio as
well later.
Decoder framedropping changes a bit. It doesn't seem to be worse than
before, and it's an obscure feature, so I'm content with its new state.
Some special code that was apparently meant to avoid dropping too many
frames in a row is removed, though.
I'm not sure how the source code tree should be organized. For one,
video/decode/vd_lavc.c is the only file in its directory, which is a bit
annoying.
2018-01-28 09:08:45 +00:00
|
|
|
#include "filters/f_decoder_wrapper.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/parse_configfile.h"
|
|
|
|
#include "options/parse_commandline.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/playlist.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2014-12-30 08:23:36 +00:00
|
|
|
#include "options/path.h"
|
2013-12-17 00:23:09 +00:00
|
|
|
#include "input/input.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
#include "audio/out/ao.h"
|
2013-11-23 21:08:42 +00:00
|
|
|
#include "demux/demux.h"
|
2018-05-17 18:58:49 +00:00
|
|
|
#include "misc/thread_tools.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "sub/osd.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "video/out/vo.h"
|
|
|
|
|
2013-12-17 00:08:53 +00:00
|
|
|
#include "core.h"
|
2014-02-10 20:01:35 +00:00
|
|
|
#include "client.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#include "command.h"
|
|
|
|
#include "screenshot.h"
|
|
|
|
|
2016-09-15 11:45:23 +00:00
|
|
|
static const char def_config[] =
|
|
|
|
#include "player/builtin_conf.inc"
|
|
|
|
;
|
|
|
|
|
2014-10-09 19:02:47 +00:00
|
|
|
#if HAVE_COCOA
|
2014-04-16 02:33:58 +00:00
|
|
|
#include "osdep/macosx_events.h"
|
2013-10-29 21:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-02 02:06:06 +00:00
|
|
|
#ifndef FULLCONFIG
|
|
|
|
#define FULLCONFIG "(missing)\n"
|
|
|
|
#endif
|
|
|
|
|
2017-02-13 05:45:40 +00:00
|
|
|
#if !HAVE_STDATOMIC
|
2016-09-06 18:13:30 +00:00
|
|
|
pthread_mutex_t mp_atomic_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
#endif
|
|
|
|
|
2014-10-30 22:54:06 +00:00
|
|
|
enum exit_reason {
|
|
|
|
EXIT_NONE,
|
|
|
|
EXIT_NORMAL,
|
|
|
|
EXIT_ERROR,
|
|
|
|
};
|
|
|
|
|
2013-12-18 16:12:07 +00:00
|
|
|
const char mp_help_text[] =
|
2013-10-29 21:38:29 +00:00
|
|
|
"Usage: mpv [options] [url|path/]filename\n"
|
|
|
|
"\n"
|
|
|
|
"Basic options:\n"
|
|
|
|
" --start=<time> seek to given (percent, seconds, or hh:mm:ss) position\n"
|
|
|
|
" --no-audio do not play sound\n"
|
|
|
|
" --no-video do not play video\n"
|
|
|
|
" --fs fullscreen playback\n"
|
2014-04-24 15:42:54 +00:00
|
|
|
" --sub-file=<file> specify subtitle file to use\n"
|
2013-10-29 21:38:29 +00:00
|
|
|
" --playlist=<file> specify playlist file\n"
|
|
|
|
"\n"
|
|
|
|
" --list-options list all mpv options\n"
|
2016-12-16 15:09:10 +00:00
|
|
|
" --h=<string> print options which contain the given string in their name\n"
|
2013-12-18 16:12:07 +00:00
|
|
|
"\n";
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-12-02 19:35:18 +00:00
|
|
|
static pthread_mutex_t terminal_owner_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
static struct MPContext *terminal_owner;
|
|
|
|
|
|
|
|
static bool cas_terminal_owner(struct MPContext *old, struct MPContext *new)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&terminal_owner_lock);
|
|
|
|
bool r = terminal_owner == old;
|
|
|
|
if (r)
|
|
|
|
terminal_owner = new;
|
|
|
|
pthread_mutex_unlock(&terminal_owner_lock);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2016-09-29 14:26:54 +00:00
|
|
|
void mp_update_logging(struct MPContext *mpctx, bool preinit)
|
2015-03-05 10:17:22 +00:00
|
|
|
{
|
2017-05-22 16:30:39 +00:00
|
|
|
bool had_log_file = mp_msg_has_log_file(mpctx->global);
|
|
|
|
|
2018-05-21 14:25:52 +00:00
|
|
|
mp_msg_update_msglevels(mpctx->global, mpctx->opts);
|
2016-09-19 17:54:54 +00:00
|
|
|
|
|
|
|
bool enable = mpctx->opts->use_terminal;
|
|
|
|
bool enabled = cas_terminal_owner(mpctx, mpctx);
|
|
|
|
if (enable != enabled) {
|
|
|
|
if (enable && cas_terminal_owner(NULL, mpctx)) {
|
|
|
|
terminal_init();
|
2016-09-29 14:26:54 +00:00
|
|
|
enabled = true;
|
2016-09-19 17:54:54 +00:00
|
|
|
} else if (!enable) {
|
|
|
|
terminal_uninit();
|
|
|
|
cas_terminal_owner(mpctx, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-22 16:30:39 +00:00
|
|
|
if (mp_msg_has_log_file(mpctx->global) && !had_log_file)
|
|
|
|
mp_print_version(mpctx->log, false); // for log-file=... in config files
|
|
|
|
|
2016-09-29 14:26:54 +00:00
|
|
|
if (enabled && !preinit && mpctx->opts->consolecontrols)
|
2016-09-19 17:54:54 +00:00
|
|
|
terminal_setup_getch(mpctx->input);
|
2015-03-05 10:17:22 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:45:42 +00:00
|
|
|
void mp_print_version(struct mp_log *log, int always)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
|
|
|
int v = always ? MSGL_INFO : MSGL_V;
|
2018-01-01 11:16:42 +00:00
|
|
|
mp_msg(log, v, "%s %s\n built on %s\n",
|
|
|
|
mpv_version, mpv_copyright, mpv_builddate);
|
2013-12-21 18:45:42 +00:00
|
|
|
print_libav_versions(log, v);
|
2013-12-21 20:49:13 +00:00
|
|
|
mp_msg(log, v, "\n");
|
2015-01-02 02:06:06 +00:00
|
|
|
// Only in verbose mode.
|
|
|
|
if (!always) {
|
|
|
|
mp_msg(log, MSGL_V, "Configuration: " CONFIGURATION "\n");
|
2015-03-11 22:33:05 +00:00
|
|
|
mp_msg(log, MSGL_V, "List of enabled features: %s\n", FULLCONFIG);
|
2018-01-01 10:29:13 +00:00
|
|
|
#ifdef NDEBUG
|
2017-11-04 16:48:30 +00:00
|
|
|
mp_msg(log, MSGL_V, "Built with NDEBUG.\n");
|
|
|
|
#endif
|
2015-01-02 02:06:06 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
void mp_destroy(struct MPContext *mpctx)
|
|
|
|
{
|
2018-03-09 03:46:09 +00:00
|
|
|
mp_shutdown_clients(mpctx);
|
2016-09-21 13:55:34 +00:00
|
|
|
|
2014-10-24 13:34:04 +00:00
|
|
|
mp_uninit_ipc(mpctx->ipc_ctx);
|
|
|
|
mpctx->ipc_ctx = NULL;
|
|
|
|
|
2014-10-03 17:57:49 +00:00
|
|
|
uninit_audio_out(mpctx);
|
|
|
|
uninit_video_out(mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2018-04-22 17:40:36 +00:00
|
|
|
// If it's still set here, it's an error.
|
2013-10-29 21:38:29 +00:00
|
|
|
encode_lavc_free(mpctx->encode_lavc_ctx);
|
|
|
|
mpctx->encode_lavc_ctx = NULL;
|
|
|
|
|
|
|
|
command_uninit(mpctx);
|
|
|
|
|
2014-10-24 13:34:04 +00:00
|
|
|
mp_clients_destroy(mpctx);
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
osd_free(mpctx->osd);
|
|
|
|
|
2015-02-12 17:39:47 +00:00
|
|
|
#if HAVE_COCOA
|
|
|
|
cocoa_set_input_context(NULL);
|
|
|
|
#endif
|
|
|
|
|
2014-12-02 19:35:18 +00:00
|
|
|
if (cas_terminal_owner(mpctx, mpctx)) {
|
2014-08-21 20:13:10 +00:00
|
|
|
terminal_uninit();
|
2014-12-02 19:35:18 +00:00
|
|
|
cas_terminal_owner(mpctx, NULL);
|
2014-06-06 15:28:13 +00:00
|
|
|
}
|
2014-08-21 20:13:10 +00:00
|
|
|
|
|
|
|
mp_input_uninit(mpctx->input);
|
|
|
|
|
2013-12-21 19:06:36 +00:00
|
|
|
uninit_libav(mpctx->global);
|
2013-12-15 17:04:13 +00:00
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_msg_uninit(mpctx->global);
|
2018-05-12 16:46:37 +00:00
|
|
|
assert(!mpctx->num_abort_list);
|
|
|
|
talloc_free(mpctx->abort_list);
|
2018-05-12 14:51:53 +00:00
|
|
|
pthread_mutex_destroy(&mpctx->abort_lock);
|
2014-02-10 20:01:35 +00:00
|
|
|
talloc_free(mpctx);
|
|
|
|
}
|
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
static bool handle_help_options(struct MPContext *mpctx)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
2013-12-21 17:46:24 +00:00
|
|
|
struct mp_log *log = mpctx->log;
|
2013-10-29 21:38:29 +00:00
|
|
|
if (opts->audio_decoders && strcmp(opts->audio_decoders, "help") == 0) {
|
2013-11-23 20:22:17 +00:00
|
|
|
struct mp_decoder_list *list = audio_decoder_list();
|
2013-12-21 17:46:24 +00:00
|
|
|
mp_print_decoders(log, MSGL_INFO, "Audio decoders:", list);
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(list);
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
2015-06-05 20:35:43 +00:00
|
|
|
if (opts->audio_spdif && strcmp(opts->audio_spdif, "help") == 0) {
|
|
|
|
MP_INFO(mpctx, "Choices: ac3,dts-hd,dts (and possibly more)\n");
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2015-06-05 20:35:43 +00:00
|
|
|
}
|
2013-10-29 21:38:29 +00:00
|
|
|
if (opts->video_decoders && strcmp(opts->video_decoders, "help") == 0) {
|
2013-11-23 20:36:20 +00:00
|
|
|
struct mp_decoder_list *list = video_decoder_list();
|
2013-12-21 17:46:24 +00:00
|
|
|
mp_print_decoders(log, MSGL_INFO, "Video decoders:", list);
|
2013-10-29 21:38:29 +00:00
|
|
|
talloc_free(list);
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
if ((opts->demuxer_name && strcmp(opts->demuxer_name, "help") == 0) ||
|
|
|
|
(opts->audio_demuxer_name && strcmp(opts->audio_demuxer_name, "help") == 0) ||
|
|
|
|
(opts->sub_demuxer_name && strcmp(opts->sub_demuxer_name, "help") == 0)) {
|
2013-12-21 19:24:20 +00:00
|
|
|
demuxer_help(log);
|
2013-10-29 21:38:29 +00:00
|
|
|
MP_INFO(mpctx, "\n");
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
2018-05-21 13:11:19 +00:00
|
|
|
if (opts->ao_opts->audio_device &&
|
|
|
|
strcmp(opts->ao_opts->audio_device, "help") == 0)
|
|
|
|
{
|
2014-10-10 16:27:21 +00:00
|
|
|
ao_print_devices(mpctx->global, log);
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2014-10-09 19:21:31 +00:00
|
|
|
}
|
2016-09-01 18:00:43 +00:00
|
|
|
if (opts->property_print_help) {
|
|
|
|
property_print_help(mpctx);
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
2016-09-01 18:00:43 +00:00
|
|
|
}
|
2014-06-11 00:04:02 +00:00
|
|
|
if (encode_lavc_showhelp(log, opts->encode_opts))
|
2017-06-23 13:20:43 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2013-12-21 18:27:19 +00:00
|
|
|
static int cfg_include(void *ctx, char *filename, int flags)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2013-12-21 18:27:19 +00:00
|
|
|
struct MPContext *mpctx = ctx;
|
2014-12-30 08:23:36 +00:00
|
|
|
char *fname = mp_get_user_path(NULL, mpctx->global, filename);
|
|
|
|
int r = m_config_parse_config_file(mpctx->mconfig, fname, NULL, flags);
|
|
|
|
talloc_free(fname);
|
|
|
|
return r;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 03:10:28 +00:00
|
|
|
// We mostly care about LC_NUMERIC, and how "." vs. "," is treated,
|
|
|
|
// Other locale stuff might break too, but probably isn't too bad.
|
|
|
|
static bool check_locale(void)
|
|
|
|
{
|
|
|
|
char *name = setlocale(LC_NUMERIC, NULL);
|
|
|
|
return !name || strcmp(name, "C") == 0 || strcmp(name, "C.UTF-8") == 0;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
struct MPContext *mp_create(void)
|
2013-10-29 21:38:29 +00:00
|
|
|
{
|
2018-03-09 03:10:28 +00:00
|
|
|
if (!check_locale()) {
|
|
|
|
// Normally, we never print anything (except if the "terminal" option
|
|
|
|
// is enabled), so this is an exception.
|
|
|
|
fprintf(stderr, "Non-C locale detected. This is not supported.\n"
|
|
|
|
"Call 'setlocale(LC_NUMERIC, \"C\");' in your code.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-09-19 17:57:31 +00:00
|
|
|
char *enable_talloc = getenv("MPV_LEAK_REPORT");
|
|
|
|
if (enable_talloc && strcmp(enable_talloc, "1") == 0)
|
|
|
|
talloc_enable_leak_report();
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
mp_time_init();
|
2013-10-29 21:38:29 +00:00
|
|
|
|
|
|
|
struct MPContext *mpctx = talloc(NULL, MPContext);
|
|
|
|
*mpctx = (struct MPContext){
|
2014-04-27 20:28:07 +00:00
|
|
|
.last_chapter = -2,
|
player: redo terminal OSD and status line handling
The terminal OSD code includes the handling of the terminal status line,
showing player OSD messages on the terminal, and showing subtitles on
terminal (the latter two only if there is no video window, or if
terminal OSD is forced).
This didn't handle some corner cases correctly. For example, showing an
OSD message on the terminal always cleared the previous line, even if
the line was an important message (or even just the command prompt, if
most other messages were silenced).
Attempt to handle this correctly by keeping track of how many lines the
terminal OSD currently consists of. Since there could be race conditions
with other messages being printed, implement this in msg.c. Now msg.c
expects that MSGL_STATUS messages rewrite the status line, so the caller
is forced to use a single mp_msg() call to set the status line.
Instead of littering print_status() all over the place, update the
status only once per playloop iteration in update_osd_msg(). In audio-
only mode, the status line might now be a little bit off, but it's
perhaps ok.
Print the status line only if it has changed, or if another message was
printed. This might help with extremely slow terminals, although in
audio+video mode, it'll still be updated very often (A-V sync display
changes on every frame).
Instead of hardcoding the terminal sequences, use
terminfo/termcap to get the sequences. Remove the --term-osd-esc option,
which allowed to override the hardcoded escapes - it's useless now.
The fallback for terminals with no escape sequences for moving the
cursor and clearing a line is removed. This somewhat breaks status line
display on these terminals, including the MS Windows console: instead of
querying the terminal size and clearing the line manually by padding the
output with spaces, the line is simply not cleared. I don't expect this
to be a problem on UNIX, and on MS Windows we could emulate escape
sequences. Note that terminal OSD (other than the status line) was
broken anyway on these terminals.
In osd.c, the function get_term_width() is not used anymore, so remove
it. To remind us that the MS Windows console apparently adds a line
break when writint the last column, adjust screen_width in terminal-
win.c accordingly.
2014-01-13 19:05:41 +00:00
|
|
|
.term_osd_contents = talloc_strdup(mpctx, ""),
|
2014-01-20 18:29:15 +00:00
|
|
|
.osd_progbar = { .type = -1 },
|
2013-10-29 21:38:29 +00:00
|
|
|
.playlist = talloc_struct(mpctx, struct playlist, {0}),
|
2014-02-10 20:01:35 +00:00
|
|
|
.dispatch = mp_dispatch_create(mpctx),
|
stream: redo playback abort handling
This mechanism originates from MPlayer's way of dealing with blocking
network, but it's still useful. On opening and closing, mpv waits for
network synchronously, and also some obscure commands and use-cases can
lead to such blocking. In these situations, the stream is asynchronously
forced to stop by "interrupting" it.
The old design interrupting I/O was a bit broken: polling with a
callback, instead of actively interrupting it. Change the direction of
this. There is no callback anymore, and the player calls
mp_cancel_trigger() to force the stream to return.
libavformat (via stream_lavf.c) has the old broken design, and fixing it
would require fixing libavformat, which won't happen so quickly. So we
have to keep that part. But everything above the stream layer is
prepared for a better design, and more sophisticated methods than
mp_cancel_test() could be easily introduced.
There's still one problem: commands are still run in the central
playback loop, which we assume can block on I/O in the worst case.
That's not a problem yet, because we simply mark some commands as being
able to stop playback of the current file ("quit" etc.), so input.c
could abort playback as soon as such a command is queued. But there are
also commands abort playback only conditionally, and the logic for that
is in the playback core and thus "unreachable". For example,
"playlist_next" aborts playback only if there's a next file. We don't
want it to always abort playback.
As a quite ugly hack, abort playback only if at least 2 abort commands
are queued - this pretty much happens only if the core is frozen and
doesn't react to input.
2014-09-13 12:23:08 +00:00
|
|
|
.playback_abort = mp_cancel_new(mpctx),
|
2018-05-06 16:27:18 +00:00
|
|
|
.thread_pool = mp_thread_pool_create(mpctx, 0, 1, 30),
|
2018-05-19 16:25:54 +00:00
|
|
|
.stop_play = PT_STOP,
|
Implement backwards playback
See manpage additions. This is a huge hack. You can bet there are shit
tons of bugs. It's literally forcing square pegs into round holes.
Hopefully, the manpage wall of text makes it clear enough that the whole
shit can easily crash and burn. (Although it shouldn't literally crash.
That would be a bug. It possibly _could_ start a fire by entering some
sort of endless loop, not a literal one, just something where it tries
to do work without making progress.)
(Some obvious bugs I simply ignored for this initial version, but
there's a number of potential bugs I can't even imagine. Normal playback
should remain completely unaffected, though.)
How this works is also described in the manpage. Basically, we demux in
reverse, then we decode in reverse, then we render in reverse.
The decoding part is the simplest: just reorder the decoder output. This
weirdly integrates with the timeline/ordered chapter code, which also
has special requirements on feeding the packets to the decoder in a
non-straightforward way (it doesn't conflict, although a bugmessmass
breaks correct slicing of segments, so EDL/ordered chapter playback is
broken in backward direction).
Backward demuxing is pretty involved. In theory, it could be much
easier: simply iterating the usual demuxer output backward. But this
just doesn't fit into our code, so there's a cthulhu nightmare of shit.
To be specific, each stream (audio, video) is reversed separately. At
least this means we can do backward playback within cached content (for
example, you could play backwards in a live stream; on that note, it
disables prefetching, which would lead to losing new live video, but
this could be avoided).
The fuckmess also meant that I didn't bother trying to support
subtitles. Subtitles are a problem because they're "sparse" streams.
They need to be "passively" demuxed: you don't try to read a subtitle
packet, you demux audio and video, and then look whether there was a
subtitle packet. This means to get subtitles for a time range, you need
to know that you demuxed video and audio over this range, which becomes
pretty messy when you demux audio and video backwards separately.
Backward display is the most weird (and potentially buggy) part. To
avoid that we need to touch a LOT of timing code, we negate all
timestamps. The basic idea is that due to the navigation, all
comparisons and subtractions of timestamps keep working, and you don't
need to touch every single of them to "reverse" them.
E.g.:
bool before = pts_a < pts_b;
would need to be:
bool before = forward
? pts_a < pts_b
: pts_a > pts_b;
or:
bool before = pts_a * dir < pts_b * dir;
or if you, as it's implemented now, just do this after decoding:
pts_a *= dir;
pts_b *= dir;
and then in the normal timing/renderer code:
bool before = pts_a < pts_b;
Consequently, we don't need many changes in the latter code. But some
assumptions inhererently true for forward playback may have been broken
anyway. What is mainly needed is fixing places where values are passed
between positive and negative "domains". For example, seeking and
timestamp user display always uses positive timestamps. The main mess is
that it's not obvious which domain a given variable should or does use.
Well, in my tests with a single file, it suddenly started to work when I
did this. I'm honestly surprised that it did, and that I didn't have to
change a single line in the timing code past decoder (just something
minor to make external/cached text subtitles display). I committed it
immediately while avoiding thinking about it. But there really likely
are subtle problems of all sorts.
As far as I'm aware, gstreamer also supports backward playback. When I
looked at this years ago, I couldn't find a way to actually try this,
and I didn't revisit it now. Back then I also read talk slides from the
person who implemented it, and I'm not sure if and which ideas I might
have taken from it. It's possible that the timestamp reversal is
inspired by it, but I didn't check. (I think it claimed that it could
avoid large changes by changing a sign?)
VapourSynth has some sort of reverse function, which provides a backward
view on a video. The function itself is trivial to implement, as
VapourSynth aims to provide random access to video by frame numbers (so
you just request decreasing frame numbers). From what I remember, it
wasn't exactly fluid, but it worked. It's implemented by creating an
index, and seeking to the target on demand, and a bunch of caching. mpv
could use it, but it would either require using VapourSynth as demuxer
and decoder for everything, or replacing the current file every time
something is supposed to be played backwards.
FFmpeg's libavfilter has reversal filters for audio and video. These
require buffering the entire media data of the file, and don't really
fit into mpv's architecture. It could be used by playing a libavfilter
graph that also demuxes, but that's like VapourSynth but worse.
2019-05-18 00:10:51 +00:00
|
|
|
.play_dir = 1,
|
2013-10-29 21:38:29 +00:00
|
|
|
};
|
|
|
|
|
2018-05-12 14:51:53 +00:00
|
|
|
pthread_mutex_init(&mpctx->abort_lock, NULL);
|
2017-01-22 14:23:35 +00:00
|
|
|
|
2013-12-21 18:45:42 +00:00
|
|
|
mpctx->global = talloc_zero(mpctx, struct mpv_global);
|
|
|
|
|
|
|
|
// Nothing must call mp_msg*() and related before this
|
|
|
|
mp_msg_init(mpctx->global);
|
|
|
|
mpctx->log = mp_log_new(mpctx, mpctx->global->log, "!cplayer");
|
2013-12-21 21:00:26 +00:00
|
|
|
mpctx->statusline = mp_log_new(mpctx, mpctx->log, "!statusline");
|
2013-12-21 18:45:42 +00:00
|
|
|
|
2013-10-29 21:38:29 +00:00
|
|
|
// Create the config context and register the options
|
2013-12-21 18:45:42 +00:00
|
|
|
mpctx->mconfig = m_config_new(mpctx, mpctx->log, sizeof(struct MPOpts),
|
2016-09-06 18:09:56 +00:00
|
|
|
&mp_default_opts, mp_opts);
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->opts = mpctx->mconfig->optstruct;
|
2019-07-12 23:22:37 +00:00
|
|
|
mpctx->global->config = mpctx->mconfig->shadow;
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->mconfig->includefunc = cfg_include;
|
2013-12-21 18:27:19 +00:00
|
|
|
mpctx->mconfig->includefunc_ctx = mpctx;
|
2013-10-29 21:38:29 +00:00
|
|
|
mpctx->mconfig->use_profiles = true;
|
2013-11-23 20:35:03 +00:00
|
|
|
mpctx->mconfig->is_toplevel = true;
|
2015-11-04 14:44:37 +00:00
|
|
|
mpctx->mconfig->global = mpctx->global;
|
2015-04-10 18:40:50 +00:00
|
|
|
m_config_parse(mpctx->mconfig, "", bstr0(def_config), NULL, 0);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-09-16 12:25:50 +00:00
|
|
|
mpctx->input = mp_input_init(mpctx->global, mp_wakeup_core_cb, mpctx);
|
2013-10-29 21:38:29 +00:00
|
|
|
screenshot_init(mpctx);
|
|
|
|
command_init(mpctx);
|
2014-02-10 20:01:35 +00:00
|
|
|
init_libav(mpctx->global);
|
|
|
|
mp_clients_init(mpctx);
|
2016-09-01 19:55:21 +00:00
|
|
|
mpctx->osd = osd_create(mpctx->global);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2015-05-27 15:57:24 +00:00
|
|
|
#if HAVE_COCOA
|
|
|
|
cocoa_set_input_context(mpctx->input);
|
|
|
|
#endif
|
|
|
|
|
2016-09-19 17:57:31 +00:00
|
|
|
char *verbose_env = getenv("MPV_VERBOSE");
|
|
|
|
if (verbose_env)
|
|
|
|
mpctx->opts->verbose = atoi(verbose_env);
|
|
|
|
|
2019-10-04 14:30:48 +00:00
|
|
|
mp_cancel_trigger(mpctx->playback_abort);
|
|
|
|
|
2016-09-01 19:55:21 +00:00
|
|
|
return mpctx;
|
2014-03-01 14:46:39 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
// Finish mpctx initialization. This must be done after setting up all options.
|
|
|
|
// Some of the initializations depend on the options, and can't be changed or
|
|
|
|
// undone later.
|
2015-03-06 09:53:49 +00:00
|
|
|
// If options is not NULL, apply them as command line player arguments.
|
2018-03-09 03:07:34 +00:00
|
|
|
// Returns: 0 on success, -1 on error, 1 if exiting normally (e.g. help).
|
2015-03-06 09:53:49 +00:00
|
|
|
int mp_initialize(struct MPContext *mpctx, char **options)
|
2014-02-10 20:01:35 +00:00
|
|
|
{
|
|
|
|
struct MPOpts *opts = mpctx->opts;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
assert(!mpctx->initialized);
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-09-19 17:54:54 +00:00
|
|
|
// Preparse the command line, so we can init the terminal early.
|
2018-05-21 14:25:52 +00:00
|
|
|
if (options) {
|
|
|
|
m_config_preparse_command_line(mpctx->mconfig, mpctx->global,
|
|
|
|
&opts->verbose, options);
|
|
|
|
}
|
2015-03-05 10:17:22 +00:00
|
|
|
|
2018-05-21 13:49:19 +00:00
|
|
|
mp_init_paths(mpctx->global, opts);
|
2016-09-29 14:26:54 +00:00
|
|
|
mp_update_logging(mpctx, true);
|
2015-03-05 10:17:22 +00:00
|
|
|
|
2016-09-19 17:54:54 +00:00
|
|
|
if (options) {
|
2015-03-06 09:53:49 +00:00
|
|
|
MP_VERBOSE(mpctx, "Command line options:");
|
|
|
|
for (int i = 0; options[i]; i++)
|
|
|
|
MP_VERBOSE(mpctx, " '%s'", options[i]);
|
2015-03-05 10:17:22 +00:00
|
|
|
MP_VERBOSE(mpctx, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_print_version(mpctx->log, false);
|
|
|
|
|
|
|
|
mp_parse_cfgfiles(mpctx);
|
|
|
|
|
2015-03-06 09:53:49 +00:00
|
|
|
if (options) {
|
2015-03-05 10:17:22 +00:00
|
|
|
int r = m_config_parse_mp_command_line(mpctx->mconfig, mpctx->playlist,
|
2015-03-06 09:53:49 +00:00
|
|
|
mpctx->global, options);
|
2015-03-05 10:17:22 +00:00
|
|
|
if (r < 0)
|
2018-03-09 03:07:34 +00:00
|
|
|
return r == M_OPT_EXIT ? 1 : -1;
|
2015-03-05 10:17:22 +00:00
|
|
|
}
|
|
|
|
|
2016-09-23 22:36:17 +00:00
|
|
|
if (opts->operation_mode == 1) {
|
|
|
|
m_config_set_profile(mpctx->mconfig, "builtin-pseudo-gui",
|
|
|
|
M_SETOPT_NO_OVERWRITE);
|
|
|
|
m_config_set_profile(mpctx->mconfig, "pseudo-gui", 0);
|
|
|
|
}
|
2016-09-23 20:35:54 +00:00
|
|
|
|
2016-09-21 13:56:54 +00:00
|
|
|
mp_get_resume_defaults(mpctx);
|
|
|
|
|
2016-09-29 14:26:54 +00:00
|
|
|
mp_input_load_config(mpctx->input);
|
|
|
|
|
2016-09-19 17:54:54 +00:00
|
|
|
// From this point on, all mpctx members are initialized.
|
|
|
|
mpctx->initialized = true;
|
|
|
|
mpctx->mconfig->option_set_callback = mp_on_set_option;
|
|
|
|
mpctx->mconfig->option_set_callback_cb = mpctx;
|
|
|
|
mpctx->mconfig->option_change_callback = mp_option_change_callback;
|
|
|
|
mpctx->mconfig->option_change_callback_ctx = mpctx;
|
|
|
|
// Run all update handlers.
|
|
|
|
mp_option_change_callback(mpctx, NULL, UPDATE_OPTS_MASK);
|
|
|
|
|
2015-03-05 10:17:22 +00:00
|
|
|
if (handle_help_options(mpctx))
|
2018-03-09 03:07:34 +00:00
|
|
|
return 1; // help
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2016-07-01 18:56:59 +00:00
|
|
|
if (!print_libav_versions(mp_null_log, 0)) {
|
|
|
|
print_libav_versions(mpctx->log, MSGL_FATAL);
|
2019-10-11 19:28:04 +00:00
|
|
|
MP_FATAL(mpctx, "\nmpv was compiled against an incompatible version of "
|
2016-07-01 18:56:59 +00:00
|
|
|
"FFmpeg/Libav than the shared\nlibrary it is linked against. "
|
|
|
|
"This is most likely a broken build and could\nresult in "
|
2019-10-11 19:28:04 +00:00
|
|
|
"misbehavior and crashes.\n\nThis is a broken build.\n");
|
2016-07-01 18:56:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-03-09 03:07:34 +00:00
|
|
|
if (!mpctx->playlist->first && !opts->player_idle_mode) {
|
|
|
|
// nothing to play
|
|
|
|
mp_print_version(mpctx->log, true);
|
|
|
|
MP_INFO(mpctx, "%s", mp_help_text);
|
|
|
|
return 1;
|
|
|
|
}
|
2015-03-05 10:17:22 +00:00
|
|
|
|
2016-09-21 13:56:54 +00:00
|
|
|
MP_STATS(mpctx, "start init");
|
|
|
|
|
2017-02-25 20:56:59 +00:00
|
|
|
#if HAVE_COCOA
|
|
|
|
mpv_handle *ctx = mp_new_client(mpctx->clients, "osx");
|
|
|
|
cocoa_set_mpv_handle(ctx);
|
|
|
|
#endif
|
|
|
|
|
2014-06-11 00:04:02 +00:00
|
|
|
if (opts->encode_opts->file && opts->encode_opts->file[0]) {
|
2018-04-22 17:40:36 +00:00
|
|
|
mpctx->encode_lavc_ctx = encode_lavc_init(mpctx->global);
|
2013-10-29 21:38:29 +00:00
|
|
|
if(!mpctx->encode_lavc_ctx) {
|
2015-07-13 21:55:26 +00:00
|
|
|
MP_INFO(mpctx, "Encoding initialization failed.\n");
|
2014-02-10 20:01:35 +00:00
|
|
|
return -1;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|
2015-05-07 19:26:11 +00:00
|
|
|
m_config_set_profile(mpctx->mconfig, "encoding", 0);
|
2013-10-29 21:38:29 +00:00
|
|
|
mp_input_enable_section(mpctx->input, "encode", MP_INPUT_EXCLUSIVE);
|
|
|
|
}
|
|
|
|
|
2014-10-03 20:32:16 +00:00
|
|
|
#if !HAVE_LIBASS
|
2013-10-29 21:38:29 +00:00
|
|
|
MP_WARN(mpctx, "Compiled without libass.\n");
|
2013-10-30 20:55:17 +00:00
|
|
|
MP_WARN(mpctx, "There will be no OSD and no text subtitles.\n");
|
2013-10-29 21:38:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-27 15:53:58 +00:00
|
|
|
mp_load_scripts(mpctx);
|
|
|
|
|
2015-09-23 20:03:11 +00:00
|
|
|
if (opts->force_vo == 2 && handle_force_window(mpctx, false) < 0)
|
2015-09-20 15:58:02 +00:00
|
|
|
return -1;
|
2013-10-29 21:38:29 +00:00
|
|
|
|
2014-04-17 19:47:00 +00:00
|
|
|
MP_STATS(mpctx, "end init");
|
|
|
|
|
2014-02-10 20:01:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:25:22 +00:00
|
|
|
int mpv_main(int argc, char *argv[])
|
2014-02-10 20:01:35 +00:00
|
|
|
{
|
|
|
|
struct MPContext *mpctx = mp_create();
|
2018-03-09 03:10:28 +00:00
|
|
|
if (!mpctx)
|
|
|
|
return 1;
|
2014-02-10 20:01:35 +00:00
|
|
|
|
2018-03-09 03:46:09 +00:00
|
|
|
mpctx->is_cli = true;
|
|
|
|
|
2015-03-06 09:53:49 +00:00
|
|
|
char **options = argv && argv[0] ? argv + 1 : NULL; // skips program name
|
|
|
|
int r = mp_initialize(mpctx, options);
|
2018-03-09 03:07:34 +00:00
|
|
|
if (r == 0)
|
|
|
|
mp_play_files(mpctx);
|
|
|
|
|
|
|
|
int rc = 0;
|
|
|
|
const char *reason = NULL;
|
|
|
|
if (r < 0) {
|
|
|
|
reason = "Fatal error";
|
|
|
|
rc = 1;
|
|
|
|
} else if (r > 0) {
|
|
|
|
// nothing
|
|
|
|
} else if (mpctx->stop_play == PT_QUIT) {
|
|
|
|
reason = "Quit";
|
|
|
|
} else if (mpctx->files_played) {
|
|
|
|
if (mpctx->files_errored || mpctx->files_broken) {
|
|
|
|
reason = "Some errors happened";
|
|
|
|
rc = 3;
|
|
|
|
} else {
|
|
|
|
reason = "End of file";
|
|
|
|
}
|
|
|
|
} else if (mpctx->files_broken && !mpctx->files_errored) {
|
|
|
|
reason = "Errors when loading file";
|
|
|
|
rc = 2;
|
|
|
|
} else if (mpctx->files_errored) {
|
|
|
|
reason = "Interrupted by error";
|
|
|
|
rc = 2;
|
|
|
|
} else {
|
|
|
|
reason = "No files played";
|
2014-02-10 20:01:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 03:07:34 +00:00
|
|
|
if (reason)
|
|
|
|
MP_INFO(mpctx, "\nExiting... (%s)\n", reason);
|
|
|
|
if (mpctx->has_quit_custom_rc)
|
|
|
|
rc = mpctx->quit_custom_rc;
|
|
|
|
|
|
|
|
mp_destroy(mpctx);
|
|
|
|
return rc;
|
2013-10-29 21:38:29 +00:00
|
|
|
}
|