Switch to unified view

a/src/ohreceiver.cxx b/src/ohreceiver.cxx
...
...
40
using namespace std::placeholders;
40
using namespace std::placeholders;
41
41
42
static const string sTpProduct("urn:av-openhome-org:service:Receiver:1");
42
static const string sTpProduct("urn:av-openhome-org:service:Receiver:1");
43
static const string sIdProduct("urn:av-openhome-org:serviceId:Receiver");
43
static const string sIdProduct("urn:av-openhome-org:serviceId:Receiver");
44
44
45
OHReceiver::OHReceiver(UpMpd *dev, OHPlaylist *pl, OHProduct *pr, int port)
45
OHReceiver::OHReceiver(UpMpd *dev, const OHReceiverParams& parms)
46
    : UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev), 
46
    : UpnpService(sTpProduct, sIdProduct, dev), m_dev(dev), 
47
      m_pl(pl), m_pr(pr), m_httpport(port)
47
      m_pl(parms.pl), m_pr(parms.pr), m_httpport(parms.httpport),
48
      m_pm(parms.pm)
48
{
49
{
49
    dev->addActionMapping(this, "Play", 
50
    dev->addActionMapping(this, "Play", 
50
                          bind(&OHReceiver::play, this, _1, _2));
51
                          bind(&OHReceiver::play, this, _1, _2));
51
    dev->addActionMapping(this, "Stop", 
52
    dev->addActionMapping(this, "Stop", 
52
                          bind(&OHReceiver::stop, this, _1, _2));
53
                          bind(&OHReceiver::stop, this, _1, _2));
...
...
66
static const string o_protocolinfo("ohz:*:*:*,ohm:*:*:*,ohu:*.*.*");
67
static const string o_protocolinfo("ohz:*:*:*,ohm:*:*:*,ohu:*.*.*");
67
68
68
bool OHReceiver::makestate(unordered_map<string, string> &st)
69
bool OHReceiver::makestate(unordered_map<string, string> &st)
69
{
70
{
70
    const MpdStatus &mpds = m_dev->getMpdStatusNoUpdate();
71
    const MpdStatus &mpds = m_dev->getMpdStatusNoUpdate();
71
72
    if (m_pm == OHReceiverParams::OHRP_MPD) {
72
    if (m_cmd && mpds.state != MpdStatus::MPDS_PLAY && 
73
        if (m_cmd && mpds.state != MpdStatus::MPDS_PLAY && 
73
        mpds.state != MpdStatus::MPDS_PAUSE) {
74
            mpds.state != MpdStatus::MPDS_PAUSE) {
74
        // playing was stopped through ohplaylist or
75
            // playing was stopped through ohplaylist or
75
        // avtransport. I'm not sure we're supposed to let this
76
            // avtransport. I'm not sure we're supposed to let this
76
        // happen, but we do. Stop too.
77
            // happen, but we do. Stop too.
77
        iStop();
78
            iStop();
79
        }
78
    }
80
    }
79
81
80
    st.clear();
82
    st.clear();
81
83
82
    st["Uri"] = m_uri;
84
    st["Uri"] = m_uri;
...
...
147
149
148
    int id = -1;
150
    int id = -1;
149
    unordered_map<int, string> urlmap;
151
    unordered_map<int, string> urlmap;
150
    string line;
152
    string line;
151
        
153
        
152
    // We start the songcast command to receive the audio flux and
154
    // We start the songcast command to receive the audio flux and either
153
    // export it as HTTP, then insert http URI at the front of the
155
    // export it as HTTP (then insert http URI at the front of the
154
    // queue and execute next/play
156
    // queue and execute next/play), or play it directly to the sound card
155
    if (m_cmd)
157
    if (m_cmd)
156
        m_cmd->zapChild();
158
        m_cmd->zapChild();
157
    m_cmd = shared_ptr<ExecCmd>(new ExecCmd());
159
    m_cmd = shared_ptr<ExecCmd>(new ExecCmd());
158
    vector<string> args;
160
    vector<string> args;
161
    if (m_pm == OHReceiverParams::OHRP_ALSA) {
162
        args.push_back("-d");
163
    }
159
    args.push_back("-u");
164
    args.push_back("-u");
160
    args.push_back(m_uri);
165
    args.push_back(m_uri);
161
    if (!g_configfilename.empty()) {
166
    if (!g_configfilename.empty()) {
162
        args.push_back("-c");
167
        args.push_back("-c");
163
        args.push_back(g_configfilename);
168
        args.push_back(g_configfilename);
...
...
170
               << endl);
175
               << endl);
171
        goto out;
176
        goto out;
172
    } else {
177
    } else {
173
        LOGDEB("OHReceiver::play: sc2mpd pid "<< m_cmd->getChildPid()<< endl);
178
        LOGDEB("OHReceiver::play: sc2mpd pid "<< m_cmd->getChildPid()<< endl);
174
    }
179
    }
180
181
    if (m_pm == OHReceiverParams::OHRP_MPD) {
175
    // Wait for sc2mpd to signal ready, then play
182
        // Wait for sc2mpd to signal ready, then play
176
    m_cmd->getline(line);
183
        m_cmd->getline(line);
177
    LOGDEB("OHReceiver: sc2mpd sent: " << line);
184
        LOGDEB("OHReceiver: sc2mpd sent: " << line);
178
179
    // And insert the appropriate uri in the mpd playlist
185
        // And insert the appropriate uri in the mpd playlist
180
    if (!m_pl->urlMap(urlmap)) {
186
        if (!m_pl->urlMap(urlmap)) {
181
        LOGERR("OHReceiver::play: urlMap() failed" <<endl);
187
            LOGERR("OHReceiver::play: urlMap() failed" <<endl);
182
        goto out;
188
            goto out;
183
    }
189
        }
184
    for (auto it = urlmap.begin(); it != urlmap.end(); it++) {
190
        for (auto it = urlmap.begin(); it != urlmap.end(); it++) {
185
        if (it->second == m_httpuri) {
191
            if (it->second == m_httpuri) {
186
            id = it->first;
192
                id = it->first;
187
        }
193
            }
188
    }
194
        }
189
    if (id == -1) {
195
        if (id == -1) {
190
        ok = m_pl->insertUri(0, m_httpuri, SoapHelp::xmlUnquote(m_metadata),
196
            ok = m_pl->insertUri(0, m_httpuri, SoapHelp::xmlUnquote(m_metadata),
197
                                 &id);
198
            if (!ok) {
199
                LOGERR("OHReceiver::play: insertUri() failed\n");
200
                goto out;
191
            &id);
201
            }
202
        }
203
204
        ok = m_dev->m_mpdcli->playId(id);
192
        if (!ok) {
205
        if (!ok) {
193
            LOGERR("OHReceiver::play: insertUri() failed\n");
206
            LOGERR("OHReceiver::play: play() failed\n");
194
            goto out;
207
            goto out;
195
        }
208
        }
196
    }
197
198
    ok = m_dev->m_mpdcli->playId(id);
199
    if (!ok) {
200
        LOGERR("OHReceiver::play: play() failed\n");
201
        goto out;
202
    }
209
    }
203
210
204
out:
211
out:
205
    if (!ok) {
212
    if (!ok) {
206
        iStop();
213
        iStop();
207
    }
214
    }
208
    maybeWakeUp(ok);
215
    maybeWakeUp(ok);
216
    LOGDEB("OHReceiver::play: returning\n");
209
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
217
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
210
}
218
}
211
219
212
bool OHReceiver::iStop()
220
bool OHReceiver::iStop()
213
{
221
{
222
    LOGDEB("OHReceiver::iStop()\n");
214
    if (m_cmd) {
223
    if (m_cmd) {
215
        m_cmd->zapChild();
224
        m_cmd->zapChild();
216
        m_cmd = shared_ptr<ExecCmd>(0);
225
        m_cmd = shared_ptr<ExecCmd>(0);
217
    }
226
    }
218
    m_dev->m_mpdcli->stop();
227
    m_dev->m_mpdcli->stop();