MythTV  master
recordingfile.cpp
Go to the documentation of this file.
1 
2 #include "recordingfile.h"
3 
4 #include "mythdbcon.h"
5 #include "mythdb.h"
6 
8 {
9  if (m_recordingId == 0)
10  return false;
11 
13  query.prepare("SELECT "
14  "hostname, storagegroup, id, basename, filesize, "
15  "video_codec, width, height, aspect, fps, "
16  "audio_codec, audio_channels, audio_sample_rate, "
17  "audio_avg_bitrate, container "
18  "FROM recordedfile "
19  "WHERE recordedid = :RECORDEDID ");
20  query.bindValue(":RECORDEDID", m_recordingId);
21 
22  if (!query.exec())
23  {
24  MythDB::DBError("RecordingFile::Load()", query);
25  return false;
26  }
27 
28  if (query.next())
29  {
30  m_storageDeviceID = query.value(0).toString();
31  m_storageGroup = query.value(1).toString();
32 
33  m_fileId = query.value(2).toUInt();
34  m_fileName = query.value(3).toString();
35  m_fileSize = static_cast<uint64_t>(query.value(4).toLongLong());
36 
37  m_videoCodec = query.value(5).toString();
38  uint width = query.value(6).toUInt();
39  uint height = query.value(7).toUInt();
40  m_videoResolution = QSize(width, height);
41  m_videoAspectRatio = query.value(8).toFloat();
42  m_videoFrameRate = query.value(9).toFloat();
43 
44  m_audioCodec = query.value(10).toString();
45  m_audioChannels = query.value(11).toUInt();
46  m_audioSampleRate = query.value(12).toUInt();
47  m_audioBitrate = query.value(13).toUInt();
48 
49  m_containerFormat = AVContainerFromString(query.value(14).toString());
50  }
51 
52  return true;
53 }
54 
56 {
57  if (m_recordingId == 0)
58  return false;
59 
61 
62  if (m_fileId > 0)
63  {
64  query.prepare("UPDATE recordedfile "
65  "SET "
66  "basename = :FILENAME, "
67  "filesize = :FILESIZE, "
68  "width = :WIDTH, "
69  "height = :HEIGHT, "
70  "fps = :FRAMERATE, "
71  "aspect = :ASPECT_RATIO, "
72  "audio_sample_rate = :AUDIO_SAMPLERATE, "
73  "audio_avg_bitrate = :AUDIO_BITRATE, "
74  "audio_channels = :AUDIO_CHANNELS, "
75  "audio_codec = :AUDIO_CODEC, "
76  "video_codec = :VIDEO_CODEC, "
77  "hostname = :STORAGE_DEVICE, "
78  "storagegroup = :STORAGE_GROUP, "
79  "recordedid = :RECORDING_ID, "
80  "container = :CONTAINER "
81  "WHERE id = :FILE_ID ");
82  query.bindValue(":FILE_ID", m_fileId);
83  }
84  else
85  {
86  query.prepare("INSERT INTO recordedfile "
87  "SET "
88  "basename = :FILENAME, "
89  "filesize = :FILESIZE, "
90  "width = :WIDTH, "
91  "height = :HEIGHT, "
92  "fps = :FRAMERATE, "
93  "aspect = :ASPECT_RATIO, "
94  "audio_sample_rate = :AUDIO_SAMPLERATE, "
95  "audio_avg_bitrate = :AUDIO_BITRATE, "
96  "audio_channels = :AUDIO_CHANNELS, "
97  "audio_codec = :AUDIO_CODEC, "
98  "video_codec = :VIDEO_CODEC, "
99  "hostname = :STORAGE_DEVICE, "
100  "storagegroup = :STORAGE_GROUP, "
101  "recordedid = :RECORDING_ID, "
102  "container = :CONTAINER ");
103  }
104 
105  query.bindValueNoNull(":FILENAME", m_fileName);
106  query.bindValue(":FILESIZE", static_cast<quint64>(m_fileSize));
107  query.bindValue(":WIDTH", m_videoResolution.width());
108  query.bindValue(":HEIGHT", m_videoResolution.height());
109  query.bindValue(":FRAMERATE", m_videoFrameRate);
110  query.bindValue(":ASPECT_RATIO", m_videoAspectRatio);
111  query.bindValue(":AUDIO_SAMPLERATE", m_audioSampleRate);
112  query.bindValue(":AUDIO_BITRATE", m_audioBitrate);
113  query.bindValue(":AUDIO_CHANNELS", m_audioChannels);
114  query.bindValueNoNull(":AUDIO_CODEC", m_audioCodec);
115  query.bindValueNoNull(":VIDEO_CODEC", m_videoCodec);
116  query.bindValueNoNull(":STORAGE_DEVICE", m_storageDeviceID);
117  query.bindValueNoNull(":STORAGE_GROUP", m_storageGroup);
118  query.bindValue(":CONTAINER", AVContainerToString(m_containerFormat));
119  query.bindValue(":RECORDING_ID", m_recordingId);
120 
121  if (!query.exec())
122  {
123  MythDB::DBError("RecordingFile::Save()", query);
124  return false;
125  }
126 
127  if (m_fileId == 0)
128  m_fileId = query.lastInsertId().toUInt();
129 
130  return true;
131 }
132 
134 {
135  if (formatStr == "NUV")
136  return formatNUV;
137  if (formatStr == "MPEG2-TS")
138  return formatMPEG2_TS;
139  if (formatStr == "MPEG2-PS")
140  return formatMPEG2_PS;
141  return formatUnknown;
142 }
143 
145 {
146  switch (format)
147  {
148  case formatNUV :
149  return "NUV";
150  case formatMPEG2_TS :
151  return "MPEG2-TS";
152  case formatMPEG2_PS :
153  return "MPEG2-PS";
154  case formatUnknown:
155  default:
156  return "";
157  }
158 }
159 
160 
QString m_fileName
Definition: recordingfile.h:44
bool next(void)
Wrap QSqlQuery::next() so we can display the query results.
Definition: mythdbcon.cpp:782
void bindValue(const QString &placeholder, const QVariant &val)
Add a single binding.
Definition: mythdbcon.cpp:863
QSize m_videoResolution
Definition: recordingfile.h:50
QString m_storageGroup
Definition: recordingfile.h:41
QSqlQuery wrapper that fetches a DB connection from the connection pool.
Definition: mythdbcon.h:125
enum AVContainerFormats AVContainer
unsigned int uint
Definition: compat.h:140
QScriptValue formatStr(QScriptContext *context, QScriptEngine *interpreter)
double m_audioSampleRate
Definition: recordingfile.h:56
QString m_audioCodec
Definition: recordingfile.h:54
QVariant value(int i) const
Definition: mythdbcon.h:198
QString m_videoCodec
Definition: recordingfile.h:49
QVariant lastInsertId()
Return the id of the last inserted row.
Definition: mythdbcon.cpp:887
QString m_storageDeviceID
Definition: recordingfile.h:40
double m_videoFrameRate
Definition: recordingfile.h:52
static MSqlQueryInfo InitCon(ConnectionReuse=kNormalConnection)
Only use this in combination with MSqlQuery constructor.
Definition: mythdbcon.cpp:535
double m_videoAspectRatio
Definition: recordingfile.h:51
bool prepare(const QString &query)
QSqlQuery::prepare() is not thread safe in Qt <= 3.3.2.
Definition: mythdbcon.cpp:807
void bindValueNoNull(const QString &placeholder, const QVariant &val)
Add a single binding, taking care not to set a NULL value.
Definition: mythdbcon.cpp:868
AVContainer m_containerFormat
Definition: recordingfile.h:47
static AVContainer AVContainerFromString(const QString &formatStr)
bool exec(void)
Wrap QSqlQuery::exec() so we can display SQL.
Definition: mythdbcon.cpp:603
static void DBError(const QString &where, const MSqlQuery &query)
Definition: mythdb.cpp:179
static QString AVContainerToString(AVContainer format)
uint64_t m_fileSize
Definition: recordingfile.h:45