diff options
Diffstat (limited to 'src/plugins/Input/ffmpeg')
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp | 83 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoder_ffmpeg.h | 34 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp | 43 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoderffmpegfactory.h | 8 |
4 files changed, 69 insertions, 99 deletions
diff --git a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp index 274e05160..c1b5ac2e2 100644 --- a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp +++ b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -30,18 +30,17 @@ // Decoder class -DecoderFFmpeg::DecoderFFmpeg(QObject *parent, DecoderFactory *d, QIODevice *i, Output *o) - : Decoder(parent, d, i, o) +DecoderFFmpeg::DecoderFFmpeg(QObject *parent, DecoderFactory *d, Output *o, const QString &path) + : Decoder(parent, d, o) { inited = FALSE; user_stop = FALSE; - stat = 0; output_buf = 0; output_bytes = 0; output_at = 0; bks = 0; done = FALSE; - finish = FALSE; + m_finish = FALSE; freq = 0; bitrate = 0; seekTime = -1.0; @@ -50,6 +49,7 @@ DecoderFFmpeg::DecoderFFmpeg(QObject *parent, DecoderFactory *d, QIODevice *i, O output_size = 0; ic = 0; wma_outbuf = 0; + m_path = path; } @@ -80,11 +80,11 @@ void DecoderFFmpeg::flush(bool final) { ulong min = final ? 0 : bks; - while ((! done && ! finish) && output_bytes > min) + while ((! done && ! m_finish) && output_bytes > min) { output()->recycler()->mutex()->lock (); - while ((! done && ! finish) && output()->recycler()->full()) + while ((! done && ! m_finish) && output()->recycler()->full()) { mutex()->unlock(); @@ -94,7 +94,7 @@ void DecoderFFmpeg::flush(bool final) done = user_stop; } - if (user_stop || finish) + if (user_stop || m_finish) { inited = FALSE; done = TRUE; @@ -118,47 +118,25 @@ void DecoderFFmpeg::flush(bool final) bool DecoderFFmpeg::initialize() { - bks = blockSize(); - inited = user_stop = done = finish = FALSE; + bks = Buffer::size(); + inited = user_stop = done = m_finish = FALSE; freq = bitrate = 0; - stat = chan = 0; + chan = 0; output_size = 0; seekTime = -1.0; totalTime = 0.0; - - if (! input()) - { - error("DecoderFFmpeg: cannot initialize. No input."); - - return FALSE; - } - - if (! output_buf) + if (!output_buf) output_buf = new char[globalBufferSize]; output_at = 0; output_bytes = 0; - if (! input()) - { - error("DecoderFFmpeg: cannot initialize. No input."); - - return FALSE; - } - - if (! output_buf) - output_buf = new char[globalBufferSize]; - output_at = 0; - output_bytes = 0; - - QString filename = qobject_cast<QFile*>(input())->fileName (); - input()->close(); avcodec_init(); avcodec_register_all(); av_register_all(); AVCodec *codec; - if (av_open_input_file(&ic, filename.toLocal8Bit(), NULL,0, NULL) < 0) + if (av_open_input_file(&ic, m_path.toLocal8Bit(), NULL,0, NULL) < 0) { qDebug("DecoderFFmpeg: cannot open input file"); return FALSE; @@ -179,7 +157,7 @@ bool DecoderFFmpeg::initialize() totalTime = ic->duration/AV_TIME_BASE; - configure(c->sample_rate, c->channels, 16, c->bit_rate); + configure(c->sample_rate, c->channels, 16); bitrate = c->bit_rate; chan = c->channels; @@ -190,7 +168,7 @@ bool DecoderFFmpeg::initialize() } -double DecoderFFmpeg::lengthInSeconds() +qint64 DecoderFFmpeg::lengthInSeconds() { if (! inited) return 0; @@ -199,7 +177,7 @@ double DecoderFFmpeg::lengthInSeconds() } -void DecoderFFmpeg::seek(double pos) +void DecoderFFmpeg::seek(qint64 pos) { seekTime = pos; } @@ -207,9 +185,9 @@ void DecoderFFmpeg::seek(double pos) void DecoderFFmpeg::deinit() { - inited = user_stop = done = finish = FALSE; + inited = user_stop = done = m_finish = FALSE; freq = bitrate = 0; - stat = chan = 0; + chan = 0; output_size = 0; } @@ -229,13 +207,9 @@ void DecoderFFmpeg::run() return; } - stat = DecoderState::Decoding; mutex()->unlock(); - { - dispatch(DecoderState ((DecoderState::Type) stat)); - } - while (! done && ! finish) + while (!done && !m_finish) { mutex()->lock (); // decode @@ -254,7 +228,7 @@ void DecoderFFmpeg::run() int l = 0; if (av_read_frame(ic, &pkt) < 0) { - finish = TRUE; + m_finish = TRUE; goto end; } size = pkt.size; @@ -277,7 +251,7 @@ void DecoderFFmpeg::run() } bitrate = c->bit_rate/1024; end: - if (finish) + if (m_finish) { flush(TRUE); @@ -298,7 +272,7 @@ end: done = TRUE; if (! user_stop) { - finish = TRUE; + m_finish = TRUE; } } @@ -307,18 +281,9 @@ end: } mutex()->lock (); - - if (finish) - stat = DecoderState::Finished; - else if (user_stop) - stat = DecoderState::Stopped; - + if (m_finish) + finish(); mutex()->unlock(); - - { - dispatch(DecoderState ((DecoderState::Type) stat)); - } - deinit(); } diff --git a/src/plugins/Input/ffmpeg/decoder_ffmpeg.h b/src/plugins/Input/ffmpeg/decoder_ffmpeg.h index 37265e31f..9e85c9089 100644 --- a/src/plugins/Input/ffmpeg/decoder_ffmpeg.h +++ b/src/plugins/Input/ffmpeg/decoder_ffmpeg.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -22,7 +22,9 @@ #define __decoder_ffmeg_h extern "C"{ -#if defined HAVE_FFMPEG_AVFORMAT_H +#if defined HAVE_FFMPEG_LIBAVFORMAT_AVFORMAT_H +#include <ffmpeg/libavformat/avformat.h> +#elif defined HAVE_FFMPEG_AVFORMAT_H #include <ffmpeg/avformat.h> #elif defined HAVE_LIBAVFORMAT_AVFORMAT_H #include <libavformat/avformat.h> @@ -30,7 +32,9 @@ extern "C"{ #include <avformat.h> #endif -#if defined HAVE_FFMPEG_AVCODEC_H +#if defined HAVE_FFMPEG_LIBAVCODEC_AVCODEC_H +#include <ffmpeg/libavcodec/avcodec.h> +#elif defined HAVE_FFMPEG_AVCODEC_H #include <ffmpeg/avcodec.h> #elif defined HAVE_LIBAVCODEC_AVCODEC_H #include <libavcodec/avcodec.h> @@ -43,22 +47,15 @@ extern "C"{ class DecoderFFmpeg : public Decoder { public: - DecoderFFmpeg(QObject *, DecoderFactory *, QIODevice *, Output *); + DecoderFFmpeg(QObject *, DecoderFactory *, Output *, const QString &); virtual ~DecoderFFmpeg(); // Standard Decoder API bool initialize(); - double lengthInSeconds(); - void seek(double); + qint64 lengthInSeconds(); + void seek(qint64); void stop(); - // Equalizer - bool isEQSupported() const { return FALSE; } - void setEQEnabled(bool) { ; } - void setEQGain(int) { ; } - void setEQBands(int[10]) { ; } - - private: // thread run function void run(); @@ -66,13 +63,11 @@ private: void flush(bool = FALSE); void deinit(); void ffmpeg_out(int size); - bool inited, user_stop; - int stat; // output buffer char *output_buf; - ulong output_bytes, output_at; + qint64 output_bytes, output_at; AVFormatContext *ic; AVCodecContext *c; @@ -80,11 +75,12 @@ private: uint8_t *wma_outbuf; unsigned int bks; - bool done, finish; + bool done, m_finish; long freq, bitrate; int chan; - unsigned long output_size; - double totalTime, seekTime; + qint64 output_size; + qint64 totalTime, seekTime; + QString m_path; }; diff --git a/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp b/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp index 3598cebbc..41a968634 100644 --- a/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp +++ b/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp @@ -21,7 +21,9 @@ #include <QtGui> extern "C"{ -#if defined HAVE_FFMPEG_AVFORMAT_H +#if defined HAVE_FFMPEG_LIBAVFORMAT_AVFORMAT_H +#include <ffmpeg/libavformat/avformat.h> +#elif defined HAVE_FFMPEG_AVFORMAT_H #include <ffmpeg/avformat.h> #elif defined HAVE_LIBAVFORMAT_AVFORMAT_H #include <libavformat/avformat.h> @@ -29,7 +31,9 @@ extern "C"{ #include <avformat.h> #endif -#if defined HAVE_FFMPEG_AVCODEC_H +#if defined HAVE_FFMPEG_LIBAVCODEC_AVCODEC_H +#include <ffmpeg/libavcodec/avcodec.h> +#elif defined HAVE_FFMPEG_AVCODEC_H #include <ffmpeg/avcodec.h> #elif defined HAVE_LIBAVCODEC_AVCODEC_H #include <libavcodec/avcodec.h> @@ -65,36 +69,41 @@ const DecoderProperties DecoderFFmpegFactory::properties() const //properties.contentType = ""; properties.hasAbout = TRUE; properties.hasSettings = FALSE; + properties.noInput = TRUE; + properties.protocols = "file"; return properties; } Decoder *DecoderFFmpegFactory::create(QObject *parent, QIODevice *input, - Output *output) + Output *output, const QString &path) { - return new DecoderFFmpeg(parent, this, input, output); + Q_UNUSED(input); + return new DecoderFFmpeg(parent, this, output, path); } -FileTag *DecoderFFmpegFactory::createTag(const QString &source) +QList<FileInfo *> DecoderFFmpegFactory::createPlayList(const QString &fileName) { - FileTag *ftag = new FileTag(); + QList <FileInfo*> list; avcodec_init(); avcodec_register_all(); av_register_all(); AVFormatContext *in; - if (av_open_input_file(&in, source.toLocal8Bit(), NULL,0, NULL) < 0) - return ftag; + if (av_open_input_file(&in, fileName.toLocal8Bit(), NULL,0, NULL) < 0) + return list; + FileInfo *info = new FileInfo(fileName); av_find_stream_info(in); - ftag->setValue(FileTag::ALBUM, QString::fromUtf8(in->album).trimmed()); - ftag->setValue(FileTag::ARTIST, QString::fromUtf8(in->author).trimmed()); - ftag->setValue(FileTag::COMMENT, QString::fromUtf8(in->comment).trimmed()); - ftag->setValue(FileTag::GENRE, QString::fromUtf8(in->genre).trimmed()); - ftag->setValue(FileTag::TITLE, QString::fromUtf8(in->title).trimmed()); - ftag->setValue(FileTag::YEAR, in->year); - ftag->setValue(FileTag::TRACK, in->track); - ftag->setValue(FileTag::LENGTH ,int(in->duration/AV_TIME_BASE)); + info->setMetaData(Qmmp::ALBUM, QString::fromUtf8(in->album).trimmed()); + info->setMetaData(Qmmp::ARTIST, QString::fromUtf8(in->author).trimmed()); + info->setMetaData(Qmmp::COMMENT, QString::fromUtf8(in->comment).trimmed()); + info->setMetaData(Qmmp::GENRE, QString::fromUtf8(in->genre).trimmed()); + info->setMetaData(Qmmp::TITLE, QString::fromUtf8(in->title).trimmed()); + info->setMetaData(Qmmp::YEAR, in->year); + info->setMetaData(Qmmp::TRACK, in->track); + info->setLength(in->duration/AV_TIME_BASE); av_close_input_file(in); - return ftag; + list << info; + return list; } QObject* DecoderFFmpegFactory::showDetails(QWidget *parent, const QString &path) diff --git a/src/plugins/Input/ffmpeg/decoderffmpegfactory.h b/src/plugins/Input/ffmpeg/decoderffmpegfactory.h index 6f24fed94..c8bb2ef62 100644 --- a/src/plugins/Input/ffmpeg/decoderffmpegfactory.h +++ b/src/plugins/Input/ffmpeg/decoderffmpegfactory.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Ilya Kotov * + * Copyright (C) 2006-2008 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -28,7 +28,7 @@ #include <qmmp/decoder.h> #include <qmmp/output.h> #include <qmmp/decoderfactory.h> -#include <qmmp/filetag.h> +#include <qmmp/fileinfo.h> @@ -43,8 +43,8 @@ public: bool supports(const QString &source) const; bool canDecode(QIODevice *input) const; const DecoderProperties properties() const; - Decoder *create(QObject *, QIODevice *, Output *); - FileTag *createTag(const QString &source); + Decoder *create(QObject *, QIODevice *, Output *, const QString &); + QList<FileInfo *> createPlayList(const QString &fileName); QObject* showDetails(QWidget *parent, const QString &path); void showSettings(QWidget *parent); void showAbout(QWidget *parent); |
