summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--mencoder.c32
-rw-r--r--mpcommon.c140
-rw-r--r--mpcommon.h7
-rw-r--r--mplayer.c135
5 files changed, 159 insertions, 156 deletions
diff --git a/Makefile b/Makefile
index 57edcbc77c..9924c13ee0 100644
--- a/Makefile
+++ b/Makefile
@@ -27,6 +27,7 @@ SRCS_COMMON = asxparser.c \
m_config.c \
m_option.c \
m_struct.c \
+ mpcommon.c \
parser-cfg.c \
playtree.c \
playtreeparser.c \
diff --git a/mencoder.c b/mencoder.c
index 0af76e36ae..1bc47508ff 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -90,7 +90,7 @@
#include "libmpcodecs/ae.h"
int vo_doublebuffering=0;
int vo_directrendering=0;
-int vo_config_count=0;
+int vo_config_count=1;
int forced_subs_only=0;
//--------------------------
@@ -199,9 +199,6 @@ int sub_auto = 0;
int subcc_enabled=0;
int suboverlap_enabled = 1;
-sub_data* subdata=NULL;
-float sub_last_pts = -303;
-
int auto_expand=1;
int encode_duplicates=1;
@@ -229,9 +226,9 @@ int mp_input_check_interrupt(int time) {
#ifdef USE_ASS
#include "libass/ass.h"
#include "libass/ass_mp.h"
-
-ass_track_t* ass_track = 0; // current track to render
#endif
+char *current_module;
+#include "mpcommon.h"
//char *out_audio_codec=NULL; // override audio codec
//char *out_video_codec=NULL; // override video codec
@@ -1475,36 +1472,19 @@ if(sh_audio && !demuxer2){
}
fflush(stdout);
- // find sub
- if(subdata && sh_video->pts>0){
- float pts=sh_video->pts;
- if(sub_fps==0) sub_fps=sh_video->fps;
- if (pts > sub_last_pts || pts < sub_last_pts-1.0 ) {
- find_sub(subdata, (pts+sub_delay) *
- (subdata->sub_uses_time? 100. : sub_fps));
- // FIXME! frame counter...
- sub_last_pts = pts;
- }
- }
-
#ifdef USE_DVDREAD
// DVD sub:
- if(vo_spudec||vobsub_writer){
+ if(vobsub_writer){
unsigned char* packet=NULL;
int len;
while((len=ds_get_packet_sub(d_dvdsub,&packet))>0){
mp_msg(MSGT_MENCODER,MSGL_V,"\rDVD sub: len=%d v_pts=%5.3f s_pts=%5.3f \n",len,sh_video->pts,d_dvdsub->pts);
- if (vo_spudec)
- spudec_assemble(vo_spudec,packet,len,90000*d_dvdsub->pts);
- if (vobsub_writer)
vobsub_out_output(vobsub_writer,packet,len,mux_v->timer + d_dvdsub->pts - sh_video->pts);
}
- if (vo_spudec) {
- spudec_heartbeat(vo_spudec,90000*sh_video->pts);
- vo_osd_changed(OSDTYPE_SPU);
- }
}
+ else
#endif
+ update_subtitles(sh_video, d_dvdsub, 0);
frame_data = (s_frame_data){ .start = NULL, .in_size = 0, .frame_time = 0., .already_read = 0 };
diff --git a/mpcommon.c b/mpcommon.c
new file mode 100644
index 0000000000..9a5c52accc
--- /dev/null
+++ b/mpcommon.c
@@ -0,0 +1,140 @@
+#include <stdlib.h>
+#include "stream/stream.h"
+#include "libmpdemux/demuxer.h"
+#include "libmpdemux/stheader.h"
+#include "mplayer.h"
+#include "libvo/sub.h"
+#include "libvo/video_out.h"
+#include "spudec.h"
+#include "vobsub.h"
+
+double sub_last_pts = -303;
+
+#ifdef USE_ASS
+#include "libass/ass.h"
+#include "libass/ass_mp.h"
+ass_track_t* ass_track = 0; // current track to render
+#endif
+
+sub_data* subdata = NULL;
+subtitle* vo_sub_last = NULL;
+
+void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset)
+{
+ unsigned char *packet=NULL;
+ int len;
+ char type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v';
+ static subtitle subs;
+ if (type == 'a')
+#ifdef USE_ASS
+ if (!ass_enabled)
+#endif
+ type = 't';
+ if (reset) {
+ sub_clear_text(&subs, MP_NOPTS_VALUE);
+ if (vo_sub) {
+ vo_sub = NULL;
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+ if (vo_spudec) {
+ spudec_reset(vo_spudec);
+ vo_osd_changed(OSDTYPE_SPU);
+ }
+ }
+ // find sub
+ if (subdata) {
+ double pts = sh_video->pts;
+ if (sub_fps==0) sub_fps = sh_video->fps;
+ current_module = "find_sub";
+ if (pts > sub_last_pts || pts < sub_last_pts-1.0) {
+ find_sub(subdata, (pts+sub_delay) *
+ (subdata->sub_uses_time ? 100. : sub_fps));
+ if (vo_sub) vo_sub_last = vo_sub;
+ // FIXME! frame counter...
+ sub_last_pts = pts;
+ }
+ }
+
+ // DVD sub:
+ if (vo_config_count && vo_spudec && type == 'v') {
+ int timestamp;
+ current_module = "spudec";
+ spudec_heartbeat(vo_spudec, 90000*sh_video->timer);
+ /* Get a sub packet from the DVD or a vobsub and make a timestamp
+ * relative to sh_video->timer */
+ while(1) {
+ // Vobsub
+ len = 0;
+ if (vo_vobsub) {
+ if (sh_video->pts+sub_delay >= 0) {
+ len = vobsub_get_packet(vo_vobsub, sh_video->pts+sub_delay,
+ (void**)&packet, &timestamp);
+ if (len > 0) {
+ timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
+ mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,sh_video->pts,sh_video->timer,timestamp / 90000.0,timestamp);
+ }
+ }
+ } else {
+ // DVD sub
+ len = ds_get_packet_sub(d_dvdsub, (unsigned char**)&packet);
+ if (len > 0) {
+ // XXX This is wrong, sh_video->pts can be arbitrarily
+ // much behind demuxing position. Unfortunately using
+ // d_video->pts which would have been the simplest
+ // improvement doesn't work because mpeg specific hacks
+ // in video.c set d_video->pts to 0.
+ float x = d_dvdsub->pts - sh_video->pts;
+ if (x > -20 && x < 20) // prevent missing subs on pts reset
+ timestamp = 90000*(sh_video->timer + d_dvdsub->pts
+ + sub_delay - sh_video->pts);
+ else timestamp = 90000*(sh_video->timer + sub_delay);
+ mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d "
+ "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len,
+ sh_video->pts, d_dvdsub->pts, timestamp);
+ }
+ }
+ if (len<=0 || !packet) break;
+ if (timestamp >= 0)
+ spudec_assemble(vo_spudec, packet, len, timestamp);
+ }
+
+ if (spudec_changed(vo_spudec))
+ vo_osd_changed(OSDTYPE_SPU);
+ } else if (dvdsub_id >= 0 && type == 't') {
+ double curpts = sh_video->pts + sub_delay;
+ double endpts;
+ vo_sub = &subs;
+ while (d_dvdsub->first) {
+ double pts = ds_get_next_pts(d_dvdsub);
+ if (pts > curpts)
+ break;
+ endpts = d_dvdsub->first->endpts;
+ len = ds_get_packet_sub(d_dvdsub, &packet);
+#ifdef USE_ASS
+ if (ass_enabled) {
+ static ass_track_t *global_ass_track = NULL;
+ if (!global_ass_track) global_ass_track = ass_default_track(ass_library);
+ ass_track = global_ass_track;
+ vo_sub = NULL;
+ if (pts != MP_NOPTS_VALUE) {
+ if (endpts == MP_NOPTS_VALUE) endpts = pts + 3;
+ sub_clear_text(&subs, MP_NOPTS_VALUE);
+ sub_add_text(&subs, packet, len, endpts);
+ subs.start = pts * 100;
+ subs.end = endpts * 100;
+ ass_process_subtitle(ass_track, &subs);
+ }
+ } else
+#endif
+ if (pts != MP_NOPTS_VALUE) {
+ if (endpts == MP_NOPTS_VALUE)
+ sub_clear_text(&subs, MP_NOPTS_VALUE);
+ sub_add_text(&subs, packet, len, endpts);
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+ }
+ if (sub_clear_text(&subs, curpts))
+ vo_osd_changed(OSDTYPE_SUBTITLE);
+ }
+ current_module=NULL;
+}
diff --git a/mpcommon.h b/mpcommon.h
new file mode 100644
index 0000000000..5b52297774
--- /dev/null
+++ b/mpcommon.h
@@ -0,0 +1,7 @@
+extern double sub_last_pts;
+#ifdef USE_ASS
+extern ass_track_t *ass_track;
+#endif
+extern sub_data *subdata;
+extern subtitle *vo_sub_last;
+void update_subtitles(sh_video_t *sh_video, demux_stream_t *d_dvdsub, int reset);
diff --git a/mplayer.c b/mplayer.c
index 0995f686da..097efd62b0 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -346,7 +346,6 @@ int suboverlap_enabled = 1;
sub_data* set_of_subtitles[MAX_SUBTITLE_FILES];
int set_of_sub_size = 0;
int set_of_sub_pos = -1;
-double sub_last_pts = -303;
int global_sub_size = 0; // this encompasses all subtitle sources
int global_sub_pos = -1; // this encompasses all subtitle sources
@@ -363,7 +362,6 @@ int global_sub_indices[SUB_SOURCES];
// set_of_ass_tracks[i] contains subtitles from set_of_subtitles[i] parsed by libass
// or NULL if format unsupported
ass_track_t* set_of_ass_tracks[MAX_SUBTITLE_FILES];
-ass_track_t* ass_track = 0; // current track to render
#endif
extern int mp_msg_levels[MSGT_MAX];
@@ -418,7 +416,7 @@ float begin_skip = MP_NOPTS_VALUE; ///< start time of the current skip while on
int use_filedir_conf;
static unsigned int inited_flags=0;
-static void update_subtitles(int reset);
+#include "mpcommon.h"
#define INITED_VO 1
#define INITED_AO 2
#define INITED_GUI 4
@@ -967,9 +965,6 @@ int sub_source(void)
return source;
}
-sub_data* subdata = NULL;
-static subtitle* vo_sub_last = NULL;
-
void add_subtitles(char *filename, float fps, int silent)
{
sub_data *subd;
@@ -2403,7 +2398,7 @@ static int mp_property_sub(m_option_t* prop,int action,void* arg) {
d_dvdsub->id = dvdsub_id;
}
#endif
- update_subtitles(1);
+ update_subtitles(sh_video, d_dvdsub, 1);
return M_PROPERTY_OK;
}
@@ -2890,126 +2885,6 @@ static double playing_audio_pts(sh_audio_t *sh_audio, demux_stream_t *d_audio,
audio_out->get_delay();
}
-static void update_subtitles(int reset)
-{
- unsigned char *packet=NULL;
- int len;
- char type = d_dvdsub->sh ? ((sh_sub_t *)d_dvdsub->sh)->type : 'v';
- static subtitle subs;
- if (type == 'a')
-#ifdef USE_ASS
- if (!ass_enabled)
-#endif
- type = 't';
- if (reset) {
- sub_clear_text(&subs, MP_NOPTS_VALUE);
- if (vo_sub) {
- vo_sub = NULL;
- vo_osd_changed(OSDTYPE_SUBTITLE);
- }
- if (vo_spudec) {
- spudec_reset(vo_spudec);
- vo_osd_changed(OSDTYPE_SPU);
- }
- }
- // find sub
- if (subdata) {
- double pts = sh_video->pts;
- if (sub_fps==0) sub_fps = sh_video->fps;
- current_module = "find_sub";
- if (pts > sub_last_pts || pts < sub_last_pts-1.0) {
- find_sub(subdata, (pts+sub_delay) *
- (subdata->sub_uses_time ? 100. : sub_fps));
- if (vo_sub) vo_sub_last = vo_sub;
- // FIXME! frame counter...
- sub_last_pts = pts;
- }
- }
-
- // DVD sub:
- if (vo_config_count && vo_spudec && type == 'v') {
- int timestamp;
- current_module = "spudec";
- spudec_heartbeat(vo_spudec, 90000*sh_video->timer);
- /* Get a sub packet from the DVD or a vobsub and make a timestamp
- * relative to sh_video->timer */
- while(1) {
- // Vobsub
- len = 0;
- if (vo_vobsub) {
- if (sh_video->pts+sub_delay >= 0) {
- len = vobsub_get_packet(vo_vobsub, sh_video->pts+sub_delay,
- (void**)&packet, &timestamp);
- if (len > 0) {
- timestamp -= (sh_video->pts + sub_delay - sh_video->timer)*90000;
- mp_dbg(MSGT_CPLAYER,MSGL_V,"\rVOB sub: len=%d v_pts=%5.3f v_timer=%5.3f sub=%5.3f ts=%d \n",len,sh_video->pts,sh_video->timer,timestamp / 90000.0,timestamp);
- }
- }
- } else {
- // DVD sub
- len = ds_get_packet_sub(d_dvdsub, (unsigned char**)&packet);
- if (len > 0) {
- // XXX This is wrong, sh_video->pts can be arbitrarily
- // much behind demuxing position. Unfortunately using
- // d_video->pts which would have been the simplest
- // improvement doesn't work because mpeg specific hacks
- // in video.c set d_video->pts to 0.
- float x = d_dvdsub->pts - sh_video->pts;
- if (x > -20 && x < 20) // prevent missing subs on pts reset
- timestamp = 90000*(sh_video->timer + d_dvdsub->pts
- + sub_delay - sh_video->pts);
- else timestamp = 90000*(sh_video->timer + sub_delay);
- mp_dbg(MSGT_CPLAYER, MSGL_V, "\rDVD sub: len=%d "
- "v_pts=%5.3f s_pts=%5.3f ts=%d \n", len,
- sh_video->pts, d_dvdsub->pts, timestamp);
- }
- }
- if (len<=0 || !packet) break;
- if (timestamp >= 0)
- spudec_assemble(vo_spudec, packet, len, timestamp);
- }
-
- if (spudec_changed(vo_spudec))
- vo_osd_changed(OSDTYPE_SPU);
- } else if (dvdsub_id >= 0 && type == 't') {
- double curpts = sh_video->pts + sub_delay;
- double endpts;
- vo_sub = &subs;
- while (d_dvdsub->first) {
- double pts = ds_get_next_pts(d_dvdsub);
- if (pts > curpts)
- break;
- endpts = d_dvdsub->first->endpts;
- len = ds_get_packet_sub(d_dvdsub, &packet);
-#ifdef USE_ASS
- if (ass_enabled) {
- static ass_track_t *global_ass_track = NULL;
- if (!global_ass_track) global_ass_track = ass_default_track(ass_library);
- ass_track = global_ass_track;
- vo_sub = NULL;
- if (pts != MP_NOPTS_VALUE) {
- if (endpts == MP_NOPTS_VALUE) endpts = pts + 3;
- sub_clear_text(&subs, MP_NOPTS_VALUE);
- sub_add_text(&subs, packet, len, endpts);
- subs.start = pts * 100;
- subs.end = endpts * 100;
- ass_process_subtitle(ass_track, &subs);
- }
- } else
-#endif
- if (pts != MP_NOPTS_VALUE) {
- if (endpts == MP_NOPTS_VALUE)
- sub_clear_text(&subs, MP_NOPTS_VALUE);
- sub_add_text(&subs, packet, len, endpts);
- vo_osd_changed(OSDTYPE_SUBTITLE);
- }
- }
- if (sub_clear_text(&subs, curpts))
- vo_osd_changed(OSDTYPE_SUBTITLE);
- }
- current_module=NULL;
-}
-
static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
{
unsigned char *start;
@@ -3039,7 +2914,7 @@ static int generate_video_frame(sh_video_t *sh_video, demux_stream_t *d_video)
current_module = "decode video";
decoded_frame = decode_video(sh_video, start, in_size, 0, pts);
if (decoded_frame) {
- update_subtitles(0);
+ update_subtitles(sh_video, d_dvdsub, 0);
update_osd_msg();
current_module = "filter video";
if (filter_video(sh_video, decoded_frame, sh_video->pts))
@@ -3469,7 +3344,7 @@ static double update_video(int *blit_frame)
drop_frame = dropped_frames = 0;
++total_frame_cnt;
}
- update_subtitles(0);
+ update_subtitles(sh_video, d_dvdsub, 0);
update_osd_msg();
current_module = "decode_video";
decoded_frame = decode_video(sh_video, start, in_size, drop_frame,
@@ -5636,7 +5511,7 @@ if(rel_seek_secs || abs_seek_pos){
audio_time_usage=0; video_time_usage=0; vout_time_usage=0;
drop_frame_cnt=0;
- update_subtitles(1);
+ update_subtitles(sh_video, d_dvdsub, 1);
}
}
/*