| 1 |
/* |
| 2 |
* SRT - Secure, Reliable, Transport |
| 3 |
* Copyright (c) 2018 Haivision Systems Inc. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#ifndef INC_SRT_COMMON_TRANMITBASE_HPP |
| 12 |
#define INC_SRT_COMMON_TRANMITBASE_HPP |
| 13 |
|
| 14 |
#include <string> |
| 15 |
#include <memory> |
| 16 |
#include <vector> |
| 17 |
#include <iostream> |
| 18 |
#include <stdexcept> |
| 19 |
|
| 20 |
#include "sync.h" |
| 21 |
#include "uriparser.hpp" |
| 22 |
|
| 23 |
typedef std::vector<char> bytevector; |
| 24 |
extern srt::sync::atomic<bool> transmit_throw_on_interrupt; |
| 25 |
extern int transmit_bw_report; |
| 26 |
extern unsigned transmit_stats_report; |
| 27 |
extern size_t transmit_chunk_size; |
| 28 |
extern bool transmit_printformat_json; |
| 29 |
extern bool transmit_use_sourcetime; |
| 30 |
extern int transmit_retry_connect; |
| 31 |
extern bool transmit_retry_always; |
| 32 |
|
| 33 |
struct MediaPacket |
| 34 |
{ |
| 35 |
bytevector payload; |
| 36 |
int64_t time = 0; |
| 37 |
|
| 38 |
MediaPacket(bytevector&& src): payload(std::move(src)) {} |
| 39 |
MediaPacket(bytevector&& src, int64_t stime): payload(std::move(src)), time(stime) {} |
| 40 |
|
| 41 |
MediaPacket(const bytevector& src): payload(src) {} |
| 42 |
MediaPacket(const bytevector& src, int64_t stime): payload(src), time(stime) {} |
| 43 |
MediaPacket() {} |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
class Location |
| 48 |
{ |
| 49 |
public: |
| 50 |
UriParser uri; |
| 51 |
Location() {} |
| 52 |
virtual bool IsOpen() = 0; |
| 53 |
virtual void Close() {} |
| 54 |
}; |
| 55 |
|
| 56 |
class Source: public virtual Location |
| 57 |
{ |
| 58 |
public: |
| 59 |
virtual MediaPacket Read(size_t chunk) = 0; |
| 60 |
virtual bool End() = 0; |
| 61 |
static std::unique_ptr<Source> Create(const std::string& url); |
| 62 |
virtual ~Source() {} |
| 63 |
|
| 64 |
class ReadEOF: public std::runtime_error |
| 65 |
{ |
| 66 |
public: |
| 67 |
ReadEOF(const std::string& fn): std::runtime_error( "EOF while reading file: " + fn ) |
| 68 |
{ |
| 69 |
} |
| 70 |
}; |
| 71 |
}; |
| 72 |
|
| 73 |
class Target: public virtual Location |
| 74 |
{ |
| 75 |
public: |
| 76 |
virtual void Write(const MediaPacket& portion) = 0; |
| 77 |
virtual bool Broken() = 0; |
| 78 |
virtual size_t Still() { return 0; } |
| 79 |
static std::unique_ptr<Target> Create(const std::string& url); |
| 80 |
virtual ~Target() {} |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
class Relay: public virtual Source, public virtual Target, public virtual Location |
| 85 |
{ |
| 86 |
public: |
| 87 |
static std::unique_ptr<Relay> Create(const std::string& url); |
| 88 |
virtual ~Relay() {} |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
#endif |