decoder/ffmpeg: convert to C++
This commit is contained in:
parent
a3ee26da64
commit
ba49f20f68
@ -617,9 +617,10 @@ endif
|
||||
|
||||
if HAVE_FFMPEG
|
||||
libdecoder_plugins_a_SOURCES += \
|
||||
src/decoder/ffmpeg_metadata.c \
|
||||
src/decoder/ffmpeg_metadata.h \
|
||||
src/decoder/ffmpeg_decoder_plugin.c
|
||||
src/decoder/FfmpegMetaData.cxx \
|
||||
src/decoder/FfmpegMetaData.hxx \
|
||||
src/decoder/FfmpegDecoderPlugin.cxx \
|
||||
src/decoder/FfmpegDecoderPlugin.hxx
|
||||
endif
|
||||
|
||||
if ENABLE_SNDFILE
|
||||
|
@ -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,12 +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 "FfmpegDecoderPlugin.hxx"
|
||||
#include "decoder_api.h"
|
||||
#include "audio_check.h"
|
||||
#include "ffmpeg_metadata.h"
|
||||
#include "FfmpegMetaData.hxx"
|
||||
#include "tag_handler.h"
|
||||
|
||||
extern "C" {
|
||||
#include "audio_check.h"
|
||||
}
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <assert.h>
|
||||
@ -34,6 +41,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavformat/avio.h>
|
||||
@ -43,6 +51,7 @@
|
||||
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
|
||||
#include <libavutil/dict.h>
|
||||
#endif
|
||||
}
|
||||
|
||||
#undef G_LOG_DOMAIN
|
||||
#define G_LOG_DOMAIN "ffmpeg"
|
||||
@ -93,7 +102,7 @@ struct mpd_ffmpeg_stream {
|
||||
static int
|
||||
mpd_ffmpeg_stream_read(void *opaque, uint8_t *buf, int size)
|
||||
{
|
||||
struct mpd_ffmpeg_stream *stream = opaque;
|
||||
struct mpd_ffmpeg_stream *stream = (struct mpd_ffmpeg_stream *)opaque;
|
||||
|
||||
return decoder_read(stream->decoder, stream->input,
|
||||
(void *)buf, size);
|
||||
@ -102,7 +111,7 @@ mpd_ffmpeg_stream_read(void *opaque, uint8_t *buf, int size)
|
||||
static int64_t
|
||||
mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
|
||||
{
|
||||
struct mpd_ffmpeg_stream *stream = opaque;
|
||||
struct mpd_ffmpeg_stream *stream = (struct mpd_ffmpeg_stream *)opaque;
|
||||
|
||||
if (whence == AVSEEK_SIZE)
|
||||
return stream->input->size;
|
||||
@ -305,7 +314,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
|
||||
/* libavcodec < 0.8 needs an aligned buffer */
|
||||
uint8_t audio_buf[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
|
||||
size_t buffer_size = sizeof(audio_buf);
|
||||
int16_t *aligned_buffer = align16(audio_buf, &buffer_size);
|
||||
int16_t *aligned_buffer = (int16_t *)align16(audio_buf, &buffer_size);
|
||||
#endif
|
||||
|
||||
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
||||
@ -426,7 +435,7 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
|
||||
PADDING = 16,
|
||||
};
|
||||
|
||||
unsigned char *buffer = g_malloc(BUFFER_SIZE);
|
||||
unsigned char *buffer = (unsigned char *)g_malloc(BUFFER_SIZE);
|
||||
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
|
||||
if (nbytes <= PADDING ||
|
||||
!input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
|
||||
@ -440,11 +449,10 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
|
||||
size */
|
||||
nbytes -= PADDING;
|
||||
|
||||
AVProbeData avpd = {
|
||||
.buf = buffer,
|
||||
.buf_size = nbytes,
|
||||
.filename = is->uri,
|
||||
};
|
||||
AVProbeData avpd;
|
||||
avpd.buf = buffer;
|
||||
avpd.buf_size = nbytes;
|
||||
avpd.filename = is->uri;
|
||||
|
||||
AVInputFormat *format = av_probe_input_format(&avpd, true);
|
||||
g_free(buffer);
|
||||
@ -791,10 +799,14 @@ static const char *const ffmpeg_mime_types[] = {
|
||||
};
|
||||
|
||||
const struct decoder_plugin ffmpeg_decoder_plugin = {
|
||||
.name = "ffmpeg",
|
||||
.init = ffmpeg_init,
|
||||
.stream_decode = ffmpeg_decode,
|
||||
.scan_stream = ffmpeg_scan_stream,
|
||||
.suffixes = ffmpeg_suffixes,
|
||||
.mime_types = ffmpeg_mime_types
|
||||
"ffmpeg",
|
||||
ffmpeg_init,
|
||||
nullptr,
|
||||
ffmpeg_decode,
|
||||
nullptr,
|
||||
nullptr,
|
||||
ffmpeg_scan_stream,
|
||||
nullptr,
|
||||
ffmpeg_suffixes,
|
||||
ffmpeg_mime_types
|
||||
};
|
25
src/decoder/FfmpegDecoderPlugin.hxx
Normal file
25
src/decoder/FfmpegDecoderPlugin.hxx
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_DECODER_FFMPEG_HXX
|
||||
#define MPD_DECODER_FFMPEG_HXX
|
||||
|
||||
extern const struct decoder_plugin ffmpeg_decoder_plugin;
|
||||
|
||||
#endif
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2012 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,11 @@
|
||||
* 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 "ffmpeg_metadata.h"
|
||||
#include "FfmpegMetaData.hxx"
|
||||
#include "tag_table.h"
|
||||
#include "tag_handler.h"
|
||||
|
||||
@ -70,7 +73,7 @@ ffmpeg_scan_dictionary(AVDictionary *dict,
|
||||
const struct tag_handler *handler, void *handler_ctx)
|
||||
{
|
||||
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
||||
ffmpeg_copy_metadata(i, dict, tag_item_names[i],
|
||||
ffmpeg_copy_metadata(tag_type(i), dict, tag_item_names[i],
|
||||
handler, handler_ctx);
|
||||
|
||||
for (const struct tag_table *i = ffmpeg_tags;
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2003-2012 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,16 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef MPD_FFMPEG_METADATA_H
|
||||
#define MPD_FFMPEG_METADATA_H
|
||||
#ifndef MPD_FFMPEG_METADATA_HXX
|
||||
#define MPD_FFMPEG_METADATA_HXX
|
||||
|
||||
extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
#include <libavutil/avutil.h>
|
||||
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
|
||||
#include <libavutil/dict.h>
|
||||
#endif
|
||||
}
|
||||
|
||||
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,1,0)
|
||||
#define AVDictionary AVMetadata
|
@ -30,6 +30,7 @@
|
||||
#include "decoder/VorbisDecoderPlugin.h"
|
||||
#include "decoder/AdPlugDecoderPlugin.h"
|
||||
#include "decoder/WavpackDecoderPlugin.hxx"
|
||||
#include "decoder/FfmpegDecoderPlugin.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
@ -47,7 +48,6 @@ extern const struct decoder_plugin mikmod_decoder_plugin;
|
||||
extern const struct decoder_plugin sidplay_decoder_plugin;
|
||||
extern const struct decoder_plugin wildmidi_decoder_plugin;
|
||||
extern const struct decoder_plugin fluidsynth_decoder_plugin;
|
||||
extern const struct decoder_plugin ffmpeg_decoder_plugin;
|
||||
extern const struct decoder_plugin gme_decoder_plugin;
|
||||
|
||||
const struct decoder_plugin *const decoder_plugins[] = {
|
||||
|
Loading…
Reference in New Issue
Block a user