MythTV  master
avfringbuffer.cpp
Go to the documentation of this file.
1 #include "avfringbuffer.h"
2 #include "mythcorecontext.h"
3 
5 URLProtocol AVFRingBuffer::s_avfrURL;
6 
7 int AVFRingBuffer::AVF_Open(URLContext *h, const char *filename, int flags)
8 {
9  (void)filename;
10  (void)flags;
11 
12  h->priv_data = nullptr;
13  return 0;
14 }
15 
16 int AVFRingBuffer::AVF_Read(URLContext *h, uint8_t *buf, int buf_size)
17 {
18  AVFRingBuffer *avfr = (AVFRingBuffer *)h->priv_data;
19 
20  if (!avfr)
21  return 0;
22 
23  int ret = avfr->GetRingBuffer()->Read(buf, buf_size);
24 
25  if (ret == 0)
26  ret = AVERROR_EOF;
27  return ret;
28 }
29 
30 int AVFRingBuffer::AVF_Write(URLContext *h, const uint8_t *buf, int buf_size)
31 {
32  AVFRingBuffer *avfr = (AVFRingBuffer *)h->priv_data;
33 
34  if (!avfr)
35  return 0;
36 
37  return avfr->GetRingBuffer()->Write(buf, buf_size);
38 }
39 
40 int64_t AVFRingBuffer::AVF_Seek(URLContext *h, int64_t offset, int whence)
41 {
42  AVFRingBuffer *avfr = (AVFRingBuffer *)h->priv_data;
43 
44  if (!avfr)
45  return 0;
46 
47  if (whence == AVSEEK_SIZE)
48  return avfr->GetRingBuffer()->GetRealFileSize();
49 
50  if (whence == SEEK_END)
51  return avfr->GetRingBuffer()->GetRealFileSize() + offset;
52 
53  return avfr->GetRingBuffer()->Seek(offset, whence);
54 }
55 
56 int AVFRingBuffer::AVF_Close(URLContext *h)
57 {
58  (void)h;
59  return 0;
60 }
61 
62 int AVFRingBuffer::AVF_Write_Packet(void *opaque, uint8_t *buf, int buf_size)
63 {
64  if (!opaque)
65  return 0;
66 
67  return ffurl_write((URLContext *)opaque, buf, buf_size);
68 }
69 
70 int AVFRingBuffer::AVF_Read_Packet(void *opaque, uint8_t *buf, int buf_size)
71 {
72  if (!opaque)
73  return 0;
74 
75  return ffurl_read((URLContext *)opaque, buf, buf_size);
76 }
77 
78 int64_t AVFRingBuffer::AVF_Seek_Packet(void *opaque, int64_t offset, int whence)
79 {
80  if (!opaque)
81  return 0;
82 
83  return ffurl_seek((URLContext *)opaque, offset, whence);
84 }
85 
87 {
88  QMutexLocker lock(avcodeclock);
90  {
91  // just in case URLProtocol's members do not have default constructor
92  memset((void *)&s_avfrURL, 0, sizeof(s_avfrURL));
93  s_avfrURL.name = "rbuffer";
94  s_avfrURL.url_open = AVF_Open;
95  s_avfrURL.url_read = AVF_Read;
96  s_avfrURL.url_write = AVF_Write;
97  s_avfrURL.url_seek = AVF_Seek;
98  s_avfrURL.url_close = AVF_Close;
99  s_avfrURL.priv_data_size = 0;
100  s_avfrURL.flags = URL_PROTOCOL_FLAG_NETWORK;
102  }
103  return &s_avfrURL;
104 }
105 
106 void AVFRingBuffer::SetInInit(bool state)
107 {
108  m_initState = state;
109 
111 }
112 
113 /* vim: set expandtab tabstop=4 shiftwidth=4: */
void SetInInit(bool state)
static int64_t AVF_Seek_Packet(void *opaque, int64_t offset, int whence)
static URLProtocol s_avfrURL
Definition: avfringbuffer.h:42
static bool s_avrprotocol_initialised
Definition: avfringbuffer.h:41
static int AVF_Write(URLContext *h, const uint8_t *buf, int buf_size)
static int AVF_Read(URLContext *h, uint8_t *buf, int buf_size)
static int AVF_Close(URLContext *h)
static int AVF_Read_Packet(void *opaque, uint8_t *buf, int buf_size)
RingBuffer * GetRingBuffer(void)
Definition: avfringbuffer.h:22
static URLProtocol * GetRingBufferURLProtocol(void)
QMutex * avcodeclock
This global variable is used to makes certain calls to avlib threadsafe.
static int AVF_Write_Packet(void *opaque, uint8_t *buf, int buf_size)
long long GetRealFileSize(void) const
Returns the size of the file we are reading/writing, or -1 if the query fails.
Definition: ringbuffer.cpp:497
int Read(void *buf, int count)
This is the public method for reading from a file, it calls the appropriate read method if the file i...
bool SetReadInternalMode(bool mode)
Definition: ringbuffer.cpp:558
static int AVF_Open(URLContext *h, const char *filename, int flags)
int Write(const void *buf, uint count)
Writes buffer to ThreadedFileWriter::Write(const void*,uint)
long long Seek(long long pos, int whence, bool has_lock=false)
Seeks to a particular position in the file.
Definition: ringbuffer.cpp:510
static int64_t AVF_Seek(URLContext *h, int64_t offset, int whence)