From 0c9f22507f753aa9cdf68084c773c9438391fb1f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 21 Jan 2013 17:38:40 +0100 Subject: [PATCH] input/ffmpeg: convert to C++ --- Makefile.am | 4 +- src/InputRegistry.cxx | 2 +- ...g_input_plugin.c => FfmpegInputPlugin.cxx} | 42 ++++++++++++------- ...g_input_plugin.h => FfmpegInputPlugin.hxx} | 6 +-- 4 files changed, 32 insertions(+), 22 deletions(-) rename src/input/{ffmpeg_input_plugin.c => FfmpegInputPlugin.cxx} (87%) rename src/input/{ffmpeg_input_plugin.h => FfmpegInputPlugin.hxx} (87%) diff --git a/Makefile.am b/Makefile.am index 131a5ef77..299286b25 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,7 +79,6 @@ mpd_headers = \ src/decoder/pcm_decoder_plugin.h \ src/input_plugin.h \ src/input_stream.h \ - src/input/ffmpeg_input_plugin.h \ src/input/despotify_input_plugin.h \ src/input/cdio_paranoia_input_plugin.h \ src/despotify_utils.h \ @@ -746,7 +745,8 @@ libinput_a_SOURCES += src/input/cdio_paranoia_input_plugin.c endif if HAVE_FFMPEG -libinput_a_SOURCES += src/input/ffmpeg_input_plugin.c +libinput_a_SOURCES += \ + src/input/FfmpegInputPlugin.cxx src/input/FfmpegInputPlugin.hxx endif if ENABLE_MMS diff --git a/src/InputRegistry.cxx b/src/InputRegistry.cxx index 669801c04..ecd892a5b 100644 --- a/src/InputRegistry.cxx +++ b/src/InputRegistry.cxx @@ -34,7 +34,7 @@ #endif #ifdef HAVE_FFMPEG -#include "input/ffmpeg_input_plugin.h" +#include "input/FfmpegInputPlugin.hxx" #endif #ifdef ENABLE_MMS diff --git a/src/input/ffmpeg_input_plugin.c b/src/input/FfmpegInputPlugin.cxx similarity index 87% rename from src/input/ffmpeg_input_plugin.c rename to src/input/FfmpegInputPlugin.cxx index 6d339a067..53e67ef17 100644 --- a/src/input/ffmpeg_input_plugin.c +++ b/src/input/FfmpegInputPlugin.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,14 +17,19 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +/* necessary because libavutil/common.h uses UINT64_C */ +#define __STDC_CONSTANT_MACROS + #include "config.h" -#include "input/ffmpeg_input_plugin.h" +#include "FfmpegInputPlugin.hxx" #include "input_internal.h" #include "input_plugin.h" +extern "C" { #include #include #include +} #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "input_ffmpeg" @@ -51,10 +56,10 @@ static inline bool input_ffmpeg_supported(void) { #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) - void *opaque = NULL; - return avio_enum_protocols(&opaque, 0) != NULL; + void *opaque = nullptr; + return avio_enum_protocols(&opaque, 0) != nullptr; #else - return av_protocol_next(NULL) != NULL; + return av_protocol_next(nullptr) != nullptr; #endif } @@ -87,7 +92,7 @@ input_ffmpeg_open(const char *uri, !g_str_has_prefix(uri, "rtmp://") && !g_str_has_prefix(uri, "rtmpt://") && !g_str_has_prefix(uri, "rtmps://")) - return NULL; + return nullptr; i = g_new(struct input_ffmpeg, 1); input_stream_init(&i->base, &input_plugin_ffmpeg, uri, @@ -104,7 +109,7 @@ input_ffmpeg_open(const char *uri, g_free(i); g_set_error(error_r, ffmpeg_quark(), ret, "libavformat failed to open the URI"); - return NULL; + return nullptr; } i->eof = false; @@ -134,9 +139,9 @@ input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size, struct input_ffmpeg *i = (struct input_ffmpeg *)is; #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) - int ret = avio_read(i->h, ptr, size); + int ret = avio_read(i->h, (unsigned char *)ptr, size); #else - int ret = url_read(i->h, ptr, size); + int ret = url_read(i->h, (unsigned char *)ptr, size); #endif if (ret <= 0) { if (ret < 0) @@ -194,11 +199,16 @@ input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence, } const struct input_plugin input_plugin_ffmpeg = { - .name = "ffmpeg", - .init = input_ffmpeg_init, - .open = input_ffmpeg_open, - .close = input_ffmpeg_close, - .read = input_ffmpeg_read, - .eof = input_ffmpeg_eof, - .seek = input_ffmpeg_seek, + "ffmpeg", + input_ffmpeg_init, + nullptr, + input_ffmpeg_open, + input_ffmpeg_close, + nullptr, + nullptr, + nullptr, + nullptr, + input_ffmpeg_read, + input_ffmpeg_eof, + input_ffmpeg_seek, }; diff --git a/src/input/ffmpeg_input_plugin.h b/src/input/FfmpegInputPlugin.hxx similarity index 87% rename from src/input/ffmpeg_input_plugin.h rename to src/input/FfmpegInputPlugin.hxx index 393836ca5..d5e3a8d9b 100644 --- a/src/input/ffmpeg_input_plugin.h +++ b/src/input/FfmpegInputPlugin.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,8 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPD_FFMPEG_INPUT_PLUGIN_H -#define MPD_FFMPEG_INPUT_PLUGIN_H +#ifndef MPD_FFMPEG_INPUT_PLUGIN_HXX +#define MPD_FFMPEG_INPUT_PLUGIN_HXX /** * An input plugin based on libavformat's "avio" library.