]> git.vomp.tv Git - vompclient.git/blob - afeedr.cc
Prebuffering
[vompclient.git] / afeedr.cc
1 /*
2     Copyright 2004-2005 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, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "afeedr.h"
22
23 AFeedR::AFeedR(Callback* tcb, Stream* tstream)
24 : cb(*tcb), stream(*tstream)
25 {
26 }
27
28 #ifndef NEW_DEMUXER
29 int AFeedR::init(int tfd)
30 {
31   fd = tfd;
32   return 1;
33 }
34 #else
35 int AFeedR::init(DrainTarget* tdt)
36 {
37   dt = tdt;
38   return 1;
39 }
40 #endif
41
42
43 int AFeedR::shutdown()
44 {
45   // FIXME
46   return 1;
47 }
48
49 int AFeedR::start()
50 {
51   return threadStart();
52 }
53
54 void AFeedR::stop()
55 {
56   threadCancel();
57 }
58
59 void AFeedR::threadMethod()
60 {
61   Log::getInstance()->log("AFeedR", Log::DEBUG, "Started");
62
63   int alen;
64
65   while(1)
66   {
67 #ifndef NEW_DEMUXER
68     alen = stream.drain(fd);
69 #else
70     alen = stream.drain(dt);
71     threadCheckExit();
72 #endif
73
74     if (alen)
75     {
76       Log::getInstance()->log("AFeedR", Log::DEBUG, "Written %i", alen);
77       cb.call(this);
78     }
79     else
80     {
81       MILLISLEEP(100);
82     }
83   }
84 }
85