| 70 | } |
| 71 | |
| 72 | ThreadQueue *tq_alloc(unsigned int nb_streams, size_t queue_size, |
| 73 | enum ThreadQueueType type) |
| 74 | { |
| 75 | ThreadQueue *tq; |
| 76 | int ret; |
| 77 | |
| 78 | tq = av_mallocz(sizeof(*tq)); |
| 79 | if (!tq) |
| 80 | return NULL; |
| 81 | |
| 82 | ret = pthread_cond_init(&tq->cond, NULL); |
| 83 | if (ret) { |
| 84 | av_freep(&tq); |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | ret = pthread_mutex_init(&tq->lock, NULL); |
| 89 | if (ret) { |
| 90 | pthread_cond_destroy(&tq->cond); |
| 91 | av_freep(&tq); |
| 92 | return NULL; |
| 93 | } |
| 94 | |
| 95 | tq->finished = av_calloc(nb_streams, sizeof(*tq->finished)); |
| 96 | if (!tq->finished) |
| 97 | goto fail; |
| 98 | tq->nb_streams = nb_streams; |
| 99 | |
| 100 | tq->type = type; |
| 101 | |
| 102 | tq->fifo = (type == THREAD_QUEUE_FRAMES) ? |
| 103 | av_container_fifo_alloc_avframe(0) : av_container_fifo_alloc_avpacket(0); |
| 104 | if (!tq->fifo) |
| 105 | goto fail; |
| 106 | |
| 107 | tq->fifo_stream_index = av_fifo_alloc2(queue_size, sizeof(unsigned), 0); |
| 108 | if (!tq->fifo_stream_index) |
| 109 | goto fail; |
| 110 | |
| 111 | return tq; |
| 112 | fail: |
| 113 | tq_free(&tq); |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | int tq_send(ThreadQueue *tq, unsigned int stream_idx, void *data) |
| 118 | { |
no test coverage detected