-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathAACPlayer.java
More file actions
783 lines (615 loc) · 25.1 KB
/
AACPlayer.java
File metadata and controls
783 lines (615 loc) · 25.1 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
/*
** AACDecoder - Freeware Advanced Audio (AAC) Decoder for Android
** Copyright (C) 2011 Spolecne s.r.o., http://www.spoledge.com
**
** This file is a part of AACDecoder.
**
** AACDecoder is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published
** by the Free Software Foundation; either version 3 of the License,
** or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.spoledge.aacdecoder;
import android.util.Log;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/**
* This is the AAC Stream player class.
* It uses Decoder to decode AAC stream into PCM samples.
* This class is not thread safe.
* <pre>
* AACPlayer player = new AACPlayer();
*
* String url = ...;
* player.playAsync( url );
* </pre>
*/
public class AACPlayer {
/**
* The default expected bitrate.
* Used only if not specified in play() methods.
*/
public static final int DEFAULT_EXPECTED_KBITSEC_RATE = 64;
/**
* The default capacity of the audio buffer (AudioTrack) in ms.
* @see setAudioBufferCapacityMs(int)
*/
public static final int DEFAULT_AUDIO_BUFFER_CAPACITY_MS = 1500;
/**
* The default capacity of the output buffer used for decoding in ms.
* @see setDecodeBufferCapacityMs(int)
*/
public static final int DEFAULT_DECODE_BUFFER_CAPACITY_MS = 700;
private static final String LOG = "AACPlayer";
////////////////////////////////////////////////////////////////////////////
// Attributes
////////////////////////////////////////////////////////////////////////////
protected boolean stopped;
protected boolean metadataEnabled = true;
protected boolean responseCodeCheckEnabled = true;
protected int audioBufferCapacityMs;
protected int decodeBufferCapacityMs;
protected PlayerCallback playerCallback;
protected String metadataCharEnc;
protected Decoder decoder;
/**
* The bit rate declared by the stream header - kb/s.
*/
protected int declaredBitRate = -1;
// variables used for computing average bitrate
private int sumKBitSecRate = 0;
private int countKBitSecRate = 0;
private int avgKBitSecRate = 0;
////////////////////////////////////////////////////////////////////////////
// Constructors
////////////////////////////////////////////////////////////////////////////
/**
* Creates a new player.
*/
public AACPlayer() {
this( null );
}
/**
* Creates a new player.
* @param playerCallback the callback, can be null
*/
public AACPlayer( PlayerCallback playerCallback ) {
this( playerCallback, DEFAULT_AUDIO_BUFFER_CAPACITY_MS, DEFAULT_DECODE_BUFFER_CAPACITY_MS );
}
/**
* Creates a new player.
* @param playerCallback the callback, can be null
* @param audioBufferCapacityMs the capacity of the audio buffer (AudioTrack) in ms
* @param decodeBufferCapacityMs the capacity of the buffer used for decoding in ms
* @see setAudioBufferCapacityMs(int)
* @see setDecodeBufferCapacityMs(int)
*/
public AACPlayer( PlayerCallback playerCallback, int audioBufferCapacityMs, int decodeBufferCapacityMs ) {
setPlayerCallback( playerCallback );
setAudioBufferCapacityMs( audioBufferCapacityMs );
setDecodeBufferCapacityMs( decodeBufferCapacityMs );
decoder = createDecoder();
}
////////////////////////////////////////////////////////////////////////////
// Public
////////////////////////////////////////////////////////////////////////////
/**
* Returns the underlying decoder.
*/
public Decoder getDecoder() {
return decoder;
}
/**
* Sets the custom decoder.
*/
public void setDecoder( Decoder decoder ) {
this.decoder = decoder;
}
/**
* Sets the audio buffer (AudioTrack) capacity.
* The capacity can be expressed in time of audio playing of such buffer.
* For example 1 second buffer capacity is 88100 samples for 44kHz stereo.
* By setting this the audio will start playing after the audio buffer is first filled.
*
* NOTE: this should be set BEFORE any of the play methods are called.
*
* @param audioBufferCapacityMs the capacity of the buffer in milliseconds
*/
public void setAudioBufferCapacityMs( int audioBufferCapacityMs ) {
this.audioBufferCapacityMs = audioBufferCapacityMs;
}
/**
* Gets the audio buffer capacity as the audio playing time.
* @return the capacity of the audio buffer in milliseconds
*/
public int getAudioBufferCapacityMs() {
return audioBufferCapacityMs;
}
/**
* Sets the capacity of the output buffer used for decoding.
* The capacity can be expressed in time of audio playing of such buffer.
* For example 1 second buffer capacity is 88100 samples for 44kHz stereo.
* Decoder tries to fill out the whole buffer in each round.
*
* NOTE: this should be set BEFORE any of the play methods are called.
*
* @param decodeBufferCapacityMs the capacity of the buffer in milliseconds
*/
public void setDecodeBufferCapacityMs( int decodeBufferCapacityMs ) {
this.decodeBufferCapacityMs = decodeBufferCapacityMs;
}
/**
* Gets the capacity of the output buffer used for decoding as the audio playing time.
* @return the capacity of the decoding buffer in milliseconds
*/
public int getDecodeBufferCapacityMs() {
return decodeBufferCapacityMs;
}
/**
* Sets the PlayerCallback.
* NOTE: this should be set BEFORE any of the play methods are called.
*/
public void setPlayerCallback( PlayerCallback playerCallback ) {
this.playerCallback = playerCallback;
}
/**
* Returns the PlayerCallback or null if no PlayerCallback was set.
*/
public PlayerCallback getPlayerCallback() {
return playerCallback;
}
/**
* Returns the flag if metadata information is enabeld / sent to PlayerCallback.
*/
public boolean getMetadataEnabled() {
return metadataEnabled;
}
/**
* Sets the flag if metadata information is enabeld / sent to PlayerCallback.
* This is enabled by default.
*/
public void setMetadataEnabled( boolean metadataEnabled ) {
this.metadataEnabled = metadataEnabled;
}
/**
* Returns the flag if the HTTP / shoutcast response code should be checked or not.
*/
public boolean getResponseCodeCheckEnabled() {
return responseCodeCheckEnabled;
}
/**
* Sets the flag if the HTTP / shoutcast response code should be checked or not.
* This method was added for backward compatibility. By disabling the check
* you also force pre-Kitkat devices to use original HttpURLConnection implementation
* even for shoutcast streams.
* This is enabled by default.
* @since 0.8
*/
public void setResponseCodeCheckEnabled( boolean responseCodeCheckEnabled ) {
this.responseCodeCheckEnabled = responseCodeCheckEnabled;
}
/**
* Sets the encoding for the metadata strings.
* If not set, then UTF-8 is used.
*/
public void setMetadataCharEnc( String metadataCharEnc ) {
this.metadataCharEnc = metadataCharEnc;
}
/**
* Returns the bit-rate as declared by the stream metadata.
* @return the bitrate in kb/s or -1 if unknown
* @since 0.8
*/
public int getDeclaredBitRate() {
return declaredBitRate;
}
/**
* Plays a stream asynchronously.
* This method starts a new thread.
* @param url the URL of the stream or file
*/
public void playAsync( final String url ) {
playAsync( url, -1 );
}
/**
* Plays a stream asynchronously.
* This method starts a new thread.
* @param url the URL of the stream or file
* @param expectedKBitSecRate the expected average bitrate in kbit/sec; -1 means unknown
*/
public void playAsync( final String url, final int expectedKBitSecRate ) {
new Thread(new Runnable() {
public void run() {
try {
play( url, expectedKBitSecRate );
}
catch (Exception e) {
Log.e( LOG, "playAsync():", e);
if (playerCallback != null) playerCallback.playerException( e );
}
}
}).start();
}
/**
* Plays a stream synchronously.
* @param url the URL of the stream or file
*/
public void play( String url ) throws Exception {
play( url, -1 );
}
/**
* Plays a stream synchronously.
* @param url the URL of the stream or file
* @param expectedKBitSecRate the expected average bitrate in kbit/sec;
* -1 means unknown;
* when setting this parameter, then the declared bit-rate from the stream header is ignored
*/
public void play( String url, int expectedKBitSecRate ) throws Exception {
declaredBitRate = -1;
if (url.indexOf( ':' ) > 0) {
URLConnection cn = openConnection( url );
InputStream is = null;
try {
if (responseCodeCheckEnabled) checkResponseCode( cn );
processHeaders( cn );
is = getInputStream( cn );
// try to get the expectedKBitSecRate from headers
// but if then expectedKBitSecRate is passed, then ignore the declared one:
play( is, expectedKBitSecRate != -1 ? expectedKBitSecRate : declaredBitRate );
}
finally {
try { is.close(); } catch (Throwable t) {}
if (cn instanceof HttpURLConnection) {
try { ((HttpURLConnection)cn).disconnect(); } catch (Throwable t) {}
}
}
}
else {
processFileType( url );
InputStream is = new FileInputStream( url );
try {
play( is, expectedKBitSecRate );
}
finally {
try { is.close(); } catch (Throwable t) {}
}
}
}
/**
* Plays a stream synchronously.
* @param is the input stream
*/
public void play( InputStream is ) throws Exception {
play( is, -1 );
}
/**
* Plays a stream synchronously.
* @param is the input stream
* @param expectedKBitSecRate the expected average bitrate in kbit/sec; -1 means unknown
*/
public final void play( InputStream is, int expectedKBitSecRate ) throws Exception {
stopped = false;
if (playerCallback != null) playerCallback.playerStarted();
if (expectedKBitSecRate <= 0) expectedKBitSecRate = DEFAULT_EXPECTED_KBITSEC_RATE;
sumKBitSecRate = 0;
countKBitSecRate = 0;
playImpl( is, expectedKBitSecRate );
}
/**
* Stops the execution thread.
*/
public void stop() {
stopped = true;
}
////////////////////////////////////////////////////////////////////////////
// Protected
////////////////////////////////////////////////////////////////////////////
/**
* Plays a stream synchronously.
* This is the implementation method calle by every play() and playAsync() methods.
* @param is the input stream
* @param expectedKBitSecRate the expected average bitrate in kbit/sec
*/
protected void playImpl( InputStream is, int expectedKBitSecRate ) throws Exception {
BufferReader reader = new BufferReader(
computeInputBufferSize( expectedKBitSecRate, decodeBufferCapacityMs ),
is );
new Thread( reader ).start();
PCMFeed pcmfeed = null;
Thread pcmfeedThread = null;
// profiling info
long profMs = 0;
long profSamples = 0;
long profSampleRate = 0;
int profCount = 0;
try {
Decoder.Info info = decoder.start( reader );
Log.d( LOG, "play(): samplerate=" + info.getSampleRate() + ", channels=" + info.getChannels());
profSampleRate = info.getSampleRate() * info.getChannels();
if (info.getChannels() > 2) {
throw new RuntimeException("Too many channels detected: " + info.getChannels());
}
// 3 buffers for result samples:
// - one is used by decoder
// - one is used by the PCMFeeder
// - one is enqueued / passed to PCMFeeder - non-blocking op
short[][] decodeBuffers = createDecodeBuffers( 3, info );
short[] decodeBuffer = decodeBuffers[0];
int decodeBufferIndex = 0;
pcmfeed = createPCMFeed( info );
pcmfeedThread = new Thread( pcmfeed );
pcmfeedThread.start();
if (info.getFirstSamples() != null) {
short[] firstSamples = info.getFirstSamples();
Log.d( LOG, "First samples length: " + firstSamples.length );
pcmfeed.feed( firstSamples, firstSamples.length );
info.setFirstSamples( null );
}
do {
long tsStart = System.currentTimeMillis();
info = decoder.decode( decodeBuffer, decodeBuffer.length );
int nsamp = info.getRoundSamples();
profMs += System.currentTimeMillis() - tsStart;
profSamples += nsamp;
profCount++;
Log.d( LOG, "play(): decoded " + nsamp + " samples" );
if (nsamp == 0 || stopped) break;
if (!pcmfeed.feed( decodeBuffer, nsamp ) || stopped) break;
int kBitSecRate = computeAvgKBitSecRate( info );
if (Math.abs(expectedKBitSecRate - kBitSecRate) > 1) {
Log.i( LOG, "play(): changing kBitSecRate: " + expectedKBitSecRate + " -> " + kBitSecRate );
reader.setCapacity( computeInputBufferSize( kBitSecRate, decodeBufferCapacityMs ));
expectedKBitSecRate = kBitSecRate;
}
decodeBuffer = decodeBuffers[ ++decodeBufferIndex % 3 ];
} while (!stopped);
}
finally {
boolean stopImmediatelly = stopped;
stopped = true;
if (pcmfeed != null) pcmfeed.stop( !stopImmediatelly );
decoder.stop();
reader.stop();
int perf = 0;
if (profCount > 0) Log.i( LOG, "play(): average decoding time: " + profMs / profCount + " ms");
if (profMs > 0) {
perf = (int)((1000*profSamples / profMs - profSampleRate) * 100 / profSampleRate);
Log.i( LOG, "play(): average rate (samples/sec): audio=" + profSampleRate
+ ", decoding=" + (1000*profSamples / profMs)
+ ", audio/decoding= " + perf
+ " % (the higher, the better; negative means that decoding is slower than needed by audio)");
}
if (pcmfeedThread != null) pcmfeedThread.join();
if (playerCallback != null) playerCallback.playerStopped( perf );
}
}
protected Decoder createDecoder() {
return Decoder.create();
}
protected short[][] createDecodeBuffers( int count, Decoder.Info info ) {
int size = PCMFeed.msToSamples( decodeBufferCapacityMs, info.getSampleRate(), info.getChannels());
short[][] ret = new short[ count ][];
for (int i=0; i < ret.length; i++) {
ret[i] = new short[ size ];
}
return ret;
}
protected PCMFeed createPCMFeed( Decoder.Info info ) {
int size = PCMFeed.msToBytes( audioBufferCapacityMs, info.getSampleRate(), info.getChannels());
return new PCMFeed( info.getSampleRate(), info.getChannels(), size, playerCallback );
}
/**
* Opens connection.
* Tries to recognize if the stream is a standard HTTP or SHOUTCAST.
* Since Android 4.4 Kitkat the HttpURLConnection implementation is strict
* and does not allow SHOUTCAST response "ICY 200 OK".
* If we detect this, we try to use alternate protocol "icy" and
* our auxiliar implementation - IcyURLConnection.
* NOTE: URL.setURLStreamHandlerFactory() must be called - this library does not call it
* itself.
*/
protected URLConnection openConnection( String url ) throws IOException {
URLConnection conn = null;
boolean close = true;
while (true) {
conn = new URL( url ).openConnection();
prepareConnection( conn );
conn.connect();
try {
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) conn;
try {
// pre-KitKat returns -1:
if (httpConn.getResponseCode() == -1) {
if (!responseCodeCheckEnabled) {
Log.w( LOG, "No response code, but ignoring - for url " + url );
close = false;
break;
}
else {
Log.w( LOG, "No response code for url " + url );
}
}
else {
// standard HTTP response / IcyURLConnection response
close = false;
break;
}
}
catch (Exception e) {
// KitKat throws exception:
// java.net.ProtocolException: Unexpected status line: ICY 200 OK
Log.w( LOG, "Invalid response code for url " + url + " - " + e );
}
}
else if (conn.getHeaderFields() == null) {
// sanity code
Log.w( LOG, "No header fields in response for url " + url );
}
else {
close = false;
break;
}
if (url.startsWith( "http:" )) {
url = "icy" + url.substring( 4 );
Log.i( LOG, "Trying to re-connect as ICY url " + url );
}
else throw new IOException( "Invalid response - no response code / headers detected" );
}
finally {
if (close) {
if (conn instanceof HttpURLConnection) {
try { ((HttpURLConnection)conn).disconnect(); } catch (Throwable t) {}
}
conn = null;
}
}
}
return conn;
}
/**
* Prepares the connection.
* This method is called before a connection is opened.
* Actually sets "Icy-MetaData" header to "1" if metadata are enabled.
*/
protected void prepareConnection( URLConnection conn ) {
// request for dynamic metadata:
if (metadataEnabled) conn.setRequestProperty("Icy-MetaData", "1");
}
/**
* Checks the response code.
* Actually for HttpURLConnection it throws an exception
* when the response code is not between 200 and 299.
*/
protected void checkResponseCode( URLConnection conn ) throws Exception {
if (conn instanceof HttpURLConnection) {
HttpURLConnection httpConn = (HttpURLConnection) conn;
int responseCode = httpConn.getResponseCode();
if (responseCode == -1) {
Log.w( LOG, "Empty response code: " + responseCode + " " + httpConn.getResponseMessage());
}
else if (responseCode < 200 || responseCode > 299) {
Log.e( LOG, "Error response code: " + responseCode + " " + httpConn.getResponseMessage());
throw new IOException( "Error response: " + responseCode + " " + httpConn.getResponseMessage());
}
else {
Log.d( LOG, "Response: " + responseCode + " " + httpConn.getResponseMessage());
}
}
}
/**
* Gets the input stream from the connection.
* Actually returns the underlying stream or IcyInputStream.
*/
protected InputStream getInputStream( URLConnection conn ) throws Exception {
String smetaint = conn.getHeaderField( "icy-metaint" );
InputStream ret = conn.getInputStream();
if (!metadataEnabled) {
Log.i( LOG, "Metadata not enabled" );
}
else if (smetaint != null) {
int period = -1;
try {
period = Integer.parseInt( smetaint );
}
catch (Exception e) {
Log.e( LOG, "The icy-metaint '" + smetaint + "' cannot be parsed: '" + e );
}
if (period > 0) {
Log.i( LOG, "The dynamic metainfo is sent every " + period + " bytes" );
ret = new IcyInputStream( ret, period, playerCallback, metadataCharEnc );
}
}
else Log.i( LOG, "This stream does not provide dynamic metainfo" );
return ret;
}
/**
* This method is called after the connection is established.
*/
protected void processHeaders( URLConnection cn ) {
dumpHeaders( cn );
String br = cn.getHeaderField( "icy-br" );
if (br != null) {
try {
declaredBitRate = Integer.parseInt( br );
if (declaredBitRate > 7) {
Log.d( LOG, "Declared bitrate is " + declaredBitRate + " kb/s" );
}
else {
Log.w( LOG, "Declared bitrate is too low - ignoring: " + declaredBitRate + " kb/s" );
declaredBitRate = -1;
}
}
catch (Exception e) {
Log.w( LOG, "Cannot parse declared bit-rate '" + br + "'" );
}
}
if (playerCallback != null) {
for (java.util.Map.Entry<String, java.util.List<String>> me : cn.getHeaderFields().entrySet()) {
for (String s : me.getValue()) {
playerCallback.playerMetadata( me.getKey(), s );
}
}
}
}
protected void dumpHeaders( URLConnection cn ) {
if (cn.getHeaderFields() == null) {
Log.d( LOG, "No headers - not an HTTP response ?" );
return;
}
for (java.util.Map.Entry<String, java.util.List<String>> me : cn.getHeaderFields().entrySet()) {
for (String s : me.getValue()) {
Log.d( LOG, "header: key=" + me.getKey() + ", val=" + s);
}
}
}
/**
* This method is called before opening the file.
* Actually this method does nothing, but subclasses may override it.
*/
protected void processFileType( String file ) {
}
protected int computeAvgKBitSecRate( Decoder.Info info ) {
// do not change the value after a while - avoid changing of the out buffer:
if (countKBitSecRate < 64) {
int kBitSecRate = computeKBitSecRate( info );
int frames = info.getRoundFrames();
sumKBitSecRate += kBitSecRate * frames;
countKBitSecRate += frames;
avgKBitSecRate = sumKBitSecRate / countKBitSecRate;
}
return avgKBitSecRate;
}
protected static int computeKBitSecRate( Decoder.Info info ) {
if (info.getRoundSamples() <= 0) return -1;
return computeKBitSecRate( info.getRoundBytesConsumed(), info.getRoundSamples(),
info.getSampleRate(), info.getChannels());
}
protected static int computeKBitSecRate( int bytesconsumed, int samples, int sampleRate, int channels ) {
long ret = 8L * bytesconsumed * channels * sampleRate / samples;
return (((int)ret) + 500) / 1000;
}
protected static int computeInputBufferSize( int kbitSec, int durationMs ) {
return kbitSec * durationMs / 8;
}
protected static int computeInputBufferSize( Decoder.Info info, int durationMs ) {
return computeInputBufferSize( info.getRoundBytesConsumed(), info.getRoundSamples(),
info.getSampleRate(), info.getChannels(), durationMs );
}
protected static int computeInputBufferSize( int bytesconsumed, int samples,
int sampleRate, int channels, int durationMs ) {
return (int)(((long) bytesconsumed) * channels * sampleRate * durationMs / (1000L * samples));
}
}