| 154 | } |
| 155 | |
| 156 | static int receive_locked(ThreadQueue *tq, int *stream_idx, |
| 157 | void *data) |
| 158 | { |
| 159 | unsigned int nb_finished = 0; |
| 160 | |
| 161 | if (tq->choked) |
| 162 | return AVERROR(EAGAIN); |
| 163 | |
| 164 | while (av_container_fifo_read(tq->fifo, data, 0) >= 0) { |
| 165 | unsigned idx; |
| 166 | int ret; |
| 167 | |
| 168 | ret = av_fifo_read(tq->fifo_stream_index, &idx, 1); |
| 169 | av_assert0(ret >= 0); |
| 170 | if (tq->finished[idx] & FINISHED_RECV) { |
| 171 | (tq->type == THREAD_QUEUE_FRAMES) ? |
| 172 | av_frame_unref(data) : av_packet_unref(data); |
| 173 | continue; |
| 174 | } |
| 175 | |
| 176 | *stream_idx = idx; |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | for (unsigned int i = 0; i < tq->nb_streams; i++) { |
| 181 | if (!tq->finished[i]) |
| 182 | continue; |
| 183 | |
| 184 | /* return EOF to the consumer at most once for each stream */ |
| 185 | if (!(tq->finished[i] & FINISHED_RECV)) { |
| 186 | tq->finished[i] |= FINISHED_RECV; |
| 187 | *stream_idx = i; |
| 188 | return AVERROR_EOF; |
| 189 | } |
| 190 | |
| 191 | nb_finished++; |
| 192 | } |
| 193 | |
| 194 | return nb_finished == tq->nb_streams ? AVERROR_EOF : AVERROR(EAGAIN); |
| 195 | } |
| 196 | |
| 197 | int tq_receive(ThreadQueue *tq, int *stream_idx, void *data) |
| 198 | { |
no test coverage detected