aboutsummaryrefslogtreecommitdiffstats
path: root/recipes-multimedia/tinycompress/tinycompress/0003-cplay-Add-pause-feature.patch
blob: 7d8492b7d2af6f083e48bb72ef6c89a18fc70b84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
From 6f778c21ee357a662cdd758cff578a3e4b85eedf Mon Sep 17 00:00:00 2001
From: Zhang Peng <peng.zhang_8@nxp.com>
Date: Tue, 4 Aug 2020 15:29:29 +0800
Subject: [PATCH] cplay: Add pause feature

Add option: -p pause

Upstream-Status: Inappropriate [i.MX specific]
Signed-off-by: Zhang Peng <peng.zhang_8@nxp.com>
---
 src/utils/cplay.c | 56 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 4 deletions(-)

diff --git a/src/utils/cplay.c b/src/utils/cplay.c
index 8882f4d..8e3dcbb 100644
--- a/src/utils/cplay.c
+++ b/src/utils/cplay.c
@@ -117,6 +117,9 @@ static void usage(void)
 		"-f\tfragments\n\n"
 		"-v\tverbose mode\n"
 		"-h\tPrints this help list\n\n"
+		"-p\tpause\n"
+		"-m\tpause blocks\n"
+		"-n\tpause time duration\n"
 		"Example:\n"
 		"\tcplay -c 1 -d 2 test.mp3\n"
 		"\tcplay -f 5 test.mp3\n\n"
@@ -133,7 +136,8 @@ static void usage(void)
 
 void play_samples(char *name, unsigned int card, unsigned int device,
 		unsigned long buffer_size, unsigned int frag,
-		unsigned long codec_id);
+		unsigned long codec_id, int pause_count, int pause_block,
+		int pause_duration);
 
 struct mp3_header {
 	uint16_t sync;
@@ -262,12 +266,15 @@ int main(int argc, char **argv)
 	int c, i;
 	unsigned int card = 0, device = 0, frag = 0;
 	unsigned int codec_id = SND_AUDIOCODEC_MP3;
+	int pause_count = 0;
+	int pause_block = 6;
+	int pause_duration = 10;
 
 	if (argc < 2)
 		usage();
 
 	verbose = 0;
-	while ((c = getopt(argc, argv, "hvb:f:c:d:I:")) != -1) {
+	while ((c = getopt(argc, argv, "hvb:f:c:d:I:p:m:n:")) != -1) {
 		switch (c) {
 		case 'h':
 			usage();
@@ -306,6 +313,23 @@ int main(int argc, char **argv)
 		case 'v':
 			verbose = 1;
 			break;
+		case 'p':
+			pause_count = strtol(optarg, NULL, 10);
+			break;
+		case 'm':
+			pause_block = strtol(optarg, NULL, 10);
+			if (pause_duration < 0) {
+				printf("Set wrong paramter! Set duration default 6.\n");
+				pause_duration = 6;
+			}
+			break;
+		case 'n':
+			pause_duration = strtol(optarg, NULL, 10);
+			if (pause_duration < 0) {
+				printf("Set wrong paramter! Set duration default 10.\n");
+				pause_duration = 10;
+			}
+			break;
 		default:
 			exit(EXIT_FAILURE);
 		}
@@ -315,7 +339,7 @@ int main(int argc, char **argv)
 
 	file = argv[optind];
 
-	play_samples(file, card, device, buffer_size, frag, codec_id);
+	play_samples(file, card, device, buffer_size, frag, codec_id, pause_count, pause_block, pause_duration);
 
 	fprintf(stderr, "Finish Playing.... Close Normally\n");
 	exit(EXIT_SUCCESS);
@@ -491,7 +515,8 @@ void get_codec_pcm(FILE *file, struct compr_config *config,
 
 void play_samples(char *name, unsigned int card, unsigned int device,
 		unsigned long buffer_size, unsigned int frag,
-		unsigned long codec_id)
+		unsigned long codec_id, int pause_count, int pause_block,
+		int pause_duration)
 {
 	struct compr_config config;
 	struct snd_codec codec;
@@ -499,6 +524,7 @@ void play_samples(char *name, unsigned int card, unsigned int device,
 	FILE *file;
 	char *buffer;
 	int size, num_read, wrote;
+	int write_count = 0;
 
 	if (verbose)
 		printf("%s: entry\n", __func__);
@@ -574,6 +600,13 @@ void play_samples(char *name, unsigned int card, unsigned int device,
 	if (verbose)
 		printf("%s: You should hear audio NOW!!!\n", __func__);
 
+	if (pause_count > 0) {
+		printf("sleep...\n");
+		compress_pause(compress);
+		sleep(pause_duration);
+		compress_resume(compress);
+	}
+
 	do {
 		num_read = fread(buffer, 1, size, file);
 		if (num_read > 0) {
@@ -592,8 +625,23 @@ void play_samples(char *name, unsigned int card, unsigned int device,
 				printf("%s: wrote %d\n", __func__, wrote);
 			}
 		}
+		write_count++;
+		if ((pause_count > 0) && (write_count % pause_block == 0)) {
+				printf("pause...\n");
+				compress_pause(compress);
+				sleep(pause_duration);
+				printf("pause release...\n");
+				compress_resume(compress);
+				pause_count--;
+		}
 	} while (num_read > 0);
 
+	if (pause_count > 0) {
+		compress_pause(compress);
+		sleep(5);
+		compress_resume(compress);
+	}
+
 	if (verbose)
 		printf("%s: exit success\n", __func__);
 	/* issue drain if it supports */
-- 
2.17.1