Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
f2ddcf8f
Commit
f2ddcf8f
authored
Mar 04, 2024
by
FatherMarco1971
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Solution #685 M3U8 noisy
parent
c95aafa0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
26 deletions
+34
-26
src/Audio.cpp
src/Audio.cpp
+33
-25
src/Audio.h
src/Audio.h
+1
-1
No files found.
src/Audio.cpp
View file @
f2ddcf8f
...
...
@@ -352,7 +352,7 @@ void Audio::setDefaults() {
m_bitRate
=
0
;
// Bitrate still unknown
m_bytesNotDecoded
=
0
;
// counts all not decodable bytes
m_chunkcount
=
0
;
// for chunked streams
m_
byteCounter
=
0
;
// count received data
//
byteCounter = 0; // count received data
m_contentlength
=
0
;
// If Content-Length is known, count it
m_curSample
=
0
;
m_metaint
=
0
;
// No metaint yet
...
...
@@ -3015,12 +3015,14 @@ void Audio::processLocalFile() {
const
uint32_t
maxFrameSize
=
InBuff
.
getMaxBlockSize
();
// every mp3/aac frame is not bigger
static
bool
f_stream
;
static
bool
f_fileDataComplete
;
static
uint32_t
byteCounter
;
// count received data
uint32_t
availableBytes
=
0
;
if
(
m_f_firstCall
)
{
// runs only one time per connection, prepare for start
m_f_firstCall
=
false
;
f_stream
=
false
;
f_fileDataComplete
=
false
;
byteCounter
=
0
;
ctime
=
millis
();
if
(
m_codec
==
CODEC_M4A
)
seek_m4a_stsz
();
// determine the pos of atom stsz
if
(
m_codec
==
CODEC_M4A
)
seek_m4a_ilst
();
// looking for metadata
...
...
@@ -3031,16 +3033,16 @@ void Audio::processLocalFile() {
availableBytes
=
16
*
1024
;
// set some large value
availableBytes
=
min
(
availableBytes
,
(
uint32_t
)
InBuff
.
writeSpace
());
availableBytes
=
min
(
availableBytes
,
audiofile
.
size
()
-
m_
byteCounter
);
availableBytes
=
min
(
availableBytes
,
audiofile
.
size
()
-
byteCounter
);
if
(
m_contentlength
)
{
if
(
m_contentlength
>
getFilePos
())
availableBytes
=
min
(
availableBytes
,
m_contentlength
-
getFilePos
());
}
if
(
m_audioDataSize
)
{
availableBytes
=
min
(
availableBytes
,
m_audioDataSize
+
m_audioDataStart
-
m_
byteCounter
);
}
if
(
m_audioDataSize
)
{
availableBytes
=
min
(
availableBytes
,
m_audioDataSize
+
m_audioDataStart
-
byteCounter
);
}
int32_t
bytesAddedToBuffer
=
audiofile
.
read
(
InBuff
.
getWritePtr
(),
availableBytes
);
if
(
bytesAddedToBuffer
>
0
)
{
m_
byteCounter
+=
bytesAddedToBuffer
;
// Pull request #42
byteCounter
+=
bytesAddedToBuffer
;
// Pull request #42
InBuff
.
bytesWritten
(
bytesAddedToBuffer
);
}
if
(
!
f_stream
)
{
...
...
@@ -3076,7 +3078,7 @@ void Audio::processLocalFile() {
return
;
}
else
{
if
((
InBuff
.
freeSpace
()
>
maxFrameSize
)
&&
(
m_file_size
-
m_
byteCounter
)
>
maxFrameSize
&&
availableBytes
)
{
if
((
InBuff
.
freeSpace
()
>
maxFrameSize
)
&&
(
m_file_size
-
byteCounter
)
>
maxFrameSize
&&
availableBytes
)
{
// fill the buffer before playing
return
;
}
...
...
@@ -3101,7 +3103,7 @@ void Audio::processLocalFile() {
if
(
m_avr_bitrate
)
m_audioCurrentTime
=
((
double
)(
m_resumeFilePos
-
m_audioDataStart
)
/
m_avr_bitrate
)
*
8
;
audiofile
.
seek
(
m_resumeFilePos
);
InBuff
.
resetBuffer
();
m_
byteCounter
=
m_resumeFilePos
;
byteCounter
=
m_resumeFilePos
;
f_fileDataComplete
=
false
;
// #570
if
(
m_f_Log
)
{
...
...
@@ -3139,7 +3141,7 @@ void Audio::processLocalFile() {
setFilePos
(
m_audioDataStart
);
if
(
m_codec
==
CODEC_FLAC
)
FLACDecoderReset
();
m_audioCurrentTime
=
0
;
m_
byteCounter
=
m_audioDataStart
;
byteCounter
=
m_audioDataStart
;
f_fileDataComplete
=
false
;
return
;
}
// loop
...
...
@@ -3164,8 +3166,8 @@ void Audio::processLocalFile() {
}
return
;
}
if
(
m_
byteCounter
==
audiofile
.
size
())
{
f_fileDataComplete
=
true
;
}
if
(
m_
byteCounter
==
m_audioDataSize
+
m_audioDataStart
)
{
f_fileDataComplete
=
true
;
}
if
(
byteCounter
==
audiofile
.
size
())
{
f_fileDataComplete
=
true
;
}
if
(
byteCounter
==
m_audioDataSize
+
m_audioDataStart
)
{
f_fileDataComplete
=
true
;
}
// play audio data - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
f_stream
)
{
playAudioData
();
}
}
...
...
@@ -3252,6 +3254,7 @@ void Audio::processWebFile() {
const
uint32_t
maxFrameSize
=
InBuff
.
getMaxBlockSize
();
// every mp3/aac frame is not bigger
static
bool
f_stream
;
// first audio data received
static
bool
f_webFileDataComplete
;
// all file data received
static
uint32_t
byteCounter
;
static
uint32_t
chunkSize
;
// chunkcount read from stream
static
size_t
audioDataCount
;
// counts the decoded audiodata only
...
...
@@ -3261,6 +3264,7 @@ void Audio::processWebFile() {
m_t0
=
millis
();
f_webFileDataComplete
=
false
;
f_stream
=
false
;
byteCounter
=
0
;
chunkSize
=
0
;
audioDataCount
=
0
;
}
...
...
@@ -3287,20 +3291,20 @@ void Audio::processWebFile() {
}
availableBytes
=
min
((
uint32_t
)
InBuff
.
writeSpace
(),
availableBytes
);
availableBytes
=
min
(
m_contentlength
-
m_
byteCounter
,
availableBytes
);
if
(
m_audioDataSize
)
availableBytes
=
min
(
m_audioDataSize
-
(
m_
byteCounter
-
m_audioDataStart
),
availableBytes
);
availableBytes
=
min
(
m_contentlength
-
byteCounter
,
availableBytes
);
if
(
m_audioDataSize
)
availableBytes
=
min
(
m_audioDataSize
-
(
byteCounter
-
m_audioDataStart
),
availableBytes
);
int16_t
bytesAddedToBuffer
=
_client
->
read
(
InBuff
.
getWritePtr
(),
availableBytes
);
if
(
bytesAddedToBuffer
>
0
)
{
m_
byteCounter
+=
bytesAddedToBuffer
;
// Pull request #42
byteCounter
+=
bytesAddedToBuffer
;
// Pull request #42
if
(
m_f_chunked
)
m_chunkcount
-=
bytesAddedToBuffer
;
if
(
m_controlCounter
==
100
)
audioDataCount
+=
bytesAddedToBuffer
;
InBuff
.
bytesWritten
(
bytesAddedToBuffer
);
}
if
(
!
f_stream
)
{
if
((
InBuff
.
freeSpace
()
>
maxFrameSize
)
&&
(
m_
byteCounter
<
m_contentlength
))
return
;
if
((
InBuff
.
freeSpace
()
>
maxFrameSize
)
&&
(
byteCounter
<
m_contentlength
))
return
;
f_stream
=
true
;
// ready to play the audio data
uint16_t
filltime
=
millis
()
-
m_t0
;
AUDIO_INFO
(
"stream ready, buffer filled in %d ms"
,
filltime
);
...
...
@@ -3373,8 +3377,8 @@ void Audio::processWebFile() {
return
;
}
if
(
m_
byteCounter
==
m_contentlength
)
{
f_webFileDataComplete
=
true
;
}
if
(
m_
byteCounter
-
m_audioDataStart
==
m_audioDataSize
)
{
f_webFileDataComplete
=
true
;
}
if
(
byteCounter
==
m_contentlength
)
{
f_webFileDataComplete
=
true
;
}
if
(
byteCounter
-
m_audioDataStart
==
m_audioDataSize
)
{
f_webFileDataComplete
=
true
;
}
// play audio data - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
f_stream
)
{
playAudioData
();
}
...
...
@@ -3387,6 +3391,7 @@ void Audio::processWebStreamTS() {
static
bool
f_stream
;
// first audio data received
static
bool
f_firstPacket
;
static
bool
f_chunkFinished
;
static
uint32_t
byteCounter
;
// count received data
static
uint8_t
ts_packet
[
188
];
// m3u8 transport stream is 188 bytes long
uint8_t
ts_packetStart
=
0
;
uint8_t
ts_packetLength
=
0
;
...
...
@@ -3399,6 +3404,7 @@ void Audio::processWebStreamTS() {
f_stream
=
false
;
f_firstPacket
=
true
;
f_chunkFinished
=
false
;
byteCounter
=
0
;
chunkSize
=
0
;
m_t0
=
millis
();
ts_packetPtr
=
0
;
...
...
@@ -3420,7 +3426,7 @@ void Audio::processWebStreamTS() {
int
res
=
_client
->
read
(
ts_packet
+
ts_packetPtr
,
ts_packetsize
-
ts_packetPtr
);
if
(
res
>
0
)
{
ts_packetPtr
+=
res
;
m_
byteCounter
+=
res
;
byteCounter
+=
res
;
if
(
ts_packetPtr
<
ts_packetsize
)
return
;
ts_packetPtr
=
0
;
if
(
f_firstPacket
)
{
// search for ID3 Header in the first packet
...
...
@@ -3452,11 +3458,11 @@ void Audio::processWebStreamTS() {
InBuff
.
bytesWritten
(
ts_packetLength
-
ws
);
}
}
if
(
m_byteCounter
==
m_contentlength
||
m_
byteCounter
==
chunkSize
)
{
if
(
byteCounter
==
m_contentlength
||
byteCounter
==
chunkSize
)
{
f_chunkFinished
=
true
;
m_
byteCounter
=
0
;
byteCounter
=
0
;
}
if
(
m_byteCounter
>
m_contentlength
)
log_e
(
"m_
byteCounter overflow"
);
if
(
byteCounter
>
m_contentlength
)
log_e
(
"
byteCounter overflow"
);
}
}
if
(
f_chunkFinished
)
{
...
...
@@ -3501,6 +3507,7 @@ void Audio::processWebStreamHLS() {
static
bool
f_stream
;
// first audio data received
static
bool
firstBytes
;
static
bool
f_chunkFinished
;
static
uint32_t
byteCounter
;
// count received data
static
size_t
chunkSize
=
0
;
static
uint16_t
ID3WritePtr
;
static
uint16_t
ID3ReadPtr
;
...
...
@@ -3510,6 +3517,7 @@ void Audio::processWebStreamHLS() {
if
(
m_f_firstCall
)
{
// runs only ont time per connection, prepare for start
f_stream
=
false
;
f_chunkFinished
=
false
;
byteCounter
=
0
;
chunkSize
=
0
;
ID3WritePtr
=
0
;
ID3ReadPtr
=
0
;
...
...
@@ -3528,7 +3536,7 @@ void Audio::processWebStreamHLS() {
if
(
m_f_chunked
&&
!
chunkSize
)
{
chunkSize
=
chunkedDataTransfer
(
&
readedBytes
);
m_
byteCounter
+=
readedBytes
;
byteCounter
+=
readedBytes
;
}
if
(
firstBytes
)
{
...
...
@@ -3560,7 +3568,7 @@ void Audio::processWebStreamHLS() {
InBuff
.
bytesWritten
(
ID3BuffSize
-
(
ID3ReadPtr
+
ws
));
}
if
(
ID3Buff
)
free
(
ID3Buff
);
m_
byteCounter
+=
ID3BuffSize
;
byteCounter
+=
ID3BuffSize
;
ID3Buff
=
NULL
;
firstBytes
=
false
;
}
...
...
@@ -3573,11 +3581,11 @@ void Audio::processWebStreamHLS() {
else
{
bytesWasWritten
=
_client
->
read
(
InBuff
.
getWritePtr
(),
InBuff
.
writeSpace
());
}
InBuff
.
bytesWritten
(
bytesWasWritten
);
m_
byteCounter
+=
bytesWasWritten
;
byteCounter
+=
bytesWasWritten
;
if
(
m_byteCounter
==
m_contentlength
||
m_
byteCounter
==
chunkSize
)
{
if
(
byteCounter
==
m_contentlength
||
byteCounter
==
chunkSize
)
{
f_chunkFinished
=
true
;
m_
byteCounter
=
0
;
byteCounter
=
0
;
}
}
...
...
@@ -4706,7 +4714,7 @@ uint32_t Audio::getFileSize() {
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
uint32_t
Audio
::
getFilePos
()
{
if
(
!
audiofile
)
return
m_byteCounter
;
if
(
!
audiofile
)
return
0
;
return
audiofile
.
position
();
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
...
...
src/Audio.h
View file @
f2ddcf8f
...
...
@@ -530,7 +530,7 @@ private:
uint32_t
m_metaint
=
0
;
// Number of databytes between metadata
uint32_t
m_chunkcount
=
0
;
// Counter for chunked transfer
uint32_t
m_t0
=
0
;
// store millis(), is needed for a small delay
uint32_t
m_byteCounter
=
0
;
// count received data
//
uint32_t m_byteCounter = 0; // count received data
uint32_t
m_contentlength
=
0
;
// Stores the length if the stream comes from fileserver
uint32_t
m_bytesNotDecoded
=
0
;
// pictures or something else that comes with the stream
uint32_t
m_PlayingStartTime
=
0
;
// Stores the milliseconds after the start of the audio
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment