/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stddef.h>
#include <stdbool.h>
#include <inttypes.h>
#include <assert.h>
#include <libavutil/avutil.h>
#include "config.h"
#include "talloc.h"
#include "osdep/io.h"
#include "osdep/terminal.h"
#include "osdep/timer.h"
#include "common/msg.h"
#include "options/path.h"
#include "options/m_config.h"
#include "options/parse_configfile.h"
#include "common/playlist.h"
#include "options/options.h"
#include "options/m_property.h"
#include "common/common.h"
#include "common/encode.h"
#include "input/input.h"
#include "audio/mixer.h"
#include "audio/audio.h"
#include "audio/audio_buffer.h"
#include "audio/decode/dec_audio.h"
#include "audio/out/ao.h"
#include "demux/demux.h"
#include "stream/stream.h"
#include "stream/resolve/resolve.h"
#include "sub/ass_mp.h"
#include "sub/dec_sub.h"
#include "sub/find_subfiles.h"
#include "video/decode/dec_video.h"
#include "video/out/vo.h"
#include "core.h"
#include "command.h"
#include "libmpv/client.h"
#if HAVE_DVBIN
#include "stream/dvbin.h"
#endif
static void uninit_sub(struct MPContext *mpctx, int order)
{
if (mpctx->d_sub[order])
sub_reset(mpctx->d_sub[order]);
mpctx->d_sub[order] = NULL; // Note: not free'd.
int obj = order ? OSDTYPE_SUB2 : OSDTYPE_SUB;
osd_set_sub(mpctx->osd, obj, NULL);
reset_subtitles(mpctx, order);
reselect_demux_streams(mpctx);
}
void uninit_player(struct MPContext *mpctx, unsigned int mask)
{
struct MPOpts *opts = mpctx->opts;
mask &= mpctx->initialized_flags;
MP_DBG(mpctx, "\n*** uninit(0x%X)\n", mask);
if (mask & INITIALIZED_ACODEC) {
mpctx->initialized_flags &= ~INITIALIZED_ACODEC;
mixer_uninit_audio(mpctx->mixer);
audio_uninit(mpctx->d_audio);
mpctx->d_audio = NULL;
reselect_demux_streams(mpctx);
}
if (mask & INITIALIZED_SUB) {
mpctx->initialized_flags &= ~INITIALIZED_SUB;
uninit_sub(mpctx, 0);
}
if (mask & INITIALIZED_SUB2) {
mpctx->initialized_flags &= ~INITIALIZED_SUB2;
uninit_sub(mpctx, 1);
}
if (mask & INITIALIZED_LIBASS) {
mpctx->initialized_flags &= ~INITIALIZED_LIBASS;
#if HAVE_LIBASS
if (mpctx->ass_renderer)
ass_renderer_done(mpctx->ass_renderer);
mpctx->ass_renderer = NULL;
ass_clear_fonts(mpctx->ass_library);
#endif
}
if (mask & INITIALIZED_VCODEC) {
mpctx->initialized_flags &= ~INITIALIZED_VCODEC;
if (mpctx->d_video)
video_uninit(mpctx->d_video);
mpctx->d_video = NULL;
mpctx->sync_audio_to_video = false;
reselect_demux_streams(mpctx);
}
if (mask & INITIALIZED_DEMUXER) {
mpctx->initialized_flags &= ~INITIALIZED_DEMUXER;
assert(!(mpctx->initialized_flags &
(INITIALIZED_VCODEC | INITIALIZED_ACODEC |
INITIALIZED_SUB2 | INITIALIZED_SUB)));
for (int i = 0; i < mpctx->num_tracks; i++) {
talloc_free(mpctx->tracks[i]);
}
mpctx->num_tracks = 0;
for (int r = 0; r < NUM_PTRACKS; r++) {
for (int t = 0; t < STREAM_TYPE_COUNT; t++)
mpctx->current_track[r][t] = NULL;
}
assert(!mpctx->d_video && !mpctx->d_audio &&
!mpctx->d_sub[0] && !mpctx->d_sub[1]);
mpctx->master_demuxer = NULL;
for (int i = 0; i < mpctx->num_sources; i++) {
uninit_subs(mpctx->sources[i]);
struct demuxer *demuxer = mpctx->sources[i];
struct stream *stream = demuxer->stream;
free_demuxer(demuxer);
if (stream != mpctx->stream)
free_stream(stream);
}
talloc_free(mpctx->sources);
mpctx->sources = NULL;
mpctx->demuxer = NULL;
mpctx->num_sources = 0;
talloc_free(mpctx->timeline);
mpctx->timeline = NULL;
mpctx->num_timeline_parts = 0;
talloc_free(mpctx->chapters);
mpctx->chapters = NULL;
mpctx->num_chapters = 0;
mpctx->video_offset = 0;
}
// kill the cache process:
if (mask & INITIALIZED_STREAM) {
mpctx->initialized_flags &= ~INITIALIZED_STREAM;
if (mpctx->stream)
free_stream(mpctx->stream);
mpctx->stream = NULL;
}
if (mask & INITIALIZED_VO) {
mpctx->initialized_flags &= ~INITIALIZED_VO;
vo_destroy(mpctx->video_out);
mpctx->video_out = NULL;
}
if (mask & INITIALIZED_AO) {
struct ao *ao = mpctx->ao;
mpctx->initialized_flags &= ~INITIALIZED_AO;
if (ao) {
// Note: with gapless_audio, stop_play is not correctly set
if (opts->gapless_audio || mpctx->stop_play == AT_END_OF_FILE)
ao_drain(ao);
ao_uninit(ao);
}
mpctx->ao = NULL;
}
if (mask & INITIALIZED_PLAYBACK)
mpctx->initialized_flags &= ~INITIALIZED_PLAYBACK;
}
static void print_stream(struct MPContext *mpctx, struct track *t)
{
struct sh_stream *s = t->stream;
const char *tname = "?";
const char *selopt = "?";
const char *langopt = "?";
const char *iid = NULL;
switch (t->type) {
case STREAM_VIDEO:
tname = "Video"; selopt = "vid"; langopt = NULL; iid = "VID";
break;
case STREAM_AUDIO:
tname = "Audio"; selopt = "aid"; langopt = "alang"; iid = "AID";
break;
case STREAM_SUB:
tname = "Subs"; selopt = "sid"; langopt = "slang"; iid = "SID";
break;
}
MP_INFO(mpctx, "[stream] %-5s %3s", tname, t->selected ? "(+)" : "");
MP_INFO(mpctx, " --%s=%d", selopt, t->user_tid);
if (t->lang && langopt)
MP_INFO(mpctx, " --%s=%s", langopt, t->lang);
if (t->default_track)
MP_INFO(mpctx, " (*)");
if (t->attached_picture)
MP_INFO(mpctx, " [P]");
if (t->title)
MP_INFO(mpctx, " '%s'", t->title);
const char *codec = s ? s->codec : NULL;
MP_INFO(mpctx, " (%s)", codec ? codec : "<unknown>");
if (t->is_external)
MP_INFO(mpctx, " (external)");
MP_INFO(mpctx, "\n");
// legacy compatibility
if (!iid)
return;
|