소스 검색

enable AirPlay to BT bridge

philippe44 5 년 전
부모
커밋
95ad5a5ef4
4개의 변경된 파일10개의 추가작업 그리고 11개의 파일을 삭제
  1. 7 11
      components/squeezelite/decode_external.c
  2. 1 0
      components/squeezelite/output_bt.c
  3. 1 0
      components/squeezelite/output_i2s.c
  4. 1 0
      components/squeezelite/squeezelite.h

+ 7 - 11
components/squeezelite/decode_external.c

@@ -39,7 +39,7 @@ extern log_level loglevel;
 static raop_event_t	raop_state;
 static bool raop_expect_stop = false;
 static struct {
-	bool start;
+	bool enabled, start;
 	s32_t error;
 	u32_t start_time;
 	u32_t playtime, len;
@@ -176,7 +176,7 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
 			u32_t ms, now = gettime_ms();
 			s32_t error;
 			
-			if (output.state < OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
+			if (!raop_sync.enabled || output.state < OUTPUT_RUNNING || output.frames_played_dmp < output.device_frames) break;
 			
 			// first must make sure we started on time
 			if (raop_sync.start) {
@@ -187,10 +187,9 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
 				if (abs(error) < 10 && abs(raop_sync.error) < 10) raop_sync.start = false;
 			} else {	
 				// in how many ms will the most recent block play (there is one extra block of FRAME_BLOCK == MAX_SILENCE_FRAMES which is not in queue and not in outputbuf)
-				ms = ((u64_t) ((_buf_used(outputbuf) - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + MAX_SILENCE_FRAMES) * 1000) / RAOP_SAMPLE_RATE - (now - output.updated);
+				ms = ((u64_t) ((_buf_used(outputbuf) - raop_sync.len) / BYTES_PER_FRAME + output.device_frames + output.frames_in_process) * 1000) / RAOP_SAMPLE_RATE - (now - output.updated);
 				error = (raop_sync.playtime - now) - ms;
 				LOG_INFO("head local:%u, remote:%u (delta:%d)", ms, raop_sync.playtime - now, error);
-				//break;
 			}	
 			
 			if (error < -10 && raop_sync.error < -10) {
@@ -217,7 +216,8 @@ void raop_sink_cmd_handler(raop_event_t event, void *param)
 			LOG_INFO("Stream", NULL);
 			raop_state = event;
 			raop_sync.error = 0;
-			raop_sync.start = true;			
+			raop_sync.start = true;		
+			raop_sync.enabled = !strcasestr(output.device, "BT");
 			output.external = true;
 			output.next_sample_rate = RAOP_SAMPLE_RATE;
 			output.state = OUTPUT_STOPPED;
@@ -277,11 +277,7 @@ void register_other(void) {
 	}	
 #endif	
 #ifdef CONFIG_AIRPLAY_SINK
-	if (!strcasestr(output.device, "BT ")) {
-		raop_sink_init(raop_sink_cmd_handler, raop_sink_data_handler);
-		LOG_INFO("Initializing AirPlay sink");		
-	} else {
-		LOG_WARN("Cannot be an AirPlay sink and BT source");
-	}	
+	raop_sink_init(raop_sink_cmd_handler, raop_sink_data_handler);
+	LOG_INFO("Initializing AirPlay sink");		
 #endif
 }

+ 1 - 0
components/squeezelite/output_bt.c

@@ -150,6 +150,7 @@ int32_t output_bt_data(uint8_t *data, int32_t len) {
 	if (wanted_len > 0) {
 		SET_MIN_MAX(wanted_len, under);
 	}
+	output.frames_in_process = len-wanted_len;
 
 	UNLOCK;
 	SET_MIN_MAX(TIME_MEASUREMENT_GET(start_timer),lock_out_time);

+ 1 - 0
components/squeezelite/output_i2s.c

@@ -442,6 +442,7 @@ static void *output_thread_i2s() {
 		// try to estimate how much we have consumed from the DMA buffer
 		output.device_frames = DMA_BUF_COUNT * DMA_BUF_LEN - ((output.updated - fullness) * output.current_sample_rate) / 1000;
 		oframes = _output_frames( iframes );
+		output.frames_in_process = oframes;
 				
 		SET_MIN_MAX_SIZED(oframes,rec,iframes);
 		SET_MIN_MAX_SIZED(_buf_used(outputbuf),o,outputbuf->size);

+ 1 - 0
components/squeezelite/squeezelite.h

@@ -676,6 +676,7 @@ struct outputstate {
 	unsigned default_sample_rate;
 	bool error_opening;
 	unsigned device_frames;
+	unsigned frames_in_process;
 	u32_t updated;
 	u32_t track_start_time;
 	u32_t current_replay_gain;