本文整理汇总了C++中taglib::ByteVector类的典型用法代码示例。如果您正苦于以下问题:C++ ByteVector类的具体用法?C++ ByteVector怎么用?C++ ByteVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ByteVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fileref
Tag::Tag(const QString &filename)
: m_filename(filename)
{
TagLib::MPEG::File mpegfile(filename.toLocal8Bit().constData());
TagLib::ID3v2::Tag* id3v2 = mpegfile.ID3v2Tag();
if (id3v2 && !id3v2->isEmpty()) {
readRegularTag(id3v2, m_data);
int picnum = 0;
TagLib::ID3v2::FrameList frames = id3v2->frameListMap()["APIC"]; // attached picture
TagLib::ID3v2::FrameList::ConstIterator it = frames.begin();
while (it != frames.end()) {
TagLib::ID3v2::AttachedPictureFrame* apic = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
TagLib::ByteVector bytes = apic->picture();
QImage img = QImage::fromData(reinterpret_cast<const uchar*>(bytes.data()), bytes.size());
if (!img.isNull()) {
m_data[QLatin1String("picture") + QString::number(picnum++)] = QVariant(img);
}
++it;
}
} else {
TagLib::FileRef fileref(filename.toLocal8Bit().constData());
if (fileref.isNull())
return;
TagLib::Tag* tag = fileref.tag();
if (!tag || tag->isEmpty())
return;
readRegularTag(tag, m_data);
}
}
示例2: writeFileFromVector
bool writeFileFromVector(const char *path, const TagLib::ByteVector &v) {
std::ofstream o(path, std::ofstream::binary);
if (!o) {
return false;
}
o.write(v.data(), v.size());
return true;
}
示例3: WriteCover
/*
** Write cover data to file.
**
*/
bool CCover::WriteCover(const TagLib::ByteVector& data, const std::wstring& target)
{
bool written = false;
FILE* f = _wfopen(target.c_str(), L"wb");
if (f)
{
written = (fwrite(data.data(), 1, data.size(), f) == data.size());
fclose(f);
}
return written;
}
示例4: readBlock
TagLib::ByteVector CloudStream::readBlock(ulong length) {
const uint start = cursor_;
const uint end = qMin(cursor_ + length - 1, length_ - 1);
if (end < start) {
return TagLib::ByteVector();
}
if (CheckCache(start, end)) {
TagLib::ByteVector cached = GetCached(start, end);
cursor_ += cached.size();
return cached;
}
QNetworkRequest request = QNetworkRequest(url_);
if (!auth_.isEmpty()) {
request.setRawHeader("Authorization", auth_.toUtf8());
}
request.setRawHeader("Range",
QString("bytes=%1-%2").arg(start).arg(end).toUtf8());
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
QNetworkRequest::AlwaysNetwork);
// The Ubuntu One server applies the byte range to the gzipped data, rather
// than the raw data so we must disable compression.
if (url_.host() == "files.one.ubuntu.com") {
request.setRawHeader("Accept-Encoding", "identity");
}
QNetworkReply* reply = network_->get(request);
connect(reply, SIGNAL(sslErrors(QList<QSslError>)),
SLOT(SSLErrors(QList<QSslError>)));
++num_requests_;
QEventLoop loop;
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
reply->deleteLater();
int code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (code >= 400) {
qLog(Debug) << "Error retrieving url to tag:" << url_;
return TagLib::ByteVector();
}
QByteArray data = reply->readAll();
TagLib::ByteVector bytes(data.data(), data.size());
cursor_ += data.size();
FillCache(start, bytes);
return bytes;
}
示例5: extractMBIDFromFile
QString extractMBIDFromFile(TagLib::MPEG::File *file)
{
TagLib::ID3v2::Tag *tag = file->ID3v2Tag();
TagLib::ID3v2::FrameList ufid = tag->frameListMap()["UFID"];
if (!ufid.isEmpty()) {
for (TagLib::ID3v2::FrameList::Iterator i = ufid.begin(); i != ufid.end(); i++) {
TagLib::ID3v2::UniqueFileIdentifierFrame *frame = dynamic_cast<TagLib::ID3v2::UniqueFileIdentifierFrame *>(*i);
if (frame && frame->owner() == "http://musicbrainz.org") {
TagLib::ByteVector id = frame->identifier();
return QString::fromAscii(id.data(), id.size());
}
}
}
return QString();
}
示例6:
void
CloudStream::FillCache( int start, TagLib::ByteVector data )
{
for ( int i = 0; i < data.size(); ++i )
{
m_cache.set( start + i, data[i] );
}
}
示例7: readBlock
TagLib::ByteVector CloudStream::readBlock(ulong length) {
const uint start = cursor_;
const uint end = qMin(cursor_ + length - 1, length_ - 1);
if (end < start) {
return TagLib::ByteVector();
}
if (CheckCache(start, end)) {
TagLib::ByteVector cached = GetCached(start, end);
cursor_ += cached.size();
return cached;
}
QNetworkRequest request = QNetworkRequest(url_);
foreach (const QString& key, headers_) {
request.setRawHeader(key.toLatin1(), headers_[key].toUtf8());
}
示例8: ExtractAPE
/*
** Extracts cover art embedded in APE tags.
**
*/
bool CCover::ExtractAPE(TagLib::APE::Tag* tag, const std::wstring& target)
{
const TagLib::APE::ItemListMap& listMap = tag->itemListMap();
if (listMap.contains("COVER ART (FRONT)"))
{
const TagLib::ByteVector nullStringTerminator(1, 0);
TagLib::ByteVector item = listMap["COVER ART (FRONT)"].value();
int pos = item.find(nullStringTerminator); // Skip the filename
if (++pos > 0)
{
const TagLib::ByteVector& pic = item.mid(pos);
return WriteCover(pic, target);
}
}
return false;
}
示例9: coverFromXiphComment
bool CoverUtils::coverFromXiphComment(TagLib::Ogg::XiphComment *xiphComment, Album *album) {
if (!xiphComment) return false;
const TagLib::StringList &stringList = xiphComment->fieldListMap()["COVERART"];
if (stringList.isEmpty()) return false;
TagLib::ByteVector byteVector = stringList.front().data(TagLib::String::Latin1);
QByteArray encodedData;
encodedData.setRawData(byteVector.data(), byteVector.size());
QByteArray data = QByteArray::fromBase64(encodedData);
QImage image;
image.loadFromData(data);
if (!isAcceptableImage(image)) return false;
qDebug() << "Cover from Xiph!";
return saveImage(image, album);
}
示例10: ExtractAPE
/*
** Extracts cover art embedded in APE tags.
**
*/
bool QCoverArt::ExtractAPE(TagLib::APE::Tag* tag)
{
const TagLib::APE::ItemListMap& listMap = tag->itemListMap();
if (listMap.contains("COVER ART (FRONT)"))
{
const TagLib::ByteVector nullStringTerminator(1, 0);
TagLib::ByteVector item = listMap["COVER ART (FRONT)"].value();
int pos = item.find(nullStringTerminator); // Skip the filename
if (++pos > 0)
{
const TagLib::ByteVector& pic = item.mid(pos);
img.loadFromData((const unsigned char*)pic.data(), pic.size());
return true;
}
}
return false;
}
示例11: if
// NOTE: representation is taken to be a binary value with units in the first column,
// 1/2 in the second and so on.
static qreal readRVA2PeakValue( const TagLib::ByteVector &data, int bits, bool *ok )
{
qreal peak = 0.0;
// discarding digits at the end reduces precision, but doesn't otherwise change the value
if ( bits > 32 )
bits = 32;
// the +7 makes sure we round up when we divide by 8
unsigned int bytes = (bits + 7) / 8;
// normalize appears not to write a peak at all, and hence sets bits to 0
if ( bits == 0 )
{
if ( ok )
*ok = true;
}
else if ( bits >= 4 && data.size() >= bytes ) // fewer than 4 bits would just be daft
{
// excessBits is the number of bits we have to discard at the end
unsigned int excessBits = (8 * bytes) - bits;
// mask has 1s everywhere but the last /excessBits/ bits
quint32 mask = 0xffffffff << excessBits;
quint32 rawValue = 0;
for ( unsigned int i = 0; i < bytes; ++i )
{
rawValue <<= 8;
rawValue += (unsigned char)data[i];
}
rawValue &= mask;
peak = rawValue;
// amount we need to "shift" the value right to make the first digit the unit column
unsigned int rightShift = (8 * bytes) - 1;
peak /= (qreal)(1 << rightShift);
if ( ok )
*ok = true;
}
else
{
if ( ok )
*ok = false;
}
return peak;
}
示例12: loadFileIntoVector
size_t loadFileIntoVector(const char *path, TagLib::ByteVector &v)
{
std::ifstream is(path, std::ifstream::binary);
if (!is.good()) {
return 0;
}
// get the file size and create an appropriate buffer
is.seekg(0, is.end);
size_t len = is.tellg();
is.seekg(0, is.beg);
char *buf = new char[len];
// read into buffer
is.read(buf, len);
v.setData(buf, len);
is.close();
delete[] buf;
return len;
}
示例13: desc
static Meta::ReplayGainTagMap readID3v2Tags( TagLib::ID3v2::Tag *tag )
{
Meta::ReplayGainTagMap map;
{ // ID3v2.4.0 native replay gain tag support (as written by Quod Libet, for example).
TagLib::ID3v2::FrameList frames = tag->frameListMap()["RVA2"];
frames.append(tag->frameListMap()["XRVA"]);
if ( !frames.isEmpty() )
{
for ( unsigned int i = 0; i < frames.size(); ++i )
{
// we have to parse this frame ourselves
// ID3v2 frame header is 10 bytes, so skip that
TagLib::ByteVector data = frames[i]->render().mid( 10 );
unsigned int offset = 0;
QString desc( data.data() );
offset += desc.count() + 1;
unsigned int channel = data.mid( offset, 1 ).toUInt( true );
// channel 1 is the main volume - the only one we care about
if ( channel == 1 )
{
++offset;
qint16 adjustment512 = data.mid( offset, 2 ).toShort( true );
qreal adjustment = ( (qreal)adjustment512 ) / 512.0;
offset += 2;
unsigned int peakBits = data.mid( offset, 1 ).toUInt( true );
++offset;
bool ok = false;
qreal peak = readRVA2PeakValue( data.mid( offset ), peakBits, &ok );
if ( ok )
{
if ( desc.toLower() == "album" )
{
map[Meta::ReplayGain_Album_Gain] = adjustment;
map[Meta::ReplayGain_Album_Peak] = peakToDecibels( peak );
}
else if ( desc.toLower() == "track" || !map.contains( Meta::ReplayGain_Track_Gain ) )
{
map[Meta::ReplayGain_Track_Gain] = adjustment;
map[Meta::ReplayGain_Track_Peak] = peakToDecibels( peak );
}
}
}
}
if ( !map.isEmpty() )
return map;
}
}
{ // Foobar2000-style ID3v2.3.0 tags
TagLib::ID3v2::FrameList frames = tag->frameListMap()["TXXX"];
for ( TagLib::ID3v2::FrameList::Iterator it = frames.begin(); it != frames.end(); ++it ) {
TagLib::ID3v2::UserTextIdentificationFrame* frame =
dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>( *it );
if ( frame && frame->fieldList().size() >= 2 )
{
QString desc = TStringToQString( frame->description() ).toLower();
if ( desc == "replaygain_album_gain" )
maybeAddGain( frame->fieldList()[1], Meta::ReplayGain_Album_Gain, &map );
if ( desc == "replaygain_album_peak" )
maybeAddPeak( frame->fieldList()[1], Meta::ReplayGain_Album_Peak, &map );
if ( desc == "replaygain_track_gain" )
maybeAddGain( frame->fieldList()[1], Meta::ReplayGain_Track_Gain, &map );
if ( desc == "replaygain_track_peak" )
maybeAddPeak( frame->fieldList()[1], Meta::ReplayGain_Track_Peak, &map );
}
}
}
return map;
}
示例14: image
/*!
* \brief Write the albumart image to the file
*
* \param filename The music file to add the albumart
* \param albumart The Album Art image to write
* \returns True if successful
*
* \note We always save the image in JPEG format
*/
bool MetaIOID3::writeAlbumArt(const QString &filename,
const AlbumArtImage *albumart)
{
if (filename.isEmpty() || !albumart)
return false;
// load the image into a QByteArray
QImage image(albumart->m_filename);
QByteArray imageData;
QBuffer buffer(&imageData);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPEG");
AttachedPictureFrame::Type type = AttachedPictureFrame::Other;
switch (albumart->m_imageType)
{
case IT_FRONTCOVER:
type = AttachedPictureFrame::FrontCover;
break;
case IT_BACKCOVER:
type = AttachedPictureFrame::BackCover;
break;
case IT_CD:
type = AttachedPictureFrame::Media;
break;
case IT_INLAY:
type = AttachedPictureFrame::LeafletPage;
break;
case IT_ARTIST:
type = AttachedPictureFrame::Artist;
break;
default:
type = AttachedPictureFrame::Other;
break;
}
if (!OpenFile(filename, true))
return false;
TagLib::ID3v2::Tag *tag = GetID3v2Tag();
if (!tag)
return false;
AttachedPictureFrame *apic = findAPIC(tag, type,
QStringToTString(albumart->m_description));
if (!apic)
{
apic = new AttachedPictureFrame();
tag->addFrame(apic);
apic->setType(type);
}
QString mimetype = "image/jpeg";
TagLib::ByteVector bytevector;
bytevector.setData(imageData.data(), imageData.size());
apic->setMimeType(QStringToTString(mimetype));
apic->setPicture(bytevector);
apic->setDescription(QStringToTString(albumart->m_description));
if (!SaveFile())
return false;
return true;
}
示例15: decoder
TagLib::ByteVector TagLib::DecodeBase64(const TagLib::ByteVector& input)
{
SFB::CFError error;
SFB::SecTransform decoder(SecDecodeTransformCreate(kSecBase64Encoding, &error));
if(!decoder) {
LOGGER_WARNING("org.sbooth.AudioEngine", "SecDecodeTransformCreate failed: " << error);
return {};
}
SFB::CFData sourceData(CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (const UInt8 *)input.data(), (CFIndex)input.size(), kCFAllocatorNull));
if(!sourceData)
return {};
if(!SecTransformSetAttribute(decoder, kSecTransformInputAttributeName, sourceData, &error)) {
LOGGER_WARNING("org.sbooth.AudioEngine", "SecTransformSetAttribute failed: " << error);
return {};
}
SFB::CFData decodedData((CFDataRef)SecTransformExecute(decoder, &error));
if(!decodedData)
return {};
return {(const char *)CFDataGetBytePtr((CFDataRef)decodedData), (size_t)CFDataGetLength((CFDataRef)decodedData)};
}