Shaka Player Embedded
net.h
Go to the documentation of this file.
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_NET_H_
16 #define SHAKA_EMBEDDED_NET_H_
17 
18 #include <future>
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "error.h"
25 #include "macros.h"
26 #include "optional.h"
27 
28 namespace shaka {
29 
30 namespace js {
31 struct Request;
32 struct Response;
33 } // namespace js
34 
38 enum class RequestType : int8_t {
39  Unknown = -1,
40 
41  Manifest = 0,
42  Segment = 1,
43  License = 2,
44  App = 3,
45  Timing = 4,
46 };
47 
55 class SHAKA_EXPORT Request final {
56  public:
57  ~Request();
58 
60 
65  std::vector<std::string> uris;
66 
68  std::string method;
69 
71  std::unordered_map<std::string, std::string> headers;
72 
73 
75  const uint8_t* body() const;
76 
78  size_t body_size() const;
79 
84  void SetBodyCopy(const uint8_t* data, size_t size);
85 
86  private:
87  friend class JsManager;
88  friend class Player;
89  Request(js::Request&& request);
90 
91  void Finalize();
92 
93  class Impl;
94  std::unique_ptr<Impl> impl_;
95 };
96 
104 class SHAKA_EXPORT Response final {
105  public:
106  ~Response();
107 
109 
114  std::string uri;
115 
120  std::string originalUri;
121 
127  std::unordered_map<std::string, std::string> headers;
128 
134 
140 
141 
143  const uint8_t* data() const;
144 
146  size_t data_size() const;
147 
149  void SetDataCopy(const uint8_t* data, size_t size);
150 
151  private:
152  friend class JsManager;
153  friend class Player;
154  Response();
155  Response(js::Response&& response);
156 
157  void Finalize();
158  js::Response* JsObject();
159 
160  class Impl;
161  std::unique_ptr<Impl> impl_;
162 };
163 
175  public:
177 
183  class Client {
184  public:
186 
193  virtual void OnProgress(double time, uint64_t bytes,
194  uint64_t remaining) = 0;
195  };
196 
197 
210  virtual std::future<optional<Error>> OnNetworkRequest(const std::string& uri,
212  const Request& request,
213  Client* client,
214  Response* response) = 0;
215 };
216 
229  public:
231 
241  virtual std::future<optional<Error>> OnRequestFilter(RequestType type,
242  Request* request);
243 
253  virtual std::future<optional<Error>> OnResponseFilter(RequestType type,
254  Response* response);
255 };
256 
257 } // namespace shaka
258 
259 #endif // SHAKA_EMBEDDED_NET_H_
optional< double > timeMs
Definition: net.h:133
#define SHAKA_EXPORT
Definition: macros.h:30
std::string uri
Definition: net.h:114
#define SHAKA_NON_COPYABLE_OR_MOVABLE_TYPE(Type)
Definition: macros.h:51
std::unordered_map< std::string, std::string > headers
Definition: net.h:71
optional< bool > fromCache
Definition: net.h:139
ExceptionCode type
std::string originalUri
Definition: net.h:120
std::unordered_map< std::string, std::string > headers
Definition: net.h:127
std::vector< std::string > uris
Definition: net.h:65
#define SHAKA_DECLARE_INTERFACE_METHODS(Type)
Definition: macros.h:55
RequestType
Definition: net.h:38
std::string method
Definition: net.h:68