瀏覽代碼

Add some statistics to pulseaudio plugin

This patch adds counters for packets and frames for debugging purposes.
fryshorts 11 年之前
父節點
當前提交
ac4a054bdd
共有 1 個文件被更改,包括 15 次插入6 次删除
  1. 15 6
      plugins/linux-pulseaudio/pulse-input.c

+ 15 - 6
plugins/linux-pulseaudio/pulse-input.c

@@ -25,18 +25,22 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 struct pulse_data {
 	obs_source_t source;
+	pa_stream *stream;
+
+	/* user settings */
+	bool ostime;
 	char *device;
 
+	/* server info */
 	enum speaker_layout speakers;
 	pa_sample_format_t format;
 	uint_fast32_t samples_per_sec;
-	uint_fast8_t channels;
-
 	uint_fast32_t bytes_per_frame;
+	uint_fast8_t channels;
 
-	pa_stream *stream;
-
-	bool ostime;
+	/* statistics */
+	uint_fast32_t packets;
+	uint_fast64_t frames;
 };
 
 static void pulse_stop_recording(struct pulse_data *data);
@@ -136,8 +140,10 @@ static void pulse_stream_read(pa_stream *p, size_t nbytes, void *userdata)
 	out.timestamp       = pa_time - (pa_latency * 1000);
 	obs_source_output_audio(data->source, &out);
 
-	pa_stream_drop(data->stream);
+	data->packets++;
+	data->frames += out.frames;
 
+	pa_stream_drop(data->stream);
 exit:
 	pulse_signal(0);
 }
@@ -244,6 +250,9 @@ static void pulse_stop_recording(struct pulse_data *data)
 
 	blog(LOG_INFO, "pulse-input: Stopped recording from '%s'",
 		data->device);
+	blog(LOG_INFO, "pulse-input: Got %"PRIuFAST32
+		" packets with %"PRIuFAST64" frames",
+		data->packets, data->frames);
 }
 
 /**