Switch to unified view

a/src/avtransport.cxx b/src/avtransport.cxx
...
...
87
                                               this, _1, _2, 0));
87
                                               this, _1, _2, 0));
88
    m_dev->addActionMapping(this, "Previous", 
88
    m_dev->addActionMapping(this, "Previous", 
89
                            bind(&UpMpdAVTransport::seqcontrol, 
89
                            bind(&UpMpdAVTransport::seqcontrol, 
90
                                 this, _1, _2, 1));
90
                                 this, _1, _2, 1));
91
91
92
    // This would make our life easier, but it's incompatible if
93
    // ohplaylist is also in use, so refrain.
92
//    dev->m_mpdcli->consume(true);
94
//    dev->m_mpdcli->consume(true);
93
#ifdef NO_SETNEXT
95
#ifdef NO_SETNEXT
94
    // If no setnext, fake stopping at each track
96
    // If no setnext, fake stopping at each track
95
    m_dev->m_mpdcli->single(true);
97
    m_dev->m_mpdcli->single(true);
96
#endif
98
#endif
...
...
359
    LOGDEB1("UpMpdAVTransport::getEventDataTransport: " << chgdata << endl);
361
    LOGDEB1("UpMpdAVTransport::getEventDataTransport: " << chgdata << endl);
360
    return true;
362
    return true;
361
}
363
}
362
364
363
// http://192.168.4.4:8200/MediaItems/246.mp3
365
// http://192.168.4.4:8200/MediaItems/246.mp3
364
int UpMpdAVTransport::setAVTransportURI(const SoapIncoming& sc, SoapOutgoing& data, 
366
int UpMpdAVTransport::setAVTransportURI(const SoapIncoming& sc,
365
                                        bool setnext)
367
                                        SoapOutgoing& data, bool setnext)
366
{
368
{
369
#ifdef NO_SETNEXT
367
    // pretend not to support setnext:
370
    // pretend not to support setnext:
368
#ifdef NO_SETNEXT
369
    if (setnext) {
371
    if (setnext) {
370
        LOGERR("SetNextAVTransportURI: faking error\n");
372
        LOGERR("SetNextAVTransportURI: faking error\n");
371
        return UPNP_E_INVALID_PARAM;
373
        return UPNP_E_INVALID_PARAM;
372
    }
374
    }
373
#endif
375
#endif
...
...
392
        LOGERR("set(Next)AVTransportURI: unsupported format: uri " << uri <<
394
        LOGERR("set(Next)AVTransportURI: unsupported format: uri " << uri <<
393
               " metadata [" << metadata << "]\n");
395
               " metadata [" << metadata << "]\n");
394
        return UPNP_E_INVALID_PARAM;
396
        return UPNP_E_INVALID_PARAM;
395
    }
397
    }
396
398
397
    bool is_song = (st == MpdStatus::MPDS_PLAY) ||
399
    bool is_song = (st == MpdStatus::MPDS_PLAY) || (st == MpdStatus::MPDS_PAUSE);
398
  (st == MpdStatus::MPDS_PAUSE);
399
    UPMPD_UNUSED(is_song);
400
    UPMPD_UNUSED(is_song);
400
    int curpos = mpds.songpos;
401
    int curpos = mpds.songpos;
401
    LOGDEB1("UpMpdAVTransport::set" << (setnext?"Next":"") << 
402
    LOGDEB1("UpMpdAVTransport::set" << (setnext?"Next":"") << 
402
            "AVTransportURI: curpos: " <<
403
            "AVTransportURI: curpos: " <<
403
            curpos << " is_song " << is_song << " qlen " << mpds.qlen << endl);
404
            curpos << " is_song " << is_song << " qlen " << mpds.qlen << endl);
...
...
410
        m_dev->m_mpdcli->clearQueue();
411
        m_dev->m_mpdcli->clearQueue();
411
        // mpds is now invalid!
412
        // mpds is now invalid!
412
        curpos = -1;
413
        curpos = -1;
413
    }
414
    }
414
415
416
    // If setAVTransport is called, the Control Point wants to control
417
    // the playing, so we reset any special mpd playlist
418
    // mode. Especially, repeat would prevent us from ever seeing the
419
    // end of the track. Note that always setting repeat to false is
420
    // one of the ways which we are incompatible with simultaneous
421
    // mpc or ohplaylist use (there are many others of course).
422
    m_dev->m_mpdcli->repeat(false);
423
    m_dev->m_mpdcli->random(false);
424
#ifdef NO_SETNEXT
425
    m_dev->m_mpdcli->single(true);
426
#endif
427
    
415
    // curpos == -1 means that the playlist was cleared or we just started. A
428
    // curpos == -1 means that the playlist was cleared or we just started. A
