Skip to content

Commit

Permalink
Use c++11 initialization. Use m_ for class member names. (programs/my…
Browse files Browse the repository at this point in the history
…thtranscode)

Convert classes to use use the new c++11 brace initialization style.
Also update class member names (when needed) so that all member names
start with 'm_'.  This makes it easy to distinguish class members.
  • Loading branch information
linuxdude42 committed Feb 15, 2019
1 parent 55bd465 commit 0000958
Show file tree
Hide file tree
Showing 8 changed files with 661 additions and 701 deletions.
6 changes: 1 addition & 5 deletions mythtv/programs/mythtranscode/audioreencodebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ extern "C" {


AudioBuffer::AudioBuffer()
: m_frames(0), m_time(-1)
{
m_size = 0;
m_buffer = (uint8_t *)av_malloc(ABLOCK_SIZE);
if (m_buffer == nullptr)
{
throw std::bad_alloc();
}
m_realsize = ABLOCK_SIZE;
}

AudioBuffer::AudioBuffer(const AudioBuffer &old)
Expand Down Expand Up @@ -67,8 +64,7 @@ void AudioBuffer::appendData(unsigned char *buffer, int len, int frames,

AudioReencodeBuffer::AudioReencodeBuffer(AudioFormat audio_format,
int audio_channels, bool passthru)
: m_last_audiotime(0), m_audioFrameSize(0),
m_initpassthru(passthru), m_saveBuffer(nullptr)
: m_initpassthru(passthru)
{
Reset();
const AudioSettings settings(audio_format, audio_channels, 0, 0, false);
Expand Down
16 changes: 8 additions & 8 deletions mythtv/programs/mythtranscode/audioreencodebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class AudioBuffer
char *data(void) { return (char *)m_buffer; }
int size(void) { return m_size; }

uint8_t *m_buffer;
int m_size;
int m_realsize;
int m_frames;
long long m_time;
uint8_t *m_buffer {nullptr};
int m_size {0};
int m_realsize {ABLOCK_SIZE};
int m_frames {0};
long long m_time {-1};
};

/**
Expand Down Expand Up @@ -71,15 +71,15 @@ class AudioReencodeBuffer : public AudioOutput
int m_channels;
int m_bytes_per_frame;
int m_eff_audiorate;
long long m_last_audiotime;
long long m_last_audiotime {0};
bool m_passthru;
int m_audioFrameSize;
int m_audioFrameSize {0};

private:
bool m_initpassthru;
QMutex m_bufferMutex;
QList<AudioBuffer *> m_bufferList;
AudioBuffer *m_saveBuffer;
AudioBuffer *m_saveBuffer {nullptr};
};

#endif
Expand Down
82 changes: 41 additions & 41 deletions mythtv/programs/mythtranscode/cutter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ void Cutter::SetCutList(frm_dir_map_t &deleteMap, PlayerContext *ctx)
int64_t start = 0;
int64_t leadinLength;

tracker.SetPlayerContext(ctx);
foreshortenedCutList.clear();
m_tracker.SetPlayerContext(ctx);
m_foreshortenedCutList.clear();

for (it = deleteMap.begin(); it != deleteMap.end(); ++it)
{
switch(it.value())
{
case MARK_CUT_START:
foreshortenedCutList[it.key()] = MARK_CUT_START;
m_foreshortenedCutList[it.key()] = MARK_CUT_START;
start = it.key();
break;

Expand All @@ -34,7 +34,7 @@ void Cutter::SetCutList(frm_dir_map_t &deleteMap, PlayerContext *ctx)
(int64_t)MAXLEADIN);
if (leadinLength >= MINCUT)
{
foreshortenedCutList[it.key() - leadinLength + 2] =
m_foreshortenedCutList[it.key() - leadinLength + 2] =
MARK_CUT_END;
remainingCutList[it.key() - leadinLength + 1] =
MARK_CUT_START;
Expand All @@ -43,7 +43,7 @@ void Cutter::SetCutList(frm_dir_map_t &deleteMap, PlayerContext *ctx)
else
{
// Cut too short to use new method.
foreshortenedCutList[it.key()] = MARK_CUT_END;
m_foreshortenedCutList[it.key()] = MARK_CUT_END;
}
break;

Expand All @@ -53,113 +53,113 @@ void Cutter::SetCutList(frm_dir_map_t &deleteMap, PlayerContext *ctx)
}
}

tracker.SetMap(remainingCutList);
m_tracker.SetMap(remainingCutList);
}

frm_dir_map_t Cutter::AdjustedCutList() const
{
return foreshortenedCutList;
return m_foreshortenedCutList;
}

void Cutter::Activate(float v2a, int64_t total)
{
active = true;
audioFramesPerVideoFrame = v2a;
totalFrames = total;
videoFramesToCut = 0;
audioFramesToCut = 0;
tracker.TrackerReset(0);
m_active = true;
m_audioFramesPerVideoFrame = v2a;
m_totalFrames = total;
m_videoFramesToCut = 0;
m_audioFramesToCut = 0;
m_tracker.TrackerReset(0);
}

void Cutter::NewFrame(int64_t currentFrame)
{
if (active)
if (m_active)
{
if (videoFramesToCut == 0)
if (m_videoFramesToCut == 0)
{
uint64_t jumpTo = 0;

if (tracker.TrackerWantsToJump(currentFrame, jumpTo))
if (m_tracker.TrackerWantsToJump(currentFrame, jumpTo))
{
// Reset the tracker and work out how much video and audio
// to drop
tracker.TrackerReset(jumpTo);
videoFramesToCut = jumpTo - currentFrame;
audioFramesToCut += llroundf(videoFramesToCut *
audioFramesPerVideoFrame);
m_tracker.TrackerReset(jumpTo);
m_videoFramesToCut = jumpTo - currentFrame;
m_audioFramesToCut += llroundf(m_videoFramesToCut *
m_audioFramesPerVideoFrame);
LOG(VB_GENERAL, LOG_INFO,
QString("Clean cut: discarding frame from %1 to %2: "
"vid %3 aud %4")
.arg(currentFrame).arg((long)jumpTo)
.arg(videoFramesToCut)
.arg(audioFramesToCut));
.arg(m_videoFramesToCut)
.arg(m_audioFramesToCut));
}
}
}
}

bool Cutter::InhibitUseVideoFrame()
{
if (videoFramesToCut == 0)
if (m_videoFramesToCut == 0)
{
return false;
}
else
{
// We are inside a cut. Inhibit use of this frame
videoFramesToCut--;
m_videoFramesToCut--;

if(videoFramesToCut == 0)
if(m_videoFramesToCut == 0)
LOG(VB_GENERAL, LOG_INFO,
QString("Clean cut: end of video cut; audio frames left "
"to cut %1") .arg(audioFramesToCut));
"to cut %1") .arg(m_audioFramesToCut));

return true;
}
}

bool Cutter::InhibitUseAudioFrames(int64_t frames, long *totalAudio)
{
int64_t delta = audioFramesToCut - frames;
int64_t delta = m_audioFramesToCut - frames;
if (delta < 0)
delta = -delta;

if (audioFramesToCut == 0)
if (m_audioFramesToCut == 0)
{
return false;
}
else if (delta < audioFramesToCut)
else if (delta < m_audioFramesToCut)
{
// Drop the packet containing these frames if doing
// so gets us closer to zero left to drop
audioFramesToCut -= frames;
if(audioFramesToCut == 0)
m_audioFramesToCut -= frames;
if(m_audioFramesToCut == 0)
LOG(VB_GENERAL, LOG_INFO,
QString("Clean cut: end of audio cut; vidio frames left "
"to cut %1") .arg(videoFramesToCut));
"to cut %1") .arg(m_videoFramesToCut));
return true;
}
else
{
// Don't drop this packet even though we still have frames to cut,
// because doing so would put us further out. Instead, inflate the
// callers record of how many audio frames have been output.
*totalAudio += audioFramesToCut;
audioFramesToCut = 0;
*totalAudio += m_audioFramesToCut;
m_audioFramesToCut = 0;
LOG(VB_GENERAL, LOG_INFO,
QString("Clean cut: end of audio cut; vidio frames left to "
"cut %1") .arg(videoFramesToCut));
"cut %1") .arg(m_videoFramesToCut));
return false;
}
}

bool Cutter::InhibitDummyFrame()
{
if (audioFramesToCut > 0)
if (m_audioFramesToCut > 0)
{
// If the cutter is in the process of dropping audio then
// it is better to drop more audio rather than insert a dummy frame
audioFramesToCut += llroundf(audioFramesPerVideoFrame);
m_audioFramesToCut += llroundf(m_audioFramesPerVideoFrame);
return true;
}
else
Expand All @@ -170,18 +170,18 @@ bool Cutter::InhibitDummyFrame()

bool Cutter::InhibitDropFrame()
{
if (audioFramesToCut > llroundf(audioFramesPerVideoFrame))
if (m_audioFramesToCut > llroundf(m_audioFramesPerVideoFrame))
{
// If the cutter is in the process of dropping audio and the
// amount to drop is sufficient then we can drop less
// audio rather than drop a frame
audioFramesToCut -= llroundf(audioFramesPerVideoFrame);
m_audioFramesToCut -= llroundf(m_audioFramesPerVideoFrame);

// But if it's a frame we are supposed to drop anyway, still do so,
// and record that we have
if (videoFramesToCut > 0)
if (m_videoFramesToCut > 0)
{
videoFramesToCut-- ;
m_videoFramesToCut-- ;
return false;
}
else
Expand Down
21 changes: 8 additions & 13 deletions mythtv/programs/mythtranscode/cutter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
class Cutter
{
public:
Cutter()
: active(false), totalFrames(0),
videoFramesToCut(0), audioFramesToCut(0),
audioFramesPerVideoFrame(0.0)
{};

Cutter() = default;
void SetCutList(frm_dir_map_t &deleteMap, PlayerContext *ctx);
frm_dir_map_t AdjustedCutList() const;
void Activate(float v2a, int64_t total);
Expand All @@ -29,13 +24,13 @@ class Cutter
bool InhibitDropFrame(void);

private:
bool active;
frm_dir_map_t foreshortenedCutList;
DeleteMap tracker;
int64_t totalFrames;
int64_t videoFramesToCut;
int64_t audioFramesToCut;
float audioFramesPerVideoFrame;
bool m_active {false};
frm_dir_map_t m_foreshortenedCutList;
DeleteMap m_tracker;
int64_t m_totalFrames {0};
int64_t m_videoFramesToCut {0};
int64_t m_audioFramesToCut {0};
float m_audioFramesPerVideoFrame {0.0};
enum
{
MAXLEADIN = 200,
Expand Down
Loading

0 comments on commit 0000958

Please sign in to comment.