File: testmediabase.hpp

package info (click to toggle)
srt 1.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,804 kB
  • sloc: cpp: 52,175; ansic: 5,746; tcl: 1,183; sh: 318; python: 99; makefile: 38
file content (92 lines) | stat: -rw-r--r-- 2,254 bytes parent folder | download | duplicates (2)
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
/*
 * SRT - Secure, Reliable, Transport
 * Copyright (c) 2018 Haivision Systems Inc.
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 */

#ifndef INC_SRT_COMMON_TRANMITBASE_HPP
#define INC_SRT_COMMON_TRANMITBASE_HPP

#include <string>
#include <memory>
#include <vector>
#include <iostream>
#include <stdexcept>

#include "sync.h"
#include "uriparser.hpp"

typedef std::vector<char> bytevector;
extern srt::sync::atomic<bool> transmit_throw_on_interrupt;
extern int transmit_bw_report;
extern unsigned transmit_stats_report;
extern size_t transmit_chunk_size;
extern bool transmit_printformat_json;
extern bool transmit_use_sourcetime;
extern int transmit_retry_connect;
extern bool transmit_retry_always;

struct MediaPacket
{
    bytevector payload;
    int64_t time = 0;

    MediaPacket(bytevector&& src): payload(std::move(src)) {}
    MediaPacket(bytevector&& src, int64_t stime): payload(std::move(src)), time(stime) {}

    MediaPacket(const bytevector& src): payload(src) {}
    MediaPacket(const bytevector& src, int64_t stime): payload(src), time(stime) {}
    MediaPacket() {}
};


class Location
{
public:
    UriParser uri;
    Location() {}
    virtual bool IsOpen() = 0;
    virtual void Close() {}
};

class Source: public virtual Location
{
public:
    virtual MediaPacket Read(size_t chunk) = 0;
    virtual bool End() = 0;
    static std::unique_ptr<Source> Create(const std::string& url);
    virtual ~Source() {}

    class ReadEOF: public std::runtime_error
    {
    public:
        ReadEOF(const std::string& fn): std::runtime_error( "EOF while reading file: " + fn )
        {
        }
    };
};

class Target: public virtual Location
{
public:
    virtual void Write(const MediaPacket& portion) = 0;
    virtual bool Broken() = 0;
    virtual size_t Still() { return 0; }
    static std::unique_ptr<Target> Create(const std::string& url);
    virtual ~Target() {}
};


class Relay: public virtual Source, public virtual Target, public virtual Location
{
public:
    static std::unique_ptr<Relay> Create(const std::string& url);
    virtual ~Relay() {}
};


#endif