|
a/upmpd/ohinfo.cxx |
|
b/upmpd/ohinfo.cxx |
|
... |
|
... |
44 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Info");
|
44 |
static const string sIdProduct("urn:av-openhome-org:serviceId:Info");
|
45 |
|
45 |
|
46 |
OHInfo::OHInfo(UpMpd *dev)
|
46 |
OHInfo::OHInfo(UpMpd *dev)
|
47 |
: UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev)
|
47 |
: UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev)
|
48 |
{
|
48 |
{
|
49 |
dev->addActionMapping(this, "Counters", bind(&OHInfo::counters,
|
49 |
dev->addActionMapping(this, "Counters",
|
50 |
this, _1, _2));
|
50 |
bind(&OHInfo::counters, this, _1, _2));
|
51 |
dev->addActionMapping(this, "Track", bind(&OHInfo::track,
|
51 |
dev->addActionMapping(this, "Track",
|
52 |
this, _1, _2));
|
52 |
bind(&OHInfo::track, this, _1, _2));
|
53 |
dev->addActionMapping(this, "Details", bind(&OHInfo::details,
|
53 |
dev->addActionMapping(this, "Details",
|
54 |
this, _1, _2));
|
54 |
bind(&OHInfo::details, this, _1, _2));
|
55 |
dev->addActionMapping(this, "Metatext", bind(&OHInfo::metatext,
|
55 |
dev->addActionMapping(this, "Metatext",
|
56 |
this, _1, _2));
|
56 |
bind(&OHInfo::metatext, this, _1, _2));
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
void OHInfo::urimetadata(string& uri, string& metadata)
|
|
|
60 |
{
|
|
|
61 |
const MpdStatus &mpds = m_dev->getMpdStatus();
|
|
|
62 |
bool is_song = (mpds.state == MpdStatus::MPDS_PLAY) ||
|
|
|
63 |
(mpds.state == MpdStatus::MPDS_PAUSE);
|
|
|
64 |
|
|
|
65 |
if (is_song) {
|
|
|
66 |
uri = mpds.currentsong.uri;
|
|
|
67 |
metadata = didlmake(mpds.currentsong);
|
|
|
68 |
} else {
|
|
|
69 |
uri.clear();
|
|
|
70 |
metadata.clear();
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
void OHInfo::makedetails(string &duration, string& bitrate,
|
|
|
75 |
string& bitdepth, string& samplerate)
|
|
|
76 |
{
|
|
|
77 |
const MpdStatus &mpds = m_dev->getMpdStatus();
|
|
|
78 |
|
|
|
79 |
bool is_song = (mpds.state == MpdStatus::MPDS_PLAY) ||
|
|
|
80 |
(mpds.state == MpdStatus::MPDS_PAUSE);
|
|
|
81 |
|
|
|
82 |
if (is_song) {
|
|
|
83 |
char cbuf[30];
|
|
|
84 |
sprintf(cbuf, "%u", mpds.songlenms / 1000);
|
|
|
85 |
duration = cbuf;
|
|
|
86 |
sprintf(cbuf, "%u", mpds.kbrate * 1000);
|
|
|
87 |
bitrate = cbuf;
|
|
|
88 |
sprintf(cbuf, "%u", mpds.bitdepth);
|
|
|
89 |
bitdepth = cbuf;
|
|
|
90 |
sprintf(cbuf, "%u", mpds.sample_rate);
|
|
|
91 |
samplerate = cbuf;
|
|
|
92 |
} else {
|
|
|
93 |
duration = bitrate = bitdepth = samplerate = "0";
|
|
|
94 |
}
|
57 |
}
|
95 |
}
|
58 |
|
96 |
|
59 |
bool OHInfo::makestate(unordered_map<string, string> &st)
|
97 |
bool OHInfo::makestate(unordered_map<string, string> &st)
|
60 |
{
|
98 |
{
|
61 |
st.clear();
|
99 |
st.clear();
|
|
... |
|
... |
68 |
st["MetatextCount"] = "0";
|
106 |
st["MetatextCount"] = "0";
|
69 |
string uri, metadata;
|
107 |
string uri, metadata;
|
70 |
urimetadata(uri, metadata);
|
108 |
urimetadata(uri, metadata);
|
71 |
st["Uri"] = uri;
|
109 |
st["Uri"] = uri;
|
72 |
st["Metadata"] = metadata;
|
110 |
st["Metadata"] = metadata;
|
73 |
string duration("0"), bitrate("0"), bitdepth("0"), samplerate("0");
|
111 |
makedetails(st["Duration"], st["BitRate"], st["BitDepth"],
|
74 |
makedetails(duration, bitrate, bitdepth, samplerate);
|
112 |
st["SampleRate"]);
|
75 |
st["Duration"] = duration;
|
|
|
76 |
st["BitRate"] = bitrate;
|
|
|
77 |
st["BitDepth"] = bitdepth;
|
|
|
78 |
st["SampleRate"] = samplerate;
|
|
|
79 |
st["Lossless"] = "0";
|
113 |
st["Lossless"] = "0";
|
80 |
st["CodecName"] = "";
|
114 |
st["CodecName"] = "";
|
81 |
|
|
|
82 |
st["Metatext"] = "";
|
115 |
st["Metatext"] = "";
|
83 |
return true;
|
116 |
return true;
|
84 |
}
|
117 |
}
|
85 |
|
118 |
|
86 |
bool OHInfo::getEventData(bool all, std::vector<std::string>& names,
|
119 |
bool OHInfo::getEventData(bool all, std::vector<std::string>& names,
|
87 |
std::vector<std::string>& values)
|
120 |
std::vector<std::string>& values)
|
88 |
{
|
121 |
{
|
89 |
//LOGDEB("OHInfo::getEventData" << endl);
|
122 |
//LOGDEB("OHInfo::getEventData" << endl);
|
90 |
|
123 |
|
91 |
unordered_map<string, string> state;
|
124 |
unordered_map<string, string> state, changed;
|
92 |
makestate(state);
|
125 |
makestate(state);
|
93 |
|
|
|
94 |
unordered_map<string, string> changed;
|
|
|
95 |
if (all) {
|
126 |
if (all) {
|
96 |
changed = state;
|
127 |
changed = state;
|
97 |
} else {
|
128 |
} else {
|
98 |
changed = diffmaps(m_state, state);
|
129 |
changed = diffmaps(m_state, state);
|
99 |
}
|
130 |
}
|
100 |
m_state = state;
|
131 |
m_state = state;
|
101 |
|
132 |
|
102 |
for (unordered_map<string, string>::iterator it = changed.begin();
|
133 |
for (auto& member : changed) {
|
103 |
it != changed.end(); it++) {
|
|
|
104 |
names.push_back(it->first);
|
134 |
names.push_back(member.first);
|
105 |
values.push_back(it->second);
|
135 |
values.push_back(member.second);
|
106 |
}
|
136 |
}
|
107 |
|
137 |
|
108 |
return true;
|
138 |
return true;
|
109 |
}
|
139 |
}
|
110 |
|
140 |
|
|
... |
|
... |
118 |
data.addarg("DetailsCount", cbuf);
|
148 |
data.addarg("DetailsCount", cbuf);
|
119 |
data.addarg("MetatextCount", "0");
|
149 |
data.addarg("MetatextCount", "0");
|
120 |
return UPNP_E_SUCCESS;
|
150 |
return UPNP_E_SUCCESS;
|
121 |
}
|
151 |
}
|
122 |
|
152 |
|
123 |
void OHInfo::urimetadata(string& uri, string& metadata)
|
|
|
124 |
{
|
|
|
125 |
const MpdStatus &mpds = m_dev->getMpdStatus();
|
|
|
126 |
bool is_song = (mpds.state == MpdStatus::MPDS_PLAY) ||
|
|
|
127 |
(mpds.state == MpdStatus::MPDS_PAUSE);
|
|
|
128 |
|
|
|
129 |
if (is_song) {
|
|
|
130 |
uri = mpds.currentsong.uri;
|
|
|
131 |
metadata = didlmake(mpds.currentsong);
|
|
|
132 |
}
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
int OHInfo::track(const SoapArgs& sc, SoapData& data)
|
153 |
int OHInfo::track(const SoapArgs& sc, SoapData& data)
|
136 |
{
|
154 |
{
|
137 |
LOGDEB("OHInfo::track" << endl);
|
155 |
LOGDEB("OHInfo::track" << endl);
|
138 |
|
156 |
|
139 |
string uri, metadata;
|
157 |
string uri, metadata;
|
|
... |
|
... |
141 |
data.addarg("Uri", uri);
|
159 |
data.addarg("Uri", uri);
|
142 |
data.addarg("Metadata", metadata);
|
160 |
data.addarg("Metadata", metadata);
|
143 |
return UPNP_E_SUCCESS;
|
161 |
return UPNP_E_SUCCESS;
|
144 |
}
|
162 |
}
|
145 |
|
163 |
|
146 |
void OHInfo::makedetails(string &duration, string& bitrate,
|
|
|
147 |
string& bitdepth, string& samplerate)
|
|
|
148 |
{
|
|
|
149 |
const MpdStatus &mpds = m_dev->getMpdStatus();
|
|
|
150 |
|
|
|
151 |
bool is_song = (mpds.state == MpdStatus::MPDS_PLAY) ||
|
|
|
152 |
(mpds.state == MpdStatus::MPDS_PAUSE);
|
|
|
153 |
|
|
|
154 |
char cbuf[30];
|
|
|
155 |
if (is_song) {
|
|
|
156 |
sprintf(cbuf, "%u", mpds.songlenms / 1000);
|
|
|
157 |
duration = cbuf;
|
|
|
158 |
sprintf(cbuf, "%u", mpds.kbrate * 1000);
|
|
|
159 |
bitrate = cbuf;
|
|
|
160 |
sprintf(cbuf, "%u", mpds.bitdepth);
|
|
|
161 |
bitdepth = cbuf;
|
|
|
162 |
sprintf(cbuf, "%u", mpds.sample_rate);
|
|
|
163 |
samplerate = cbuf;
|
|
|
164 |
}
|
|
|
165 |
}
|
|
|
166 |
|
|
|
167 |
int OHInfo::details(const SoapArgs& sc, SoapData& data)
|
164 |
int OHInfo::details(const SoapArgs& sc, SoapData& data)
|
168 |
{
|
165 |
{
|
169 |
LOGDEB("OHInfo::details" << endl);
|
166 |
LOGDEB("OHInfo::details" << endl);
|
170 |
|
167 |
|
171 |
string duration("0"), bitrate("0"), bitdepth("0"), samplerate("0");
|
168 |
string duration, bitrate, bitdepth, samplerate;
|
172 |
makedetails(duration, bitrate, bitdepth, samplerate);
|
169 |
makedetails(duration, bitrate, bitdepth, samplerate);
|
173 |
data.addarg("Duration", duration);
|
170 |
data.addarg("Duration", duration);
|
174 |
data.addarg("BitRate", bitrate);
|
171 |
data.addarg("BitRate", bitrate);
|
175 |
data.addarg("BitDepth", bitdepth);
|
172 |
data.addarg("BitDepth", bitdepth);
|
176 |
data.addarg("SampleRate", samplerate);
|
173 |
data.addarg("SampleRate", samplerate);
|