From 0112143fdaae0a6264d9e02355e9dc0ca4f7741c Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 Dec 2013 02:39:45 +0100 Subject: Split mpvcore/ into common/, misc/, bstr/ --- audio/audio.c | 2 +- audio/audio_buffer.c | 2 +- audio/chmap.c | 2 +- audio/chmap.h | 2 +- audio/decode/ad.h | 2 +- audio/decode/ad_lavc.c | 8 +- audio/decode/ad_mpg123.c | 2 +- audio/decode/ad_spdif.c | 4 +- audio/decode/dec_audio.c | 6 +- audio/filter/af.h | 2 +- audio/filter/af_center.c | 2 +- audio/filter/af_channels.c | 2 +- audio/filter/af_delay.c | 2 +- audio/filter/af_drc.c | 2 +- audio/filter/af_equalizer.c | 2 +- audio/filter/af_extrastereo.c | 2 +- audio/filter/af_lavfi.c | 2 +- audio/filter/af_lavrresample.c | 4 +- audio/filter/af_pan.c | 2 +- audio/filter/af_scaletempo.c | 2 +- audio/filter/af_sub.c | 2 +- audio/filter/af_volume.c | 2 +- audio/filter/tools.c | 2 +- audio/fmt-conversion.c | 2 +- audio/format.c | 2 +- audio/format.h | 2 +- audio/mixer.c | 2 +- audio/out/ao.c | 4 +- audio/out/ao.h | 4 +- audio/out/ao_alsa.c | 2 +- audio/out/ao_coreaudio.c | 4 +- audio/out/ao_coreaudio_utils.h | 2 +- audio/out/ao_dsound.c | 2 +- audio/out/ao_jack.c | 4 +- audio/out/ao_lavc.c | 6 +- audio/out/ao_null.c | 2 +- audio/out/ao_openal.c | 2 +- audio/out/ao_oss.c | 2 +- audio/out/ao_pcm.c | 2 +- audio/out/ao_portaudio.c | 4 +- audio/out/ao_pulse.c | 2 +- audio/out/ao_sdl.c | 2 +- audio/out/ao_sndio.c | 2 +- audio/out/ao_wasapi.c | 6 +- bstr/bstr.c | 385 ++++++++++++++ bstr/bstr.h | 200 +++++++ common/asxparser.c | 581 +++++++++++++++++++++ common/asxparser.h | 27 + common/av_common.c | 178 +++++++ common/av_common.h | 39 ++ common/av_log.c | 176 +++++++ common/av_log.h | 2 + common/av_opts.c | 55 ++ common/av_opts.h | 30 ++ common/codecs.c | 147 ++++++ common/codecs.h | 43 ++ common/common.c | 163 ++++++ common/common.h | 81 +++ common/cpudetect.c | 56 ++ common/cpudetect.h | 40 ++ common/encode.h | 21 + common/encode_lavc.c | 1115 ++++++++++++++++++++++++++++++++++++++++ common/encode_lavc.h | 101 ++++ common/global.h | 12 + common/msg.c | 389 ++++++++++++++ common/msg.h | 180 +++++++ common/playlist.c | 241 +++++++++ common/playlist.h | 82 +++ common/playlist_parser.c | 566 ++++++++++++++++++++ common/playlist_parser.h | 29 ++ common/version.c | 26 + compat/atomics.h | 23 + demux/codec_tags.c | 2 +- demux/demux.c | 4 +- demux/demux.h | 4 +- demux/demux_cue.c | 2 +- demux/demux_lavf.c | 8 +- demux/demux_libass.c | 4 +- demux/demux_mf.c | 2 +- demux/demux_mkv.c | 4 +- demux/demux_playlist.c | 6 +- demux/demux_subreader.c | 4 +- demux/ebml.c | 2 +- demux/ebml.h | 2 +- demux/mf.c | 2 +- demux/stheader.h | 2 +- input/input.c | 8 +- input/input.h | 2 +- input/joystick.c | 2 +- input/lirc.c | 2 +- misc/charset_conv.c | 287 +++++++++++ misc/charset_conv.h | 19 + misc/ring.c | 138 +++++ misc/ring.h | 108 ++++ mpvcore/asxparser.c | 581 --------------------- mpvcore/asxparser.h | 27 - mpvcore/av_common.c | 178 ------- mpvcore/av_common.h | 39 -- mpvcore/av_log.c | 176 ------- mpvcore/av_log.h | 2 - mpvcore/av_opts.c | 55 -- mpvcore/av_opts.h | 30 -- mpvcore/bstr.c | 385 -------------- mpvcore/bstr.h | 200 ------- mpvcore/charset_conv.c | 287 ----------- mpvcore/charset_conv.h | 19 - mpvcore/codecs.c | 147 ------ mpvcore/codecs.h | 43 -- mpvcore/cpudetect.c | 56 -- mpvcore/cpudetect.h | 40 -- mpvcore/encode.h | 21 - mpvcore/encode_lavc.c | 1115 ---------------------------------------- mpvcore/encode_lavc.h | 101 ---- mpvcore/mp_common.c | 163 ------ mpvcore/mp_common.h | 81 --- mpvcore/mp_memory_barrier.h | 23 - mpvcore/mp_msg.c | 389 -------------- mpvcore/mp_msg.h | 180 ------- mpvcore/mp_ring.c | 138 ----- mpvcore/mp_ring.h | 108 ---- mpvcore/mpv_global.h | 12 - mpvcore/playlist.c | 241 --------- mpvcore/playlist.h | 82 --- mpvcore/playlist_parser.c | 566 -------------------- mpvcore/playlist_parser.h | 29 -- mpvcore/version.c | 26 - old-makefile | 30 +- options/m_config.c | 2 +- options/m_config.h | 2 +- options/m_option.c | 4 +- options/m_option.h | 2 +- options/m_property.c | 4 +- options/parse_commandline.c | 6 +- options/parse_configfile.c | 2 +- options/path.c | 2 +- options/path.h | 2 +- osdep/getch2.c | 4 +- osdep/priority.c | 2 +- osdep/timer-darwin.c | 2 +- player/audio.c | 4 +- player/command.c | 6 +- player/configfiles.c | 4 +- player/core.h | 2 +- player/dvdnav.c | 4 +- player/loadfile.c | 8 +- player/lua.c | 6 +- player/main.c | 18 +- player/misc.c | 8 +- player/osd.c | 6 +- player/playloop.c | 8 +- player/screenshot.c | 4 +- player/sub.c | 4 +- player/timeline/tl_cue.c | 6 +- player/timeline/tl_matroska.c | 10 +- player/timeline/tl_mpv_edl.c | 6 +- player/video.c | 6 +- stream/ai_alsa1x.c | 2 +- stream/ai_oss.c | 2 +- stream/ai_sndio.c | 2 +- stream/audio_in.c | 2 +- stream/cache.c | 4 +- stream/cdinfo.c | 2 +- stream/cookies.c | 2 +- stream/dvb_tune.c | 2 +- stream/rar.c | 2 +- stream/resolve/resolve_quvi.c | 2 +- stream/resolve/resolve_quvi9.c | 4 +- stream/stream.c | 6 +- stream/stream.h | 4 +- stream/stream_bluray.c | 2 +- stream/stream_cdda.c | 2 +- stream/stream_dvd.c | 2 +- stream/stream_dvd_common.c | 2 +- stream/stream_dvdnav.c | 2 +- stream/stream_file.c | 2 +- stream/stream_lavf.c | 4 +- stream/stream_pvr.c | 2 +- stream/stream_radio.c | 2 +- stream/stream_rar.c | 2 +- stream/stream_smb.c | 2 +- stream/stream_vcd.c | 2 +- stream/tv.c | 2 +- stream/tvi_v4l2.c | 2 +- stream/vcd_read.h | 2 +- stream/vcd_read_darwin.h | 2 +- stream/vcd_read_fbsd.h | 2 +- stream/vcd_read_win32.h | 2 +- sub/ass_mp.c | 2 +- sub/dec_sub.c | 4 +- sub/draw_bmp.c | 2 +- sub/find_subfiles.c | 4 +- sub/osd.c | 4 +- sub/osd_libass.c | 4 +- sub/sd_ass.c | 4 +- sub/sd_lavc.c | 4 +- sub/sd_lavc_conv.c | 6 +- sub/sd_lavf_srt.c | 2 +- sub/sd_microdvd.c | 4 +- sub/sd_srt.c | 4 +- sub/spudec.c | 4 +- video/decode/dec_video.c | 4 +- video/decode/vaapi.c | 4 +- video/decode/vd_lavc.c | 10 +- video/decode/vda.c | 4 +- video/decode/vdpau.c | 4 +- video/filter/pullup.c | 4 +- video/filter/vf.c | 2 +- video/filter/vf.h | 2 +- video/filter/vf_crop.c | 2 +- video/filter/vf_delogo.c | 4 +- video/filter/vf_divtc.c | 4 +- video/filter/vf_dlopen.c | 2 +- video/filter/vf_dsize.c | 2 +- video/filter/vf_eq.c | 4 +- video/filter/vf_expand.c | 2 +- video/filter/vf_flip.c | 2 +- video/filter/vf_format.c | 2 +- video/filter/vf_gradfun.c | 2 +- video/filter/vf_hqdn3d.c | 2 +- video/filter/vf_ilpack.c | 4 +- video/filter/vf_lavfi.c | 4 +- video/filter/vf_lavfi.h | 2 +- video/filter/vf_mirror.c | 2 +- video/filter/vf_noformat.c | 2 +- video/filter/vf_noise.c | 4 +- video/filter/vf_phase.c | 2 +- video/filter/vf_pp.c | 4 +- video/filter/vf_pullup.c | 4 +- video/filter/vf_rotate.c | 2 +- video/filter/vf_scale.c | 2 +- video/filter/vf_softpulldown.c | 2 +- video/filter/vf_stereo3d.c | 2 +- video/filter/vf_sub.c | 2 +- video/filter/vf_swapuv.c | 2 +- video/filter/vf_unsharp.c | 4 +- video/filter/vf_yadif.c | 4 +- video/fmt-conversion.c | 2 +- video/img_format.h | 2 +- video/mp_image.h | 2 +- video/mp_image_pool.c | 2 +- video/out/aspect.c | 2 +- video/out/bitmap_packer.c | 4 +- video/out/gl_common.h | 4 +- video/out/gl_lcms.c | 6 +- video/out/gl_video.c | 2 +- video/out/vo.c | 6 +- video/out/vo.h | 2 +- video/out/vo_caca.c | 2 +- video/out/vo_direct3d.c | 2 +- video/out/vo_image.c | 4 +- video/out/vo_lavc.c | 4 +- video/out/vo_null.c | 2 +- video/out/vo_opengl.c | 6 +- video/out/vo_opengl_old.c | 2 +- video/out/vo_sdl.c | 2 +- video/out/vo_vaapi.c | 2 +- video/out/vo_vdpau.c | 2 +- video/out/vo_wayland.c | 2 +- video/out/vo_x11.c | 2 +- video/out/vo_xv.c | 2 +- video/out/w32_common.c | 4 +- video/out/wayland_common.c | 4 +- video/out/x11_common.c | 4 +- video/sws_utils.c | 4 +- video/vaapi.c | 4 +- video/vdpau.h | 2 +- wscript_build.py | 34 +- 267 files changed, 5898 insertions(+), 5894 deletions(-) create mode 100644 bstr/bstr.c create mode 100644 bstr/bstr.h create mode 100644 common/asxparser.c create mode 100644 common/asxparser.h create mode 100644 common/av_common.c create mode 100644 common/av_common.h create mode 100644 common/av_log.c create mode 100644 common/av_log.h create mode 100644 common/av_opts.c create mode 100644 common/av_opts.h create mode 100644 common/codecs.c create mode 100644 common/codecs.h create mode 100644 common/common.c create mode 100644 common/common.h create mode 100644 common/cpudetect.c create mode 100644 common/cpudetect.h create mode 100644 common/encode.h create mode 100644 common/encode_lavc.c create mode 100644 common/encode_lavc.h create mode 100644 common/global.h create mode 100644 common/msg.c create mode 100644 common/msg.h create mode 100644 common/playlist.c create mode 100644 common/playlist.h create mode 100644 common/playlist_parser.c create mode 100644 common/playlist_parser.h create mode 100644 common/version.c create mode 100644 compat/atomics.h create mode 100644 misc/charset_conv.c create mode 100644 misc/charset_conv.h create mode 100644 misc/ring.c create mode 100644 misc/ring.h delete mode 100644 mpvcore/asxparser.c delete mode 100644 mpvcore/asxparser.h delete mode 100644 mpvcore/av_common.c delete mode 100644 mpvcore/av_common.h delete mode 100644 mpvcore/av_log.c delete mode 100644 mpvcore/av_log.h delete mode 100644 mpvcore/av_opts.c delete mode 100644 mpvcore/av_opts.h delete mode 100644 mpvcore/bstr.c delete mode 100644 mpvcore/bstr.h delete mode 100644 mpvcore/charset_conv.c delete mode 100644 mpvcore/charset_conv.h delete mode 100644 mpvcore/codecs.c delete mode 100644 mpvcore/codecs.h delete mode 100644 mpvcore/cpudetect.c delete mode 100644 mpvcore/cpudetect.h delete mode 100644 mpvcore/encode.h delete mode 100644 mpvcore/encode_lavc.c delete mode 100644 mpvcore/encode_lavc.h delete mode 100644 mpvcore/mp_common.c delete mode 100644 mpvcore/mp_common.h delete mode 100644 mpvcore/mp_memory_barrier.h delete mode 100644 mpvcore/mp_msg.c delete mode 100644 mpvcore/mp_msg.h delete mode 100644 mpvcore/mp_ring.c delete mode 100644 mpvcore/mp_ring.h delete mode 100644 mpvcore/mpv_global.h delete mode 100644 mpvcore/playlist.c delete mode 100644 mpvcore/playlist.h delete mode 100644 mpvcore/playlist_parser.c delete mode 100644 mpvcore/playlist_parser.h delete mode 100644 mpvcore/version.c diff --git a/audio/audio.c b/audio/audio.c index a5cf52f5b3..950d25be75 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -20,7 +20,7 @@ #include #include "talloc.h" -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "audio.h" static void update_redundant_info(struct mp_audio *mpa) diff --git a/audio/audio_buffer.c b/audio/audio_buffer.c index 53563f90c6..2bd546a532 100644 --- a/audio/audio_buffer.c +++ b/audio/audio_buffer.c @@ -19,7 +19,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "audio_buffer.h" #include "audio.h" diff --git a/audio/chmap.c b/audio/chmap.c index 0e714f3c83..ce301b6565 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -18,7 +18,7 @@ #include #include -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "chmap.h" // Names taken from libavutil/channel_layout.c (Not accessible by API.) diff --git a/audio/chmap.h b/audio/chmap.h index cd6c49f716..ca1e6c2508 100644 --- a/audio/chmap.h +++ b/audio/chmap.h @@ -20,7 +20,7 @@ #include #include -#include "mpvcore/bstr.h" +#include "bstr/bstr.h" #define MP_NUM_CHANNELS 8 diff --git a/audio/decode/ad.h b/audio/decode/ad.h index 56f8944120..2ac9fb21f6 100644 --- a/audio/decode/ad.h +++ b/audio/decode/ad.h @@ -19,7 +19,7 @@ #ifndef MPLAYER_AD_H #define MPLAYER_AD_H -#include "mpvcore/codecs.h" +#include "common/codecs.h" #include "demux/stheader.h" #include "demux/demux.h" diff --git a/audio/decode/ad_lavc.c b/audio/decode/ad_lavc.c index 8b2c2d1727..9e1ba49fc1 100644 --- a/audio/decode/ad_lavc.c +++ b/audio/decode/ad_lavc.c @@ -29,11 +29,11 @@ #include "talloc.h" #include "config.h" -#include "mpvcore/av_common.h" -#include "mpvcore/codecs.h" -#include "mpvcore/mp_msg.h" +#include "common/av_common.h" +#include "common/codecs.h" +#include "common/msg.h" #include "options/options.h" -#include "mpvcore/av_opts.h" +#include "common/av_opts.h" #include "ad.h" #include "audio/fmt-conversion.h" diff --git a/audio/decode/ad_mpg123.c b/audio/decode/ad_mpg123.c index f65553bd77..57f84e136f 100644 --- a/audio/decode/ad_mpg123.c +++ b/audio/decode/ad_mpg123.c @@ -25,7 +25,7 @@ #include "config.h" #include "ad.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index fdc12772b8..5532d6b5a8 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -26,8 +26,8 @@ #include #include "config.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/av_common.h" +#include "common/msg.h" +#include "common/av_common.h" #include "options/options.h" #include "ad.h" diff --git a/audio/decode/dec_audio.c b/audio/decode/dec_audio.c index 1c34c6abe9..51966a7cc6 100644 --- a/audio/decode/dec_audio.c +++ b/audio/decode/dec_audio.c @@ -26,9 +26,9 @@ #include "demux/codec_tags.h" #include "config.h" -#include "mpvcore/codecs.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/bstr.h" +#include "common/codecs.h" +#include "common/msg.h" +#include "bstr/bstr.h" #include "stream/stream.h" #include "demux/demux.h" diff --git a/audio/filter/af.h b/audio/filter/af.h index 260d4dae7e..1e78c01718 100644 --- a/audio/filter/af.h +++ b/audio/filter/af.h @@ -29,7 +29,7 @@ #include "audio/format.h" #include "audio/chmap.h" #include "audio/audio.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" struct af_instance; diff --git a/audio/filter/af_center.c b/audio/filter/af_center.c index d1095e611c..2e626bffb6 100644 --- a/audio/filter/af_center.c +++ b/audio/filter/af_center.c @@ -29,7 +29,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" // Data for specific instances of this filter diff --git a/audio/filter/af_channels.c b/audio/filter/af_channels.c index 8edaa4285a..7bbf952ffe 100644 --- a/audio/filter/af_channels.c +++ b/audio/filter/af_channels.c @@ -27,7 +27,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" #define FR 0 diff --git a/audio/filter/af_delay.c b/audio/filter/af_delay.c index b2c03697fd..f29d065427 100644 --- a/audio/filter/af_delay.c +++ b/audio/filter/af_delay.c @@ -27,7 +27,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" #define L 65536 diff --git a/audio/filter/af_drc.c b/audio/filter/af_drc.c index 0edb99f469..fad34ba500 100644 --- a/audio/filter/af_drc.c +++ b/audio/filter/af_drc.c @@ -26,7 +26,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" // Methods: diff --git a/audio/filter/af_equalizer.c b/audio/filter/af_equalizer.c index c14fc8451d..7f79dab8ca 100644 --- a/audio/filter/af_equalizer.c +++ b/audio/filter/af_equalizer.c @@ -29,7 +29,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" #define L 2 // Storage for filter taps diff --git a/audio/filter/af_extrastereo.c b/audio/filter/af_extrastereo.c index 92cc4dd216..1e814e8351 100644 --- a/audio/filter/af_extrastereo.c +++ b/audio/filter/af_extrastereo.c @@ -26,7 +26,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" // Data for specific instances of this filter diff --git a/audio/filter/af_lavfi.c b/audio/filter/af_lavfi.c index e764d4fae8..6fee39afea 100644 --- a/audio/filter/af_lavfi.c +++ b/audio/filter/af_lavfi.c @@ -39,7 +39,7 @@ #include "af.h" #include "options/m_option.h" -#include "mpvcore/av_opts.h" +#include "common/av_opts.h" #define IS_LIBAV_FORK (LIBAVFILTER_VERSION_MICRO < 100) diff --git a/audio/filter/af_lavrresample.c b/audio/filter/af_lavrresample.c index 65d380e873..ee453cc1de 100644 --- a/audio/filter/af_lavrresample.c +++ b/audio/filter/af_lavrresample.c @@ -54,9 +54,9 @@ #error "config.h broken or no resampler found" #endif -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "options/m_option.h" -#include "mpvcore/av_opts.h" +#include "common/av_opts.h" #include "audio/filter/af.h" #include "audio/fmt-conversion.h" #include "audio/reorder_ch.h" diff --git a/audio/filter/af_pan.c b/audio/filter/af_pan.c index 800221e4bf..accea8026d 100644 --- a/audio/filter/af_pan.c +++ b/audio/filter/af_pan.c @@ -25,7 +25,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" // Data for specific instances of this filter diff --git a/audio/filter/af_scaletempo.c b/audio/filter/af_scaletempo.c index c54fe44e36..5b93914851 100644 --- a/audio/filter/af_scaletempo.c +++ b/audio/filter/af_scaletempo.c @@ -36,7 +36,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" #include "options/m_option.h" diff --git a/audio/filter/af_sub.c b/audio/filter/af_sub.c index ff88272b34..7012e1e129 100644 --- a/audio/filter/af_sub.c +++ b/audio/filter/af_sub.c @@ -32,7 +32,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" #include "dsp.h" diff --git a/audio/filter/af_volume.c b/audio/filter/af_volume.c index 06a1f7dd3c..6a27081b28 100644 --- a/audio/filter/af_volume.c +++ b/audio/filter/af_volume.c @@ -26,7 +26,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" struct priv { diff --git a/audio/filter/tools.c b/audio/filter/tools.c index c5f423ebf9..217224150e 100644 --- a/audio/filter/tools.c +++ b/audio/filter/tools.c @@ -19,7 +19,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "af.h" /* Convert to gain value from dB. Returns AF_OK if of and AF_ERROR if diff --git a/audio/fmt-conversion.c b/audio/fmt-conversion.c index da770a8eda..65f84945c1 100644 --- a/audio/fmt-conversion.c +++ b/audio/fmt-conversion.c @@ -16,7 +16,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include #include #include "format.h" diff --git a/audio/format.c b/audio/format.c index 1f6b0cac20..e343ca36db 100644 --- a/audio/format.c +++ b/audio/format.c @@ -25,7 +25,7 @@ #include #include -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "audio/filter/af.h" int af_fmt2bits(int format) diff --git a/audio/format.h b/audio/format.h index b318d4cdca..d21707e677 100644 --- a/audio/format.h +++ b/audio/format.h @@ -26,7 +26,7 @@ #include #include #include "config.h" -#include "mpvcore/bstr.h" +#include "bstr/bstr.h" #if BYTE_ORDER == BIG_ENDIAN #define AF_SELECT_LE_BE(LE, BE) BE diff --git a/audio/mixer.c b/audio/mixer.c index 0972b80533..b3ba9c3a58 100644 --- a/audio/mixer.c +++ b/audio/mixer.c @@ -24,7 +24,7 @@ #include "config.h" #include "audio/out/ao.h" #include "audio/filter/af.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "talloc.h" #include "mixer.h" diff --git a/audio/out/ao.c b/audio/out/ao.c index 6434949cd9..ddd177400d 100644 --- a/audio/out/ao.c +++ b/audio/out/ao.c @@ -29,8 +29,8 @@ #include "options/options.h" #include "options/m_config.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/mpv_global.h" +#include "common/msg.h" +#include "common/global.h" extern const struct ao_driver audio_out_oss; extern const struct ao_driver audio_out_coreaudio; diff --git a/audio/out/ao.h b/audio/out/ao.h index dff9ad6a8b..81737e094d 100644 --- a/audio/out/ao.h +++ b/audio/out/ao.h @@ -21,8 +21,8 @@ #include -#include "mpvcore/bstr.h" -#include "mpvcore/mp_common.h" +#include "bstr/bstr.h" +#include "common/common.h" #include "audio/chmap.h" #include "audio/chmap_sel.h" diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c index 372b490e9f..a65b9b05ec 100644 --- a/audio/out/ao_alsa.c +++ b/audio/out/ao_alsa.c @@ -38,7 +38,7 @@ #include "config.h" #include "options/options.h" #include "options/m_option.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #define ALSA_PCM_NEW_HW_PARAMS_API #define ALSA_PCM_NEW_SW_PARAMS_API diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c index 2fb7976c67..4a4091daf9 100644 --- a/audio/out/ao_coreaudio.c +++ b/audio/out/ao_coreaudio.c @@ -40,8 +40,8 @@ #include "audio/format.h" #include "osdep/timer.h" #include "options/m_option.h" -#include "mpvcore/mp_ring.h" -#include "mpvcore/mp_msg.h" +#include "misc/ring.h" +#include "common/msg.h" #include "audio/out/ao_coreaudio_properties.h" #include "audio/out/ao_coreaudio_utils.h" diff --git a/audio/out/ao_coreaudio_utils.h b/audio/out/ao_coreaudio_utils.h index 296f1d2497..cf69248b47 100644 --- a/audio/out/ao_coreaudio_utils.h +++ b/audio/out/ao_coreaudio_utils.h @@ -22,7 +22,7 @@ #include #include #include -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "audio/out/ao.h" #define CA_CFSTR_ENCODING kCFStringEncodingASCII diff --git a/audio/out/ao_dsound.c b/audio/out/ao_dsound.c index 1ace4093b4..26c7bb83ed 100644 --- a/audio/out/ao_dsound.c +++ b/audio/out/ao_dsound.c @@ -39,7 +39,7 @@ #include "audio/format.h" #include "ao.h" #include "audio/reorder_ch.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "osdep/timer.h" #include "options/m_option.h" diff --git a/audio/out/ao_jack.c b/audio/out/ao_jack.c index 8c54796e2b..f4cb5c475e 100644 --- a/audio/out/ao_jack.c +++ b/audio/out/ao_jack.c @@ -29,14 +29,14 @@ #include #include "config.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "ao.h" #include "audio/format.h" #include "osdep/timer.h" #include "options/m_option.h" -#include "mpvcore/mp_ring.h" +#include "misc/ring.h" #include diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index 713b952229..3e4ba01105 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -31,14 +31,14 @@ #include "compat/libav.h" #include "config.h" #include "options/options.h" -#include "mpvcore/mp_common.h" +#include "common/common.h" #include "audio/format.h" #include "audio/fmt-conversion.h" #include "talloc.h" #include "ao.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" -#include "mpvcore/encode_lavc.h" +#include "common/encode_lavc.h" struct priv { uint8_t *buffer; diff --git a/audio/out/ao_null.c b/audio/out/ao_null.c index 282511ae40..7c912d94a4 100644 --- a/audio/out/ao_null.c +++ b/audio/out/ao_null.c @@ -31,7 +31,7 @@ #include "config.h" #include "osdep/timer.h" #include "options/m_option.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "audio/format.h" #include "ao.h" diff --git a/audio/out/ao_openal.c b/audio/out/ao_openal.c index c6c2e9e8b8..d613b74208 100644 --- a/audio/out/ao_openal.c +++ b/audio/out/ao_openal.c @@ -35,7 +35,7 @@ #include #endif -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "ao.h" #include "audio/format.h" diff --git a/audio/out/ao_oss.c b/audio/out/ao_oss.c index 9ff7d1a165..574fcf6beb 100644 --- a/audio/out/ao_oss.c +++ b/audio/out/ao_oss.c @@ -36,7 +36,7 @@ #include "config.h" #include "options/options.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #if HAVE_SYS_SOUNDCARD_H #include diff --git a/audio/out/ao_pcm.c b/audio/out/ao_pcm.c index 2a086c549f..14548d3be3 100644 --- a/audio/out/ao_pcm.c +++ b/audio/out/ao_pcm.c @@ -34,7 +34,7 @@ #include "audio/format.h" #include "audio/reorder_ch.h" #include "ao.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #ifdef __MINGW32__ // for GetFileType to detect pipes diff --git a/audio/out/ao_portaudio.c b/audio/out/ao_portaudio.c index 6e3d9680fd..8b4efe7944 100644 --- a/audio/out/ao_portaudio.c +++ b/audio/out/ao_portaudio.c @@ -28,8 +28,8 @@ #include "config.h" #include "options/m_option.h" #include "audio/format.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/mp_ring.h" +#include "common/msg.h" +#include "misc/ring.h" #include "ao.h" struct priv { diff --git a/audio/out/ao_pulse.c b/audio/out/ao_pulse.c index 651589c34f..f3bce40574 100644 --- a/audio/out/ao_pulse.c +++ b/audio/out/ao_pulse.c @@ -28,7 +28,7 @@ #include "config.h" #include "audio/format.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "ao.h" #include "input/input.h" diff --git a/audio/out/ao_sdl.c b/audio/out/ao_sdl.c index dd2fb894be..ac1fd6febb 100644 --- a/audio/out/ao_sdl.c +++ b/audio/out/ao_sdl.c @@ -23,7 +23,7 @@ #include "audio/format.h" #include "talloc.h" #include "ao.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "options/m_option.h" #include "osdep/timer.h" diff --git a/audio/out/ao_sndio.c b/audio/out/ao_sndio.c index 6cf08cd095..75ea5d095b 100644 --- a/audio/out/ao_sndio.c +++ b/audio/out/ao_sndio.c @@ -23,7 +23,7 @@ #include #include "options/m_option.h" -#include "mpvcore/mp_msg.h" +#include "common/msg.h" #include "audio/format.h" #include "ao.h" diff --git a/audio/out/ao_wasapi.c b/audio/out/ao_wasapi.c index b2ac1f2343..d70b66a493 100644 --- a/audio/out/ao_wasapi.c +++ b/audio/out/ao_wasapi.c @@ -31,10 +31,10 @@ #include "config.h" #include "options/m_option.h" -#include "mpvcore/m_config.h" +#include "common/m_config.h" #include "audio/format.h" -#include "mpvcore/mp_msg.h" -#include "mpvcore/mp_ring.h" +#include "common/msg.h" +#include "common/mp_ring.h" #include "ao.h" #ifndef BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE diff --git a/bstr/bstr.c b/bstr/bstr.c new file mode 100644 index 0000000000..65ae928d31 --- /dev/null +++ b/bstr/bstr.c @@ -0,0 +1,385 @@ +/* + * 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 +#include +#include +#include + +#include + +#include "talloc.h" + +#include "bstr/bstr.h" + +int bstrcmp(struct bstr str1, struct bstr str2) +{ + int ret = memcmp(str1.start, str2.start, FFMIN(str1.len, str2.len)); + + if (!ret) { + if (str1.len == str2.len) + return 0; + else if (str1.len > str2.len) + return 1; + else + return -1; + } + return ret; +} + +int bstrcasecmp(struct bstr str1, struct bstr str2) +{ + int ret = strncasecmp(str1.start, str2.start, FFMIN(str1.len, str2.len)); + + if (!ret) { + if (str1.len == str2.len) + return 0; + else if (str1.len > str2.len) + return 1; + else + return -1; + } + return ret; +} + +int bstrchr(struct bstr str, int c) +{ + for (int i = 0; i < str.len; i++) + if (str.start[i] == c) + return i; + return -1; +} + +int bstrrchr(struct bstr str, int c) +{ + for (int i = str.len - 1; i >= 0; i--) + if (str.start[i] == c) + return i; + return -1; +} + +int bstrcspn(struct bstr str, const char *reject) +{ + int i; + for (i = 0; i < str.len; i++) + if (strchr(reject, str.start[i])) + break; + return i; +} + +int bstrspn(struct bstr str, const char *accept) +{ + int i; + for (i = 0; i < str.len; i++) + if (!strchr(accept, str.start[i])) + break; + return i; +} + +int bstr_find(struct bstr haystack, struct bstr needle) +{ + for (int i = 0; i < haystack.len; i++) + if (bstr_startswith(bstr_splice(haystack, i, haystack.len), needle)) + return i; + return -1; +} + +struct bstr bstr_lstrip(struct bstr str) +{ + while (str.len && isspace(*str.start)) { + str.start++; + str.len--; + } + return str; +} + +struct bstr bstr_strip(struct bstr str) +{ + str = bstr_lstrip(str); + while (str.len && isspace(str.start[str.len - 1])) + str.len--; + return str; +} + +struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest) +{ + int start; + for (start = 0; start < str.len; start++) + if (!strchr(sep, str.start[start])) + break; + str = bstr_cut(str, start); + int end = bstrcspn(str, sep); + if (rest) { + *rest = bstr_cut(str, end); + } + return bstr_splice(str, 0, end); +} + +// Unlike with bstr_split(), tok is a string, and not a set of char. +// If tok is in str, return true, and: concat(out_left, tok, out_right) == str +// Otherwise, return false, and set out_left==str, out_right=="" +bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right) +{ + bstr bsep = bstr0(tok); + int pos = bstr_find(str, bsep); + if (pos < 0) + pos = str.len; + *out_left = bstr_splice(str, 0, pos); + *out_right = bstr_cut(str, pos + bsep.len); + return pos != str.len; +} + +struct bstr bstr_splice(struct bstr str, int start, int end) +{ + if (start < 0) + start += str.len; + if (end < 0) + end += str.len; + end = FFMIN(end, str.len); + start = FFMAX(start, 0); + end = FFMAX(end, start); + str.start += start; + str.len = end - start; + return str; +} + +long long bstrtoll(struct bstr str, struct bstr *rest, int base) +{ + str = bstr_lstrip(str); + char buf[51]; + int len = FFMIN(str.len, 50); + memcpy(buf, str.start, len); + buf[len] = 0; + char *endptr; + long long r = strtoll(buf, &endptr, base); + if (rest) + *rest = bstr_cut(str, endptr - buf); + return r; +} + +double bstrtod(struct bstr str, struct bstr *rest) +{ + str = bstr_lstrip(str); + char buf[101]; + int len = FFMIN(str.len, 100); + memcpy(buf, str.start, len); + buf[len] = 0; + char *endptr; + double r = strtod(buf, &endptr); + if (rest) + *rest = bstr_cut(str, endptr - buf); + return r; +} + +struct bstr *bstr_splitlines(void *talloc_ctx, struct bstr str) +{ + if (str.len == 0) + return NULL; + int count = 0; + for (int i = 0; i < str.len; i++) + if (str.start[i] == '\n') + count++; + if (str.start[str.len - 1] != '\n') + count++; + struct bstr *r = talloc_array_ptrtype(talloc_ctx, r, count); + unsigned char *p = str.start; + for (int i = 0; i < count - 1; i++) { + r[i].start = p; + while (*p++ != '\n'); + r[i].len = p - r[i].start; + } + r[count - 1].start = p; + r[count - 1].len = str.start + str.len - p; + return r; +} + +struct bstr bstr_getline(struct bstr str, struct bstr *rest) +{ + int pos = bstrchr(str, '\n'); + if (pos < 0) + pos = str.len; + if (rest) + *rest = bstr_cut(str, pos + 1); + return bstr_splice(str, 0, pos + 1); +} + +struct bstr bstr_strip_linebreaks(struct bstr str) +{ + if (bstr_endswith0(str, "\r\n")) { + str = bstr_splice(str, 0, str.len - 2); + } else if (bstr_endswith0(str, "\n")) { + str = bstr_splice(str, 0, str.len - 1); + } + return str; +} + +bool bstr_eatstart(struct bstr *s, struct bstr prefix) +{ + if (!bstr_startswith(*s, prefix)) + return false; + *s = bstr_cut(*s, prefix.len); + return true; +} + +void bstr_lower(struct bstr str) +{ + for (int i = 0; i < str.len; i++) + str.start[i] = tolower(str.start[i]); +} + +int bstr_sscanf(struct bstr str, const char *format, ...) +{ + char *ptr = bstrdup0(NULL, str); + va_list va; + va_start(va, format); + int ret = vsscanf(ptr, format, va); + va_end(va); + talloc_free(ptr); + return ret; +} + +int bstr_parse_utf8_code_length(unsigned char b) +{ + if (b < 128) + return 1; + int bytes = 7 - av_log2(b ^ 255); + return (bytes >= 2 && bytes <= 4) ? bytes : -1; +} + +int bstr_decode_utf8(struct bstr s, struct bstr *out_next) +{ + if (s.len == 0) + return -1; + unsigned int codepoint = s.start[0]; + s.start++; s.len--; + if (codepoint >= 128) { + int bytes = bstr_parse_utf8_code_length(codepoint); + if (bytes < 0 || s.len < bytes - 1) + return -1; + codepoint &= 127 >> bytes; + for (int n = 1; n < bytes; n++) { + int tmp = (unsigned char)s.start[0]; + if ((tmp & 0xC0) != 0x80) + return -1; + codepoint = (codepoint << 6) | (tmp & ~0xC0); + s.start++; s.len--; + } + if (codepoint > 0x10FFFF || (codepoint >= 0xD800 && codepoint <= 0xDFFF)) + return -1; + // Overlong sequences - check taken from libavcodec. + // (The only reason we even bother with this is to make libavcodec's + // retarded subtitle utf-8 check happy.) + unsigned int min = bytes == 2 ? 0x80 : 1 << (5 * bytes - 4); + if (codepoint < min) + return -1; + } + if (out_next) + *out_next = s; + return codepoint; +} + +int bstr_validate_utf8(struct bstr s) +{ + while (s.len) { + if (bstr_decode_utf8(s, &s) < 0) { + // Try to guess whether the sequence was just cut-off. + unsigned int codepoint = (unsigned char)s.start[0]; + int bytes = bstr_parse_utf8_code_length(codepoint); + if (bytes > 1 && s.len < 6) { + // Manually check validity of left bytes + for (int n = 1; n < bytes; n++) { + if (n >= s.len) { + // Everything valid until now - just cut off. + return -(bytes - s.len); + } + int tmp = (unsigned char)s.start[n]; + if ((tmp & 0xC0) != 0x80) + break; + } + } + return -8; + } + } + return 0; +} + +static void append_bstr(bstr *buf, bstr s) +{ + buf->start = talloc_realloc(NULL, buf->start, unsigned char, buf->len + s.len); + memcpy(buf->start + buf->len, s.start, s.len); + buf->len += s.len; +} + +struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s) +{ + bstr new = {0}; + bstr left = s; + unsigned char *first_ok = s.start; + while (left.len) { + int r = bstr_decode_utf8(left, &left); + if (r < 0) { + append_bstr(&new, (bstr){first_ok, left.start - first_ok}); + uint32_t codepoint = (unsigned char)left.start[0]; + char data[8]; + uint8_t tmp; + char *output = data; + PUT_UTF8(codepoint, tmp, *output++ = tmp;); + append_bstr(&new, (bstr){data, output - data}); + left.start += 1; + left.len -= 1; + first_ok = left.start; + } + } + if (!new.start) + return s; + if (first_ok != left.start) + append_bstr(&new, (bstr){first_ok, left.start - first_ok}); + // For convenience + append_bstr(&new, (bstr){"\0", 1}); + new.len -= 1; + talloc_steal(talloc_ctx, new.start); + return new; +} + +bool bstr_case_startswith(struct bstr s, struct bstr prefix) +{ + struct bstr start = bstr_splice(s, 0, prefix.len); + return start.len == prefix.len && bstrcasecmp(start, prefix) == 0; +} + +bool bstr_case_endswith(struct bstr s, struct bstr suffix) +{ + struct bstr end = bstr_cut(s, -suffix.len); + return end.len == suffix.len && bstrcasecmp(end, suffix) == 0; +} + +struct bstr bstr_strip_ext(struct bstr str) +{ + int dotpos = bstrrchr(str, '.'); + if (dotpos < 0) + return str; + return (struct bstr){str.start, dotpos}; +} + +struct bstr bstr_get_ext(struct bstr s) +{ + int dotpos = bstrrchr(s, '.'); + if (dotpos < 0) + return (struct bstr){NULL, 0}; + return bstr_splice(s, dotpos + 1, s.len); +} diff --git a/bstr/bstr.h b/bstr/bstr.h new file mode 100644 index 0000000000..67e85655c4 --- /dev/null +++ b/bstr/bstr.h @@ -0,0 +1,200 @@ +/* + * 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. + */ + +#ifndef MPLAYER_BSTR_H +#define MPLAYER_BSTR_H + +#include +#include +#include +#include + +#include "talloc.h" + +/* NOTE: 'len' is size_t, but most string-handling functions below assume + * that input size has been sanity checked and len fits in an int. + */ +typedef struct bstr { + unsigned char *start; + size_t len; +} bstr; + +// If str.start is NULL, return NULL. +static inline char *bstrdup0(void *talloc_ctx, struct bstr str) +{ + return talloc_strndup(talloc_ctx, (char *)str.start, str.len); +} + +// Like bstrdup0(), but always return a valid C-string. +static inline char *bstrto0(void *talloc_ctx, struct bstr str) +{ + return str.start ? bstrdup0(talloc_ctx, str) : talloc_strdup(talloc_ctx, ""); +} + +// Return start = NULL iff that is true for the original. +static inline struct bstr bstrdup(void *talloc_ctx, struct bstr str) +{ + struct bstr r = { NULL, str.len }; + if (str.start) + r.start = (unsigned char *)talloc_memdup(talloc_ctx, str.start, str.len); + return r; +} + +static inline struct bstr bstr0(const char *s) +{ + return (struct bstr){(unsigned char *)s, s ? strlen(s) : 0}; +} + +int bstrcmp(struct bstr str1, struct bstr str2); +int bstrcasecmp(struct bstr str1, struct bstr str2); +int bstrchr(struct bstr str, int c); +int bstrrchr(struct bstr str, int c); +int bstrspn(struct bstr str, const char *accept); +int bstrcspn(struct bstr str, const char *reject); + +int bstr_find(struct bstr haystack, struct bstr needle); +struct bstr *bstr_splitlines(void *talloc_ctx, struct bstr str); +struct bstr bstr_lstrip(struct bstr str); +struct bstr bstr_strip(struct bstr str); +struct bstr bstr_split(struct bstr str, const char *sep, struct bstr *rest); +bool bstr_split_tok(bstr str, const char *tok, bstr *out_left, bstr *out_right); +struct bstr bstr_splice(struct bstr str, int start, int end); +long long bstrtoll(struct bstr str, struct bstr *rest, int base); +double bstrtod(struct bstr str, struct bstr *rest); +void bstr_lower(struct bstr str); +int bstr_sscanf(struct bstr str, const char *format, ...); + +// Decode the UTF-8 code point at the start of the string,, and return the +// character. +// After calling this function, *out_next will point to the next character. +// out_next can be NULL. +// On error, -1 is returned, and *out_next is not modified. +int bstr_decode_utf8(struct bstr str, struct bstr *out_next); + +// Return the length of the UTF-8 sequence that starts with the given byte. +// Given a string char *s, the next UTF-8 code point is to be expected at +// s + bstr_parse_utf8_code_length(s[0]) +// On error, -1 is returned. On success, it returns a value in the range [1, 4]. +int bstr_parse_utf8_code_length(unsigned char b); + +// Return >= 0 if the string is valid UTF-8, otherwise negative error code. +// Embedded \0 bytes are considered valid. +// This returns -N if the UTF-8 string was likely just cut-off in the middle of +// an UTF-8 sequence: -1 means 1 byte was missing, -5 5 bytes missing. +// If the string was likely not cut off, -8 is returned. +// Use (return_value > -8) to check whether the string is valid UTF-8 or valid +// but cut-off UTF-8. +int bstr_validate_utf8(struct bstr s); + +// Force the input string to valid UTF-8. If invalid UTF-8 encoding is +// encountered, the invalid bytes are interpreted as Latin-1. +// Embedded \0 bytes are considered valid. +// If replacement happens, a newly allocated string is returned (with a \0 +// byte added past its end for convenience). The string is allocated via +// talloc, with talloc_ctx as parent. +struct bstr bstr_sanitize_utf8_latin1(void *talloc_ctx, struct bstr s); + +// Return the text before the next line break, and return it. Change *rest to +// point to the text following this line break. (rest can be NULL.) +// Line break characters are not stripped. +struct bstr bstr_getline(struct bstr str, struct bstr *rest); + +// Strip one trailing line break. This is intended for use with bstr_getline, +// and will remove the trailing \n or \r\n sequence. +struct bstr bstr_strip_linebreaks(struct bstr str); + +// If s starts with prefix, return true and return the rest of the string in s. +bool bstr_eatstart(struct bstr *s, struct bstr prefix); + +bool bstr_case_startswith(struct bstr s, struct bstr prefix); +bool bstr_case_endswith(struct bstr s, struct bstr suffix); +struct bstr bstr_strip_ext(struct bstr str); +struct bstr bstr_get_ext(struct bstr s); + +static inline struct bstr bstr_cut(struct bstr str, int n) +{ + if (n < 0) { + n += str.len; + if (n < 0) + n = 0; + } + if (((size_t)n) > str.len) + n = str.len; + return (struct bstr){str.start + n, str.len - n}; +} + +static inline bool bstr_startswith(struct bstr str, struct bstr prefix) +{ + if (str.len < prefix.len) + return false; + return !memcmp(str.start, prefix.start, prefix.len); +} + +static inline bool bstr_startswith0(struct bstr str, const char *prefix) +{ + return bstr_startswith(str, bstr0(prefix)); +} + +static inline bool bstr_endswith(struct bstr str, struct bstr suffix) +{ + if (str.len < suffix.len) + return false; + return !memcmp(str.start + str.len - suffix.len, suffix.start, suffix.len); +} + +static inline bool bstr_endswith0(struct bstr str, const char *suffix) +{ + return bstr_endswith(str, bstr0(suffix)); +} + +static inline int bstrcmp0(struct bstr str1, const char *str2) +{ + return bstrcmp(str1, bstr0(str2)); +} + +static inline bool bstr_equals(struct bstr str1, struct bstr str2) +{ + return bstrcmp(str1, str2) == 0; +} + +static inline bool bstr_equals0(struct bstr str1, const char *str2) +{ + return bstrcmp(str1, bstr0(str2)) == 0; +} + +static inline int bstrcasecmp0(struct bstr str1, const char *str2) +{ + return bstrcasecmp(str1, bstr0(str2)); +} + +static inline int bstr_find0(struct bstr haystack, const char *needle) +{ + return bstr_find(haystack, bstr0(needle)); +} + +static inline int bstr_eatstart0(struct bstr *s, const char *prefix) +{ + return bstr_eatstart(s, bstr0(prefix)); +} + +// create a pair (not single value!) for "%.*s" printf syntax +#define BSTR_P(bstr) (int)((bstr).len), (bstr).start + +#define WHITESPACE " \f\n\r\t\v" + +#endif /* MPLAYER_BSTR_H */ diff --git a/common/asxparser.c b/common/asxparser.c new file mode 100644 index 0000000000..5b1d5652a3 --- /dev/null +++ b/common/asxparser.c @@ -0,0 +1,581 @@ +/* + * 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 "config.h" + +#include +#include +#include +#include +#include + +#include "playlist.h" +#include "playlist_parser.h" +#include "stream/stream.h" +#include "asxparser.h" +#include "common/msg.h" + + +typedef struct ASX_Parser_t ASX_Parser_t; + +typedef struct { + char* buffer; + int line; +} ASX_LineSave_t; + +struct ASX_Parser_t { + int line; // Curent line + ASX_LineSave_t *ret_stack; + int ret_stack_size; + char* last_body; + int deep; + struct playlist *pl; +}; + +ASX_Parser_t *asx_parser_new(struct playlist *pl); + +void +asx_parser_free(ASX_Parser_t* parser); + +/* + * Return -1 on error, 0 when nothing is found, 1 on sucess + */ +int +asx_get_element(ASX_Parser_t* parser,char** _buffer, + char** _element,char** _body,char*** _attribs); + +int +asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs); + +/////// Attribs utils + +char* +asx_get_attrib(const char* attrib,char** attribs); + +#define asx_free_attribs(a) asx_list_free(&a,free) + +////// List utils + +typedef void (*ASX_FreeFunc)(void* arg); + +void +asx_list_free(void* list_ptr,ASX_FreeFunc free_func); + + +////// List utils + +void +asx_list_free(void* list_ptr,ASX_FreeFunc free_func) { + void** ptr = *(void***)list_ptr; + if(ptr == NULL) return; + if(free_func != NULL) { + for( ; *ptr != NULL ; ptr++) + free_func(*ptr); + } + free(*(void**)list_ptr); + *(void**)list_ptr = NULL; +} + +/////// Attribs utils + +char* +asx_get_attrib(const char* attrib,char** attribs) { + char** ptr; + + if(attrib == NULL || attribs == NULL) return NULL; + for(ptr = attribs; ptr[0] != NULL; ptr += 2){ + if(strcasecmp(ptr[0],attrib) == 0) + return strdup(ptr[1]); + } + return NULL; +} + +#define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a) +#define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e) + +ASX_Parser_t *asx_parser_new(struct playlist *pl) +{ + ASX_Parser_t* parser = calloc(1,sizeof(ASX_Parser_t)); + parser->pl = pl; + return parser; +} + +void +asx_parser_free(ASX_Parser_t* parser) { + if(!parser) return; + free(parser->ret_stack); + free(parser); + +} + +#define LETTER "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" +#define SPACE " \n\t\r" + +int +asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) { + char *ptr1, *ptr2, *ptr3; + int n_attrib = 0; + char **attribs = NULL; + char *attrib, *val; + + ptr1 = buffer; + while(1) { + for( ; strchr(SPACE,*ptr1) != NULL; ptr1++) { // Skip space + if(*ptr1 == '\0') break; + } + ptr3 = strchr(ptr1,'='); + if(ptr3 == NULL) break; + for(ptr2 = ptr3-1; strchr(SPACE,*ptr2) != NULL; ptr2--) { + if (ptr2 == ptr1) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : this should never append, back to attribute begin while skipping end space",parser->line); + break; + } + } + attrib = malloc(ptr2-ptr1+2); + strncpy(attrib,ptr1,ptr2-ptr1+1); + attrib[ptr2-ptr1+1] = '\0'; + + ptr1 = strchr(ptr3,'"'); + if(ptr1 == NULL || ptr1[1] == '\0') ptr1 = strchr(ptr3,'\''); + if(ptr1 == NULL || ptr1[1] == '\0') { + mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : can't find attribute %s value",parser->line,attrib); + free(attrib); + break; + } + ptr2 = strchr(ptr1+1,ptr1[0]); + if (ptr2 == NULL) { + mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : value of attribute %s isn't finished",parser->line,attrib); + free(attrib); + break; + } + ptr1++; + val = malloc(ptr2-ptr1+1); + strncpy(val,ptr1,ptr2-ptr1); + val[ptr2-ptr1] = '\0'; + n_attrib++; + + attribs = realloc(attribs, (2 * n_attrib + 1) * sizeof(char*)); + attribs[n_attrib*2-2] = attrib; + attribs[n_attrib*2-1] = val; + + ptr1 = ptr2+1; + } + + if(n_attrib > 0) + attribs[n_attrib*2] = NULL; + + *_attribs = attribs; + + return n_attrib; +} + +/* + * Return -1 on error, 0 when nothing is found, 1 on sucess + */ +int +asx_get_element(ASX_Parser_t* parser,char** _buffer, + char** _element,char** _body,char*** _attribs) { + char *ptr1,*ptr2, *ptr3, *ptr4; + char *attribs = NULL; + char *element = NULL, *body = NULL, *ret = NULL, *buffer; + int n_attrib = 0; + int body_line = 0,attrib_line,ret_line,in = 0; + int quotes = 0; + + if(_buffer == NULL || _element == NULL || _body == NULL || _attribs == NULL) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : asx_get_element called with invalid value",parser->line); + return -1; + } + + *_body = *_element = NULL; + *_attribs = NULL; + buffer = *_buffer; + + if(buffer == NULL) return 0; + + if(parser->ret_stack && /*parser->last_body && */buffer != parser->last_body) { + ASX_LineSave_t* ls = parser->ret_stack; + int i; + for(i = 0 ; i < parser->ret_stack_size ; i++) { + if(buffer == ls[i].buffer) { + parser->line = ls[i].line; + break; + } + + } + if( i < parser->ret_stack_size) { + i++; + if( i < parser->ret_stack_size) + memmove(parser->ret_stack,parser->ret_stack+i, (parser->ret_stack_size - i)*sizeof(ASX_LineSave_t)); + parser->ret_stack_size -= i; + if(parser->ret_stack_size > 0) + parser->ret_stack = realloc(parser->ret_stack,parser->ret_stack_size*sizeof(ASX_LineSave_t)); + else { + free(parser->ret_stack); + parser->ret_stack = NULL; + } + } + } + + ptr1 = buffer; + while(1) { + for( ; ptr1[0] != '<' ; ptr1++) { + if(ptr1[0] == '\0') { + ptr1 = NULL; + break; + } + if(ptr1[0] == '\n') parser->line++; + } + //ptr1 = strchr(ptr1,'<'); + if(!ptr1 || ptr1[1] == '\0') return 0; // Nothing found + + if(strncmp(ptr1,"",3) != 0 ; ptr1++) { + if(ptr1[0] == '\0') { + ptr1 = NULL; + break; + } + if(ptr1[0] == '\n') parser->line++; + } + //ptr1 = strstr(ptr1,"-->"); + if(!ptr1) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : unfinished comment",parser->line); + return -1; + } + } else { + break; + } + } + + // Is this space skip very useful ?? + for(ptr1++; strchr(SPACE,ptr1[0]) != NULL; ptr1++) { // Skip space + if(ptr1[0] == '\0') { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line); + return -1; + } + if(ptr1[0] == '\n') parser->line++; + } + + for(ptr2 = ptr1; strchr(LETTER,*ptr2) != NULL;ptr2++) { // Go to end of name + if(*ptr2 == '\0'){ + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line); + return -1; + } + if(ptr2[0] == '\n') parser->line++; + } + + element = malloc(ptr2-ptr1+1); + strncpy(element,ptr1,ptr2-ptr1); + element[ptr2-ptr1] = '\0'; + + for( ; strchr(SPACE,*ptr2) != NULL; ptr2++) { // Skip space + if(ptr2[0] == '\0') { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line); + free(element); + return -1; + } + if(ptr2[0] == '\n') parser->line++; + } + attrib_line = parser->line; + + + + for(ptr3 = ptr2; ptr3[0] != '\0'; ptr3++) { // Go to element end + if(ptr3[0] == '"') quotes ^= 1; + if(!quotes && (ptr3[0] == '>' || strncmp(ptr3,"/>",2) == 0)) + break; + if(ptr3[0] == '\n') parser->line++; + } + if(ptr3[0] == '\0' || ptr3[1] == '\0') { // End of file + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line); + free(element); + return -1; + } + + // Save attribs string + if(ptr3-ptr2 > 0) { + attribs = malloc(ptr3-ptr2+1); + strncpy(attribs,ptr2,ptr3-ptr2); + attribs[ptr3-ptr2] = '\0'; + } + //bs_line = parser->line; + if(ptr3[0] != '/') { // Not Self closed element + ptr3++; + for( ; strchr(SPACE,*ptr3) != NULL; ptr3++) { // Skip space on body begin + if(*ptr3 == '\0') { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element); + free(element); + free(attribs); + return -1; + } + if(ptr3[0] == '\n') parser->line++; + } + ptr4 = ptr3; + body_line = parser->line; + while(1) { // Find closing element + for( ; ptr4[0] != '<' ; ptr4++) { + if(ptr4[0] == '\0') { + ptr4 = NULL; + break; + } + if(ptr4[0] == '\n') parser->line++; + } + if(ptr4 && strncmp(ptr4,"",3) != 0 ; ptr4++) { + if(ptr4[0] == '\0') { + ptr4 = NULL; + break; + } + if(ptr1[0] == '\n') parser->line++; + } + continue; + } + if(ptr4 == NULL || ptr4[1] == '\0') { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element); + free(element); + free(attribs); + return -1; + } + if(ptr4[1] != '/' && strncasecmp(element,ptr4+1,strlen(element)) == 0) { + in++; + ptr4+=2; + continue; + } else if(strncasecmp(element,ptr4+2,strlen(element)) == 0) { // Extract body + if(in > 0) { + in--; + ptr4 += 2+strlen(element); + continue; + } + ret = ptr4+strlen(element)+3; + if(ptr4 != ptr3) { + ptr4--; + for( ; ptr4 != ptr3 && strchr(SPACE,*ptr4) != NULL; ptr4--) ;// Skip space on body end + // if(ptr4[0] == '\0') parser->line--; + //} + ptr4++; + body = malloc(ptr4-ptr3+1); + strncpy(body,ptr3,ptr4-ptr3); + body[ptr4-ptr3] = '\0'; + } + break; + } else { + ptr4 += 2; + } + } + } else { + ret = ptr3 + 2; // 2 is for /> + } + + for( ; ret[0] != '\0' && strchr(SPACE,ret[0]) != NULL; ret++) { // Skip space + if(ret[0] == '\n') parser->line++; + } + + ret_line = parser->line; + + if(attribs) { + parser->line = attrib_line; + n_attrib = asx_parse_attribs(parser,attribs,_attribs); + free(attribs); + if(n_attrib < 0) { + mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing element %s attributes",parser->line,element); + free(element); + free(body); + return -1; + } + } else + *_attribs = NULL; + + *_element = element; + *_body = body; + + parser->last_body = body; + parser->ret_stack_size++; + parser->ret_stack = realloc(parser->ret_stack,parser->ret_stack_size*sizeof(ASX_LineSave_t)); + if(parser->ret_stack_size > 1) + memmove(parser->ret_stack+1,parser->ret_stack,(parser->ret_stack_size-1)*sizeof(ASX_LineSave_t)); + parser->ret_stack[0].buffer = ret; + parser->ret_stack[0].line = ret_line; + parser->line = body ? body_line : ret_line; + + *_buffer = ret; + return 1; + +} + +static void +asx_parse_ref(ASX_Parser_t* parser, char** attribs) { + char *href; + + href = asx_get_attrib("HREF",attribs); + if(href == NULL) { + asx_warning_attrib_required(parser,"REF" ,"HREF" ); + return; + } +#if 0 + // replace http my mmshttp to avoid infinite loops + // disabled since some playlists for e.g. WinAMP use asx as well + // "-user-agent NSPlayer/4.1.0.3856" is a possible workaround + if (strncmp(href, "http://", 7) == 0) { + char *newref = malloc(3 + strlen(href) + 1); + strcpy(newref, "mms"); + strcpy(newref + 3, href); + free(href); + href = newref; + } +#endif + + playlist_add_file(parser->pl, href); + + mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding file %s to element entry\n",href); + + free(href); + +} + +static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs) { + char *href; + + if(parser->deep > 0) + return; + + href = asx_get_attrib("HREF",_attribs); + if(href == NULL) { + asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" ); + return; + } + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Recursive playlist %s\n", href); + playlist_add_file(parser->pl, href); + free(href); + //mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n"); +} + +static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) { + char *element,*body,**attribs; + int r; + + while(buffer && buffer[0] != '\0') { + r = asx_get_element(parser,&buffer,&element,&body,&attribs); + if(r < 0) { + asx_warning_body_parse_error(parser,"ENTRY"); + return; + } else if (r == 0) { // No more element + break; + } + if(strcasecmp(element,"REF") == 0) { + asx_parse_ref(parser,attribs); + mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to entry\n",element); + } else + mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); + free(body); + asx_free_attribs(attribs); + } + +} + + +static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs) { + char *element,*body,**attribs; + int r; + + asx_get_attrib("COUNT",_attribs); + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Ignoring repeated playlist entries\n"); + + while(buffer && buffer[0] != '\0') { + r = asx_get_element(parser,&buffer,&element,&body,&attribs); + if(r < 0) { + asx_warning_body_parse_error(parser,"REPEAT"); + return; + } else if (r == 0) { // No more element + break; + } + if(strcasecmp(element,"ENTRY") == 0) { + asx_parse_entry(parser,body,attribs); + } else if(strcasecmp(element,"ENTRYREF") == 0) { + asx_parse_entryref(parser,body,attribs); + } else if(strcasecmp(element,"REPEAT") == 0) { + asx_parse_repeat(parser,body,attribs); + } else + mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); + free(body); + asx_free_attribs(attribs); + } + +} + + +bool asx_parse(char* buffer, struct playlist *pl) +{ + char *element,*asx_body,**asx_attribs,*body = NULL, **attribs; + int r; + ASX_Parser_t* parser = asx_parser_new(pl); + + parser->line = 1; + parser->deep = 0; + + r = asx_get_element(parser,&buffer,&element,&asx_body,&asx_attribs); + if(r < 0) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : Syntax error ???",parser->line); + asx_parser_free(parser); + return false; + } else if(r == 0) { // No contents + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"empty asx element"); + asx_parser_free(parser); + return false; + } + + if(strcasecmp(element,"ASX") != 0) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"first element isn't ASX, it's %s\n",element); + asx_free_attribs(asx_attribs); + asx_parser_free(parser); + return false; + } + + if(!asx_body) { + mp_msg(MSGT_PLAYTREE,MSGL_ERR,"ASX element is empty"); + asx_free_attribs(asx_attribs); + asx_parser_free(parser); + return false; + } + + buffer = asx_body; + while(buffer && buffer[0] != '\0') { + r = asx_get_element(parser,&buffer,&element,&body,&attribs); + if(r < 0) { + asx_warning_body_parse_error(parser,"ASX"); + asx_parser_free(parser); + return false; + } else if (r == 0) { // No more element + break; + } + if(strcasecmp(element,"ENTRY") == 0) { + asx_parse_entry(parser,body,attribs); + } else if(strcasecmp(element,"ENTRYREF") == 0) { + asx_parse_entryref(parser,body,attribs); + } else if(strcasecmp(element,"REPEAT") == 0) { + asx_parse_repeat(parser,body,attribs); + } else + mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element); + free(body); + asx_free_attribs(attribs); + } + + free(asx_body); + asx_free_attribs(asx_attribs); + asx_parser_free(parser); + return true; +} diff --git a/common/asxparser.h b/common/asxparser.h new file mode 100644 index 0000000000..e49a2cedc0 --- /dev/null +++ b/common/asxparser.h @@ -0,0 +1,27 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms