diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.cpp b/mythtv/libs/libmythtv/DeviceReadBuffer.cpp
index 2e1dfbc..f27c015 100644
a
|
b
|
using namespace std; |
19 | 19 | |
20 | 20 | DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll) |
21 | 21 | : videodevice(QString::null), _stream_fd(-1), |
22 | | readerPausedCB(cb), |
| 22 | readerPausedCB(cb), thread(NULL), |
23 | 23 | |
24 | 24 | // Data for managing the device ringbuffer |
25 | 25 | run(false), running(false), |
… |
… |
DeviceReadBuffer::DeviceReadBuffer(ReaderPausedCB *cb, bool use_poll) |
35 | 35 | |
36 | 36 | // statistics |
37 | 37 | max_used(0), avg_used(0), |
38 | | avg_cnt(0), thread(NULL) |
| 38 | avg_cnt(0) |
39 | 39 | { |
40 | 40 | } |
41 | 41 | |
… |
… |
DeviceReadBuffer::~DeviceReadBuffer() |
43 | 43 | { |
44 | 44 | if (buffer) |
45 | 45 | delete[] buffer; |
| 46 | if (thread) |
| 47 | Stop(); |
46 | 48 | } |
47 | 49 | |
48 | 50 | bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd) |
… |
… |
bool DeviceReadBuffer::Setup(const QString &streamName, int streamfd) |
94 | 96 | |
95 | 97 | void DeviceReadBuffer::Start(void) |
96 | 98 | { |
97 | | bool was_running; |
| 99 | QMutexLocker locker(&thread_lock); |
98 | 100 | |
99 | 101 | { |
100 | 102 | QMutexLocker locker(&lock); |
101 | | was_running = running; |
102 | 103 | error = false; |
103 | 104 | } |
104 | 105 | |
105 | | if (was_running) |
| 106 | if (thread) |
106 | 107 | { |
107 | 108 | VERBOSE(VB_IMPORTANT, LOC_ERR + "Start(): Already running."); |
108 | 109 | SetRequestPause(false); |
… |
… |
void DeviceReadBuffer::Reset(const QString &streamName, int streamfd) |
135 | 136 | |
136 | 137 | void DeviceReadBuffer::Stop(void) |
137 | 138 | { |
138 | | bool was_running = IsRunning(); |
139 | | |
140 | | if (!was_running) |
| 139 | QMutexLocker locker(&thread_lock); |
| 140 | if (!thread) |
141 | 141 | { |
142 | 142 | VERBOSE(VB_IMPORTANT, LOC + "Stop(): Not running."); |
| 143 | return; |
143 | 144 | } |
144 | 145 | |
145 | 146 | { |
… |
… |
void DeviceReadBuffer::Stop(void) |
147 | 148 | run = false; |
148 | 149 | } |
149 | 150 | |
150 | | if ( thread ) { |
151 | | pthread_join(thread, NULL); |
152 | | thread = (pthread_t)NULL; |
153 | | } |
| 151 | pthread_join(thread, NULL); |
| 152 | thread = (pthread_t)NULL; |
154 | 153 | } |
155 | 154 | |
156 | 155 | void DeviceReadBuffer::SetRequestPause(bool req) |
… |
… |
uint DeviceReadBuffer::Read(unsigned char *buf, const uint count) |
491 | 490 | } |
492 | 491 | |
493 | 492 | /** \fn DeviceReadBuffer::WaitForUnused(uint) const |
| 493 | * \brief Return the amount of empty space in our internal buffer. |
| 494 | * If there is less than what is needed, and something is emptying the buffer, wait. |
494 | 495 | * \param needed Number of bytes we want to write |
495 | 496 | * \return bytes available for writing |
496 | 497 | */ |
… |
… |
uint DeviceReadBuffer::WaitForUnused(uint needed) const |
517 | 518 | } |
518 | 519 | |
519 | 520 | /** \fn DeviceReadBuffer::WaitForUsed(uint) const |
| 521 | * \brief Return the number of bytes available in our buffer. |
| 522 | * Wait if another thread is actively reading from the device. |
520 | 523 | * \param needed Number of bytes we want to read |
521 | 524 | * \return bytes available for reading |
522 | 525 | */ |
diff --git a/mythtv/libs/libmythtv/DeviceReadBuffer.h b/mythtv/libs/libmythtv/DeviceReadBuffer.h
index 70fc262..84c1ba7 100644
a
|
b
|
class DeviceReadBuffer |
78 | 78 | |
79 | 79 | ReaderPausedCB *readerPausedCB; |
80 | 80 | pthread_t thread; |
| 81 | mutable QMutex thread_lock; // Manage access to thread variable |
81 | 82 | |
82 | 83 | // Data for managing the device ringbuffer |
83 | 84 | mutable QMutex lock; |
84 | | bool run; |
85 | | bool running; |
| 85 | bool run; // Set to false if we want the thread to stop |
| 86 | bool running; // If the read thread is running |
86 | 87 | bool eof; |
87 | 88 | mutable bool error; |
88 | 89 | bool request_pause; |