mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	pw-cat: Use multiple encoded frames if single frames don't fill the quantum
This commit is contained in:
		
							parent
							
								
									14b242c737
								
							
						
					
					
						commit
						1c991a329e
					
				
					 1 changed files with 30 additions and 16 deletions
				
			
		| 
						 | 
					@ -253,8 +253,10 @@ static int encoded_playback_fill(struct data *d, void *dest, unsigned int n_fram
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	AVPacket *packet = d->encoded.packet;
 | 
						AVPacket *packet = d->encoded.packet;
 | 
				
			||||||
	int ret;
 | 
						int ret;
 | 
				
			||||||
 | 
						uint8_t *dest_ptr = (uint8_t *)dest;
 | 
				
			||||||
	struct pw_time time;
 | 
						struct pw_time time;
 | 
				
			||||||
	int64_t quantum_duration;
 | 
						int64_t quantum_duration;
 | 
				
			||||||
 | 
						int64_t accumulated_duration;
 | 
				
			||||||
	int64_t excess_playtime;
 | 
						int64_t excess_playtime;
 | 
				
			||||||
	int64_t cycle_length;
 | 
						int64_t cycle_length;
 | 
				
			||||||
	int64_t av_time_base_num, av_time_base_denom;
 | 
						int64_t av_time_base_num, av_time_base_denom;
 | 
				
			||||||
| 
						 | 
					@ -302,6 +304,13 @@ static int encoded_playback_fill(struct data *d, void *dest, unsigned int n_fram
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						accumulated_duration = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* Continue filling the buffer until at least a quantum's worth of data
 | 
				
			||||||
 | 
						 * has been written. Encoded frames may have a playtime that is _shorter_
 | 
				
			||||||
 | 
						 * than a quantum. In that case, multiple frames must be written into the
 | 
				
			||||||
 | 
						 * buffer to cover a quantum length. */
 | 
				
			||||||
 | 
						while (true) {
 | 
				
			||||||
		/* Keep reading packets until we get one from the stream we are
 | 
							/* Keep reading packets until we get one from the stream we are
 | 
				
			||||||
		 * interested in. This is relevant when playing data that contains
 | 
							 * interested in. This is relevant when playing data that contains
 | 
				
			||||||
		 * several multiplexed streams. */
 | 
							 * several multiplexed streams. */
 | 
				
			||||||
| 
						 | 
					@ -313,15 +322,20 @@ static int encoded_playback_fill(struct data *d, void *dest, unsigned int n_fram
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memcpy(dest, packet->data, packet->size);
 | 
							memcpy(dest_ptr, packet->data, packet->size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (packet->duration > quantum_duration)
 | 
							accumulated_duration += packet->duration;
 | 
				
			||||||
		excess_playtime = packet->duration - quantum_duration;
 | 
							dest_ptr += packet->size;
 | 
				
			||||||
	else
 | 
					
 | 
				
			||||||
		excess_playtime = 0;
 | 
							if (accumulated_duration >= quantum_duration)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								excess_playtime = accumulated_duration - quantum_duration;
 | 
				
			||||||
			d->encoded.accumulated_excess_playtime += excess_playtime;
 | 
								d->encoded.accumulated_excess_playtime += excess_playtime;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return packet->size;
 | 
						return (dest_ptr - ((uint8_t*)dest));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int av_codec_params_to_audio_info(struct data *data, AVCodecParameters *codec_params, struct spa_audio_info *info)
 | 
					static int av_codec_params_to_audio_info(struct data *data, AVCodecParameters *codec_params, struct spa_audio_info *info)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue