libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
avtransport.hxx
1 /* Copyright (C) 2006-2016 J.F.Dockes
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18 #ifndef _AVTRANSPORT_HXX_INCLUDED_
19 #define _AVTRANSPORT_HXX_INCLUDED_
20 
21 #include "libupnpp/config.h"
22 
23 #include <string>
24 
25 #include "libupnpp/control/cdircontent.hxx" // for UPnPDirObject
26 #include "libupnpp/control/service.hxx" // for Service
27 #include "libupnpp/log.hxx"
28 
29 namespace UPnPClient {
30 
31 class AVTransport;
32 class UPnPDeviceDesc;
33 class UPnPServiceDesc;
34 
35 typedef std::shared_ptr<AVTransport> AVTH;
36 
41 class AVTransport : public Service {
42 public:
43 
45  AVTransport(const UPnPDeviceDesc& dev, const UPnPServiceDesc& srv)
46  : Service(dev, srv) {
47  }
48  AVTransport() {}
49  virtual ~AVTransport() {}
50 
51  int setAVTransportURI(const std::string& uri, const std::string& metadata,
52  int instanceID=0)
53  {
54  return setURI(uri, metadata, instanceID, false);
55  }
56 
57  int setNextAVTransportURI(const std::string& uri, const std::string& md,
58  int instanceID=0)
59  {
60  return setURI(uri, md, instanceID, true);
61  }
62 
63 
64  enum PlayMode {PM_Unknown, PM_Normal, PM_Shuffle, PM_RepeatOne,
65  PM_RepeatAll, PM_Random, PM_Direct1
66  };
67  int setPlayMode(PlayMode pm, int instanceID=0);
68 
69  struct MediaInfo {
70  int nrtracks;
71  int mduration; // seconds
72  std::string cururi;
73  UPnPDirObject curmeta;
74  std::string nexturi;
75  UPnPDirObject nextmeta;
76  std::string pbstoragemed;
77  std::string rcstoragemed;
78  std::string ws;
79  };
80  int getMediaInfo(MediaInfo& info, int instanceID=0);
81 
82  enum TransportState {Unknown, Stopped, Playing, Transitioning,
83  PausedPlayback, PausedRecording, Recording,
84  NoMediaPresent
85  };
86  enum TransportStatus {TPS_Unknown, TPS_Ok, TPS_Error};
87  struct TransportInfo {
88  TransportState tpstate;
89  TransportStatus tpstatus;
90  int curspeed;
91  };
92  int getTransportInfo(TransportInfo& info, int instanceID=0);
93 
94  struct PositionInfo {
95  int track;
96  int trackduration; // secs
97  UPnPDirObject trackmeta;
98  std::string trackuri;
99  int reltime;
100  int abstime;
101  int relcount;
102  int abscount;
103  };
104  int getPositionInfo(PositionInfo& info, int instanceID=0);
105 
107  std::string playmedia;
108  std::string recmedia;
109  std::string recqualitymodes;
110  };
111  int getDeviceCapabilities(DeviceCapabilities& info, int instanceID=0);
112 
114  PlayMode playmode;
115  std::string recqualitymode;
116  };
117  int getTransportSettings(TransportSettings& info, int instanceID=0);
118 
119  int stop(int instanceID=0);
120  int pause(int instanceID=0);
121  int play(int speed = 1, int instanceID = 0);
122 
123  enum SeekMode {SEEK_TRACK_NR, SEEK_ABS_TIME, SEEK_REL_TIME, SEEK_ABS_COUNT,
124  SEEK_REL_COUNT, SEEK_CHANNEL_FREQ, SEEK_TAPE_INDEX,
125  SEEK_FRAME
126  };
127  // Target in seconds for times.
128  int seek(SeekMode mode, int target, int instanceID=0);
129 
130  // These are for multitrack medium like a CD. No meaning for electronic
131  // tracks where set(next)AVTransportURI() is used
132  int next(int instanceID=0);
133  int previous(int instanceID=0);
134 
135  enum TransportActions {TPA_Next = 1, TPA_Pause = 2, TPA_Play = 4,
136  TPA_Previous = 8, TPA_Seek = 16, TPA_Stop = 32
137  };
138  int getCurrentTransportActions(int& actions, int instanceID=0);
139 
141  static bool isAVTService(const std::string& st);
142  virtual bool serviceTypeMatch(const std::string& tp);
143 
144 protected:
145  /* My service type string */
146  static const std::string SType;
147 
148  int setURI(const std::string& uri, const std::string& metadata,
149  int instanceID, bool next);
150  int CTAStringToBits(const std::string& actions, int& iacts);
151 
152 private:
153  void evtCallback(const std::unordered_map<std::string, std::string>&);
154  void registerCallback();
155 };
156 
157 } // namespace UPnPClient
158 
159 #endif /* _AVTRANSPORT_HXX_INCLUDED_ */
Definition: service.hxx:73
Definition: avtransport.hxx:106
Definition: avtransport.hxx:94
AVTransport Service client class.
Definition: avtransport.hxx:41
Definition: avtransport.hxx:69
Definition: avtransport.hxx:113
virtual bool serviceTypeMatch(const std::string &tp)
Perform a comparison to the service type string for this specific service.
Definition: avtransport.cxx:51
Data holder for a UPnP service, parsed from the device XML description.
Definition: description.hxx:46
UPnP Media Server directory entry, converted from XML data.
Definition: cdircontent.hxx:62
Data holder for a UPnP device, parsed from the XML description obtained during discovery.
Definition: description.hxx:142
static bool isAVTService(const std::string &st)
Test service type from discovery message.
Definition: avtransport.cxx:46
AVTransport(const UPnPDeviceDesc &dev, const UPnPServiceDesc &srv)
Construct by copying data from device and service objects.
Definition: avtransport.hxx:45
UPnP Description phase: interpreting the device description which we downloaded from the URL obtained...
Definition: avlastchg.cxx:28
Definition: avtransport.hxx:87