mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge pull request #3453 from birarda/clement-recording-changes
Rec file format tweaks (on behalf of @Atlante45)
This commit is contained in:
commit
b63ef1f7fe
6 changed files with 46 additions and 53 deletions
|
@ -17,15 +17,15 @@
|
|||
#include "Player.h"
|
||||
|
||||
Player::Player(AvatarData* avatar) :
|
||||
_recording(new Recording()),
|
||||
_avatar(avatar),
|
||||
_audioThread(NULL),
|
||||
_playFromCurrentPosition(true),
|
||||
_loop(false),
|
||||
_useAttachments(true),
|
||||
_useDisplayName(true),
|
||||
_useHeadURL(true),
|
||||
_useSkeletonURL(true)
|
||||
_recording(new Recording()),
|
||||
_avatar(avatar),
|
||||
_audioThread(NULL),
|
||||
_playFromCurrentPosition(true),
|
||||
_loop(false),
|
||||
_useAttachments(true),
|
||||
_useDisplayName(true),
|
||||
_useHeadURL(true),
|
||||
_useSkeletonURL(true)
|
||||
{
|
||||
_timer.invalidate();
|
||||
_options.setLoop(false);
|
||||
|
@ -157,10 +157,9 @@ void Player::loopRecording() {
|
|||
setupAudioThread();
|
||||
_currentFrame = 0;
|
||||
_timer.restart();
|
||||
|
||||
}
|
||||
|
||||
void Player::loadFromFile(QString file) {
|
||||
void Player::loadFromFile(const QString& file) {
|
||||
if (_recording) {
|
||||
_recording->clear();
|
||||
} else {
|
||||
|
|
|
@ -34,10 +34,10 @@ public:
|
|||
|
||||
RecordingPointer getRecording() const { return _recording; }
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void startPlaying();
|
||||
void stopPlaying();
|
||||
void loadFromFile(QString file);
|
||||
void loadFromFile(const QString& file);
|
||||
void loadRecording(RecordingPointer recording);
|
||||
void play();
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ void Recorder::stopRecording() {
|
|||
qDebug().nospace() << "Recorded " << _recording->getFrameNumber() << " during " << _recording->getLength() << " msec (" << _recording->getFrameNumber() / (_recording->getLength() / 1000.0f) << " fps)";
|
||||
}
|
||||
|
||||
void Recorder::saveToFile(QString file) {
|
||||
void Recorder::saveToFile(const QString& file) {
|
||||
if (_recording->isEmpty()) {
|
||||
qDebug() << "Cannot save recording to file, recording is empty.";
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
public slots:
|
||||
void startRecording();
|
||||
void stopRecording();
|
||||
void saveToFile(QString file);
|
||||
void saveToFile(const QString& file);
|
||||
void record();
|
||||
void record(char* samples, int size);
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
#include <QEventLoop>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
#include <QPair>
|
||||
|
||||
#include "AvatarData.h"
|
||||
|
@ -74,7 +73,7 @@ void Recording::addFrame(int timestamp, RecordingFrame &frame) {
|
|||
_frames << frame;
|
||||
}
|
||||
|
||||
void Recording::addAudioPacket(QByteArray byteArray) {
|
||||
void Recording::addAudioPacket(const QByteArray& byteArray) {
|
||||
if (!_audio) {
|
||||
_audio = new Sound(byteArray);
|
||||
return;
|
||||
|
@ -89,7 +88,7 @@ void Recording::clear() {
|
|||
_audio = NULL;
|
||||
}
|
||||
|
||||
void writeVec3(QDataStream& stream, glm::vec3 value) {
|
||||
void writeVec3(QDataStream& stream, const glm::vec3& value) {
|
||||
unsigned char buffer[sizeof(value)];
|
||||
memcpy(buffer, &value, sizeof(value));
|
||||
stream.writeRawData(reinterpret_cast<char*>(buffer), sizeof(value));
|
||||
|
@ -102,7 +101,7 @@ bool readVec3(QDataStream& stream, glm::vec3& value) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void writeQuat(QDataStream& stream, glm::quat value) {
|
||||
void writeQuat(QDataStream& stream, const glm::quat& value) {
|
||||
unsigned char buffer[256];
|
||||
int writtenToBuffer = packOrientationQuatToBytes(buffer, value);
|
||||
stream.writeRawData(reinterpret_cast<char*>(buffer), writtenToBuffer);
|
||||
|
@ -136,7 +135,7 @@ bool readFloat(QDataStream& stream, float& value, int radix) {
|
|||
return true;
|
||||
}
|
||||
|
||||
void writeRecordingToFile(RecordingPointer recording, QString filename) {
|
||||
void writeRecordingToFile(RecordingPointer recording, const QString& filename) {
|
||||
if (!recording || recording->getFrameNumber() < 1) {
|
||||
qDebug() << "Can't save empty recording";
|
||||
return;
|
||||
|
@ -329,7 +328,7 @@ void writeRecordingToFile(RecordingPointer recording, QString filename) {
|
|||
|
||||
fileStream << recording->_audio->getByteArray();
|
||||
|
||||
qint64 writtingTime = timer.restart();
|
||||
qint64 writingTime = timer.restart();
|
||||
// Write data length and CRC-16
|
||||
quint32 dataLength = file.pos() - dataOffset;
|
||||
file.seek(dataOffset); // Go to beginning of data for checksum
|
||||
|
@ -374,10 +373,10 @@ void writeRecordingToFile(RecordingPointer recording, QString filename) {
|
|||
}
|
||||
|
||||
qint64 checksumTime = timer.elapsed();
|
||||
qDebug() << "Wrote" << file.size() << "bytes in" << writtingTime + checksumTime << "ms. (" << checksumTime << "ms for checksum)";
|
||||
qDebug() << "Wrote" << file.size() << "bytes in" << writingTime + checksumTime << "ms. (" << checksumTime << "ms for checksum)";
|
||||
}
|
||||
|
||||
RecordingPointer readRecordingFromFile(RecordingPointer recording, QString filename) {
|
||||
RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString& filename) {
|
||||
QByteArray byteArray;
|
||||
QUrl url(filename);
|
||||
QElapsedTimer timer;
|
||||
|
@ -416,10 +415,6 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, QString filen
|
|||
|
||||
if (filename.endsWith(".rec") || filename.endsWith(".REC")) {
|
||||
qDebug() << "Old .rec format";
|
||||
QMessageBox::warning(NULL,
|
||||
QString("Old recording format"),
|
||||
QString("Converting your file to the new format."),
|
||||
QMessageBox::Ok);
|
||||
readRecordingFromRecFile(recording, filename, byteArray);
|
||||
return recording;
|
||||
} else if (!filename.endsWith(".hfr") && !filename.endsWith(".HFR")) {
|
||||
|
@ -641,7 +636,7 @@ RecordingPointer readRecordingFromFile(RecordingPointer recording, QString filen
|
|||
}
|
||||
|
||||
|
||||
RecordingPointer readRecordingFromRecFile(RecordingPointer recording, QString filename, QByteArray byteArray) {
|
||||
RecordingPointer readRecordingFromRecFile(RecordingPointer recording, const QString& filename, const QByteArray& byteArray) {
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
|
@ -786,21 +781,18 @@ RecordingPointer readRecordingFromRecFile(RecordingPointer recording, QString fi
|
|||
qDebug() << "Read " << byteArray.size() << " bytes in " << timer.elapsed() << " ms.";
|
||||
|
||||
// Set new filename
|
||||
if (filename.startsWith("http") || filename.startsWith("https") || filename.startsWith("ftp")) {
|
||||
filename = QUrl(filename).fileName();
|
||||
QString newFilename = filename;
|
||||
if (newFilename.startsWith("http") || newFilename.startsWith("https") || newFilename.startsWith("ftp")) {
|
||||
newFilename = QUrl(newFilename).fileName();
|
||||
}
|
||||
if (filename.endsWith(".rec") || filename.endsWith(".REC")) {
|
||||
filename.chop(qstrlen(".rec"));
|
||||
if (newFilename.endsWith(".rec") || newFilename.endsWith(".REC")) {
|
||||
newFilename.chop(qstrlen(".rec"));
|
||||
}
|
||||
filename.append(".hfr");
|
||||
filename = QFileInfo(filename).absoluteFilePath();
|
||||
newFilename.append(".hfr");
|
||||
newFilename = QFileInfo(newFilename).absoluteFilePath();
|
||||
|
||||
// Set recording to new format
|
||||
writeRecordingToFile(recording, filename);
|
||||
QMessageBox::warning(NULL,
|
||||
QString("New recording location"),
|
||||
QString("The new recording was saved at:\n" + filename),
|
||||
QMessageBox::Ok);
|
||||
qDebug() << "Recording has been successfully converted at" << filename;
|
||||
writeRecordingToFile(recording, newFilename);
|
||||
qDebug() << "Recording has been successfully converted at" << newFilename;
|
||||
return recording;
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public:
|
|||
|
||||
protected:
|
||||
void addFrame(int timestamp, RecordingFrame& frame);
|
||||
void addAudioPacket(QByteArray byteArray);
|
||||
void addAudioPacket(const QByteArray& byteArray);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
|
@ -74,9 +74,10 @@ private:
|
|||
|
||||
friend class Recorder;
|
||||
friend class Player;
|
||||
friend void writeRecordingToFile(RecordingPointer recording, QString file);
|
||||
friend RecordingPointer readRecordingFromFile(RecordingPointer recording, QString file);
|
||||
friend RecordingPointer readRecordingFromRecFile(RecordingPointer recording, QString filename, QByteArray byteArray);
|
||||
friend void writeRecordingToFile(RecordingPointer recording, const QString& file);
|
||||
friend RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString& file);
|
||||
friend RecordingPointer readRecordingFromRecFile(RecordingPointer recording, const QString& filename,
|
||||
const QByteArray& byteArray);
|
||||
};
|
||||
|
||||
/// Stores the different values associated to one recording frame
|
||||
|
@ -95,13 +96,13 @@ public:
|
|||
protected:
|
||||
void setBlendshapeCoefficients(QVector<float> blendshapeCoefficients);
|
||||
void setJointRotations(QVector<glm::quat> jointRotations) { _jointRotations = jointRotations; }
|
||||
void setTranslation(glm::vec3 translation) { _translation = translation; }
|
||||
void setRotation(glm::quat rotation) { _rotation = rotation; }
|
||||
void setTranslation(const glm::vec3& translation) { _translation = translation; }
|
||||
void setRotation(const glm::quat& rotation) { _rotation = rotation; }
|
||||
void setScale(float scale) { _scale = scale; }
|
||||
void setHeadRotation(glm::quat headRotation) { _headRotation = headRotation; }
|
||||
void setLeanSideways(float leanSideways) { _leanSideways = leanSideways; }
|
||||
void setLeanForward(float leanForward) { _leanForward = leanForward; }
|
||||
void setLookAtPosition(glm::vec3 lookAtPosition) { _lookAtPosition = lookAtPosition; }
|
||||
void setLookAtPosition(const glm::vec3& lookAtPosition) { _lookAtPosition = lookAtPosition; }
|
||||
|
||||
private:
|
||||
QVector<float> _blendshapeCoefficients;
|
||||
|
@ -115,13 +116,14 @@ private:
|
|||
glm::vec3 _lookAtPosition;
|
||||
|
||||
friend class Recorder;
|
||||
friend void writeRecordingToFile(RecordingPointer recording, QString file);
|
||||
friend RecordingPointer readRecordingFromFile(RecordingPointer recording, QString file);
|
||||
friend RecordingPointer readRecordingFromRecFile(RecordingPointer recording, QString filename, QByteArray byteArray);
|
||||
friend void writeRecordingToFile(RecordingPointer recording, const QString& file);
|
||||
friend RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString& file);
|
||||
friend RecordingPointer readRecordingFromRecFile(RecordingPointer recording, const QString& filename,
|
||||
const QByteArray& byteArray);
|
||||
};
|
||||
|
||||
void writeRecordingToFile(RecordingPointer recording, QString filename);
|
||||
RecordingPointer readRecordingFromFile(RecordingPointer recording, QString filename);
|
||||
RecordingPointer readRecordingFromRecFile(RecordingPointer recording, QString filename, QByteArray byteArray);
|
||||
void writeRecordingToFile(RecordingPointer recording, const QString& filename);
|
||||
RecordingPointer readRecordingFromFile(RecordingPointer recording, const QString& filename);
|
||||
RecordingPointer readRecordingFromRecFile(RecordingPointer recording, const QString& filename, const QByteArray& byteArray);
|
||||
|
||||
#endif // hifi_Recording_h
|
Loading…
Reference in a new issue