-
Notifications
You must be signed in to change notification settings - Fork 343
/
streamingringbuffer.cpp
74 lines (59 loc) · 1.47 KB
/
streamingringbuffer.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
#include "mythverbose.h"
#include "streamingringbuffer.h"
#define LOC QString("StreamRingBuf(%1): ").arg(filename)
StreamingRingBuffer::StreamingRingBuffer(const QString &lfilename)
: m_context(NULL)
{
startreadahead = true;
OpenFile(lfilename);
}
StreamingRingBuffer::~StreamingRingBuffer()
{
if (m_context)
url_close(m_context);
}
bool StreamingRingBuffer::IsOpen(void) const
{
return m_context;
}
long long StreamingRingBuffer::GetReadPosition(void) const
{
return 0;
}
bool StreamingRingBuffer::OpenFile(const QString &lfilename, uint retry_ms)
{
av_register_all();
filename = lfilename;
VERBOSE(VB_GENERAL, LOC + QString("Trying %1").arg(filename));
int res = url_open(&m_context, filename.toAscii(), URL_RDONLY);
if (res < 0 || !m_context)
{
VERBOSE(VB_IMPORTANT, LOC + QString("Failed to open stream (error %1)")
.arg(res));
return false;
}
return true;
}
long long StreamingRingBuffer::Seek(long long pos, int whence, bool has_lock)
{
if (!m_context)
return 0;
if (url_seek(m_context, pos, whence) < 0)
{
ateof = true;
return 0;
}
return pos;
}
int StreamingRingBuffer::safe_read(void *data, uint sz)
{
if (m_context)
return url_read_complete(m_context, (unsigned char*)data, sz);
return 0;
}
long long StreamingRingBuffer::GetRealFileSize(void) const
{
if (m_context)
return url_filesize(m_context);
return -1;
}