New upstream version 26.0.0+dfsg1
This commit is contained in:
parent
8e020cdacb
commit
240080891f
837 changed files with 41275 additions and 9196 deletions
10
deps/media-playback/CMakeLists.txt
vendored
10
deps/media-playback/CMakeLists.txt
vendored
|
|
@ -31,13 +31,9 @@ target_include_directories(media-playback
|
|||
PUBLIC .
|
||||
)
|
||||
|
||||
|
||||
if(NOT MSVC)
|
||||
if(NOT MINGW)
|
||||
target_compile_options(media-playback PRIVATE -fPIC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_link_libraries(media-playback
|
||||
${FFMPEG_LIBRARIES}
|
||||
)
|
||||
set_target_properties(media-playback PROPERTIES
|
||||
FOLDER "deps"
|
||||
POSITION_INDEPENDENT_CODE ON)
|
||||
|
|
|
|||
|
|
@ -21,7 +21,18 @@ static enum AVPixelFormat closest_format(enum AVPixelFormat fmt)
|
|||
switch (fmt) {
|
||||
case AV_PIX_FMT_YUYV422:
|
||||
return AV_PIX_FMT_YUYV422;
|
||||
|
||||
case AV_PIX_FMT_YUV444P:
|
||||
case AV_PIX_FMT_YUV444P16LE:
|
||||
case AV_PIX_FMT_YUV444P16BE:
|
||||
case AV_PIX_FMT_YUV444P9BE:
|
||||
case AV_PIX_FMT_YUV444P9LE:
|
||||
case AV_PIX_FMT_YUV444P10BE:
|
||||
case AV_PIX_FMT_YUV444P10LE:
|
||||
case AV_PIX_FMT_YUV444P12BE:
|
||||
case AV_PIX_FMT_YUV444P12LE:
|
||||
case AV_PIX_FMT_YUV444P14BE:
|
||||
case AV_PIX_FMT_YUV444P14LE:
|
||||
return AV_PIX_FMT_YUV444P;
|
||||
|
||||
case AV_PIX_FMT_YUV422P:
|
||||
|
|
@ -68,6 +79,16 @@ static enum AVPixelFormat closest_format(enum AVPixelFormat fmt)
|
|||
return AV_PIX_FMT_YUVA422P;
|
||||
|
||||
case AV_PIX_FMT_YUVA444P:
|
||||
case AV_PIX_FMT_YUVA444P9BE:
|
||||
case AV_PIX_FMT_YUVA444P9LE:
|
||||
case AV_PIX_FMT_YUVA444P10BE:
|
||||
case AV_PIX_FMT_YUVA444P10LE:
|
||||
case AV_PIX_FMT_YUVA444P16BE:
|
||||
case AV_PIX_FMT_YUVA444P16LE:
|
||||
#if LIBAVUTIL_BUILD >= AV_VERSION_INT(56, 31, 100)
|
||||
case AV_PIX_FMT_YUVA444P12BE:
|
||||
case AV_PIX_FMT_YUVA444P12LE:
|
||||
#endif
|
||||
return AV_PIX_FMT_YUVA444P;
|
||||
|
||||
case AV_PIX_FMT_RGBA:
|
||||
|
|
|
|||
6
deps/media-playback/media-playback/decode.h
vendored
6
deps/media-playback/media-playback/decode.h
vendored
|
|
@ -44,12 +44,6 @@ extern "C" {
|
|||
#define CODEC_FLAG_TRUNC CODEC_FLAG_TRUNCATED
|
||||
#endif
|
||||
|
||||
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(54, 31, 100)
|
||||
#define AV_PIX_FMT_VDTOOL AV_PIX_FMT_VIDEOTOOLBOX
|
||||
#else
|
||||
#define AV_PIX_FMT_VDTOOL AV_PIX_FMT_VDA_VLD
|
||||
#endif
|
||||
|
||||
struct mp_media;
|
||||
|
||||
struct mp_decode {
|
||||
|
|
|
|||
91
deps/media-playback/media-playback/media.c
vendored
91
deps/media-playback/media-playback/media.c
vendored
|
|
@ -109,9 +109,21 @@ static inline enum speaker_layout convert_speaker_layout(uint8_t channels)
|
|||
}
|
||||
}
|
||||
|
||||
static inline enum video_colorspace convert_color_space(enum AVColorSpace s)
|
||||
static inline enum video_colorspace
|
||||
convert_color_space(enum AVColorSpace s, enum AVColorTransferCharacteristic trc)
|
||||
{
|
||||
return s == AVCOL_SPC_BT709 ? VIDEO_CS_709 : VIDEO_CS_DEFAULT;
|
||||
switch (s) {
|
||||
case AVCOL_SPC_BT709:
|
||||
return (trc == AVCOL_TRC_IEC61966_2_1) ? VIDEO_CS_SRGB
|
||||
: VIDEO_CS_709;
|
||||
case AVCOL_SPC_FCC:
|
||||
case AVCOL_SPC_BT470BG:
|
||||
case AVCOL_SPC_SMPTE170M:
|
||||
case AVCOL_SPC_SMPTE240M:
|
||||
return VIDEO_CS_601;
|
||||
default:
|
||||
return VIDEO_CS_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
static inline enum video_range_type convert_color_range(enum AVColorRange r)
|
||||
|
|
@ -205,7 +217,7 @@ static bool mp_media_init_scaling(mp_media_t *m)
|
|||
m->v.decoder->pix_fmt,
|
||||
m->v.decoder->width,
|
||||
m->v.decoder->height, m->scale_format,
|
||||
SWS_FAST_BILINEAR, NULL, NULL, NULL);
|
||||
SWS_POINT, NULL, NULL, NULL);
|
||||
if (!m->swscale) {
|
||||
blog(LOG_WARNING, "MP: Failed to initialize scaler");
|
||||
return false;
|
||||
|
|
@ -216,7 +228,7 @@ static bool mp_media_init_scaling(mp_media_t *m)
|
|||
|
||||
int ret = av_image_alloc(m->scale_pic, m->scale_linesizes,
|
||||
m->v.decoder->width, m->v.decoder->height,
|
||||
m->scale_format, 1);
|
||||
m->scale_format, 32);
|
||||
if (ret < 0) {
|
||||
blog(LOG_WARNING, "MP: Failed to create scale pic data");
|
||||
return false;
|
||||
|
|
@ -227,13 +239,20 @@ static bool mp_media_init_scaling(mp_media_t *m)
|
|||
|
||||
static bool mp_media_prepare_frames(mp_media_t *m)
|
||||
{
|
||||
bool actively_seeking = m->seek_next_ts && m->pause;
|
||||
|
||||
while (!mp_media_ready_to_start(m)) {
|
||||
if (!m->eof) {
|
||||
int ret = mp_media_next_packet(m);
|
||||
if (ret == AVERROR_EOF || ret == AVERROR_EXIT)
|
||||
m->eof = true;
|
||||
else if (ret < 0)
|
||||
if (ret == AVERROR_EOF || ret == AVERROR_EXIT) {
|
||||
if (!actively_seeking) {
|
||||
m->eof = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if (ret < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (m->has_video && !mp_decode_frame(&m->v))
|
||||
|
|
@ -365,7 +384,7 @@ static void mp_media_next_video(mp_media_t *m, bool preload)
|
|||
frame->data[0] -= frame->linesize[0] * (f->height - 1);
|
||||
|
||||
new_format = convert_pixel_format(m->scale_format);
|
||||
new_space = convert_color_space(f->colorspace);
|
||||
new_space = convert_color_space(f->colorspace, f->color_trc);
|
||||
new_range = m->force_range == VIDEO_RANGE_DEFAULT
|
||||
? convert_color_range(f->color_range)
|
||||
: m->force_range;
|
||||
|
|
@ -409,23 +428,34 @@ static void mp_media_next_video(mp_media_t *m, bool preload)
|
|||
d->got_first_keyframe = true;
|
||||
}
|
||||
|
||||
if (preload)
|
||||
m->v_preload_cb(m->opaque, frame);
|
||||
else
|
||||
if (preload) {
|
||||
if (m->seek_next_ts && m->v_seek_cb) {
|
||||
m->v_seek_cb(m->opaque, frame);
|
||||
} else {
|
||||
m->v_preload_cb(m->opaque, frame);
|
||||
}
|
||||
} else {
|
||||
m->v_cb(m->opaque, frame);
|
||||
}
|
||||
}
|
||||
|
||||
static void mp_media_calc_next_ns(mp_media_t *m)
|
||||
{
|
||||
int64_t min_next_ns = mp_media_get_next_min_pts(m);
|
||||
int64_t delta = min_next_ns - m->next_pts_ns;
|
||||
|
||||
if (m->seek_next_ts) {
|
||||
delta = 0;
|
||||
m->seek_next_ts = false;
|
||||
} else {
|
||||
#ifdef _DEBUG
|
||||
assert(delta >= 0);
|
||||
assert(delta >= 0);
|
||||
#endif
|
||||
if (delta < 0)
|
||||
delta = 0;
|
||||
if (delta > 3000000000)
|
||||
delta = 0;
|
||||
if (delta < 0)
|
||||
delta = 0;
|
||||
if (delta > 3000000000)
|
||||
delta = 0;
|
||||
}
|
||||
|
||||
m->next_ns += delta;
|
||||
m->next_pts_ns = min_next_ns;
|
||||
|
|
@ -455,8 +485,12 @@ static void seek_to(mp_media_t *m, int64_t pos)
|
|||
}
|
||||
}
|
||||
|
||||
if (m->has_video && m->is_local_file)
|
||||
if (m->has_video && m->is_local_file) {
|
||||
mp_decode_flush(&m->v);
|
||||
if (m->seek_next_ts && m->pause && m->v_preload_cb &&
|
||||
mp_media_prepare_frames(m))
|
||||
mp_media_next_video(m, true);
|
||||
}
|
||||
if (m->has_audio && m->is_local_file)
|
||||
mp_decode_flush(&m->a);
|
||||
}
|
||||
|
|
@ -473,6 +507,7 @@ static bool mp_media_reset(mp_media_t *m)
|
|||
|
||||
m->eof = false;
|
||||
m->base_ts += next_ts;
|
||||
m->seek_next_ts = false;
|
||||
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
stopping = m->stopping;
|
||||
|
|
@ -583,7 +618,11 @@ static bool init_avformat(mp_media_t *m)
|
|||
av_dict_set_int(&opts, "buffer_size", m->buffering, 0);
|
||||
|
||||
m->fmt = avformat_alloc_context();
|
||||
if (m->buffering == 0) {
|
||||
m->fmt->flags |= AVFMT_FLAG_NOBUFFER;
|
||||
}
|
||||
if (!m->is_local_file) {
|
||||
av_dict_set(&opts, "stimeout", "30000000", 0);
|
||||
m->fmt->interrupt_callback.callback = interrupt_callback;
|
||||
m->fmt->interrupt_callback.opaque = m;
|
||||
}
|
||||
|
|
@ -593,7 +632,9 @@ static bool init_avformat(mp_media_t *m)
|
|||
av_dict_free(&opts);
|
||||
|
||||
if (ret < 0) {
|
||||
blog(LOG_WARNING, "MP: Failed to open media: '%s'", m->path);
|
||||
if (!m->reconnecting)
|
||||
blog(LOG_WARNING, "MP: Failed to open media: '%s'",
|
||||
m->path);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -603,6 +644,7 @@ static bool init_avformat(mp_media_t *m)
|
|||
return false;
|
||||
}
|
||||
|
||||
m->reconnecting = false;
|
||||
m->has_video = mp_decode_init(m, AVMEDIA_TYPE_VIDEO, m->hw);
|
||||
m->has_audio = mp_decode_init(m, AVMEDIA_TYPE_AUDIO, m->hw);
|
||||
|
||||
|
|
@ -643,11 +685,14 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
is_active = m->active;
|
||||
pause = m->pause;
|
||||
pthread_mutex_unlock(&m->mutex);
|
||||
|
||||
if (!is_active) {
|
||||
if (!is_active || pause) {
|
||||
if (os_sem_wait(m->sem) < 0)
|
||||
return false;
|
||||
if (pause)
|
||||
reset_ts(m);
|
||||
} else {
|
||||
timeout = mp_media_sleepto(m);
|
||||
}
|
||||
|
|
@ -677,6 +722,7 @@ static inline bool mp_media_thread(mp_media_t *m)
|
|||
}
|
||||
|
||||
if (seek) {
|
||||
m->seek_next_ts = true;
|
||||
seek_to(m, seek_pos);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -754,6 +800,7 @@ bool mp_media_init(mp_media_t *media, const struct mp_media_info *info)
|
|||
media->v_cb = info->v_cb;
|
||||
media->a_cb = info->a_cb;
|
||||
media->stop_cb = info->stop_cb;
|
||||
media->v_seek_cb = info->v_seek_cb;
|
||||
media->v_preload_cb = info->v_preload_cb;
|
||||
media->force_range = info->force_range;
|
||||
media->buffering = info->buffering;
|
||||
|
|
@ -817,7 +864,7 @@ void mp_media_free(mp_media_t *media)
|
|||
pthread_mutex_init_value(&media->mutex);
|
||||
}
|
||||
|
||||
void mp_media_play(mp_media_t *m, bool loop)
|
||||
void mp_media_play(mp_media_t *m, bool loop, bool reconnecting)
|
||||
{
|
||||
pthread_mutex_lock(&m->mutex);
|
||||
|
||||
|
|
@ -826,6 +873,7 @@ void mp_media_play(mp_media_t *m, bool loop)
|
|||
|
||||
m->looping = loop;
|
||||
m->active = true;
|
||||
m->reconnecting = reconnecting;
|
||||
|
||||
pthread_mutex_unlock(&m->mutex);
|
||||
|
||||
|
|
@ -859,8 +907,7 @@ void mp_media_stop(mp_media_t *m)
|
|||
|
||||
int64_t mp_get_current_time(mp_media_t *m)
|
||||
{
|
||||
int speed = (int)((float)m->speed / 100.0f);
|
||||
return (mp_media_get_base_pts(m) / 1000000) * speed;
|
||||
return mp_media_get_base_pts(m) * (int64_t)m->speed / 100000000LL;
|
||||
}
|
||||
|
||||
void mp_media_seek_to(mp_media_t *m, int64_t pos)
|
||||
|
|
|
|||
7
deps/media-playback/media-playback/media.h
vendored
7
deps/media-playback/media-playback/media.h
vendored
|
|
@ -46,6 +46,7 @@ struct mp_media {
|
|||
AVFormatContext *fmt;
|
||||
|
||||
mp_video_cb v_preload_cb;
|
||||
mp_video_cb v_seek_cb;
|
||||
mp_stop_cb stop_cb;
|
||||
mp_video_cb v_cb;
|
||||
mp_audio_cb a_cb;
|
||||
|
|
@ -64,6 +65,7 @@ struct mp_media {
|
|||
struct mp_decode v;
|
||||
struct mp_decode a;
|
||||
bool is_local_file;
|
||||
bool reconnecting;
|
||||
bool has_video;
|
||||
bool has_audio;
|
||||
bool is_file;
|
||||
|
|
@ -97,6 +99,7 @@ struct mp_media {
|
|||
bool pause;
|
||||
bool reset_ts;
|
||||
bool seek;
|
||||
bool seek_next_ts;
|
||||
int64_t seek_pos;
|
||||
};
|
||||
|
||||
|
|
@ -107,6 +110,7 @@ struct mp_media_info {
|
|||
|
||||
mp_video_cb v_cb;
|
||||
mp_video_cb v_preload_cb;
|
||||
mp_video_cb v_seek_cb;
|
||||
mp_audio_cb a_cb;
|
||||
mp_stop_cb stop_cb;
|
||||
|
||||
|
|
@ -117,12 +121,13 @@ struct mp_media_info {
|
|||
enum video_range_type force_range;
|
||||
bool hardware_decoding;
|
||||
bool is_local_file;
|
||||
bool reconnecting;
|
||||
};
|
||||
|
||||
extern bool mp_media_init(mp_media_t *media, const struct mp_media_info *info);
|
||||
extern void mp_media_free(mp_media_t *media);
|
||||
|
||||
extern void mp_media_play(mp_media_t *media, bool loop);
|
||||
extern void mp_media_play(mp_media_t *media, bool loop, bool reconnecting);
|
||||
extern void mp_media_stop(mp_media_t *media);
|
||||
extern void mp_media_play_pause(mp_media_t *media, bool pause);
|
||||
extern int64_t mp_get_current_time(mp_media_t *m);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue