mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
filesharing: use mediaplayer
GitLab: #485 Change-Id: Ie3f129cd0cee14a97764eb22ee2b5f530a3f3023
This commit is contained in:

committed by
Sébastien Blin

parent
39b9cf9608
commit
809600018b
@ -75,17 +75,19 @@ public:
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
std::string aliceId;
|
||||
std::string bobId;
|
||||
std::string recordDir;
|
||||
std::string recordedFile;
|
||||
std::string aliceId {};
|
||||
std::string bobId {};
|
||||
std::string recordDir {};
|
||||
std::string recordedFile {};
|
||||
std::string playerId {};
|
||||
std::shared_ptr<MediaPlayer> player {};
|
||||
CallData bobCall {};
|
||||
|
||||
std::mutex mtx;
|
||||
std::unique_lock<std::mutex> lk {mtx};
|
||||
std::condition_variable cv;
|
||||
|
||||
std::string videoPath = std::filesystem::absolute("media/test_video_file.mp4").string();
|
||||
std::string videoPath = "file://" + std::filesystem::absolute("media/test_video_file.mp4").string();
|
||||
|
||||
private:
|
||||
void registerSignalHandlers();
|
||||
@ -118,6 +120,10 @@ RecorderTest::setUp()
|
||||
aliceId = actors["alice"];
|
||||
bobId = actors["bob"];
|
||||
bobCall.reset();
|
||||
playerId = jami::createMediaPlayer(videoPath);
|
||||
player = jami::getMediaPlayer(playerId);
|
||||
player->setAutoRestart(true);
|
||||
player->pause(false);
|
||||
|
||||
libjami::setRecordPath(recordDir);
|
||||
}
|
||||
@ -127,6 +133,7 @@ RecorderTest::tearDown()
|
||||
{
|
||||
libjami::setIsAlwaysRecording(false);
|
||||
dhtnet::fileutils::removeAll(recordDir);
|
||||
player.reset();
|
||||
|
||||
wait_for_removal_of({aliceId, bobId});
|
||||
}
|
||||
@ -210,7 +217,7 @@ RecorderTest::testRecordCall()
|
||||
{libjami::Media::MediaAttributeKey::ENABLED, TRUE_STR},
|
||||
{libjami::Media::MediaAttributeKey::MUTED, FALSE_STR},
|
||||
{libjami::Media::MediaAttributeKey::LABEL, "video_0"},
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, "file://" + videoPath}};
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, videoPath}};
|
||||
mediaList.emplace_back(mediaAttributeA);
|
||||
auto callId = libjami::placeCallWithMedia(aliceId, bobUri, mediaList);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !bobCall.callId.empty(); }));
|
||||
@ -406,7 +413,7 @@ RecorderTest::testStopCallWhileRecording()
|
||||
{libjami::Media::MediaAttributeKey::ENABLED, TRUE_STR},
|
||||
{libjami::Media::MediaAttributeKey::MUTED, FALSE_STR},
|
||||
{libjami::Media::MediaAttributeKey::LABEL, "video_0"},
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, "file://" + videoPath}};
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, videoPath}};
|
||||
mediaList.emplace_back(mediaAttributeA);
|
||||
mediaList.emplace_back(mediaAttributeV);
|
||||
auto callId = libjami::placeCallWithMedia(aliceId, bobUri, mediaList);
|
||||
@ -458,7 +465,7 @@ RecorderTest::testDaemonPreference()
|
||||
{libjami::Media::MediaAttributeKey::ENABLED, TRUE_STR},
|
||||
{libjami::Media::MediaAttributeKey::MUTED, FALSE_STR},
|
||||
{libjami::Media::MediaAttributeKey::LABEL, "video_0"},
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, "file://" + videoPath}};
|
||||
{libjami::Media::MediaAttributeKey::SOURCE, videoPath}};
|
||||
mediaList.emplace_back(mediaAttributeA);
|
||||
mediaList.emplace_back(mediaAttributeV);
|
||||
auto callId = libjami::placeCallWithMedia(aliceId, bobUri, mediaList);
|
||||
|
@ -56,9 +56,9 @@ private:
|
||||
|
||||
std::string playerId1_ {};
|
||||
std::string playerId2_ {};
|
||||
std::string duration_ {};
|
||||
std::string audio_stream_ {};
|
||||
std::string video_stream_ {};
|
||||
int64_t duration_ {};
|
||||
int audio_stream_ {};
|
||||
int video_stream_ {};
|
||||
std::shared_ptr<MediaPlayer> mediaPlayer {};
|
||||
|
||||
std::mutex mtx;
|
||||
@ -79,45 +79,53 @@ MediaPlayerTest::setUp()
|
||||
handler.insert(libjami::exportable_callback<libjami::MediaPlayerSignal::FileOpened>(
|
||||
[=](const std::string& playerId,
|
||||
const std::map<std::string, std::string>& info) {
|
||||
duration_ = info.at("duration");
|
||||
audio_stream_ = info.at("audio_stream");
|
||||
video_stream_ = info.at("video_stream");
|
||||
duration_ = std::stol(info.at("duration"));
|
||||
audio_stream_ = std::stoi(info.at("audio_stream"));
|
||||
video_stream_ = std::stoi(info.at("video_stream"));
|
||||
playerId2_ = playerId;
|
||||
cv.notify_all();
|
||||
}));
|
||||
|
||||
libjami::registerSignalHandlers(handler);
|
||||
|
||||
playerId1_ = libjami::createMediaPlayer(filePath);
|
||||
mediaPlayer = Manager::instance().getVideoManager().mediaPlayers[playerId1_];
|
||||
playerId1_ = jami::createMediaPlayer(filePath);
|
||||
mediaPlayer = jami::getMediaPlayer(playerId1_);
|
||||
cv.wait_for(lk, 5s);
|
||||
}
|
||||
|
||||
void
|
||||
MediaPlayerTest::tearDown()
|
||||
{
|
||||
jami::closeMediaPlayer(playerId1_);
|
||||
mediaPlayer.reset();
|
||||
playerId1_ = {};
|
||||
playerId2_ = {};
|
||||
libjami::fini();
|
||||
}
|
||||
|
||||
void
|
||||
MediaPlayerTest::testCreate()
|
||||
{
|
||||
JAMI_INFO() << "Start testCreate";
|
||||
CPPUNIT_ASSERT(playerId1_ == playerId2_);
|
||||
CPPUNIT_ASSERT(mediaPlayer->getId() == playerId1_);
|
||||
CPPUNIT_ASSERT(mediaPlayer->isInputValid());
|
||||
CPPUNIT_ASSERT(audio_stream_ != "-1");
|
||||
CPPUNIT_ASSERT(video_stream_ != "-1");
|
||||
CPPUNIT_ASSERT(audio_stream_ != -1);
|
||||
CPPUNIT_ASSERT(video_stream_ != -1);
|
||||
CPPUNIT_ASSERT(mediaPlayer->isPaused());
|
||||
CPPUNIT_ASSERT(mediaPlayer->getPlayerPosition() == 0);
|
||||
JAMI_INFO() << "End testCreate";
|
||||
}
|
||||
|
||||
void
|
||||
MediaPlayerTest::testPause()
|
||||
{
|
||||
mediaPlayer->pause(true);
|
||||
JAMI_INFO() << "Start testPause";
|
||||
// should start paused
|
||||
CPPUNIT_ASSERT(mediaPlayer->isPaused());
|
||||
mediaPlayer->pause(false);
|
||||
CPPUNIT_ASSERT(!mediaPlayer->isPaused());
|
||||
JAMI_INFO() << "End testPause";
|
||||
}
|
||||
|
||||
bool
|
||||
@ -129,10 +137,9 @@ MediaPlayerTest::isWithinUsec(int64_t currentTime, int64_t seekTime, int64_t mar
|
||||
void
|
||||
MediaPlayerTest::testSeekWhilePaused()
|
||||
{
|
||||
mediaPlayer->pause(true);
|
||||
JAMI_INFO() << "Start testSeekWhilePaused";
|
||||
|
||||
int64_t startTime = mediaPlayer->getPlayerPosition();
|
||||
int64_t duration = std::stoi(duration_);
|
||||
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(startTime+100));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), startTime+100, 1));
|
||||
@ -143,18 +150,20 @@ MediaPlayerTest::testSeekWhilePaused()
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(startTime+500));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), startTime+500, 1));
|
||||
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(duration-1));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), duration-1, 1));
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(duration_-1));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), duration_-1, 1));
|
||||
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(0));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), 0, 1));
|
||||
|
||||
CPPUNIT_ASSERT(!(mediaPlayer->seekToTime(duration+1)));
|
||||
CPPUNIT_ASSERT(!(mediaPlayer->seekToTime(duration_+1)));
|
||||
JAMI_INFO() << "End testSeekWhilePaused";
|
||||
}
|
||||
|
||||
void
|
||||
MediaPlayerTest::testSeekWhilePlaying()
|
||||
{
|
||||
JAMI_INFO() << "Start testSeekWhilePlaying";
|
||||
mediaPlayer->pause(false);
|
||||
|
||||
int64_t startTime = mediaPlayer->getPlayerPosition();
|
||||
@ -172,7 +181,8 @@ MediaPlayerTest::testSeekWhilePlaying()
|
||||
CPPUNIT_ASSERT(mediaPlayer->seekToTime(0));
|
||||
CPPUNIT_ASSERT(isWithinUsec(mediaPlayer->getPlayerPosition(), 0, 50));
|
||||
|
||||
CPPUNIT_ASSERT(!(mediaPlayer->seekToTime(std::stoi(duration_)+1)));
|
||||
CPPUNIT_ASSERT(!(mediaPlayer->seekToTime(duration_+1)));
|
||||
JAMI_INFO() << "End testSeekWhilePlaying";
|
||||
}
|
||||
|
||||
}} // namespace jami::test
|
||||
|
Reference in New Issue
Block a user