-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: pingkai <[email protected]>
- Loading branch information
Showing
11 changed files
with
363 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// Created by moqi on 2020/1/10. | ||
// | ||
|
||
#include <utils/ffmpeg_utils.h> | ||
#include <base/media/AVAFPacket.h> | ||
#include "CheaterAudioRender.h" | ||
|
||
int Cicada::CheaterAudioRender::init_device() | ||
{ | ||
mOutputInfo.format = AF_SAMPLE_FMT_S16; | ||
mOutputInfo.sample_rate = 44100; | ||
mOutputInfo.channels = std::min(mInputInfo.channels, 2); | ||
mClock.set(0); | ||
mClock.start(); | ||
return 0; | ||
} | ||
|
||
int Cicada::CheaterAudioRender::pause_device() | ||
{ | ||
mClock.pause(); | ||
return 0; | ||
} | ||
|
||
int Cicada::CheaterAudioRender::start_device() | ||
{ | ||
mClock.start(); | ||
return 0; | ||
} | ||
|
||
void Cicada::CheaterAudioRender::flush_device() | ||
{ | ||
mClock.reset(); | ||
mPCMDuration = 0; | ||
} | ||
|
||
int64_t Cicada::CheaterAudioRender::device_get_position() | ||
{ | ||
int64_t clock = mClock.get(); | ||
if (clock > mPCMDuration) { | ||
mClock.set(mPCMDuration); | ||
return mPCMDuration; | ||
} | ||
return clock; | ||
} | ||
|
||
int Cicada::CheaterAudioRender::device_write(unique_ptr<IAFFrame> &frame) | ||
{ | ||
if (!frame) | ||
return 0; | ||
if (mPCMDuration - mClock.get() > 1000000) { | ||
return -EAGAIN; | ||
} | ||
auto *avafFrame = dynamic_cast<AVAFFrame *> (frame.get()); | ||
if (avafFrame) { | ||
int duration = getPCMFrameDuration(avafFrame->ToAVFrame()); | ||
if (duration > 0) | ||
mPCMDuration += duration; | ||
} | ||
frame = nullptr; | ||
return 0; | ||
} | ||
|
||
uint64_t Cicada::CheaterAudioRender::device_get_que_duration() | ||
{ | ||
int64_t clock = mClock.get(); | ||
return std::max((int64_t) 0, mPCMDuration - clock); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// Created by moqi on 2020/1/10. | ||
// | ||
|
||
#ifndef CICADAMEDIA_CHEATERAUDIORENDER_H | ||
#define CICADAMEDIA_CHEATERAUDIORENDER_H | ||
|
||
#include "filterAudioRender.h" | ||
#include "utils/af_clock.h" | ||
|
||
namespace Cicada { | ||
class CheaterAudioRender : public filterAudioRender { | ||
public: | ||
CheaterAudioRender() | ||
{ | ||
|
||
} | ||
|
||
~CheaterAudioRender() override | ||
{ | ||
|
||
} | ||
|
||
private: | ||
int init_device() override; | ||
|
||
int pause_device() override; | ||
|
||
int start_device() override; | ||
|
||
void flush_device() override; | ||
|
||
void device_setVolume(float gain) override | ||
{ | ||
|
||
} | ||
|
||
int64_t device_get_position() override; | ||
|
||
int device_write(unique_ptr<IAFFrame> &frame) override; | ||
|
||
uint64_t device_get_que_duration() override; | ||
|
||
private: | ||
af_clock mClock{}; | ||
int64_t mPCMDuration{0}; | ||
|
||
|
||
}; | ||
} | ||
|
||
|
||
#endif //CICADAMEDIA_CHEATERAUDIORENDER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.