]> git.vomp.tv Git - vompclient.git/blob - afeed.cc
Rename TCP class to TCPOld
[vompclient.git] / afeed.cc
1 /*
2     Copyright 2004-2020 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "log.h"
21 #include "demuxer.h"
22 #include "callback.h"
23
24 #include "afeed.h"
25
26 AFeed::AFeed(Callback* tcb)
27 : cb(*tcb)
28 {
29   audioEnabled = 1;
30 }
31
32 void AFeed::disable()
33 {
34   audioEnabled = 0;
35 }
36
37 void AFeed::enable()
38 {
39   audioEnabled = 1;
40 }
41
42 void AFeed::start()
43 {
44   audioEnabled = 1;
45
46   threadStartProtect.lock();
47   feedThread = std::thread( [this]
48   {
49     threadStartProtect.lock();
50     threadStartProtect.unlock();
51     threadMethod();
52   });
53   threadStartProtect.unlock();
54 }
55
56 void AFeed::stop()
57 {
58   Log::getInstance()->log("AFeed", Log::DEBUG, "Stop1");
59   if (!feedThread.joinable()) return;
60   stopThread = true;
61   feedThread.join();
62   stopThread = false;
63   Log::getInstance()->log("AFeed", Log::DEBUG, "Stop2");
64 }
65
66 void AFeed::threadMethod()
67 {
68   bool alen;
69
70   while(1)
71   {
72     if (stopThread) return;
73
74     if (audioEnabled)
75     {
76       bool newdata=false;
77       alen = Demuxer::getInstance()->writeAudio(&newdata);
78
79       if (newdata) cb.call(this);
80       if (alen)
81       {
82            //Log::getInstance()->log("Afeed", Log::DEBUG, "written");
83            cb.call(this);
84       }
85       else
86       {
87         //MILLISLEEP(100);
88         MILLISLEEP(5); //Performance Issue Marten
89       }
90     }
91     else
92     {
93       Demuxer::getInstance()->flushAudio();
94       //Log::getInstance()->log("AFeed", Log::DEBUG, "No data delay");
95       //MILLISLEEP(100);
96       MILLISLEEP(5); //Performance Issue
97     }
98   }
99 }
100