Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion source/agent/audio/audioMixer/AcmEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ AcmEncoder::AcmEncoder(const FrameFormat format)
, m_valid(false)
, m_running(false)
, m_incomingFrameCount(0)
, m_lastTimestamp(0)
{
AudioCodingModule::Config config;
m_audioCodingModule.reset(AudioCodingModule::Create(config));
Expand Down Expand Up @@ -175,7 +176,17 @@ int32_t AcmEncoder::SendData(FrameType frame_type,
frame.additionalInfo.audio.channels = getAudioChannels(frame.format);
frame.payload = const_cast<uint8_t*>(payload_data);
frame.length = payload_len_bytes;
frame.timeStamp = (AudioTime::currentTime()) * m_rtpSampleRate / 1000;

int64_t computedTimestamp = AudioTime::currentTime() * m_rtpSampleRate / 1000;
int64_t sizeFor10Ms = m_rtpSampleRate * 10 / 1000 * frame.additionalInfo.audio.channels; //size for 10 ms, such as 48000 * 10/1000 * 2 = 960
Copy link
Collaborator

@daijh daijh Jul 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiply by frame.additionalInfo.audio.channels is not correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, would you please tell me why it's not correct?

int64_t tolerance = sizeFor10Ms * 10; //100ms
if (m_lastTimestamp > 0 && abs((computedTimestamp - m_lastTimestamp) - sizeFor10Ms) <= tolerance) { //for normal case, computedTimestamp - m_lastTimestamp should equlas to sizeFor10Ms
frame.timeStamp = m_lastTimestamp + sizeFor10Ms;
} else {
frame.timeStamp = computedTimestamp;
ELOG_INFO("sendData(), this: %p, timestamp: %ud, diff(%ld) is bigger than tolerance(%ld), current diff: %ld", (void *)this, frame.timeStamp, computedTimestamp - m_lastTimestamp - sizeFor10Ms, tolerance, computedTimestamp - m_lastTimestamp);
}
m_lastTimestamp = frame.timeStamp;

ELOG_TRACE_T("deliverFrame(%s), sampleRate(%d), channels(%d), timeStamp(%d), length(%d), %s",
getFormatStr(frame.format),
Expand Down
2 changes: 2 additions & 0 deletions source/agent/audio/audioMixer/AcmEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class AcmEncoder : public AudioEncoder,

uint32_t m_incomingFrameCount;
boost::shared_ptr<AudioFrame> m_frame;

uint32_t m_lastTimestamp;
};

} /* namespace mcu */
Expand Down
4 changes: 2 additions & 2 deletions source/agent/audio/audioMixer/AudioTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

namespace mcu {

uint32_t AudioTime::sTimestampOffset = 0;
uint64_t AudioTime::sTimestampOffset = 0;

void AudioTime::setTimestampOffset(uint32_t offset)
void AudioTime::setTimestampOffset(uint64_t offset)
{
sTimestampOffset = offset;
}
Expand Down
5 changes: 2 additions & 3 deletions source/agent/audio/audioMixer/AudioTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
namespace mcu {

class AudioTime {

public:
static int64_t currentTime(void); //Millisecond
static void setTimestampOffset(uint32_t offset);
static void setTimestampOffset(uint64_t offset);

private:
static uint32_t sTimestampOffset;
static uint64_t sTimestampOffset;

};

Expand Down