input/ffmpeg: convert to C++

This commit is contained in:
Max Kellermann 2013-01-21 17:38:40 +01:00
parent 9c870e4276
commit 0c9f22507f
4 changed files with 32 additions and 22 deletions

View File

@ -79,7 +79,6 @@ mpd_headers = \
src/decoder/pcm_decoder_plugin.h \ src/decoder/pcm_decoder_plugin.h \
src/input_plugin.h \ src/input_plugin.h \
src/input_stream.h \ src/input_stream.h \
src/input/ffmpeg_input_plugin.h \
src/input/despotify_input_plugin.h \ src/input/despotify_input_plugin.h \
src/input/cdio_paranoia_input_plugin.h \ src/input/cdio_paranoia_input_plugin.h \
src/despotify_utils.h \ src/despotify_utils.h \
@ -746,7 +745,8 @@ libinput_a_SOURCES += src/input/cdio_paranoia_input_plugin.c
endif endif
if HAVE_FFMPEG if HAVE_FFMPEG
libinput_a_SOURCES += src/input/ffmpeg_input_plugin.c libinput_a_SOURCES += \
src/input/FfmpegInputPlugin.cxx src/input/FfmpegInputPlugin.hxx
endif endif
if ENABLE_MMS if ENABLE_MMS

View File

@ -34,7 +34,7 @@
#endif #endif
#ifdef HAVE_FFMPEG #ifdef HAVE_FFMPEG
#include "input/ffmpeg_input_plugin.h" #include "input/FfmpegInputPlugin.hxx"
#endif #endif
#ifdef ENABLE_MMS #ifdef ENABLE_MMS

View File

@ -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 * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * 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. * 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 "config.h"
#include "input/ffmpeg_input_plugin.h" #include "FfmpegInputPlugin.hxx"
#include "input_internal.h" #include "input_internal.h"
#include "input_plugin.h" #include "input_plugin.h"
extern "C" {
#include <libavutil/avutil.h> #include <libavutil/avutil.h>
#include <libavformat/avio.h> #include <libavformat/avio.h>
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
}
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_ffmpeg" #define G_LOG_DOMAIN "input_ffmpeg"
@ -51,10 +56,10 @@ static inline bool
input_ffmpeg_supported(void) input_ffmpeg_supported(void)
{ {
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) #if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
void *opaque = NULL; void *opaque = nullptr;
return avio_enum_protocols(&opaque, 0) != NULL; return avio_enum_protocols(&opaque, 0) != nullptr;
#else #else
return av_protocol_next(NULL) != NULL; return av_protocol_next(nullptr) != nullptr;
#endif #endif
} }
@ -87,7 +92,7 @@ input_ffmpeg_open(const char *uri,
!g_str_has_prefix(uri, "rtmp://") && !g_str_has_prefix(uri, "rtmp://") &&
!g_str_has_prefix(uri, "rtmpt://") && !g_str_has_prefix(uri, "rtmpt://") &&
!g_str_has_prefix(uri, "rtmps://")) !g_str_has_prefix(uri, "rtmps://"))
return NULL; return nullptr;
i = g_new(struct input_ffmpeg, 1); i = g_new(struct input_ffmpeg, 1);
input_stream_init(&i->base, &input_plugin_ffmpeg, uri, input_stream_init(&i->base, &input_plugin_ffmpeg, uri,
@ -104,7 +109,7 @@ input_ffmpeg_open(const char *uri,
g_free(i); g_free(i);
g_set_error(error_r, ffmpeg_quark(), ret, g_set_error(error_r, ffmpeg_quark(), ret,
"libavformat failed to open the URI"); "libavformat failed to open the URI");
return NULL; return nullptr;
} }
i->eof = false; 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; struct input_ffmpeg *i = (struct input_ffmpeg *)is;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0) #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 #else
int ret = url_read(i->h, ptr, size); int ret = url_read(i->h, (unsigned char *)ptr, size);
#endif #endif
if (ret <= 0) { if (ret <= 0) {
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 = { const struct input_plugin input_plugin_ffmpeg = {
.name = "ffmpeg", "ffmpeg",
.init = input_ffmpeg_init, input_ffmpeg_init,
.open = input_ffmpeg_open, nullptr,
.close = input_ffmpeg_close, input_ffmpeg_open,
.read = input_ffmpeg_read, input_ffmpeg_close,
.eof = input_ffmpeg_eof, nullptr,
.seek = input_ffmpeg_seek, nullptr,
nullptr,
nullptr,
input_ffmpeg_read,
input_ffmpeg_eof,
input_ffmpeg_seek,
}; };

View File

@ -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 * http://www.musicpd.org
* *
* This program is free software; you can redistribute it and/or modify * 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. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_FFMPEG_INPUT_PLUGIN_H #ifndef MPD_FFMPEG_INPUT_PLUGIN_HXX
#define MPD_FFMPEG_INPUT_PLUGIN_H #define MPD_FFMPEG_INPUT_PLUGIN_HXX
/** /**
* An input plugin based on libavformat's "avio" library. * An input plugin based on libavformat's "avio" library.