summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Yves Avenard <jyavenard@mythtv.org>2010-12-11 03:08:44 (GMT)
committer Jean-Yves Avenard <jyavenard@mythtv.org>2010-12-13 11:28:58 (GMT)
commit8115c4470f48595932035ee6dfac161ffffb86af (patch)
treeb1275e6297fd9e3059fe85b5cb884eadddce3f6b
parent1b695d73025805dccfd86426c388945db1912469 (diff)
Tidy up the block processing in AddFrames by renaming variables. Block size is properly calculated based on the source channels.
Properly cast all variables involved in 64 bits timecode calculation as int64_t, and make all constants long long ones. Make the code easier to re-read
-rw-r--r--mythtv/libs/libmyth/audiooutputbase.cpp73
-rw-r--r--mythtv/libs/libmyth/audiooutputdigitalencoder.h1
2 files changed, 41 insertions, 33 deletions
diff --git a/mythtv/libs/libmyth/audiooutputbase.cpp b/mythtv/libs/libmyth/audiooutputbase.cpp
index 519a483..0f46bef 100644
--- a/mythtv/libs/libmyth/audiooutputbase.cpp
+++ b/mythtv/libs/libmyth/audiooutputbase.cpp
@@ -714,7 +714,7 @@ void AudioOutputBase::Reset()
void AudioOutputBase::SetTimecode(int64_t timecode)
{
audbuf_timecode = audiotime = timecode;
- frames_buffered = (int64_t)((timecode * source_samplerate) / 1000);
+ frames_buffered = (timecode * (int64_t)source_samplerate) / 1000LL;
}
/**
@@ -771,10 +771,10 @@ int AudioOutputBase::audioready()
*/
int64_t AudioOutputBase::GetAudiotime(void)
{
- if (audbuf_timecode == 0)
- return 0;
+ if (audbuf_timecode == 0LL)
+ return 0LL;
- int obpf = output_bytes_per_frame;
+ int64_t obpf = (int64_t)output_bytes_per_frame;
int64_t oldaudiotime;
/* We want to calculate 'audiotime', which is the timestamp of the audio
@@ -793,8 +793,8 @@ int64_t AudioOutputBase::GetAudiotime(void)
QMutexLocker lockav(&avsync_lock);
- int64_t soundcard_buffer = GetBufferedOnSoundcard(); // bytes
- int64_t main_buffer = audioready();
+ int64_t soundcard_buffer = (int64_t)GetBufferedOnSoundcard(); // bytes
+ int64_t main_buffer =(int64_t)audioready();
/* audioready tells us how many bytes are in audiobuffer
scaled appropriately if output format != internal format */
@@ -806,8 +806,8 @@ int64_t AudioOutputBase::GetAudiotime(void)
processing latencies are catered for in AddFrames/SetAudiotime
to eliminate race */
audiotime = audbuf_timecode - (
- ((main_buffer + soundcard_buffer) * eff_stretchfactor ) /
- (effdsp * obpf));
+ ((main_buffer + soundcard_buffer) * (int64_t)eff_stretchfactor ) /
+ ((int64_t)effdsp * obpf));
/* audiotime should never go backwards, but we might get a negative
value if GetBufferedOnSoundcard() isn't updated by the driver very
@@ -837,33 +837,39 @@ int64_t AudioOutputBase::GetAudiotime(void)
*/
void AudioOutputBase::SetAudiotime(int frames, int64_t timecode)
{
- int64_t processframes_stretched = 0;
- int64_t processframes_unstretched = 0;
+ int64_t processframes_stretched = 0LL;
+ int64_t processframes_unstretched = 0LL;
+ int64_t old_audbuf_timecode = audbuf_timecode;
if (needs_upmix && upmixer)
- processframes_unstretched -= upmixer->frameLatency();
+ processframes_unstretched -= (int64_t)upmixer->frameLatency();
if (pSoundStretch)
{
- processframes_unstretched -= pSoundStretch->numUnprocessedSamples();
- processframes_stretched -= pSoundStretch->numSamples();
+ processframes_unstretched -=
+ (int64_t)pSoundStretch->numUnprocessedSamples();
+ processframes_stretched -=
+ (int64_t)pSoundStretch->numSamples();
}
if (encoder)
+ {
// the input buffered data is still in audio_bytes_per_sample format
- processframes_stretched -= encoder->Buffered() / output_bytes_per_frame;
-
- int64_t old_audbuf_timecode = audbuf_timecode;
+ processframes_stretched -=
+ (int64_t)(encoder->Buffered() / output_bytes_per_frame);
+ }
- audbuf_timecode = timecode +
- (((frames + processframes_unstretched) * 100000) +
- (processframes_stretched * eff_stretchfactor )) / effdsp;
+ audbuf_timecode =
+ timecode + (
+ ((int64_t)frames + processframes_unstretched * 100000LL) +
+ (processframes_stretched * (int64_t)eff_stretchfactor)
+ ) / (int64_t)effdsp;
// check for timecode wrap and reset audiotime if detected
// timecode will always be monotonic asc if not seeked and reset
// happens if seek or pause happens
if (audbuf_timecode < old_audbuf_timecode)
- audiotime = 0;
+ audiotime = 0LL;
VBAUDIOTS(QString("SetAudiotime atc=%1 tc=%2 f=%3 pfu=%4 pfs=%5")
.arg(audbuf_timecode)
@@ -883,10 +889,10 @@ void AudioOutputBase::SetAudiotime(int frames, int64_t timecode)
*/
int64_t AudioOutputBase::GetAudioBufferedTime(void)
{
- int ret = audbuf_timecode - GetAudiotime();
+ int64_t ret = audbuf_timecode - (int64_t)GetAudiotime();
// Pulse can give us values that make this -ve
- if (ret < 0)
- return 0;
+ if (ret < 0LL)
+ return 0LL;
return ret;
}
@@ -1064,8 +1070,8 @@ bool AudioOutputBase::AddFrames(void *in_buffer, int in_frames,
if (timecode < 0)
{
// Send original samples to mythmusic visualisation
- timecode = (int64_t)(frames_buffered) * 1000 / source_samplerate;
- frames_buffered += frames;
+ timecode = (frames_buffered * 1000LL) / (int64_t)source_samplerate;
+ frames_buffered += (int64_t)frames;
dispatchVisual((uchar *)in_buffer, len, timecode, source_channels,
output_settings->FormatToBits(format));
music = true;
@@ -1103,13 +1109,13 @@ bool AudioOutputBase::AddFrames(void *in_buffer, int in_frames,
}
int frames_remaining = in_frames;
- int frames_offset = 0;
int frames_final = 0;
- int maxframes = (kAudioSRCInputSize / channels) & ~0xf;
+ int maxframes = (kAudioSRCInputSize / source_channels) & ~0xf;
+ int offset = 0;
while(frames_remaining > 0)
{
- buffer = (char *)in_buffer + frames_offset;
+ buffer = (char *)in_buffer + offset;
frames = frames_remaining;
len = frames * source_bytes_per_frame;
@@ -1120,7 +1126,7 @@ bool AudioOutputBase::AddFrames(void *in_buffer, int in_frames,
{
frames = maxframes;
len = frames * source_bytes_per_frame;
- frames_offset += len;
+ offset += len;
}
// Convert to floats
len = AudioOutputUtil::toFloat(format, src_in, buffer, len);
@@ -1222,15 +1228,16 @@ bool AudioOutputBase::AddFrames(void *in_buffer, int in_frames,
int remaining = len;
int to_get = 0;
// The AC3 encoder can only work on 128kB of data at a time
- int maxframes = ((INBUFSIZE / encoder->FrameSize() - 1) *
- encoder->FrameSize()) & ~0xf;
+ int maxlength =
+ ((ENCODER_INBUFSIZE / encoder->FrameSize() - 1) *
+ encoder->FrameSize()) & ~0xf;
do
{
len = remaining;
- if (len > maxframes)
+ if (len > maxlength)
{
- len = maxframes;
+ len = maxlength;
}
remaining -= len;
diff --git a/mythtv/libs/libmyth/audiooutputdigitalencoder.h b/mythtv/libs/libmyth/audiooutputdigitalencoder.h
index c4afbac..648c313 100644
--- a/mythtv/libs/libmyth/audiooutputdigitalencoder.h
+++ b/mythtv/libs/libmyth/audiooutputdigitalencoder.h
@@ -7,6 +7,7 @@ extern "C" {
#define INBUFSIZE 131072
#define OUTBUFSIZE 98304
+#define ENCODER_INBUFSIZE INBUFSIZE
class AudioOutputDigitalEncoder
{