Debian Codegraph @

apps/transmitbase.hpp

raw
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 #include "srt.h"
20 #include "uriparser.hpp"
21 #include "apputil.hpp"
22 #include "statswriter.hpp"
23
24 typedef std::vector<char> bytevector;
25 extern bool transmit_total_stats;
26 extern bool g_stats_are_printed_to_stdout;
27 extern unsigned long transmit_bw_report;
28 extern unsigned long transmit_stats_report;
29 extern unsigned long transmit_chunk_size;
30
31 struct MediaPacket
32 {
33 bytevector payload;
34 int64_t time = 0;
35
36 MediaPacket(bytevector&& src) : payload(std::move(src)) {}
37 MediaPacket(bytevector&& src, int64_t stime) : payload(std::move(src)), time(stime) {}
38
39 MediaPacket(size_t payload_size) : payload(payload_size), time(0) {}
40 MediaPacket(const bytevector& src) : payload(src) {}
41 MediaPacket(const bytevector& src, int64_t stime) : payload(src), time(stime) {}
42 MediaPacket() {}
43 };
44
45 extern std::shared_ptr<SrtStatsWriter> transmit_stats_writer;
46
47 class Location
48 {
49 public:
50 UriParser uri;
51 Location() {}
52 };
53
54 class Source: public Location
55 {
56 public:
57 virtual int Read(size_t chunk, MediaPacket& pkt, std::ostream &out_stats = std::cout) = 0;
58 virtual bool IsOpen() = 0;
59 virtual bool End() = 0;
60 static std::unique_ptr<Source> Create(const std::string& url);
61 virtual void Close() {}
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 virtual SRTSOCKET GetSRTSocket() const { return SRT_INVALID_SOCK; }
73 virtual int GetSysSocket() const { return -1; }
74 virtual bool MayBlock() const { return false; }
75 virtual bool AcceptNewClient() { return false; }
76 };
77
78 class Target: public Location
79 {
80 public:
81 virtual int Write(const char* data, size_t size, int64_t src_time, std::ostream &out_stats = std::cout) = 0;
82 virtual bool IsOpen() = 0;
83 virtual bool Broken() = 0;
84 virtual void Close() {}
85 virtual size_t Still() { return 0; }
86 static std::unique_ptr<Target> Create(const std::string& url);
87 virtual ~Target() {}
88
89 virtual SRTSOCKET GetSRTSocket() const { return SRT_INVALID_SOCK; }
90 virtual int GetSysSocket() const { return -1; }
91 virtual bool AcceptNewClient() { return false; }
92 };
93
94 #endif