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  auto *avfr = (AVFRingBuffer *)h->priv_data;
19  if (!avfr)
20  return 0;
21 
22  int ret = avfr->GetRingBuffer()->Read(buf, buf_size);
23 
24  if (ret == 0)
25  ret = AVERROR_EOF;
26  return ret;
27 }
28 
29 int AVFRingBuffer::AVF_Write(URLContext *h, const uint8_t *buf, int buf_size)
30 {
31  auto *avfr = (AVFRingBuffer *)h->priv_data;
32  if (!avfr)
33  return 0;
34 
35  return avfr->GetRingBuffer()->Write(buf, buf_size);
36 }
37 
38 int64_t AVFRingBuffer::AVF_Seek(URLContext *h, int64_t offset, int whence)
39 {
40  auto *avfr = (AVFRingBuffer *)h->priv_data;
41  if (!avfr)
42  return 0;
43 
44  if (whence == AVSEEK_SIZE)
45  return avfr->GetRingBuffer()->GetRealFileSize();
46 
47  if (whence == SEEK_END)
48  return avfr->GetRingBuffer()->GetRealFileSize() + offset;
49 
50  return avfr->GetRingBuffer()->Seek(offset, whence);
51 }
52 
53 int AVFRingBuffer::AVF_Close(URLContext *h)
54 {
55  (void)h;
56  return 0;
57 }
58 
59 int AVFRingBuffer::AVF_Write_Packet(void *opaque, uint8_t *buf, int buf_size)
60 {
61  if (!opaque)
62  return 0;
63 
64  return ffurl_write((URLContext *)opaque, buf, buf_size);
65 }
66 
67 int AVFRingBuffer::AVF_Read_Packet(void *opaque, uint8_t *buf, int buf_size)
68 {
69  if (!opaque)
70  return 0;
71 
72  return ffurl_read((URLContext *)opaque, buf, buf_size);
73 }
74 
75 int64_t AVFRingBuffer::AVF_Seek_Packet(void *opaque, int64_t offset, int whence)
76 {
77  if (!opaque)
78  return 0;
79 
80  return ffurl_seek((URLContext *)opaque, offset, whence);
81 }
82 
84 {
85  QMutexLocker lock(avcodeclock);
87  {
88  // just in case URLProtocol's members do not have default constructor
89  memset((void *)&s_avfrURL, 0, sizeof(s_avfrURL));
90  s_avfrURL.name = "rbuffer";
91  s_avfrURL.url_open = AVF_Open;
92  s_avfrURL.url_read = AVF_Read;
93  s_avfrURL.url_write = AVF_Write;
94  s_avfrURL.url_seek = AVF_Seek;
95  s_avfrURL.url_close = AVF_Close;
96  s_avfrURL.priv_data_size = 0;
97  s_avfrURL.flags = URL_PROTOCOL_FLAG_NETWORK;
99  }
100  return &s_avfrURL;
101 }
102 
103 void AVFRingBuffer::SetInInit(bool state)
104 {
105  m_initState = state;
106 
108 }
109 
110 /* 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 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)
static bool s_avfrProtocolInitialised
Definition: avfringbuffer.h:41
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)
bool SetReadInternalMode(bool mode)
Definition: ringbuffer.cpp:558
static int AVF_Open(URLContext *h, const char *filename, int flags)
static int64_t AVF_Seek(URLContext *h, int64_t offset, int whence)