Commits

Ivan Andrianov committed 60aac70

Work in progress.

  • Participants
  • Parent commits d0bccc9
  • Branches devel

Comments (0)

Files changed (8)

 
 find_package(FFmpeg COMPONENTS AVCODEC AVFORMAT AVUTIL)
 find_package(FLAC)
+find_package(Lame)
 
 include_directories(${FFTRANSCODER_SOURCE_DIR}/src)
 

cmake/FindLame.cmake

+# Copyright (c) 2009, Whispersoft s.r.l.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Whispersoft s.r.l. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Finds Lame library
+#
+#  Lame_INCLUDE_DIR - where to find lame.h lame/lame.h, etc.
+#  Lame_LIBRARIES   - List of libraries when using Lame.
+#  Lame_FOUND       - True if Lame found.
+#
+
+if (Lame_INCLUDE_DIR)
+  # Already in cache, be silent
+  set(Lame_FIND_QUIETLY TRUE)
+endif (Lame_INCLUDE_DIR)
+
+find_path(Lame_INCLUDE_DIR lame/lame.h
+  /opt/local/include
+  /usr/local/include
+  /usr/include
+)
+
+set(Lame_NAMES mp3lame)
+find_library(Lame_LIBRARY
+  NAMES ${Lame_NAMES}
+  PATHS /usr/lib /usr/local/lib /opt/local/lib
+)
+
+if (Lame_INCLUDE_DIR AND Lame_LIBRARY)
+   set(Lame_FOUND TRUE)
+   set( Lame_LIBRARIES ${Lame_LIBRARY} )
+else (Lame_INCLUDE_DIR AND Lame_LIBRARY)
+   set(Lame_FOUND FALSE)
+   set(Lame_LIBRARIES)
+endif (Lame_INCLUDE_DIR AND Lame_LIBRARY)
+
+if (Lame_FOUND)
+   if (NOT Lame_FIND_QUIETLY)
+      message(STATUS "Found Lame: ${Lame_LIBRARY}")
+   endif (NOT Lame_FIND_QUIETLY)
+else (Lame_FOUND)
+   if (Lame_FIND_REQUIRED)
+      message(STATUS "Looked for Lame libraries named ${Lame_NAMES}.")
+      message(STATUS "Include file detected: [${Lame_INCLUDE_DIR}].")
+      message(STATUS "Lib file detected: [${Lame_LIBRARY}].")
+      message(FATAL_ERROR "=========> Could NOT find Lame library")
+   endif (Lame_FIND_REQUIRED)
+endif (Lame_FOUND)
+
+mark_as_advanced(
+  Lame_LIBRARY
+  Lame_INCLUDE_DIR
+  )

src/codecs/CMakeLists.txt

 if(FLAC_FOUND)
   add_subdirectory(plugins/flacencoder)
 endif(FLAC_FOUND)
+
+if(Lame_FOUND)
+  add_subdirectory(plugins/lameencoder)
+endif(Lame_FOUND)

src/codecs/plugins/lameencoder/CMakeLists.txt

+# Copyright (C) 2012 by Ivan Andrianov
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+include_directories(${Lame_INCLUDE_DIR})
+
+set(Lame_ENCODER_SRCS_CXX
+  lameencoder.cpp
+  #lameencoderplugin.cpp
+)
+
+set(Lame_ENCODER_MOC_SRCS
+  lameencoderplugin.h
+)
+
+qt4_wrap_cpp(Lame_ENCODER_SRCS_CXX ${Lame_ENCODER_MOC_SRCS})
+
+add_library(lame_encoder MODULE ${Lame_ENCODER_SRCS_CXX})
+
+target_link_libraries(lame_encoder fftranscoder_codecs ${QT_QTCORE_LIBRARY}
+                      ${Lame_LIBRARIES})
+
+install(TARGETS lame_encoder
+        LIBRARY DESTINATION ${FFTRANSCODER_PLUGIN_INSTALL_DIR})

src/codecs/plugins/lameencoder/lameencoder.cpp

