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");
42 STATIC
void limits_lock(void)
46 r
= pthread_mutex_lock(&limits_p
.mutex
);
48 fatal("unable to lock the limits\n");
50 STATIC
void limits_unlock(void)
54 r
= pthread_mutex_unlock(&limits_p
.mutex
);
56 fatal("unable to unlock the limits\n");
58 STATIC
void read_thd_start(void)
64 r
= pthread_attr_init(&attr
);
66 fatal("unable to initialize read thread attribute\n");
67 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
69 fatal("unable to set the read thread attribute to detach mode\n");
70 r
= pthread_create(&id
, &attr
, &read_thd_entry
, 0);
72 fatal("unable to create the read thread\n");
73 pout("read thread %lu\n", (unsigned long)id
);
74 pthread_attr_destroy(&attr
);
76 STATIC
void audio_thd_start(void)
82 r
= pthread_attr_init(&attr
);
84 fatal("unable to initialize audio thread attribute\n");
85 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
87 fatal("unable to set the audio thread attribute to detach mode\n");
88 r
= pthread_create(&id
, &attr
, &audio_thd_entry
, 0);
90 fatal("unable to create the audio thread\n");
91 pout("audio thread %lu\n", (unsigned long)id
);
92 pthread_attr_destroy(&attr
);
94 STATIC
void video_thd_start(void)
100 r
= pthread_attr_init(&attr
);
102 fatal("unable to initialize video thread attribute\n");
103 r
= pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
105 fatal("unable to set the video thread attribute to detach mode\n");
106 r
= pthread_create(&id
, &attr
, &video_thd_entry
, 0);
108 fatal("unable to create the video thread\n");
109 pout("video thread %lu\n", (unsigned long)id
);
110 pthread_attr_destroy(&attr
);