-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
114 lines (92 loc) · 3.59 KB
/
main.cpp
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "listdevice.hpp"
#include "audiodevice.hpp"
#include "audioresampler.hpp"
#include "audioencoder.hpp"
#include "videodevice.hpp"
#include "videoencoder.hpp"
#include "videorescaler.hpp"
#include "rtmpwriter.hpp"
#include "timer.hpp"
#include <boost/asio.hpp>
#include "filereader.hpp"
#include "remotereader.hpp"
#include "imgoverlay.hpp"
#include "txtoverlay.hpp"
#include <thread>
int main()
{
av_log_set_level(AV_LOG_DEBUG);
avdevice_register_all();
ListDevice *ld = new ListDevice();
ld->RefreshDevices();
ld->QueryForDevices();
AVChannelLayout stereo = AV_CHANNEL_LAYOUT_STEREO;
AudioDevice *adevice = new AudioDevice(ld->adi_);
AudioResampler *aresampler = new AudioResampler(stereo, 44100, AV_SAMPLE_FMT_FLT, stereo, 44100, AV_SAMPLE_FMT_FLTP);
AudioEncoder *aencoder = new AudioEncoder();
VideoDevice *vdevice = new VideoDevice(ld->vdi_);
VideoRescaler *vrescaler = new VideoRescaler(1920,1080,AV_PIX_FMT_YUVA444P, 1920, 1080, AV_PIX_FMT_YUV444P);
VideoEncoder *vencoder = new VideoEncoder();
RtmpWriter *rtmpwriter = new RtmpWriter(vencoder->encCtx_, aencoder->encCtx_);
// RtmpWriter *rtmpwriter = new RtmpWriter(vencoder->encCtx_,nullptr);
int aret,vret;
std::atomic_bool isRunning = ATOMIC_VAR_INIT(false);
std::thread audioThread([&](){
while(!isRunning.load()){} // wait for the trigger
while(1)
{
if(!isRunning.load()) break;
adevice->ReadDevice();
aresampler->Resample(adevice->doubleFrame_);
aret = aencoder->EncodeFrame(aresampler->outFrame_);
if(aret) rtmpwriter->SendAudioPacket(aencoder->outPkt_);
// adevice->Flush() // need to call this in the adevice ReadDevice() code because of doubleFrame_
// aencoder->Flush(); // no need to call this for AAC
}
});
ImgOverlay *wm = new ImgOverlay("logo.png",306,158);
wm->InitFilterGraph(vdevice->decCtx_,1600,920,0.8);
TxtOverlay *np = new TxtOverlay();
np->InitFilterGraph(vdevice->decCtx_,28,"white",50,50);
std::thread videoThread([&](){
while(!isRunning.load()){} // wait for the trigger
while(1)
{
if(!isRunning.load()) break;
vdevice->ReadDevice();
np->OverlayText(vdevice->outFrame_);
wm->OverlayImage(np->outFrame_);
vrescaler->Rescale(wm->outFrame_);
vret = vencoder->EncodeFrame(vrescaler->outFrame_);
if(vret) rtmpwriter->SendVideoPacket(vencoder->encPkt_);
vdevice->Flush();
// vencoder->Flush(); // no need to call this for x264
np->Flush();
wm->Flush();
}
});
// boost::asio::io_context ioContext;
// Timer* npTimer = new Timer(ioContext, 1); // now playing timer
// FileReader *filereader = new FileReader("hello.txt");
// RemoteReader *remotereader = new RemoteReader(ioContext);
// npTimer->OnTimeout = [&](){
// printf("NOW PLAYING REFRESH!\n");
// if(filereader->Refresh())
// {
// printf("NEW CONTENT %s\n",filereader->content_.c_str());
// std::string content = filereader->content_;
// np->content_ = std::move(content);
// np->ReInitFilterGraph();
// }
// remotereader->Run("949fm.ca","80","/",10);
// };
// npTimer->StartTimer();
// std::thread helperThread([&](){
// while(!isRunning.load()) {}
// ioContext.run();
// });
isRunning.store(1);
audioThread.join();
videoThread.join();
// helperThread.join();
}