1 STATIC
void limits_reset(void)
3 limits_p
.pkts
.audio_bytes_n
= 0;
4 limits_p
.pkts
.video_bytes_n
= 0;
5 /* hardcoded for now: arbitrary rough estimates */
6 /* ~8s of 400kb audio */
7 limits_p
.pkts
.limit
.audio_bytes_n
= 400000 / 8 * 8;
8 /* ~8s of 10Mb video */
9 limits_p
.pkts
.limit
.video_bytes_n
= 10000000 / 8 * 8;
11 STATIC
void prefill_reset(u8 percent
)
14 fatal("invalid prefill of %u%% for the buffer of packet queues\n", percent
);
16 limits_p
.pkts
.prefill
.audio_bytes_rem
=
17 limits_p
.pkts
.limit
.audio_bytes_n
* percent
/ 100;
18 pout("prefill size for the audio packet queue buffer is %u%%/%"PRId64
" bytes\n", percent
, limits_p
.pkts
.prefill
.audio_bytes_rem
);
19 limits_p
.pkts
.prefill
.video_bytes_rem
=
20 limits_p
.pkts
.limit
.video_bytes_n
* percent
/ 100;
21 pout("prefill size for the video packet queue buffer is %u%%/%"PRId64
" bytes\n", percent
, limits_p
.pkts
.prefill
.video_bytes_rem
);
23 limits_p
.pkts
.prefill
.audio_bytes_rem
= 0;
24 limits_p
.pkts
.prefill
.video_bytes_rem
= 0;
25 pout("prefill for the packet queue buffers is disabled\n");
28 STATIC
void init_once(void)
32 eof_pkt_l
= avcodec_pkt_ref_alloc();
34 fatal("ffmpeg:unable to allocate a null/eof reference on a packet\n");
38 r
= pthread_mutex_init(&limits_p
.mutex
, 0);
40 fatal("unable to initialize the mutex to guard the accounting of limits\n");
41 memset(&rate_limiter_previous_tp
, 0, sizeof(rate_limiter_previous_tp
));
43 STATIC
void limits_lock(void)
47 r
= pthread_mutex_lock(&limits_p
.mutex
);
49 fatal("unable to lock the limits\n");
51 STATIC
void limits_unlock(void)
55 r
= pthread_mutex_unlock(&limits_p
.mutex
);
57 fatal("unable to unlock the limits\n");
59 STATIC
void read_thd_start(void)
65 r
= pthread_attr_init(&attr
);
67 fatal("unable to initialize read thread attribute\n");
68 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
70 fatal("unable to set the read thread attribute to detach mode\n");
71 r
= pthread_create(&id
, &attr
, &read_thd_entry
, 0);
73 fatal("unable to create the read thread\n");
74 pout("read thread %lu\n", (unsigned long)id
);
75 pthread_attr_destroy(&attr
);
77 STATIC
void audio_thd_start(void)
83 r
= pthread_attr_init(&attr
);
85 fatal("unable to initialize audio thread attribute\n");
86 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
88 fatal("unable to set the audio thread attribute to detach mode\n");
89 r
= pthread_create(&id
, &attr
, &audio_thd_entry
, 0);
91 fatal("unable to create the audio thread\n");
92 pout("audio thread %lu\n", (unsigned long)id
);
93 pthread_attr_destroy(&attr
);
95 STATIC
void video_thd_start(void)
101 r
= pthread_attr_init(&attr
);
103 fatal("unable to initialize video thread attribute\n");
104 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
106 fatal("unable to set the video thread attribute to detach mode\n");
107 r
= pthread_create(&id
, &attr
, &video_thd_entry
, 0);
109 fatal("unable to create the video thread\n");
110 pout("video thread %lu\n", (unsigned long)id
);
111 pthread_attr_destroy(&attr
);