Browse code

libavdevice/decklink: configurablity to set max queue size

Signed-off-by: Ravindra Patagar <rpatagar@akamai.com>
Signed-off-by: Marton Balint <cus@passwd.hu>

Ravindra authored on 2017/08/10 15:29:30
Showing 6 changed files
... ...
@@ -289,6 +289,11 @@ Sets the audio packet timestamp source. Must be @samp{video}, @samp{audio},
289 289
 If set to @samp{true}, color bars are drawn in the event of a signal loss.
290 290
 Defaults to @samp{true}.
291 291
 
292
+@item queue_size
293
+Sets maximum input buffer size in bytes. If the buffering reaches this value,
294
+incoming frames will be dropped.
295
+Defaults to @samp{1073741824}.
296
+
292 297
 @end table
293 298
 
294 299
 @subsection Examples
... ...
@@ -1,6 +1,7 @@
1 1
 /*
2 2
  * Blackmagic DeckLink common code
3 3
  * Copyright (c) 2013-2014 Ramiro Polla, Luca Barbato, Deti Fliegl
4
+ * Copyright (c) 2017 Akamai Technologies, Inc.
4 5
  *
5 6
  * This file is part of FFmpeg.
6 7
  *
... ...
@@ -38,6 +39,7 @@ typedef struct AVPacketQueue {
38 38
     pthread_mutex_t mutex;
39 39
     pthread_cond_t cond;
40 40
     AVFormatContext *avctx;
41
+    int64_t max_q_size;
41 42
 } AVPacketQueue;
42 43
 
43 44
 struct decklink_ctx {
... ...
@@ -1,6 +1,7 @@
1 1
 /*
2 2
  * Blackmagic DeckLink common code
3 3
  * Copyright (c) 2013-2014 Ramiro Polla
4
+ * Copyright (c) 2017 Akamai Technologies, Inc.
4 5
  *
5 6
  * This file is part of FFmpeg.
6 7
  *
... ...
@@ -48,6 +49,7 @@ struct decklink_cctx {
48 48
     int video_input;
49 49
     int draw_bars;
50 50
     char *format_code;
51
+    int64_t queue_size;
51 52
 };
52 53
 
53 54
 #endif /* AVDEVICE_DECKLINK_COMMON_C_H */
... ...
@@ -1,6 +1,7 @@
1 1
 /*
2 2
  * Blackmagic DeckLink input
3 3
  * Copyright (c) 2013-2014 Luca Barbato, Deti Fliegl
4
+ * Copyright (c) 2017 Akamai Technologies, Inc.
4 5
  *
5 6
  * This file is part of FFmpeg.
6 7
  *
... ...
@@ -187,10 +188,12 @@ static uint8_t* teletext_data_unit_from_vanc_data(uint8_t *src, uint8_t *tgt, in
187 187
 
188 188
 static void avpacket_queue_init(AVFormatContext *avctx, AVPacketQueue *q)
189 189
 {
190
+    struct decklink_cctx *ctx = (struct decklink_cctx *)avctx->priv_data;
190 191
     memset(q, 0, sizeof(AVPacketQueue));
191 192
     pthread_mutex_init(&q->mutex, NULL);
192 193
     pthread_cond_init(&q->cond, NULL);
193 194
     q->avctx = avctx;
195
+    q->max_q_size = ctx->queue_size;
194 196
 }
195 197
 
196 198
 static void avpacket_queue_flush(AVPacketQueue *q)
... ...
@@ -230,8 +233,8 @@ static int avpacket_queue_put(AVPacketQueue *q, AVPacket *pkt)
230 230
 {
231 231
     AVPacketList *pkt1;
232 232
 
233
-    // Drop Packet if queue size is > 1GB
234
-    if (avpacket_queue_size(q) >  1024 * 1024 * 1024 ) {
233
+    // Drop Packet if queue size is > maximum queue size
234
+    if (avpacket_queue_size(q) > q->max_q_size) {
235 235
         av_log(q->avctx, AV_LOG_WARNING,  "Decklink input buffer overrun!\n");
236 236
         return -1;
237 237
     }
... ...
@@ -1,6 +1,7 @@
1 1
 /*
2 2
  * Blackmagic DeckLink input
3 3
  * Copyright (c) 2014 Deti Fliegl
4
+ * Copyright (c) 2017 Akamai Technologies, Inc.
4 5
  *
5 6
  * This file is part of FFmpeg.
6 7
  *
... ...
@@ -64,6 +65,7 @@ static const AVOption options[] = {
64 64
     { "reference",     NULL,                                          0,  AV_OPT_TYPE_CONST, { .i64 = PTS_SRC_REFERENCE}, 0, 0, DEC, "pts_source"},
65 65
     { "wallclock",     NULL,                                          0,  AV_OPT_TYPE_CONST, { .i64 = PTS_SRC_WALLCLOCK}, 0, 0, DEC, "pts_source"},
66 66
     { "draw_bars",     "draw bars on signal loss" , OFFSET(draw_bars),    AV_OPT_TYPE_BOOL,  { .i64 = 1}, 0, 1, DEC },
67
+    { "queue_size",    "input queue buffer size",   OFFSET(queue_size),   AV_OPT_TYPE_INT64, { .i64 = (1024 * 1024 * 1024)}, 0, INT64_MAX, DEC },
67 68
     { NULL },
68 69
 };
69 70
 
... ...
@@ -29,7 +29,7 @@
29 29
 
30 30
 #define LIBAVDEVICE_VERSION_MAJOR  57
31 31
 #define LIBAVDEVICE_VERSION_MINOR   7
32
-#define LIBAVDEVICE_VERSION_MICRO 100
32
+#define LIBAVDEVICE_VERSION_MICRO 101
33 33
 
34 34
 #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \
35 35
                                                LIBAVDEVICE_VERSION_MINOR, \