npv:_reasonable_ "pedanticage" of the code
[nyanmp.git] / npv / pipeline / public / code.frag.c
blobf522590c6df4684f575857f6554c51e43c767115
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)
13 if (percent > 100)
14 fatal("invalid prefill of %u%% for the buffer of packet queues\n", percent);
15 if (percent != 0) {
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);
22 } else {
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)
30 int r;
32 eof_pkt_l = avcodec_pkt_ref_alloc();
33 if (eof_pkt_l == 0)
34 fatal("ffmpeg:unable to allocate a null/eof reference on a packet\n");
35 eof_pkt_l->data = 0;
36 eof_pkt_l->sz = 0;
38 r = pthread_mutex_init(&limits_p.mutex, 0);
39 if (r != 0)
40 fatal("unable to initialize the mutex to guard the accounting of limits\n");
42 STATIC void limits_lock(void)
44 int r;
46 r = pthread_mutex_lock(&limits_p.mutex);
47 if (r != 0)
48 fatal("unable to lock the limits\n");
50 STATIC void limits_unlock(void)
52 int r;
54 r = pthread_mutex_unlock(&limits_p.mutex);
55 if (r != 0)
56 fatal("unable to unlock the limits\n");
58 STATIC void read_thd_start(void)
60 int r;
61 pthread_t id;
62 pthread_attr_t attr;
64 r = pthread_attr_init(&attr);
65 if (r != 0)
66 fatal("unable to initialize read thread attribute\n");
67 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
68 if (r != 0)
69 fatal("unable to set the read thread attribute to detach mode\n");
70 r = pthread_create(&id, &attr, &read_thd_entry, 0);
71 if (r != 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)
78 int r;
79 pthread_t id;
80 pthread_attr_t attr;
82 r = pthread_attr_init(&attr);
83 if (r != 0)
84 fatal("unable to initialize audio thread attribute\n");
85 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
86 if (r != 0)
87 fatal("unable to set the audio thread attribute to detach mode\n");
88 r = pthread_create(&id, &attr, &audio_thd_entry, 0);
89 if (r != 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)
96 int r;
97 pthread_t id;
98 pthread_attr_t attr;
100 r = pthread_attr_init(&attr);
101 if (r != 0)
102 fatal("unable to initialize video thread attribute\n");
103 r = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
104 if (r != 0)
105 fatal("unable to set the video thread attribute to detach mode\n");
106 r = pthread_create(&id, &attr, &video_thd_entry, 0);
107 if (r != 0)
108 fatal("unable to create the video thread\n");
109 pout("video thread %lu\n", (unsigned long)id);
110 pthread_attr_destroy(&attr);