kwave  18.07.70
OggEncoder.cpp
Go to the documentation of this file.
1 /*************************************************************************
2  OggEncoder.cpp - encoder for Ogg/Vorbis data
3  -------------------
4  begin : Tue Sep 10 2002
5  copyright : (C) 2002 by Thomas Eschenbacher
6  email : Thomas.Eschenbacher@gmx.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "config.h"
19 
20 #include <math.h>
21 #include <stdlib.h>
22 
23 #include <QList>
24 #include <QSharedPointer>
25 
26 #include <KLocalizedString>
27 
28 #include "libkwave/FileInfo.h"
29 #include "libkwave/MessageBox.h"
30 #include "libkwave/MetaDataList.h"
32 #include "libkwave/Sample.h"
33 
34 #include "OggCodecPlugin.h"
35 #include "OggEncoder.h"
36 #include "OggSubEncoder.h"
37 #include "OpusEncoder.h"
38 #include "VorbisEncoder.h"
39 
40 
41 /***************************************************************************/
43  :Kwave::Encoder(), m_comments_map()
44 {
45 #ifdef HAVE_OGG_OPUS
48 #endif /* HAVE_OGG_OPUS */
49 
50 #ifdef HAVE_OGG_VORBIS
53 #endif /* HAVE_OGG_VORBIS */
54 }
55 
56 /***************************************************************************/
58 {
59 }
60 
61 /***************************************************************************/
63 {
64  return new Kwave::OggEncoder();
65 }
66 
67 /***************************************************************************/
68 QList<Kwave::FileProperty> Kwave::OggEncoder::supportedProperties()
69 {
70  return m_comments_map.values();
71 }
72 
73 /***************************************************************************/
75  QIODevice &dst,
76  const Kwave::MetaDataList &meta_data)
77 {
78  const Kwave::FileInfo info(meta_data);
79  QSharedPointer<Kwave::OggSubEncoder> sub_encoder;
80 
81  // determine which codec (sub encoder) to use,
82  // by examining the compression type
83  const Kwave::Compression::Type compression =
86 
87 #ifdef HAVE_OGG_OPUS
88  if (compression == Compression::OGG_OPUS) {
89  qDebug(" OggEncoder: using Opus codec");
90  sub_encoder =
91  QSharedPointer<Kwave::OpusEncoder>(new Kwave::OpusEncoder());
92  }
93 #endif /* HAVE_OGG_OPUS */
94 #ifdef HAVE_OGG_VORBIS
95  if (compression == Compression::OGG_VORBIS) {
96  qDebug(" OggEncoder: using Vorbis codec");
97  sub_encoder =
98  QSharedPointer<Kwave::VorbisEncoder>(new Kwave::VorbisEncoder());
99  }
100 #endif /* HAVE_OGG_VORBIS */
101 
102  if (!sub_encoder) {
103  qDebug(" OggEncoder: compression='%d'", compression);
104  Kwave::MessageBox::error(widget, i18nc(
105  "error in Ogg encoder, no support for a compression type "
106  "(e.g. opus, vorbis etc)",
107  "Error: No Codec for '%1' available",
108  Kwave::Compression(compression).name()
109  ));
110  return false;
111  }
112 
113  if (!sub_encoder->open(widget, info, src))
114  return false;
115 
116  // open the output device
117  if (!dst.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
119  i18n("Unable to open the file for saving."));
120  return false;
121  }
122 
123  if (!sub_encoder->writeHeader(dst))
124  return false;
125 
126  if (!sub_encoder->encode(src, dst))
127  return false;
128 
129  // clean up and exit.
130  sub_encoder->close();
131 
132  // the sub encoder will be deleted automatically (QSharedPointer)
133 
134  return true;
135 }
136 
137 //***************************************************************************
138 //***************************************************************************
bool contains(const FileProperty property) const
Definition: FileInfo.cpp:354
Definition: App.h:33
Kwave::VorbisCommentMap m_comments_map
Definition: OggEncoder.h:68
QVariant get(FileProperty key) const
Definition: FileInfo.cpp:372
virtual QList< Kwave::FileProperty > supportedProperties() Q_DECL_OVERRIDE
Definition: OggEncoder.cpp:68
static Kwave::Compression::Type fromInt(int i)
Definition: Compression.cpp:78
virtual Kwave::Encoder * instance() Q_DECL_OVERRIDE
Definition: OggEncoder.cpp:62
const char name[16]
Definition: memcpy.c:510
#define REGISTER_OGG_VORBIS_MIME_TYPES
static int error(QWidget *widget, QString message, QString caption=QString())
Definition: MessageBox.cpp:126
virtual bool encode(QWidget *widget, Kwave::MultiTrackReader &src, QIODevice &dst, const Kwave::MetaDataList &meta_data) Q_DECL_OVERRIDE
Definition: OggEncoder.cpp:74
#define REGISTER_COMPRESSION_TYPE_OGG_OPUS
#define REGISTER_OGG_OPUS_MIME_TYPES
#define REGISTER_COMPRESSION_TYPE_OGG_VORBIS
virtual ~OggEncoder() Q_DECL_OVERRIDE
Definition: OggEncoder.cpp:57