2
* This file is part of MPlayer.
4
* MPlayer is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* MPlayer is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27
#include "osdep/timer.h"
29
#include "common/msg.h"
30
#include "options/options.h"
31
#include "options/m_property.h"
32
#include "common/common.h"
33
#include "common/encode.h"
34
#include "common/playlist.h"
35
#include "input/input.h"
37
#include "audio/out/ao.h"
38
#include "demux/demux.h"
39
#include "stream/stream.h"
40
#include "video/out/vo.h"
45
double get_relative_time(struct MPContext *mpctx)
47
int64_t new_time = mp_time_us();
48
int64_t delta = new_time - mpctx->last_time;
49
mpctx->last_time = new_time;
50
return delta * 0.000001;
53
double rel_time_to_abs(struct MPContext *mpctx, struct m_rel_time t,
56
double length = get_time_length(mpctx);
58
case REL_TIME_ABSOLUTE:
60
case REL_TIME_NEGATIVE:
62
return MPMAX(length - t.pos, 0.0);
64
case REL_TIME_PERCENT:
66
return length * (t.pos / 100.0);
68
case REL_TIME_CHAPTER:
69
if (chapter_start_time(mpctx, t.pos) >= 0)
70
return chapter_start_time(mpctx, t.pos);
76
double get_play_end_pts(struct MPContext *mpctx)
78
struct MPOpts *opts = mpctx->opts;
79
if (opts->play_end.type) {
80
return rel_time_to_abs(mpctx, opts->play_end, MP_NOPTS_VALUE);
81
} else if (opts->play_length.type) {
82
double startpts = get_start_time(mpctx);
83
double start = rel_time_to_abs(mpctx, opts->play_start, startpts);
84
double length = rel_time_to_abs(mpctx, opts->play_length, -1);
85
if (start != -1 && length != -1)
86
return start + length;
88
return MP_NOPTS_VALUE;
91
// Time used to seek external tracks to.
92
double get_main_demux_pts(struct MPContext *mpctx)
94
double main_new_pos = MP_NOPTS_VALUE;
96
for (int n = 0; n < mpctx->demuxer->num_streams; n++) {
97
if (main_new_pos == MP_NOPTS_VALUE)
98
main_new_pos = demux_get_next_pts(mpctx->demuxer->streams[n]);
104
double get_start_time(struct MPContext *mpctx)
106
struct demuxer *demuxer = mpctx->demuxer;
109
return demuxer_get_start_time(demuxer);
112
int mp_get_cache_percent(struct MPContext *mpctx)
117
stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_SIZE, &size);
118
stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_FILL, &fill);
119
if (size > 0 && fill >= 0)
120
return fill / (size / 100);
125
bool mp_get_cache_idle(struct MPContext *mpctx)
129
stream_control(mpctx->stream, STREAM_CTRL_GET_CACHE_IDLE, &idle);
133
void update_window_title(struct MPContext *mpctx, bool force)
135
if (!mpctx->video_out && !mpctx->ao) {
136
talloc_free(mpctx->last_window_title);
137
mpctx->last_window_title = false;
140
char *title = mp_property_expand_string(mpctx, mpctx->opts->wintitle);
141
if (!mpctx->last_window_title || force ||
142
strcmp(title, mpctx->last_window_title) != 0)
144
talloc_free(mpctx->last_window_title);
145
mpctx->last_window_title = talloc_steal(mpctx, title);
147
if (mpctx->video_out) {
148
mpctx->video_out->window_title = talloc_strdup(mpctx->video_out, title);
149
vo_control(mpctx->video_out, VOCTRL_UPDATE_WINDOW_TITLE, title);
153
ao_control(mpctx->ao, AOCONTROL_UPDATE_STREAM_TITLE, title);
160
void stream_dump(struct MPContext *mpctx)
162
struct MPOpts *opts = mpctx->opts;
163
char *filename = opts->stream_dump;
164
stream_t *stream = mpctx->stream;
165
assert(stream && filename);
167
stream_set_capture_file(stream, filename);
169
while (mpctx->stop_play == KEEP_PLAYING && !stream->eof) {
170
if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) {
171
uint64_t pos = stream->pos - stream->start_pos;
172
uint64_t end = stream->end_pos - stream->start_pos;
173
char *line = talloc_asprintf(NULL, "Dumping %lld/%lld...",
174
(long long int)pos, (long long int)end);
175
write_status_line(mpctx, line);
178
stream_fill_buffer(stream);
180
mp_cmd_t *cmd = mp_input_get_cmd(mpctx->input, 0, false);
183
run_command(mpctx, cmd);
189
void merge_playlist_files(struct playlist *pl)
193
char *edl = talloc_strdup(NULL, "edl://");
194
for (struct playlist_entry *e = pl->first; e; e = e->next) {
196
edl = talloc_strdup_append_buffer(edl, ";");
198
if (e->filename[strcspn(e->filename, "=%,;\n")] ||
199
bstr_strip(bstr0(e->filename)).len != strlen(e->filename))
202
edl = talloc_asprintf_append_buffer(edl, "%%%zd%%", strlen(e->filename));
204
edl = talloc_strdup_append_buffer(edl, e->filename);
207
playlist_add_file(pl, edl);