416
    // play will use position 0, so it's actually equivalent to curpos == 0
429
    // play will use position 0, so it's actually equivalent to curpos == 0
417
    if (curpos == -1) {
430
    if (curpos == -1) {
418
        curpos = 0;
431
        curpos = 0;
419
    }
432
    }
...
...
472
        default: break;
485
        default: break;
473
        }
486
        }
474
#endif
487
#endif
475
        // Clean up old song ids
488
        // Clean up old song ids
476
        if (!(m_dev->m_options & UpMpd::upmpdOwnQueue)) {
489
        if (!(m_dev->m_options & UpMpd::upmpdOwnQueue)) {
477
            for (set<int>::iterator it = m_songids.begin();
490
            for (auto id : m_songids) {
478
                 it != m_songids.end(); it++) {
479
                // Can't just delete here. If the id does not exist, MPD 
491
                // Can't just delete here. If the id does not exist, MPD 
480
                // gets into an apparently permanent error state, where even 
492
                // gets into an apparently permanent error state, where even 
481
                // get_status does not work
493
                // get_status does not work
482
                if (m_dev->m_mpdcli->statId(*it)) {
494
                if (m_dev->m_mpdcli->statId(id)) {
483
                    m_dev->m_mpdcli->deleteId(*it);
495
                    m_dev->m_mpdcli->deleteId(id);
484
                }
496
                }
485
            }
497
            }
486
            m_songids.clear();
498
            m_songids.clear();
487
        }
499
        }
488
    }
500
    }
...
...
680
    }
692
    }
681
693
682
    m_dev->loopWakeup();
694
    m_dev->loopWakeup();
683
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
695
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
684
}
696
}
685
  
697
698
/*
699
 * For the AVTransport service, this only makes sense if we're playing a
700
 * multi-track media, else we're only dealing with a single track (and
701
 * possibly the next), and none of the repeat/shuffle modes make
702
 * sense. If ownqueue is 0, it might still make sense for us to
703
 * control the mpd play mode though, but any special mode will be reset if
704
 * set(Next)AVTransport is called.
705
*/
686
int UpMpdAVTransport::setPlayMode(const SoapIncoming& sc, SoapOutgoing& data)
706
int UpMpdAVTransport::setPlayMode(const SoapIncoming& sc, SoapOutgoing& data)
687
{
707
{
688
    string playmode;
708
    string playmode;
689
    if (!sc.get("NewPlayMode", &playmode)) {
709
    if (!sc.get("NewPlayMode", &playmode)) {
690
        return UPNP_E_INVALID_PARAM;
710
        return UPNP_E_INVALID_PARAM;
691
    }
711
    }
692
    LOGDEB("UpMpdAVTransport::setPlayMode: " << playmode << endl);
712
    LOGDEB("UpMpdAVTransport::setPlayMode: " << playmode << endl);
713
714
    if ((m_dev->m_options & UpMpd::upmpdOwnQueue)) {
715
        // If we own the queue then none of this makes sense, we're
716
        // only keeping 1 or 2 entries on the queue and controlling
717
        // everything.
718
        LOGDEB("AVTRansport::setPlayMode: ownqueue is set, doing nothing\n");
719
        return 0;
720
    }
693
721
694
    bool ok;
722
    bool ok;
695
    if (!playmode.compare("NORMAL")) {
723
    if (!playmode.compare("NORMAL")) {
696
        ok = m_dev->m_mpdcli->repeat(false) && m_dev->m_mpdcli->random(false) &&
724
        ok = m_dev->m_mpdcli->repeat(false) && m_dev->m_mpdcli->random(false) &&
697
            m_dev->m_mpdcli->single(false);
725
            m_dev->m_mpdcli->single(false);
...
...
715
    }
743
    }
716
    m_dev->loopWakeup();
744
    m_dev->loopWakeup();
717
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
745
    return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
718
}
746
}
719
747
720
int UpMpdAVTransport::getTransportSettings(const SoapIncoming& sc, SoapOutgoing& data)
748
int UpMpdAVTransport::getTransportSettings(const SoapIncoming& sc,
749
                                           SoapOutgoing& data)
721
{
750
{
722
    const MpdStatus &mpds = m_dev->getMpdStatus();
751
    const MpdStatus &mpds = m_dev->getMpdStatus();
723
    string playmode = mpdsToPlaymode(mpds);
752
    string playmode = mpdsToPlaymode(mpds);
724
    data.addarg("PlayMode", playmode);
753
    data.addarg("PlayMode", playmode);
725
    data.addarg("RecQualityMode", "NOT_IMPLEMENTED");
754
    data.addarg("RecQualityMode", "NOT_IMPLEMENTED");