Last active
February 24, 2020 07:58
-
-
Save aisouard/537c2a42cc5bbb8da292 to your computer and use it in GitHub Desktop.
peeracle-sample-1
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
using namespace peeracle; | |
// Ouvrir le fichier de métadonnées | |
DataStreamInit init; | |
init.path = "./ma_video.peeracle"; | |
DataStreamInterface *dataStream = new FileDataStream(init); | |
// Charger le fichier de métadonnées | |
MetadataInterface *metadata = new Metadata(); | |
metadata->unserialize(dataStream); | |
// Créer un SessionObserver | |
class MySessionObserver : public SessionObserver { | |
void onTrackerConnect(TrackerClientInterface *tracker) { | |
std::cout << "Connecte au tracker " << tracker->getUrl() << std::endl; | |
} | |
void onTrackerDisconnect(TrackerClientInterface *tracker) { | |
std::cout << "Deconnecte du tracker " << tracker->getUrl() << std::endl; | |
} | |
void onPeer(TrackerClientInterface *tracker, const std::string &peerId, | |
const std::string &hash, uint32_t got) { | |
std::cout << "Nouveau peer " << peerId << " pour le media " << hash << | |
std::endl; | |
} | |
}; | |
SessionObserver *sessionObserver = new MySessionObserver(); | |
// Créer une Session | |
SessionInterface *session = new Session(sessionObserver); | |
// Créer un SessionHandleObserver | |
class MySessionHandleObserver : public SessionHandleObserver { | |
void onMediaSegment(uint32_t timecode, const uint8_t *bytes) { | |
std::cout << "J'ai recu le segment " << timecode << std::endl; | |
// Passer les bytes dans le lecteur média. | |
} | |
}; | |
SessionHandleObserver *handleObserver = new MySessionHandleObserver(); | |
// Ajouter le fichier de métadonnées | |
SessionHandleInterface *handle = session->addMetadata(metadata, handleObserver); | |
// Démarrer la session | |
handle->start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment