22 #include <KLocalizedString>    40      m_vorbis_comment_map()
    60         FLAC__byte buffer[], 
size_t *bytes)
    64     if (!bytes || !
m_source) 
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
    69         return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
    73     *bytes = 
static_cast<unsigned>(
m_source->read(
    74         reinterpret_cast<char *>(&(buffer[0])),
    75         static_cast<qint64>(*bytes)
    78     if (!*bytes) 
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
    80     return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
    85         const ::FLAC__Frame *frame,
    86         const FLAC__int32 * 
const buffer[])
    91     if (!buffer || !frame || !
m_dest)
    92         return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
    94     const unsigned int samples = frame->header.blocksize;
    99     if (!samples || !tracks)
   100         return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
   106     if (shift < 0) shift = 0;
   107     unsigned int mul = (1 << shift);
   111     for (
unsigned int track=0; track < tracks; track++) {
   114         if (!writer) 
continue;
   115         const FLAC__int32 *src = buffer[track];
   118         for (
unsigned int sample = 0; sample < samples; sample++) {
   136         FLAC__STREAM_DECODER_WRITE_STATUS_ABORT :
   137         FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
   142     const FLAC::Metadata::StreamInfo &stream_info)
   144     qDebug(
"FLAC stream info");
   145     qDebug(
"\tmin_blocksize   = %d", stream_info.get_min_blocksize());
   146     qDebug(
"\tmax_blocksize   = %d", stream_info.get_max_blocksize());
   147     qDebug(
"\tmin_framesize   = %d", stream_info.get_min_framesize());
   148     qDebug(
"\tmax_framesize   = %d", stream_info.get_max_framesize());
   151     info.setRate(stream_info.get_sample_rate());
   152     info.setTracks(stream_info.get_channels());
   153     info.setBits(stream_info.get_bits_per_sample());
   154     info.setLength(stream_info.get_total_samples());
   157     qDebug(
"Bitstream is %u channel, %uHz",
   158            stream_info.get_channels(),
   159            stream_info.get_sample_rate());
   164         const FLAC::Metadata::VorbisComment &vorbis_comments)
   169     QString vendor = QString::fromUtf8(reinterpret_cast<const char *>(
   170         vorbis_comments.get_vendor_string()));
   171     if (vendor.length()) {
   173         qDebug(
"Encoded by: '%s'\n\n", 
DBG(vendor));
   177     for (
unsigned int i = 0; i < vorbis_comments.get_num_comments(); i++) {
   178         FLAC::Metadata::VorbisComment::Entry comment =
   179             vorbis_comments.get_comment(i);
   180         Q_ASSERT(comment.is_valid());
   181         if (!comment.is_valid()) 
continue;
   183         QString 
name = QString::fromUtf8(
   184             comment.get_field_name(), comment.get_field_name_length());
   185         QString value = QString::fromUtf8(
   186             comment.get_field_value(), comment.get_field_value_length());
   192         info.
set(prop, value);
   200         date = QDate::fromString(str_date, Qt::ISODate);
   201         if (!date.isValid()) {
   202             int year = str_date.toInt();
   203             date.setDate(year, 1, 1);
   213     const ::FLAC__StreamMetadata *metadata)
   216     if (!metadata) 
return;
   218     switch (metadata->type) {
   219         case FLAC__METADATA_TYPE_STREAMINFO: {
   220             FLAC::Metadata::StreamInfo stream_info(
   221                 const_cast< ::FLAC__StreamMetadata * >(metadata), 
true);
   225         case FLAC__METADATA_TYPE_PADDING:
   228         case FLAC__METADATA_TYPE_APPLICATION:
   229             qDebug(
"FLAC metadata: application data");
   231         case FLAC__METADATA_TYPE_SEEKTABLE:
   232             qDebug(
"FLAC metadata: seektable - not supported yet");
   234         case FLAC__METADATA_TYPE_VORBIS_COMMENT: {
   235             FLAC::Metadata::VorbisComment vorbis_comments(
   236                 const_cast< ::FLAC__StreamMetadata * >(metadata), 
true);
   240         case FLAC__METADATA_TYPE_CUESHEET:
   241             qDebug(
"FLAC metadata: cuesheet - not supported yet");
   243         case FLAC__METADATA_TYPE_UNDEFINED:
   245             qDebug(
"FLAC metadata: unknown/undefined type");
   252     qDebug(
"FlacDecoder::error_callback: status=%d", status);
   260     if (
m_source) qWarning(
"FlacDecoder::open(), already open !");
   263     if (!src.open(QIODevice::ReadOnly)) {
   264         qWarning(
"failed to open source !");
   272     qDebug(
"--- FlacDecoder::open() ---");
   273     set_metadata_respond_all();
   276     FLAC__StreamDecoderInitStatus init_state = init();
   277     if (init_state > FLAC__STREAM_DECODER_INIT_STATUS_OK) {
   279            "Opening the FLAC bitstream failed."));
   284     process_until_end_of_metadata();
   286     FLAC::Decoder::Stream::State state = get_state();
   287     if (state >= FLAC__STREAM_DECODER_END_OF_STREAM) {
   289            "Error while parsing the FLAC metadata. (%s)"),
   290            _(state.as_cstring()));
   313     qDebug(
"FlacDecoder::decode(...)");
   314     process_until_end_of_stream();
 
bool contains(const FileProperty property) const
virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) Q_DECL_OVERRIDE
virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) Q_DECL_OVERRIDE
QVariant get(FileProperty key) const
Kwave::MultiWriter * m_dest
Kwave::VorbisCommentMap m_vorbis_comment_map
virtual Kwave::Decoder * instance() Q_DECL_OVERRIDE
virtual ::FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[]) Q_DECL_OVERRIDE
void set(FileProperty key, const QVariant &value)
virtual sample_index_t last() const
virtual ::FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes) Q_DECL_OVERRIDE
static int error(QWidget *widget, QString message, QString caption=QString())
#define DEFAULT_MIME_TYPE
void setLength(sample_index_t length)
virtual bool open(QWidget *widget, QIODevice &source) Q_DECL_OVERRIDE
virtual Kwave::MetaDataList & metaData()
virtual ~FlacDecoder() Q_DECL_OVERRIDE
#define REGISTER_MIME_TYPES
unsigned int tracks() const
virtual bool decode(QWidget *widget, Kwave::MultiWriter &dst) Q_DECL_OVERRIDE
#define REGISTER_COMPRESSION_TYPES
void parseStreamInfo(const FLAC::Metadata::StreamInfo &stream_info)
unsigned int bits() const
virtual void close() Q_DECL_OVERRIDE
void parseVorbisComments(const FLAC::Metadata::VorbisComment &vorbis_comments)