@@ -62,8 +62,8 @@ void client_disconnect(struct Client *c, int write_trailer)
62
62
c -> ofmt_ctx = NULL ;
63
63
c -> ffinfo = NULL ;
64
64
pthread_mutex_lock (& c -> buffer_lock );
65
- while (av_fifo_size (c -> buffer )) {
66
- av_fifo_generic_read (c -> buffer , & seg , sizeof ( struct Segment * ), NULL );
65
+ while (av_fifo_can_read (c -> buffer )) {
66
+ av_fifo_read (c -> buffer , & seg , 1 );
67
67
segment_unref (seg );
68
68
}
69
69
pthread_mutex_unlock (& c -> buffer_lock );
@@ -81,14 +81,14 @@ void client_set_state(struct Client *c, enum State state)
81
81
void client_push_segment (struct Client * c , struct Segment * seg )
82
82
{
83
83
pthread_mutex_lock (& c -> buffer_lock );
84
- if (av_fifo_space (c -> buffer ) == 0 ) {
84
+ if (av_fifo_can_write (c -> buffer ) == 0 ) {
85
85
av_log (NULL , AV_LOG_WARNING , "Client buffer full, dropping Segment.\n" );
86
86
client_set_state (c , BUFFER_FULL );
87
87
pthread_mutex_unlock (& c -> buffer_lock );
88
88
return ;
89
89
}
90
90
segment_ref (seg );
91
- av_fifo_generic_write (c -> buffer , & seg , sizeof ( struct Segment * ), NULL );
91
+ av_fifo_write (c -> buffer , & seg , 1 );
92
92
pthread_mutex_unlock (& c -> buffer_lock );
93
93
client_set_state (c , WRITABLE );
94
94
}
@@ -105,24 +105,24 @@ void publisher_init(struct PublisherContext **pub, char *stream_name)
105
105
pc -> stream_name = stream_name ;
106
106
pc -> current_segment_id = -1 ;
107
107
pc -> shutdown = 0 ;
108
- pc -> buffer = av_fifo_alloc_array ( sizeof (struct Segment ), MAX_SEGMENTS );
108
+ pc -> buffer = av_fifo_alloc2 ( MAX_SEGMENTS , sizeof (struct Segment * ), 0 );
109
109
if (!pc -> buffer ) {
110
110
av_log (NULL , AV_LOG_ERROR , "Could not allocate publisher buffer.\n" );
111
111
av_free (pc );
112
112
return ;
113
113
}
114
- pc -> fs_buffer = av_fifo_alloc_array ( sizeof (struct Segment ), MAX_SEGMENTS );
114
+ pc -> fs_buffer = av_fifo_alloc2 ( MAX_SEGMENTS , sizeof (struct Segment * ), 0 );
115
115
if (!pc -> fs_buffer ) {
116
116
av_log (NULL , AV_LOG_ERROR , "Could not allocate publisher fast-start buffer.\n" );
117
- av_fifo_free ( pc -> buffer );
117
+ av_fifo_freep2 ( & pc -> buffer );
118
118
av_free (pc );
119
119
return ;
120
120
}
121
121
pthread_mutex_init (& pc -> buffer_lock , NULL );
122
122
pthread_mutex_init (& pc -> fs_buffer_lock , NULL );
123
123
for (i = 0 ; i < MAX_CLIENTS ; i ++ ) {
124
124
struct Client * c = & pc -> clients [i ];
125
- c -> buffer = av_fifo_alloc_array ( sizeof (struct Segment ), MAX_SEGMENTS );
125
+ c -> buffer = av_fifo_alloc2 ( MAX_SEGMENTS , sizeof (struct Segment * ), 0 );
126
126
if (!c -> buffer ) {
127
127
av_log (NULL , AV_LOG_ERROR , "Could not allocate client buffer.\n" );
128
128
publisher_free (pc );
@@ -144,13 +144,13 @@ void publisher_push_segment(struct PublisherContext *pub, struct Segment *seg)
144
144
struct Segment * drop ;
145
145
pthread_mutex_lock (& pub -> buffer_lock );
146
146
pthread_mutex_lock (& pub -> fs_buffer_lock );
147
- av_fifo_generic_write (pub -> buffer , & seg , sizeof ( struct Segment * ), NULL );
147
+ av_fifo_write (pub -> buffer , & seg , 1 );
148
148
segment_ref (seg );
149
- if (av_fifo_size (pub -> fs_buffer ) >= BUFFER_SEGMENTS * sizeof ( struct Segment * ) ) {
150
- av_fifo_generic_read (pub -> fs_buffer , & drop , sizeof ( struct Segment * ), NULL );
149
+ if (av_fifo_can_read (pub -> fs_buffer ) >= BUFFER_SEGMENTS ) {
150
+ av_fifo_read (pub -> fs_buffer , & drop , 1 );
151
151
segment_unref (drop );
152
152
}
153
- av_fifo_generic_write (pub -> fs_buffer , & seg , sizeof ( struct Segment * ), NULL );
153
+ av_fifo_write (pub -> fs_buffer , & seg , 1 );
154
154
pthread_mutex_unlock (& pub -> buffer_lock );
155
155
pthread_mutex_unlock (& pub -> fs_buffer_lock );
156
156
segment_ref (seg );
@@ -192,9 +192,9 @@ void client_push_prebuffer(struct PublisherContext *pub, struct Client *c)
192
192
int size ;
193
193
struct Segment * seg ;
194
194
pthread_mutex_lock (& pub -> fs_buffer_lock );
195
- size = av_fifo_size (pub -> fs_buffer );
196
- for (off = 0 ; off < size ; off += sizeof ( struct Segment * ) ) {
197
- av_fifo_generic_peek_at (pub -> fs_buffer , & seg , off , sizeof ( struct Segment * ), NULL );
195
+ size = av_fifo_can_read (pub -> fs_buffer );
196
+ for (off = 0 ; off < size ; off ++ ) {
197
+ av_fifo_peek (pub -> fs_buffer , & seg , 1 , off );
198
198
client_push_segment (c , seg );
199
199
}
200
200
pthread_mutex_unlock (& pub -> fs_buffer_lock );
@@ -222,21 +222,21 @@ void publisher_free(struct PublisherContext *pub)
222
222
int i ;
223
223
struct Segment * seg ;
224
224
pthread_mutex_lock (& pub -> buffer_lock );
225
- while (av_fifo_size (pub -> buffer )) {
226
- av_fifo_generic_read (pub -> buffer , & seg , sizeof ( struct Segment * ), NULL );
225
+ while (av_fifo_can_read (pub -> buffer )) {
226
+ av_fifo_read (pub -> buffer , & seg , 1 );
227
227
segment_unref (seg );
228
228
}
229
- av_fifo_freep (& pub -> buffer );
229
+ av_fifo_freep2 (& pub -> buffer );
230
230
pthread_mutex_unlock (& pub -> buffer_lock );
231
-
231
+
232
232
pthread_mutex_lock (& pub -> fs_buffer_lock );
233
- while (av_fifo_size (pub -> fs_buffer )) {
234
- av_fifo_generic_read (pub -> fs_buffer , & seg , sizeof ( struct Segment * ), NULL );
233
+ while (av_fifo_can_read (pub -> fs_buffer )) {
234
+ av_fifo_read (pub -> fs_buffer , & seg , 1 );
235
235
segment_unref (seg );
236
236
}
237
- av_fifo_freep (& pub -> fs_buffer );
237
+ av_fifo_freep2 (& pub -> fs_buffer );
238
238
for (i = 0 ; i < MAX_CLIENTS ; i ++ ) {
239
- av_fifo_freep (& pub -> clients [i ].buffer );
239
+ av_fifo_freep2 (& pub -> clients [i ].buffer );
240
240
}
241
241
pthread_mutex_unlock (& pub -> fs_buffer_lock );
242
242
av_free (pub );
@@ -256,18 +256,18 @@ void publish(struct PublisherContext *pub)
256
256
struct Segment * seg ;
257
257
char filename [128 ] = {0 };
258
258
pthread_mutex_lock (& pub -> buffer_lock );
259
- av_log (NULL , AV_LOG_DEBUG , "pub->buffer size: %d \n" , av_fifo_size (pub -> buffer ));
260
- if (av_fifo_size (pub -> buffer ) == 0 ) {
259
+ av_log (NULL , AV_LOG_DEBUG , "pub->buffer size: %ld \n" , av_fifo_can_read (pub -> buffer ));
260
+ if (av_fifo_can_read (pub -> buffer ) == 0 ) {
261
261
pthread_mutex_unlock (& pub -> buffer_lock );
262
262
return ;
263
263
}
264
- av_fifo_generic_read (pub -> buffer , & seg , sizeof ( struct Segment * ), NULL );
264
+ av_fifo_read (pub -> buffer , & seg , 1 );
265
265
pthread_mutex_unlock (& pub -> buffer_lock );
266
266
if (seg ) {
267
267
pub -> current_segment_id = seg -> id ;
268
268
snprintf (filename , 127 , "segment-%04d.mkv" , seg -> id );
269
269
// segment_save(seg, filename);
270
-
270
+
271
271
for (i = 0 ; i < MAX_CLIENTS ; i ++ ) {
272
272
switch (pub -> clients [i ].state ) {
273
273
case BUFFER_FULL :
@@ -304,7 +304,7 @@ void publisher_gen_status_json(struct PublisherContext *pub, char *status)
304
304
}
305
305
states [c -> state ]++ ;
306
306
}
307
-
307
+
308
308
309
309
snprintf (status , 4095 ,
310
310
"{\n\t\"free\": %d,\n"
0 commit comments