Changeset 4846:58d1d4cb7602 in roaraudio


Ignore:
Timestamp:
04/08/11 13:11:56 (9 years ago)
Author:
phi
Branch:
default
Message:

Auto select a stream if no stream has sync flag. (Closes: #30)

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r4844 r4846  
    1212        * Added support for HTTP Basic Auth 
    1313        * Fixed time display of roarvorbis if file has unknown playback length 
     14        * Auto select a stream if no stream has sync flag. (Closes: #30) 
    1415 
    1516v. 0.4beta4 - Sun Mar 20 2011 12:15 CET 
  • roard/driver_oss.c

    r4819 r4846  
    426426 
    427427int     driver_oss_nonblock(struct roar_vio_calls * vio, int state) { 
    428  if ( roar_socket_nonblock(_get(vio,fh), state) == -1 ) 
    429   return -1; 
    430  
    431  if ( state == ROAR_SOCKET_NONBLOCK ) 
     428 ROAR_DBG("driver_oss_nonblock(vio=%p, state=%i) = ?", vio, state); 
     429 
     430 if ( roar_socket_nonblock(_get(vio,fh), state) == -1 ) { 
     431  ROAR_DBG("driver_oss_nonblock(vio=%p, state=%i) = -1", vio, state); 
     432  return -1; 
     433 } 
     434 
     435 if ( state == ROAR_SOCKET_NONBLOCK ) { 
     436  ROAR_DBG("driver_oss_nonblock(vio=%p, state=%i) = 0", vio, state); 
    432437  return 0; 
     438 } 
    433439 
    434440 roar_vio_sync(vio); 
     441 
     442 ROAR_DBG("driver_oss_nonblock(vio=%p, state=%i) = 0", vio, state); 
    435443 
    436444 return 0; 
  • roard/include/streams.h

    r4819 r4846  
    119119 
    120120int streams_thru_num; 
     121int streams_sync_num; 
    121122int streams_recsource_id; 
     123 
     124void streams_change_sync_num(int id, int diff); 
    122125 
    123126int streams_init   (void); 
  • roard/roard.c

    r4842 r4846  
    28602860#endif 
    28612861 
     2862 // update sync counter. 
     2863 streams_change_sync_num(-1, 0); 
     2864 
    28622865 ROAR_INFO("Startup complet", ROAR_DBG_INFO_INFO); 
    28632866 
  • roard/streams.c

    r4819 r4846  
    3030 
    3131int streams_thru_num     =  0; 
     32int streams_sync_num     =  0; 
    3233int streams_recsource_id = -1; 
    3334 
     
    4849 
    4950 roar_notify_core_emit_simple(ROAR_OE_BASICS_CHANGE_STATE, -1, id, ROAR_OT_STREAM, old, new, NULL, 0); 
     51} 
     52 
     53void 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 } 
    50120} 
    51121 
     
    289359*/ 
    290360 
     361 if ( s->flags & ROAR_FLAG_SYNC ) 
     362  streams_change_sync_num(id, -1); 
     363 
    291364 if ( !no_vio_close ) 
    292365  roar_vio_close(s->viop); 
     
    781854 int fh = streams_get_fh(id); 
    782855 
    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 ) { 
    786861  if ( roar_socket_nonblock(fh, sync ? ROAR_SOCKET_BLOCK : ROAR_SOCKET_NONBLOCK) == -1 ) 
    787862   return -1; 
     
    910985 int tmp; 
    911986 
    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); 
    913992 
    914993 if ( flag & ROAR_FLAG_IMMUTABLE ) 
     
    916995 
    917996 
     997 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     998 
    918999 // check if flags we are going to change are protected: 
    9191000 if ( g_streams[id]->flags_protection & flag ) 
    9201001  return -1; 
    9211002 
     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); 
    9221007 
    9231008 if ( flag & ROAR_FLAG_MMAP ) { 
     
    9281013 } 
    9291014 
     1015 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1016 
    9301017 if ( flag & ROAR_FLAG_PRIMARY ) { 
    9311018  streams_set_primary(id, 1); 
     
    9331020 } 
    9341021 
     1022 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1023 
    9351024 if ( flag & ROAR_FLAG_SINGLESINK ) { 
    9361025  if ( streams_set_single_sink(id, 0) == -1 ) { 
     
    9401029 } 
    9411030 
     1031 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1032 
    9421033 if ( flag & ROAR_FLAG_VIRTUAL ) { 
    9431034  if ( (parent = ROAR_STREAM(g_streams[id])->pos_rel_id) == -1 ) 
     
    9541045 } 
    9551046 
     1047 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1048 
    9561049 if ( flag & ROAR_FLAG_SYNC ) { 
     1050  ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
    9571051  switch (ROAR_STREAM(g_streams[id])->dir) { 
    9581052   // for this stream types the flag is used in the subsystem: 
     
    9631057   // normal behavor (vio blocking): 
    9641058   default: 
     1059     ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
    9651060     // 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); 
    9681065       flag -= ROAR_FLAG_SYNC; 
     1066      } 
    9691067     } 
    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); 
    9721079 
    9731080 if ( flag & ROAR_FLAG_HWMIXER ) { // currently not supported -> ignored 
     
    9791086 } 
    9801087 
     1088 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1089 
    9811090 if ( flag & ROAR_FLAG_RECSOURCE ) { 
    9821091  if ( streams_recsource_id != -1 ) { 
     
    9941103 } 
    9951104 
     1105 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1106 
    9961107 g_streams[id]->flags |= flag; 
    9971108 
     
    10011112#endif 
    10021113 
     1114 ROAR_DBG("streams_set_flag(id=%i, flag=0x%.8X) = ?", id, flag); 
     1115 
    10031116 return 0; 
    10041117} 
     
    10081121 
    10091122 g_streams[id]->flags |= flag; 
     1123 
     1124 if ( flag & ROAR_FLAG_SYNC ) 
     1125  streams_change_sync_num(id, +1); 
    10101126 
    10111127 return 0; 
     
    10251141  flag -= ROAR_FLAG_PRIMARY; 
    10261142 } 
     1143 
     1144 flag &= g_streams[id]->flags; 
    10271145 
    10281146 if ( (flag & ROAR_FLAG_RECSOURCE) && streams_recsource_id == id ) { 
     
    10621180   return -1; 
    10631181  } 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); 
    10651189  } 
    10661190 } 
Note: See TracChangeset for help on using the changeset viewer.