Changeset 4846:58d1d4cb7602 in roaraudio for roard/streams.c
- Timestamp:
- 04/08/11 13:11:56 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/streams.c
r4819 r4846 30 30 31 31 int streams_thru_num = 0; 32 int streams_sync_num = 0; 32 33 int streams_recsource_id = -1; 33 34 … … 48 49 49 50 roar_notify_core_emit_simple(ROAR_OE_BASICS_CHANGE_STATE, -1, id, ROAR_OT_STREAM, old, new, NULL, 0); 51 } 52 53 void streams_change_sync_num(int id, int diff) { 54 struct roar_stream_server * ss; 55 int i; 56 57 if ( diff != 0 ) 58 if ( streams_get_dir(id) != ROAR_DIR_OUTPUT ) 59 return; 60 61 ROAR_INFO("streams_change_sync_num(id=%i, diff=%i): Number of sync streams changed from %i to %i", 62 ROAR_DBG_INFO_VERBOSE, 63 id, diff, 64 streams_sync_num, streams_sync_num + diff); 65 streams_sync_num += diff; 66 67 if ( !streams_sync_num && alive ) { 68 ROAR_INFO("streams_change_sync_num(id=%i, diff=%i): Number of sync streams changed to zero. Bad.", 69 ROAR_DBG_INFO_VERBOSE, id, diff 70 ); 71 72 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 73 if ( (ss = g_streams[i]) == NULL ) 74 continue; 75 76 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_OUTPUT ) 77 continue; 78 79 if ( !ss->ready ) 80 continue; 81 82 if ( ss->state == ROAR_STREAMSTATE_CLOSING ) 83 continue; 84 85 if ( streams_get_flag(i, ROAR_FLAG_PRIMARY) ) { 86 ROAR_DBG("streams_change_sync_num(*): try to set sync on primary stream %i", i); 87 streams_set_flag(i, ROAR_FLAG_SYNC); 88 if ( streams_sync_num ) 89 return; 90 } 91 } 92 93 for (i = 0; i < ROAR_STREAMS_MAX; i++) { 94 if ( (ss = g_streams[i]) == NULL ) 95 continue; 96 97 if ( ROAR_STREAM(ss)->dir != ROAR_DIR_OUTPUT ) 98 continue; 99 100 if ( !ss->ready ) 101 continue; 102 103 if ( ss->state == ROAR_STREAMSTATE_CLOSING ) 104 continue; 105 106 if ( !streams_get_flag(i, ROAR_FLAG_PRIMARY) ) { 107 ROAR_DBG("streams_change_sync_num(*): try to set sync on non-primary stream %i", i); 108 streams_set_flag(i, ROAR_FLAG_SYNC); 109 if ( streams_sync_num ) 110 return; 111 } 112 } 113 114 ROAR_INFO("streams_change_sync_num(id=%i, diff=%i): Can not auto set sync flag to an output. Very Bad", 115 ROAR_DBG_INFO_VERBOSE, id, diff 116 ); 117 ROAR_WARN("streams_change_sync_num(id=%i, diff=%i): Lost all sync streams and failed to set a new one. Very Bad.", 118 id, diff); 119 } 50 120 } 51 121 … … 289 359 */ 290 360 361 if ( s->flags & ROAR_FLAG_SYNC ) 362 streams_change_sync_num(id, -1); 363 291 364 if ( !no_vio_close ) 292 365 roar_vio_close(s->viop); … … 781 854 int fh = streams_get_fh(id); 782 855 783 _CHECK_SID(id); 784 785 if ( fh != -1 ) { 856 ROAR_DBG("streams_set_sync(id=%i, sync=%i) = ?", id, sync); 857 858 _CHECK_SID(id); 859 860 if ( fh > -1 ) { 786 861 if ( roar_socket_nonblock(fh, sync ? ROAR_SOCKET_BLOCK : ROAR_SOCKET_NONBLOCK) == -1 ) 787 862 return -1; … … 910 985 int tmp; 911 986 912 _CHECK_SID(id); 987 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 988 989 _CHECK_SID(id); 990 991 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 913 992 914 993 if ( flag & ROAR_FLAG_IMMUTABLE ) … … 916 995 917 996 997 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 998 918 999 // check if flags we are going to change are protected: 919 1000 if ( g_streams[id]->flags_protection & flag ) 920 1001 return -1; 921 1002 1003 flag |= g_streams[id]->flags; 1004 flag -= g_streams[id]->flags; 1005 1006 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 922 1007 923 1008 if ( flag & ROAR_FLAG_MMAP ) { … … 928 1013 } 929 1014 1015 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1016 930 1017 if ( flag & ROAR_FLAG_PRIMARY ) { 931 1018 streams_set_primary(id, 1); … … 933 1020 } 934 1021 1022 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1023 935 1024 if ( flag & ROAR_FLAG_SINGLESINK ) { 936 1025 if ( streams_set_single_sink(id, 0) == -1 ) { … … 940 1029 } 941 1030 1031 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1032 942 1033 if ( flag & ROAR_FLAG_VIRTUAL ) { 943 1034 if ( (parent = ROAR_STREAM(g_streams[id])->pos_rel_id) == -1 ) … … 954 1045 } 955 1046 1047 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1048 956 1049 if ( flag & ROAR_FLAG_SYNC ) { 1050 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 957 1051 switch (ROAR_STREAM(g_streams[id])->dir) { 958 1052 // for this stream types the flag is used in the subsystem: … … 963 1057 // normal behavor (vio blocking): 964 1058 default: 1059 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 965 1060 // the fh is updated as soon as the fh get ready in case the default ask to set sync 966 if ( !g_streams[id]->ready && !(g_config->streams[ROAR_STREAM(g_streams[id])->dir].flags & ROAR_FLAG_SYNC) ) { 967 if ( streams_set_sync(id, 1) == -1 ) 1061 if ( g_streams[id]->ready || (!g_streams[id]->ready && !(g_config->streams[ROAR_STREAM(g_streams[id])->dir].flags & ROAR_FLAG_SYNC)) ) { 1062 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1063 if ( streams_set_sync(id, 1) == -1 ) { 1064 ROAR_WARN("streams_set_flag(id=%i, flag=0x%.8X): Can not set SYNC flag.", id, flag); 968 1065 flag -= ROAR_FLAG_SYNC; 1066 } 969 1067 } 970 } 971 } 1068 break; 1069 } 1070 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1071 1072 if ( flag & ROAR_FLAG_SYNC ) { 1073 g_streams[id]->flags |= ROAR_FLAG_SYNC; 1074 streams_change_sync_num(id, +1); 1075 } 1076 } 1077 1078 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 972 1079 973 1080 if ( flag & ROAR_FLAG_HWMIXER ) { // currently not supported -> ignored … … 979 1086 } 980 1087 1088 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1089 981 1090 if ( flag & ROAR_FLAG_RECSOURCE ) { 982 1091 if ( streams_recsource_id != -1 ) { … … 994 1103 } 995 1104 1105 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1106 996 1107 g_streams[id]->flags |= flag; 997 1108 … … 1001 1112 #endif 1002 1113 1114 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 1115 1003 1116 return 0; 1004 1117 } … … 1008 1121 1009 1122 g_streams[id]->flags |= flag; 1123 1124 if ( flag & ROAR_FLAG_SYNC ) 1125 streams_change_sync_num(id, +1); 1010 1126 1011 1127 return 0; … … 1025 1141 flag -= ROAR_FLAG_PRIMARY; 1026 1142 } 1143 1144 flag &= g_streams[id]->flags; 1027 1145 1028 1146 if ( (flag & ROAR_FLAG_RECSOURCE) && streams_recsource_id == id ) { … … 1062 1180 return -1; 1063 1181 } else { 1064 streams_set_sync(id, 0); 1182 if ( streams_set_sync(id, 0) == -1 ) 1183 return -1; 1184 1185 g_streams[id]->flags |= ROAR_FLAG_SYNC; 1186 g_streams[id]->flags -= ROAR_FLAG_SYNC; 1187 flag -= ROAR_FLAG_SYNC; 1188 streams_change_sync_num(id, -1); 1065 1189 } 1066 1190 }
Note: See TracChangeset
for help on using the changeset viewer.