2
* Copyright (C) 2016 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <sys/types.h>
31
#include <mcs/logger.h>
33
#include <mcs/report/reportfactory.h>
35
#include <mcs/streaming/mpegtspacketizer.h>
36
#include <mcs/streaming/rtpsender.h>
39
static constexpr unsigned int kBufferSize = 2048;
42
int main(int argc, char **argv) {
44
if (argc != 2 || argv[1] == nullptr) {
45
std::cout << "Usage: " << std::endl
46
<< " " << argv[0] << " <input>" << std::endl;
50
int fin = ::open(argv[1], O_RDONLY);
52
MCS_ERROR("Failed to open input file %s", argv[1]);
56
auto report_factory = mcs::report::ReportFactory::Create();
58
auto packetizer = mcs::streaming::MPEGTSPacketizer::Create(report_factory->CreatePacketizerReport());
59
auto sender = mcs::streaming::RTPSender::Create("192.168.178.1", 5000, report_factory->CreateSenderReport());
64
int track_index = packetizer->AddTrack(mcs::streaming::MPEGTSPacketizer::TrackFormat{"video/avc"});
69
uint8_t inbuf[kBufferSize];
71
auto bytes_read = ::read(fin, inbuf, kBufferSize);
73
MCS_ERROR("Failed to read input data");
76
else if (bytes_read == 0)
79
auto buffer = mcs::video::Buffer::Create(bytes_read, mcs::Utils::GetNowUs());
80
::memcpy(buffer->Data(), inbuf, bytes_read);
82
mcs::video::Buffer::Ptr outbuf;
86
flags = mcs::streaming::MPEGTSPacketizer::kEmitPCR |
87
mcs::streaming::MPEGTSPacketizer::kEmitPATandPMT;
89
packetizer->Packetize(track_index, buffer, &outbuf, flags);
90
sender->Queue(outbuf);
93
std::this_thread::sleep_for(std::chrono::milliseconds{1});