mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-22 20:56:39 +00:00 
			
		
		
		
	audiohook: add directional awareness
Add enum to allow setting optional direction. If set to only one direction, only feed matching-direction frames to the associated slin factory. This prevents mangling the transcoder on non-mixed frames when the READ and WRITE frames would have otherwise required it. Also removes the need to mute or discard the un-wanted frames as they are no longer added in the first place. res_stasis_snoop is changed to use this addition to set direction on audiohook based on spy direction. If no direction is set, the ast_audiohook_init will init this enum to BOTH which maintains existing functionality. ASTERISK-30252 Change-Id: If8716bad334562a5d812be4eeb2a92e4f3be28eb
This commit is contained in:
		
				
					committed by
					
						 Friendly Automation
						Friendly Automation
					
				
			
			
				
	
			
			
			
						parent
						
							2b930d7c3b
						
					
				
				
					commit
					bb44e3edca
				
			| @@ -109,6 +109,9 @@ int ast_audiohook_init(struct ast_audiohook *audiohook, enum ast_audiohook_type | ||||
|  | ||||
| 	audiohook->init_flags = init_flags; | ||||
|  | ||||
| 	/* Set direction to BOTH so that we feed frames in both directions */ | ||||
| 	audiohook->direction = AST_AUDIOHOOK_DIRECTION_BOTH; | ||||
|  | ||||
| 	/* initialize internal rate at 8khz, this will adjust if necessary */ | ||||
| 	audiohook_set_internal_rate(audiohook, DEFAULT_INTERNAL_SAMPLE_RATE, 0); | ||||
|  | ||||
| @@ -144,6 +147,18 @@ int ast_audiohook_destroy(struct ast_audiohook *audiohook) | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int ast_audiohook_set_frame_feed_direction(struct ast_audiohook *audiohook, enum ast_audiohook_direction direction) | ||||
| { | ||||
| 	/* Only set the direction on new audiohooks */ | ||||
| 	if (audiohook->status != AST_AUDIOHOOK_STATUS_NEW) { | ||||
| 		ast_debug(3, "Can not set direction on attached Audiohook %p\n", audiohook); | ||||
| 		return -1; | ||||
| 	} | ||||
|  | ||||
| 	audiohook->direction = direction; | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| #define SHOULD_MUTE(hook, dir) \ | ||||
| 	((ast_test_flag(hook, AST_AUDIOHOOK_MUTE_READ) && (dir == AST_AUDIOHOOK_DIRECTION_READ)) || \ | ||||
| 	(ast_test_flag(hook, AST_AUDIOHOOK_MUTE_WRITE) && (dir == AST_AUDIOHOOK_DIRECTION_WRITE)) || \ | ||||
| @@ -159,6 +174,13 @@ int ast_audiohook_write_frame(struct ast_audiohook *audiohook, enum ast_audiohoo | ||||
| 	int other_factory_samples; | ||||
| 	int other_factory_ms; | ||||
|  | ||||
| 	/* Don't feed the frame if we are set to read and this is a write frame or if set to | ||||
| 	   write and this is a read frame as we don't want it. Plus, it can cause mis-resampling | ||||
| 	   if the READ and WRITE frames have different bitrates */ | ||||
| 	if (audiohook->direction != AST_AUDIOHOOK_DIRECTION_BOTH && audiohook->direction != direction) { | ||||
| 		return 0; | ||||
| 	} | ||||
|  | ||||
| 	/* Update last feeding time to be current */ | ||||
| 	*rwtime = ast_tvnow(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user