+/*
+ * Copyright (C) 2012 by Ivan Andrianov
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "lameencoder.h"
+#include "lameencoder_p.h"
+
+#include <codecs/frame.h>
+
+LameEncoder::LameEncoder(const QString & fileName) :
+        d(new LameEncoderPrivate())
+{
+    d->fileName = fileName;
+    d->initValues();
+}
+
+LameEncoder::~LameEncoder()
+{
+    if(d->encoder)
+    {
+        lame_close(d->encoder);
+    }
+    // TODO if(d->metaData)
+    {
+        //Lame__metadata_object_delete(d->metaData);
+    }
+}
+
+bool LameEncoder::setQuality(uint quality)
+{
+    if(quality >= 0 && quality <= 7)
+    {
+        d->quality = quality;
+        return true;
+    }
+    return false;
+}
+
+bool LameEncoder::setStreamInfo(const StreamInfo & streamInfo)
+{
+    if(streamInfo.bytesPerSample() == 2
+            && (streamInfo.sampleRate() == 16000
+                    || streamInfo.sampleRate() == 22050
+                    || streamInfo.sampleRate() == 24000
+                    || streamInfo.sampleRate() == 32000
+                    || streamInfo.sampleRate() == 44100
+                    || streamInfo.sampleRate() == 48000)
+            && streamInfo.channelCount() >= 1 && streamInfo.channelCount() <= 2)
+    {
+        d->streamInfo = streamInfo;
+        return true;
+    }
+    return false;
+}
+
+bool LameEncoder::setTagBlock(const TagBlock & tagBlock)
+{
+    d->tagBlock = tagBlock;
+    return true;
+}
+
+bool LameEncoder::writeMetaData()
+{
+    if(d->isMetaDataWritten)
+    {
+        return d->isMetaDataWrittenSuccessfully;
+    }
+
+    d->isMetaDataWritten = true;
+
+    if(d->createEncoder() && d->createMetaData() && d->initEncoder())
+    {
+        d->isMetaDataWrittenSuccessfully = true;
+        return true;
+    }
+    return false;
+}
+
+bool LameEncoder::writeFrame(const Frame * frame)
+{
+    if(d->isMetaDataWrittenSuccessfully)
+    {
+        return lame_encode_buffer(d->encoder,
+                frame->samples(), frame->sampleCount());
+    }
+    return false;
+}
+
+bool LameEncoder::flush()
+{
+    if(d->isMetaDataWrittenSuccessfully)
+    {
+        // TODO return Lame__stream_encoder_finish(d->encoder);
+        return true;
+    }
+    return false;
+}
+
+LameEncoderPrivate::LameEncoderPrivate()
+{
+}
+
+LameEncoderPrivate::~LameEncoderPrivate()
+{
+}
+
+void LameEncoderPrivate::initValues()
+{
+    streamInfo = StreamInfo(2, 44100, 2);
+
+    encoder = 0;
+    // TODO metaData = 0;
+
+    isMetaDataWritten = false;
+    isMetaDataWrittenSuccessfully = false;
+}
+
+bool LameEncoderPrivate::createEncoder()
+{
+    encoder = lame_init();
+    return encoder && lame_set_in_samplerate(encoder, streamInfo.sampleRate())
+            && lame_set_num_channels(encoder, streamInfo.channelCount())
+            && lame_set_quality(encoder, 7 - quality);
+}
+
+bool LameEncoderPrivate::createMetaData()
+{
+    // TODO metaData = Lame__metadata_object_new(Lame__METADATA_TYPE_VORBIS_COMMENT);
+    //return metaData && writeArtistName() && writeAlbumName() && writeYear()
+            //&& writeTrackName() && writeTrackNumber()
+            //&& Lame__stream_encoder_set_metadata(encoder, &metaData, 1);
+    return true;
+}
+
+bool LameEncoderPrivate::initEncoder()
+{
+    return lame_init_params(encoder) != -1;
+}
+
+bool LameEncoderPrivate::writeTag(const char * tagName, const char * tagValue)
+{
+    // TODO Lame__StreamMetadata_VorbisComment_Entry entry;
+    //return Lame__metadata_object_vorbiscomment_entry_from_name_value_pair(
+            //&entry, tagName, tagValue)
+            //&& Lame__metadata_object_vorbiscomment_append_comment(metaData,
+                    //entry, false);
+    return true;
+}
+
+bool LameEncoderPrivate::writeStringTag(const char * tagName,
+        const QString & tagValue)
+{
+    if(!tagValue.isEmpty())
+    {
+        return writeTag(tagName, tagValue.toUtf8().data());
+    }
+    return true;
+}
+
+bool LameEncoderPrivate::writeIntTag(const char * tagName, uint tagValue)
+{
+    if(tagValue > 0)
+    {
+        return writeTag(tagName, QString::number(tagValue).toUtf8().data());
+    }
+    return true;
+}
+
+bool LameEncoderPrivate::writeArtistName()
+{
+    return writeStringTag("ARTIST", tagBlock.artistName());
+}
+
+bool LameEncoderPrivate::writeAlbumName()
+{
+    return writeStringTag("ALBUM", tagBlock.albumName());
+}
+
+bool LameEncoderPrivate::writeYear()
+{
+    return writeIntTag("DATE", tagBlock.year());
+}
+
+bool LameEncoderPrivate::writeTrackName()
+{
+    return writeStringTag("TITLE", tagBlock.trackName());
+}
+
+bool LameEncoderPrivate::writeTrackNumber()
+{
+    return writeIntTag("TRACKNUMBER", tagBlock.trackNumber());
+}

src/codecs/plugins/lameencoder/lameencoder.h

+/*
+ * Copyright (C) 2012 by Ivan Andrianov
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef LAMEENCODER_H
+#define LAMEENCODER_H
+
+#include <QString>
+#include <QScopedPointer>
+
+#include <codecs/encoder.h>
+#include <codecs/streaminfo.h>
+#include <codecs/tagblock.h>
+
+namespace FFTranscoder
+{
+namespace Codecs
+{
+class Frame;
+}
+}
+
+class LameEncoderPrivate;
+
+using FFTranscoder::Codecs::Encoder;
+using FFTranscoder::Codecs::Frame;
+using FFTranscoder::Codecs::StreamInfo;
+using FFTranscoder::Codecs::TagBlock;
+
+class LameEncoder : public Encoder
+{
+    Q_DISABLE_COPY(LameEncoder)
+
+public:
+    LameEncoder(const QString & fileName);
+    virtual ~LameEncoder();
+
+    virtual bool setQuality(uint quality);
+
+    virtual bool setStreamInfo(const StreamInfo & streamInfo);
+
+    virtual bool setTagBlock(const TagBlock & tagBlock);
+
+    virtual bool writeMetaData();
+    virtual bool writeFrame(const Frame * frame);
+    virtual bool flush();
+
+private:
+    QScopedPointer<LameEncoderPrivate> d;
+};
+
+#endif // LAMEENCODER_H

src/codecs/plugins/lameencoder/lameencoder_p.h

+/*
+ * Copyright (C) 2012 by Ivan Andrianov
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef LAMEENCODER_P_H
+#define LAMEENCODER_P_H
+
+#include <QString>
+
+#include <lame/lame.h>
+
+#include <codecs/streaminfo.h>
+#include <codecs/tagblock.h>
+
+using FFTranscoder::Codecs::TagBlock;
+
+class LameEncoder;
+
+class LameEncoderPrivate
+{
+    Q_DISABLE_COPY(LameEncoderPrivate)
+
+public:
+    LameEncoderPrivate();
+    ~LameEncoderPrivate();
+
+    void initValues();
+
+    bool createEncoder();
+    bool createMetaData();
+    bool initEncoder();
+
+    bool writeTag(const char * tagName, const char * tagValue);
+    bool writeStringTag(const char * tagName, const QString & tagValue);
+    bool writeIntTag(const char * tagName, uint tagValue);
+    bool writeArtistName();
+    bool writeAlbumName();
+    bool writeYear();
+    bool writeTrackName();
+    bool writeTrackNumber();
+
+    QString fileName;
+
+    StreamInfo streamInfo;
+    TagBlock tagBlock;
+    uint quality;
+
+    lame_global_flags * encoder;
+    // XXX metadata
+
+    bool isMetaDataWritten;
+    bool isMetaDataWrittenSuccessfully;
+};
+
+#endif // LAMEENCODER_P_H

src/codecs/plugins/lameencoder/lameencoderplugin.h

+/*
+ * Copyright (C) 2012 by Ivan Andrianov
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef LAMEENCODERPLUGIN_H
+#define LAMEENCODERPLUGIN_H
+
+#include <QString>
+#include <QObject>
+
+#include <codecs/encoderplugin.h>
+
+namespace FFTranscoder
+{
+namespace Codecs
+{
+class Encoder;
+}
+}
+
+using FFTranscoder::Codecs::Encoder;
+using FFTranscoder::Codecs::EncoderPlugin;
+
+class LameEncoderPlugin : public QObject, public EncoderPlugin
+{
+    Q_OBJECT
+    Q_DISABLE_COPY(LameEncoderPlugin)
+    Q_INTERFACES(FFTranscoder::Codecs::EncoderPlugin)
+
+public:
+    LameEncoderPlugin();
+    virtual ~LameEncoderPlugin();
+
+    virtual Encoder * createEncoder(const QString & fileName);
+    virtual QString encoderName() const;
+    virtual QString codecName() const;
+    virtual QString fileNameExtension() const;
+    virtual bool isLossless() const;
+    virtual QString version() const;
+};
+
+#endif // LAMEENCODERPLUGIN_H