]> git.vomp.tv Git - vompclient.git/blob - afeed.cc
Bitmap and VPictureBanner CWFs
[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 #include "util.h"
24
25 #include "afeed.h"
26
27 AFeed::AFeed(Callback* tcb)
28 : cb(*tcb)
29 {
30   audioEnabled = 1;
31 }
32
33 void AFeed::disable()
34 {
35   audioEnabled = 0;
36 }
37
38 void AFeed::enable()
39 {
40   audioEnabled = 1;
41 }
42
43 void AFeed::start()
44 {
45   audioEnabled = 1;
46
47   threadStartProtect.lock();
48   feedThread = std::thread( [this]
49   {
50     threadStartProtect.lock();
51     threadStartProtect.unlock();
52     threadMethod();
53   });
54   threadStartProtect.unlock();
55 }
56
57 void AFeed::stop()
58 {
59   Log::getInstance()->log("AFeed", Log::DEBUG, "Stop1");
60   if (!feedThread.joinable()) return;
61   stopThread = true;
62   feedThread.join();
63   stopThread = false;
64   Log::getInstance()->log("AFeed", Log::DEBUG, "Stop2");
65 }
66
67 void AFeed::threadMethod()
68 {
69   bool alen;
70
71   while(1)
72   {
73     if (stopThread) return;
74
75     if (audioEnabled)
76     {
77       bool newdata=false;
78       alen = Demuxer::getInstance()->writeAudio(&newdata);
79
80       if (newdata) cb.call(this);
81       if (alen)
82       {
83            //Log::getInstance()->log("Afeed", Log::DEBUG, "written");
84            cb.call(this);
85       }
86       else
87       {
88         //MILLISLEEP(100);
89         MILLISLEEP(5); //Performance Issue Marten
90       }
91     }
92     else
93     {
94       Demuxer::getInstance()->flushAudio();
95       //Log::getInstance()->log("AFeed", Log::DEBUG, "No data delay");
96       //MILLISLEEP(100);
97       MILLISLEEP(5); //Performance Issue
98     }
99   }
100 }
101