Skip to content

Commit

Permalink
adjust timestamps after filtering, not before
Browse files Browse the repository at this point in the history
  • Loading branch information
artclarke committed Aug 20, 2014
1 parent f6370ec commit 10cb830
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions humble-video-native/src/main/gnu/src/io/humble/video/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,29 +400,6 @@ Encoder::encodeAudio(MediaPacket* aOutput, MediaAudio* samples) {
if (samples) {
// make copy so we can modify meta-data
inputAudio = MediaAudio::make(samples, false);
RefPointer<Rational> inputAudioTb = inputAudio->getTimeBase();
/**
* check time stamps and drop frames when needed if the time
* base of the input frame cannot be converted to the encoder
* time base without rounding.
*
*/
int64_t inTs = coderTb->rescale(inputAudio->getTimeStamp(), inputAudioTb.value(), Rational::ROUND_DOWN);
if (mLastPtsEncoded != Global::NO_PTS) {
if (inTs <= mLastPtsEncoded) {
VS_LOG_DEBUG(
"Encoder@%p Dropping frame with timestamp %lld (if coder supports higher time-base use that instead)",
this,
inputAudio->getPts());
dropFrame = true;
}
}
if (!dropFrame) {
mLastPtsEncoded = inTs;
inputAudio->setTimeBase(coderTb.value());
// set the timestamp after the timbase as setTimeBase does a conversion.
inputAudio->setTimeStamp(inTs);
}
}
if (!(codec->getCapabilities() & Codec::CAP_VARIABLE_FRAME_SIZE)) {
// this codec requires that the right number of audio samples
Expand Down Expand Up @@ -457,6 +434,31 @@ Encoder::encodeAudio(MediaPacket* aOutput, MediaAudio* samples) {
} else
inputAudio = 0;
}
if (inputAudio) {
RefPointer<Rational> inputAudioTb = inputAudio->getTimeBase();
/**
* check time stamps and drop frames when needed if the time
* base of the input frame cannot be converted to the encoder
* time base without rounding.
*
*/
int64_t inTs = coderTb->rescale(inputAudio->getTimeStamp(), inputAudioTb.value(), Rational::ROUND_DOWN);
if (mLastPtsEncoded != Global::NO_PTS) {
if (inTs <= mLastPtsEncoded) {
VS_LOG_DEBUG(
"Encoder@%p Dropping frame with timestamp %lld (if coder supports higher time-base use that instead)",
this,
inputAudio->getPts());
dropFrame = true;
}
}
if (!dropFrame) {
mLastPtsEncoded = inTs;
inputAudio->setTimeBase(coderTb.value());
// set the timestamp after the timbase as setTimeBase does a conversion.
inputAudio->setTimeStamp(inTs);
}
}
// now a sanity check
if (!(!samples || !inputAudio || inputAudio->getNumSamples() == getFrameSize())) {
VS_THROW(HumbleRuntimeError::make("not flushing, but samples returned (%ld) are less than frame size (%ld)",
Expand Down

0 comments on commit 10cb830

Please sign in to comment.