Recognizes if input is ogg or not.
[xiph.git] / postfish / feedback.c
blob2d16b53eb10d88f1d80b671efb4e0d3d9745b26f
1 /*
3 * postfish
4 *
5 * Copyright (C) 2002-2005 Monty and Xiph.Org
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "postfish.h"
25 #include "feedback.h"
27 static pthread_mutex_t feedback_mutex=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
29 feedback_generic *feedback_new(feedback_generic_pool *pool,
30 feedback_generic *(*constructor)(void)){
31 feedback_generic *ret;
33 pthread_mutex_lock(&feedback_mutex);
34 if(pool->feedback_pool){
35 ret=pool->feedback_pool;
36 pool->feedback_pool=pool->feedback_pool->next;
37 pthread_mutex_unlock(&feedback_mutex);
38 return ret;
40 pthread_mutex_unlock(&feedback_mutex);
42 ret=constructor();
43 return ret;
46 void feedback_push(feedback_generic_pool *pool,
47 feedback_generic *f){
48 f->next=NULL;
50 pthread_mutex_lock(&feedback_mutex);
51 if(!pool->feedback_list_tail){
52 pool->feedback_list_tail=f;
53 pool->feedback_list_head=f;
54 }else{
55 pool->feedback_list_head->next=f;
56 pool->feedback_list_head=f;
58 pthread_mutex_unlock(&feedback_mutex);
61 feedback_generic *feedback_pull(feedback_generic_pool *pool){
62 feedback_generic *f;
64 pthread_mutex_lock(&feedback_mutex);
65 if(pool->feedback_list_tail){
67 f=pool->feedback_list_tail;
68 pool->feedback_list_tail=pool->feedback_list_tail->next;
69 if(!pool->feedback_list_tail)pool->feedback_list_head=0;
71 }else{
72 pthread_mutex_unlock(&feedback_mutex);
73 return 0;
75 pthread_mutex_unlock(&feedback_mutex);
76 return(f);
79 void feedback_old(feedback_generic_pool *pool,
80 feedback_generic *f){
82 pthread_mutex_lock(&feedback_mutex);
83 f->next=pool->feedback_pool;
84 pool->feedback_pool=f;
85 pthread_mutex_unlock(&feedback_mutex);
88 /* are there multiple feedback outputs waiting or just one (a metric
89 of 'are we behind?') */
90 int feedback_deep(feedback_generic_pool *pool){
91 if(pool){
92 pthread_mutex_lock(&feedback_mutex);
93 if(pool->feedback_list_tail)
94 if(pool->feedback_list_tail->next){
95 pthread_mutex_unlock(&feedback_mutex);
96 return 1;
98 pthread_mutex_unlock(&feedback_mutex);
100 return 0;