[vlc-commits] sout: sdi: skip when no samples
Francois Cartegnie
git at videolan.org
Mon Oct 8 18:11:31 CEST 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Oct 4 15:13:59 2018 +0200| [ae38239e34845fedb450fc75dcf18738e0478cb7] | committer: Francois Cartegnie
sout: sdi: skip when no samples
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ae38239e34845fedb450fc75dcf18738e0478cb7
---
modules/stream_out/sdi/AES3Audio.cpp | 27 ++++++++++++++++-----------
modules/stream_out/sdi/AES3Audio.hpp | 10 +++++-----
modules/stream_out/sdi/DBMSDIOutput.cpp | 5 +++--
modules/stream_out/sdi/SDIAudioMultiplex.cpp | 12 ++++++------
modules/stream_out/sdi/SDIAudioMultiplex.hpp | 4 ++--
5 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/modules/stream_out/sdi/AES3Audio.cpp b/modules/stream_out/sdi/AES3Audio.cpp
index 39bee4cd95..60d46ee509 100644
--- a/modules/stream_out/sdi/AES3Audio.cpp
+++ b/modules/stream_out/sdi/AES3Audio.cpp
@@ -51,7 +51,7 @@ void AES3AudioBuffer::push(block_t *p_block)
bytestream_mutex.unlock();
}
-void AES3AudioBuffer::read(void *dstbuf, unsigned count,
+void AES3AudioBuffer::read(void *dstbuf, unsigned count, unsigned skip,
const AES3AudioSubFrameIndex &dstbufsubframeidx,
const AES3AudioSubFrameIndex &srcchannelidx,
unsigned dstbufframeswidth)
@@ -65,7 +65,7 @@ void AES3AudioBuffer::read(void *dstbuf, unsigned count,
uint8_t *dst = reinterpret_cast<uint8_t *>(dstbuf);
for(unsigned i=0; i<count; i++)
{
- size_t srcoffset = sizeof(uint16_t) * (i * buffersubframes + srcchannelidx.index());
+ size_t srcoffset = sizeof(uint16_t) * ((i + skip) * buffersubframes + srcchannelidx.index());
size_t dstoffset = sizeof(uint16_t) * (i * 2 * dstbufframeswidth + dstbufsubframeidx.index());
block_PeekOffsetBytes(&bytestream, srcoffset, &dst[dstoffset], sizeof(uint16_t));
}
@@ -139,12 +139,16 @@ vlc_tick_t AES3AudioBuffer::bufferEnd() const
return start;
}
-unsigned AES3AudioBuffer::availableSamples() const
+unsigned AES3AudioBuffer::availableSamples(vlc_tick_t from) const
{
+ vlc_tick_t start = bufferStart();
+ if(start == VLC_TICK_INVALID)
+ return 0;
bytestream_mutex.lock();
unsigned samples = BytesToFrames(block_BytestreamRemaining(&bytestream));
bytestream_mutex.unlock();
- return samples;
+ unsigned offset = TicksDurationToFrames(from - start);
+ return samples + offset;
}
AES3AudioSubFrameSource::AES3AudioSubFrameSource()
@@ -167,12 +171,13 @@ vlc_tick_t AES3AudioSubFrameSource::bufferStartTime() const
void AES3AudioSubFrameSource::copy(void *buf,
unsigned count,
+ unsigned skip,
const AES3AudioSubFrameIndex &srcsubframeidx,
unsigned widthinframes)
{
if(aes3AudioBuffer == NULL)
return;
- aes3AudioBuffer->read(buf, count, srcsubframeidx, bufferSubFrameIdx, widthinframes);
+ aes3AudioBuffer->read(buf, count, skip, srcsubframeidx, bufferSubFrameIdx, widthinframes);
}
void AES3AudioSubFrameSource::flushConsumed()
@@ -203,11 +208,11 @@ bool AES3AudioSubFrameSource::available() const
return aes3AudioBuffer == NULL;
}
-unsigned AES3AudioSubFrameSource::availableSamples() const
+unsigned AES3AudioSubFrameSource::availableSamples(vlc_tick_t from) const
{
if(aes3AudioBuffer == NULL)
return 0;
- return aes3AudioBuffer->availableSamples();
+ return aes3AudioBuffer->availableSamples(from);
}
AES3AudioFrameSource::AES3AudioFrameSource()
@@ -235,14 +240,14 @@ unsigned AES3AudioFrameSource::samplesUpToTime(vlc_tick_t t) const
return diff / (48000 * 2 * 2);
}
-unsigned AES3AudioFrameSource::availableSamples() const
+unsigned AES3AudioFrameSource::availableSamples(vlc_tick_t from) const
{
if(!subframe0.available() && !subframe1.available())
- return std::min(subframe0.availableSamples(), subframe1.availableSamples());
+ return std::min(subframe0.availableSamples(from), subframe1.availableSamples(from));
else if(subframe1.available())
- return subframe0.availableSamples();
+ return subframe0.availableSamples(from);
else
- return subframe1.availableSamples();
+ return subframe1.availableSamples(from);
}
void AES3AudioFrameSource::flushConsumed()
diff --git a/modules/stream_out/sdi/AES3Audio.hpp b/modules/stream_out/sdi/AES3Audio.hpp
index 322318e15e..c4f90dbf91 100644
--- a/modules/stream_out/sdi/AES3Audio.hpp
+++ b/modules/stream_out/sdi/AES3Audio.hpp
@@ -48,9 +48,9 @@ namespace sdi_sout
void setSubFramesCount(uint8_t);
vlc_tick_t bufferStart() const;
vlc_tick_t bufferEnd() const;
- unsigned availableSamples() const;
+ unsigned availableSamples(vlc_tick_t) const;
void push(block_t *);
- void read(void *, unsigned,
+ void read(void *, unsigned, unsigned,
const AES3AudioSubFrameIndex &,
const AES3AudioSubFrameIndex &, unsigned);
void flushConsumed();
@@ -74,12 +74,12 @@ namespace sdi_sout
AES3AudioSubFrameSource();
AES3AudioSubFrameSource(AES3AudioBuffer *, AES3AudioSubFrameIndex);
vlc_tick_t bufferStartTime() const;
- void copy(void *, unsigned count,
+ void copy(void *, unsigned count, unsigned,
const AES3AudioSubFrameIndex &, unsigned width);
void flushConsumed();
void tagConsumed(unsigned);
- unsigned availableSamples() const;
void forwardTo(vlc_tick_t t);
+ unsigned availableSamples(vlc_tick_t) const;
const AES3AudioSubFrameIndex & index() const;
bool available() const;
@@ -94,7 +94,7 @@ namespace sdi_sout
AES3AudioFrameSource();
vlc_tick_t bufferStartTime() const;
unsigned samplesUpToTime(vlc_tick_t) const;
- unsigned availableSamples() const;
+ unsigned availableSamples(vlc_tick_t) const;
void flushConsumed();
void tagConsumed(unsigned);
void forwardTo(vlc_tick_t t);
diff --git a/modules/stream_out/sdi/DBMSDIOutput.cpp b/modules/stream_out/sdi/DBMSDIOutput.cpp
index 6aad020a2d..b54473785f 100644
--- a/modules/stream_out/sdi/DBMSDIOutput.cpp
+++ b/modules/stream_out/sdi/DBMSDIOutput.cpp
@@ -504,8 +504,9 @@ int DBMSDIOutput::Process()
picture_t *p;
while((p = reinterpret_cast<picture_t *>(videoBuffer.Dequeue())))
{
- while(audioMultiplex->availableSamples() >= SAMPLES_PER_FRAME &&
- audioMultiplex->bufferStart() <= p->date)
+ vlc_tick_t bufferStart = audioMultiplex->bufferStart();
+ while(bufferStart <= p->date &&
+ audioMultiplex->availableSamples(bufferStart) >= SAMPLES_PER_FRAME)
{
block_t *out = audioMultiplex->Extract(SAMPLES_PER_FRAME);
if(out)
diff --git a/modules/stream_out/sdi/SDIAudioMultiplex.cpp b/modules/stream_out/sdi/SDIAudioMultiplex.cpp
index 179802028a..70d8f175f7 100644
--- a/modules/stream_out/sdi/SDIAudioMultiplex.cpp
+++ b/modules/stream_out/sdi/SDIAudioMultiplex.cpp
@@ -329,7 +329,7 @@ SDIAudioMultiplex::~SDIAudioMultiplex()
}
-unsigned SDIAudioMultiplex::availableSamples() const
+unsigned SDIAudioMultiplex::availableSamples(vlc_tick_t from) const
{
unsigned samples = std::numeric_limits<unsigned>::max();
for(size_t i=0; i<MAX_AES3_AUDIO_FRAMES; i++)
@@ -337,7 +337,7 @@ unsigned SDIAudioMultiplex::availableSamples() const
if(framesources[i].subframe0.available() &&
framesources[i].subframe1.available())
continue;
- samples = std::min(samples, framesources[i].availableSamples());
+ samples = std::min(samples, framesources[i].availableSamples(from));
}
return samples < std::numeric_limits<unsigned>::max() ? samples : 0;
}
@@ -406,7 +406,7 @@ block_t * SDIAudioMultiplex::Extract(unsigned samples)
for(unsigned i=0; i<MAX_AES3_AUDIO_FRAMES; i++)
{
AES3AudioFrameSource *source = &framesources[i];
- unsigned avail = source->availableSamples();
+ unsigned avail = source->availableSamples(start);
if(avail == 0)
continue;
@@ -414,12 +414,12 @@ block_t * SDIAudioMultiplex::Extract(unsigned samples)
unsigned tocopy = std::min(samples, avail);
toskip = source->samplesUpToTime(start);
- if(toskip > tocopy)
+ if(toskip >= tocopy)
continue;
tocopy -= toskip;
- source->subframe0.copy(p_block->p_buffer, tocopy, (i * 2 + 0), interleavedframes);
- source->subframe1.copy(p_block->p_buffer, tocopy, (i * 2 + 1), interleavedframes);
+ source->subframe0.copy(p_block->p_buffer, tocopy, toskip, (i * 2 + 0), interleavedframes);
+ source->subframe1.copy(p_block->p_buffer, tocopy, toskip, (i * 2 + 1), interleavedframes);
}
for(unsigned i=0; i<MAX_AES3_AUDIO_FRAMES; i++)
diff --git a/modules/stream_out/sdi/SDIAudioMultiplex.hpp b/modules/stream_out/sdi/SDIAudioMultiplex.hpp
index 07d73dc39b..e7b245c3f6 100644
--- a/modules/stream_out/sdi/SDIAudioMultiplex.hpp
+++ b/modules/stream_out/sdi/SDIAudioMultiplex.hpp
@@ -25,7 +25,7 @@
#include <vector>
-#define SAMPLES_PER_FRAME (1536/4)
+#define SAMPLES_PER_FRAME (1536U/4)
namespace sdi_sout
{
@@ -86,7 +86,7 @@ namespace sdi_sout
SDIAudioMultiplex(uint8_t channels);
~SDIAudioMultiplex();
vlc_tick_t bufferStart() const;
- unsigned availableSamples() const;
+ unsigned availableSamples(vlc_tick_t) const;
block_t * Extract(unsigned);
unsigned getFreeSubFrameSlots() const;
void SetSubFrameSource(uint8_t, AES3AudioBuffer *, AES3AudioSubFrameIndex);
More information about the vlc-commits
mailing list