mirror of
https://github.com/mpv-player/mpv
synced 2025-04-01 23:00:41 +00:00
Move seek-reset functionality out of demuxer.c
Move code for resetting decoders after seeks, chapter seeks and angle changes out of demuxer.c. This functionality belongs on a higher level; the demux layer can't always know what kind of reinitialization is required.
This commit is contained in:
parent
97db8519c8
commit
e3bd668ebd
11
command.c
11
command.c
@ -45,6 +45,7 @@
|
|||||||
#include "mpcommon.h"
|
#include "mpcommon.h"
|
||||||
#include "mixer.h"
|
#include "mixer.h"
|
||||||
#include "libmpcodecs/dec_video.h"
|
#include "libmpcodecs/dec_video.h"
|
||||||
|
#include "libmpcodecs/dec_audio.h"
|
||||||
#include "libmpcodecs/dec_teletext.h"
|
#include "libmpcodecs/dec_teletext.h"
|
||||||
#include "vobsub.h"
|
#include "vobsub.h"
|
||||||
#include "spudec.h"
|
#include "spudec.h"
|
||||||
@ -523,6 +524,16 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
|
|||||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
angle = demuxer_set_angle(mpctx->demuxer, angle);
|
angle = demuxer_set_angle(mpctx->demuxer, angle);
|
||||||
|
if (angle >= 0) {
|
||||||
|
struct sh_video *sh_video = mpctx->demuxer->video->sh;
|
||||||
|
if (sh_video)
|
||||||
|
resync_video_stream(sh_video);
|
||||||
|
|
||||||
|
struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
|
||||||
|
if (sh_audio)
|
||||||
|
resync_audio_stream(sh_audio);
|
||||||
|
}
|
||||||
|
|
||||||
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
|
set_osd_tmsg(OSD_MSG_TEXT, 1, opts->osd_duration,
|
||||||
"Angle: %d/%d", angle, angles);
|
"Angle: %d/%d", angle, angles);
|
||||||
if (angle_name)
|
if (angle_name)
|
||||||
|
@ -59,8 +59,6 @@
|
|||||||
#define PARSE_ON_ADD 0
|
#define PARSE_ON_ADD 0
|
||||||
|
|
||||||
static void clear_parser(sh_common_t *sh);
|
static void clear_parser(sh_common_t *sh);
|
||||||
void resync_video_stream(sh_video_t *sh_video);
|
|
||||||
void resync_audio_stream(sh_audio_t *sh_audio);
|
|
||||||
|
|
||||||
// Demuxer list
|
// Demuxer list
|
||||||
extern const demuxer_desc_t demuxer_desc_rawaudio;
|
extern const demuxer_desc_t demuxer_desc_rawaudio;
|
||||||
@ -1218,10 +1216,6 @@ void demux_flush(demuxer_t *demuxer)
|
|||||||
int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
||||||
int flags)
|
int flags)
|
||||||
{
|
{
|
||||||
demux_stream_t *d_audio = demuxer->audio;
|
|
||||||
demux_stream_t *d_video = demuxer->video;
|
|
||||||
sh_audio_t *sh_audio = d_audio->sh;
|
|
||||||
sh_video_t *sh_video = d_video->sh;
|
|
||||||
double tmp = 0;
|
double tmp = 0;
|
||||||
double pts;
|
double pts;
|
||||||
|
|
||||||
@ -1238,16 +1232,9 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
|||||||
}
|
}
|
||||||
// clear demux buffers:
|
// clear demux buffers:
|
||||||
demux_flush(demuxer);
|
demux_flush(demuxer);
|
||||||
if (sh_audio)
|
|
||||||
sh_audio->a_buffer_len = 0;
|
|
||||||
|
|
||||||
demuxer->stream->eof = 0;
|
|
||||||
demuxer->video->eof = 0;
|
demuxer->video->eof = 0;
|
||||||
demuxer->audio->eof = 0;
|
demuxer->audio->eof = 0;
|
||||||
|
|
||||||
if (sh_video)
|
|
||||||
sh_video->timer = 0; // !!!!!!
|
|
||||||
|
|
||||||
if (flags & SEEK_ABSOLUTE)
|
if (flags & SEEK_ABSOLUTE)
|
||||||
pts = 0.0f;
|
pts = 0.0f;
|
||||||
else {
|
else {
|
||||||
@ -1274,9 +1261,6 @@ int demux_seek(demuxer_t *demuxer, float rel_seek_secs, float audio_delay,
|
|||||||
if (demuxer->desc->seek)
|
if (demuxer->desc->seek)
|
||||||
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
|
demuxer->desc->seek(demuxer, rel_seek_secs, audio_delay, flags);
|
||||||
|
|
||||||
if (sh_audio)
|
|
||||||
resync_audio_stream(sh_audio);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1497,8 +1481,6 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
|
|||||||
char **chapter_name)
|
char **chapter_name)
|
||||||
{
|
{
|
||||||
int ris;
|
int ris;
|
||||||
sh_video_t *sh_video = demuxer->video->sh;
|
|
||||||
sh_audio_t *sh_audio = demuxer->audio->sh;
|
|
||||||
|
|
||||||
if (!demuxer->num_chapters || !demuxer->chapters) {
|
if (!demuxer->num_chapters || !demuxer->chapters) {
|
||||||
demux_flush(demuxer);
|
demux_flush(demuxer);
|
||||||
@ -1507,15 +1489,7 @@ int demuxer_seek_chapter(demuxer_t *demuxer, int chapter, double *seek_pts,
|
|||||||
&chapter);
|
&chapter);
|
||||||
if (ris != STREAM_UNSUPPORTED)
|
if (ris != STREAM_UNSUPPORTED)
|
||||||
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
||||||
if (sh_video) {
|
|
||||||
ds_fill_buffer(demuxer->video);
|
|
||||||
resync_video_stream(sh_video);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sh_audio) {
|
|
||||||
ds_fill_buffer(demuxer->audio);
|
|
||||||
resync_audio_stream(sh_audio);
|
|
||||||
}
|
|
||||||
// exit status may be ok, but main() doesn't have to seek itself
|
// exit status may be ok, but main() doesn't have to seek itself
|
||||||
// (because e.g. dvds depend on sectors, not on pts)
|
// (because e.g. dvds depend on sectors, not on pts)
|
||||||
*seek_pts = -1.0;
|
*seek_pts = -1.0;
|
||||||
@ -1644,8 +1618,6 @@ int demuxer_get_current_angle(demuxer_t *demuxer)
|
|||||||
int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
||||||
{
|
{
|
||||||
int ris, angles = -1;
|
int ris, angles = -1;
|
||||||
sh_video_t *sh_video = demuxer->video->sh;
|
|
||||||
sh_audio_t *sh_audio = demuxer->audio->sh;
|
|
||||||
|
|
||||||
angles = demuxer_angles_count(demuxer);
|
angles = demuxer_angles_count(demuxer);
|
||||||
if ((angles < 1) || (angle > angles))
|
if ((angles < 1) || (angle > angles))
|
||||||
@ -1658,15 +1630,6 @@ int demuxer_set_angle(demuxer_t *demuxer, int angle)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
demux_control(demuxer, DEMUXER_CTRL_RESYNC, NULL);
|
||||||
if (sh_video) {
|
|
||||||
ds_fill_buffer(demuxer->video);
|
|
||||||
resync_video_stream(sh_video);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sh_audio) {
|
|
||||||
ds_fill_buffer(demuxer->audio);
|
|
||||||
resync_audio_stream(sh_audio);
|
|
||||||
}
|
|
||||||
|
|
||||||
return angle;
|
return angle;
|
||||||
}
|
}
|
||||||
|
21
mplayer.c
21
mplayer.c
@ -2741,7 +2741,9 @@ static int seek(MPContext *mpctx, double amount, int style)
|
|||||||
if (mpctx->sh_video) {
|
if (mpctx->sh_video) {
|
||||||
current_module = "seek_video_reset";
|
current_module = "seek_video_reset";
|
||||||
resync_video_stream(mpctx->sh_video);
|
resync_video_stream(mpctx->sh_video);
|
||||||
|
mpctx->sh_video->timer = 0;
|
||||||
vo_seek_reset(mpctx->video_out);
|
vo_seek_reset(mpctx->video_out);
|
||||||
|
mpctx->sh_video->timer = 0;
|
||||||
mpctx->sh_video->num_buffered_pts = 0;
|
mpctx->sh_video->num_buffered_pts = 0;
|
||||||
mpctx->sh_video->last_pts = MP_NOPTS_VALUE;
|
mpctx->sh_video->last_pts = MP_NOPTS_VALUE;
|
||||||
mpctx->delay = 0;
|
mpctx->delay = 0;
|
||||||
@ -2759,6 +2761,7 @@ static int seek(MPContext *mpctx, double amount, int style)
|
|||||||
|
|
||||||
if (mpctx->sh_audio) {
|
if (mpctx->sh_audio) {
|
||||||
current_module = "seek_audio_reset";
|
current_module = "seek_audio_reset";
|
||||||
|
resync_audio_stream(mpctx->sh_audio);
|
||||||
mpctx->audio_out->reset(); // stop audio, throwing away buffered data
|
mpctx->audio_out->reset(); // stop audio, throwing away buffered data
|
||||||
mpctx->sh_audio->a_buffer_len = 0;
|
mpctx->sh_audio->a_buffer_len = 0;
|
||||||
mpctx->sh_audio->a_out_buffer_len = 0;
|
mpctx->sh_audio->a_out_buffer_len = 0;
|
||||||
@ -2806,9 +2809,21 @@ char *chapter_display_name(struct MPContext *mpctx, int chapter)
|
|||||||
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
|
int seek_chapter(struct MPContext *mpctx, int chapter, double *seek_pts,
|
||||||
char **chapter_name)
|
char **chapter_name)
|
||||||
{
|
{
|
||||||
if (!mpctx->chapters || !mpctx->sh_video)
|
if (!mpctx->chapters || !mpctx->sh_video) {
|
||||||
return demuxer_seek_chapter(mpctx->demuxer, chapter, seek_pts,
|
int res = demuxer_seek_chapter(mpctx->demuxer, chapter, seek_pts,
|
||||||
chapter_name);
|
chapter_name);
|
||||||
|
if (res >= 0) {
|
||||||
|
struct sh_video *sh_video = mpctx->demuxer->video->sh;
|
||||||
|
if (sh_video)
|
||||||
|
resync_video_stream(sh_video);
|
||||||
|
|
||||||
|
struct sh_audio *sh_audio = mpctx->demuxer->audio->sh;
|
||||||
|
if (sh_audio)
|
||||||
|
resync_audio_stream(sh_audio);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
if (chapter >= mpctx->num_chapters)
|
if (chapter >= mpctx->num_chapters)
|
||||||
return -1;
|
return -1;
|
||||||
if (chapter < 0)
|
if (chapter < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user