Skip to content

Commit

Permalink
revert playing workflow...
Browse files Browse the repository at this point in the history
  • Loading branch information
zhang-ray committed Nov 5, 2018
1 parent 3c51869 commit 33b6cd3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions client_essential/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ using namespace webrtc;

Worker::Worker(bool needAec)
:needAec_(needAec)
#ifdef RINGBUFFER
, s2cPcmBuffer_(sizeof(short)*160,100)
#endif
{
if (needAec_){
aec = WebRtcAec_Create();
Expand Down Expand Up @@ -95,8 +97,8 @@ bool Worker::initDevice(std::function<void(const std::string &, const std::strin
vadReporter_ = vadReporter;

/// TODO: LPC

playbackThread_ = std::make_shared<std::thread>([this](){
#ifdef RINGBUFFER
playbackThread_ = std::make_shared<std::thread>([this]() {
std::vector<short> pcmLPC(s2cPcmBuffer_.bytePerElement(), 0);
std::vector<short> tmp(s2cPcmBuffer_.bytePerElement());

Expand Down Expand Up @@ -133,7 +135,7 @@ bool Worker::initDevice(std::function<void(const std::string &, const std::strin
}
}
});

#endif // RINGBUFFER
return true;
}
return false;
Expand Down Expand Up @@ -186,11 +188,14 @@ void Worker::syncStart(const std::string &host,const std::string &port,
}
}

#ifdef RINGBUFFER
auto bRet = s2cPcmBuffer_.pushElements((uint8_t*)decodedPcm.data(), 1);
if (!bRet){
//qDebug() << "pushElements failed!";
}

#else //RINGBUFFER
device_->write(decodedPcm);
#endif
break;
}
}
Expand Down
4 changes: 4 additions & 0 deletions include/evc/Worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <memory>
#include <thread>
#include <string>
#ifdef RINGBUFFER
#include "evc/RingBuffer.hpp"
#endif // RINGBUFFER
#include "evc/AudioVolume.hpp"

class AudioDecoder;
Expand Down Expand Up @@ -67,7 +69,9 @@ class Worker {
SuckAudioVolume sav;
private:
std::shared_ptr<std::thread> playbackThread_ = nullptr;
#ifdef RINGBUFFER
RingBuffer s2cPcmBuffer_;
#endif // RINGBUFFER
public:
Worker(bool needAec);
~Worker();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/RingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(void){
printf("pop failed\n");
}
else {
printf("got %d, remain %d element(s)\n" , data, ringBuff.size());
printf("got %d, \t remain %d \t element(s)\n" , data, ringBuff.size());
}

std::this_thread::sleep_for(std::chrono::milliseconds(5));
Expand Down

0 comments on commit 33b6cd3

Please sign in to comment.