summaryrefslogtreecommitdiff
path: root/include/media/mediaManager.h
blob: 36987ab9aa8b931f1c026e3fd133c74dee8bd423 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * mediaManager.h
 *
 *  Created on: 31.08.2012
 *      Author: savop
 */

#ifndef MEDIAMANAGER_H_
#define MEDIAMANAGER_H_

#include "../../include/plugin.h"
#include "../../include/tools.h"
#include <vdr/thread.h>
#include <list>
#include <string>
#include <stdint.h>

namespace upnp {

class cResourceStreamer;
class cPluginManager;

class cMediaManager : public cThread {
  friend void cUPnPResourceProvider::OnContainerUpdate(const string& uri, long updateID, const StringList& target = StringList());
private:

  struct MediaRequest {
    std::string objectID;
    std::string filter;
    uint32_t    startIndex;
    uint32_t    requestCount;
    std::string sortCriteria;
    std::string result;
    uint32_t    numberReturned;
    uint32_t    totalMatches;
    uint32_t    updateID;
  };

public:

  enum BrowseFlag {
    CD_BROWSE_METADATA,
    CD_BROWSE_DIRECT_CHILDREN,
    NumBrowseFlags
  };

  struct BrowseRequest : public MediaRequest {
    BrowseFlag  browseMetadata;
  };

  struct SearchRequest : public MediaRequest {
    std::string searchCriteria;
  };

  cMediaManager();
  virtual ~cMediaManager();

  bool Initialise();
  void Housekeeping();

  uint32_t GetSystemUpdateID() const;
  IdList GetContainerUpdateIDs(bool unevented = false);
  StringList GetSearchCapabilities() const;
  StringList GetSortCapabilities() const;
  StringList GetSupportedProtocolInfos() const;

  int Browse(BrowseRequest& request);
  int Search(SearchRequest& request);

  static BrowseFlag ToBrowseFlag(const std::string& browseFlag);

  cResourceStreamer* GetResourceStreamer(const std::string& objectID, int resourceID = 0);

private:

  void Action();
  bool CheckIntegrity();

  int CreateResponse(MediaRequest&, const string&, const string&);

  void OnContainerUpdate(const string& uri, long updateID, const StringList& target);
  bool UpdateContainerUpdateId(const string& objectID, long updateID);

  bool ScanURI(const string& uri, cUPnPResourceProvider* provider);

  bool RefreshObject(cMetadata& metadata);

  cUPnPResourceProvider* CreateResourceProvider(const std::string& uri);

  uint32_t          systemUpdateID;
  IdList            eventedContainerUpdateIDs;
  StringList        scanTargets;
  tntdb::Connection connection;

  upnp::cPluginManager* pluginManager;

};

class cResourceStreamer {
  friend class cMediaManager;
private:
  cUPnPResourceProvider* provider;
  cMetadata::Resource* resource;

  cMediaManager* manager;

  StringVector protocolInfo;

  cResourceStreamer(cMediaManager* manager, cUPnPResourceProvider* provider, cMetadata::Resource* resource);
public:
  virtual ~cResourceStreamer();
  std::string GetContentFeatures() const;
  size_t GetContentLength() const;
  std::string GetContentType() const;
  std::string GetTransferMode(const std::string& requestedMode ) const;
  bool Seekable() const;

  bool Open();
  size_t Read(char* buf, size_t bufLen);
  bool Seek(size_t offset, int origin);
  void Close();
};

}  // namespace upnp


#endif /* MEDIAMANAGER_H_ */