Skip to content
Snippets Groups Projects
Commit d19747e3 authored by Rafaël Carré's avatar Rafaël Carré
Browse files

test_video_rtp: use VideoRtpSession instead of RtpFactory

VideoRtpSession and VideoRtpFactory now take a std::map in ctor
parent c6d3bd49
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ check_PROGRAMS=test_video_endpoint test_video_rtp test_thread test_video_preview ...@@ -5,7 +5,7 @@ check_PROGRAMS=test_video_endpoint test_video_rtp test_thread test_video_preview
test_video_endpoint_SOURCES=test_video_endpoint.cpp test_video_endpoint.h test_video_endpoint_SOURCES=test_video_endpoint.cpp test_video_endpoint.h
test_video_endpoint_LDADD=$(top_builddir)/src/video/libvideo.la test_video_endpoint_LDADD=$(top_builddir)/src/video/libvideo.la
test_video_rtp_SOURCES=test_video_rtp.cpp test_video_rtp.h test_video_rtp_SOURCES=test_video_rtp.cpp
test_video_rtp_LDADD=$(top_builddir)/src/libsflphone.la test_video_rtp_LDADD=$(top_builddir)/src/libsflphone.la
test_video_preview_SOURCES=test_video_preview.cpp test_video_preview.h test_video_preview_SOURCES=test_video_preview.cpp test_video_preview.h
......
...@@ -31,20 +31,26 @@ ...@@ -31,20 +31,26 @@
#include <iostream> #include <iostream>
#include <cassert> #include <cassert>
#include <unistd.h> // for sleep #include <unistd.h> // for sleep
#include "test_video_rtp.h" #include <map>
#include "video_rtp_factory.h" #include <string>
#include "video_rtp_session.h"
void VideoRtpTest::testRTPSession() int main (int argc, char* argv[])
{ {
sfl_video::VideoRtpFactory videortp; std::map<std::string, std::string> args;
videortp.start(); args["input"] = "/dev/video0";
args["codec"] = "mpeg4";
args["bitrate"] = "1000000";
args["destination"] = "rtp://127.0.0.1:5000";
args["format"] = "rgb24";
args["width"] = "640";
args["height"] = "480";
sfl_video::VideoRtpSession videosend(args);
//sfl_video::VideoRtpSession videorecv("rtp://127.0.0.1:5000", "libx264", 1000000, "rtp://127.0.0.1:5000", "rgb24");
videosend.start();
sleep(10); sleep(10);
videortp.stop(); videosend.stop();
}
int main (int argc, char* argv[])
{
VideoRtpTest test;
test.testRTPSession();
return 0; return 0;
} }
/*
* Copyright (C) 2011 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#ifndef _VIDEO_RTP_TEST_
#define _VIDEO_RTP_TEST_
class VideoRtpTest {
public:
void testRTPSession();
};
#endif // _VIDEO_RTP_TEST_
...@@ -72,7 +72,7 @@ union semun ...@@ -72,7 +72,7 @@ union semun
}; };
#endif #endif
int createSemSet(int shm_id, int shmKey, int *semKey) int createSemSet(int shmKey, int *semKey)
{ {
/* this variable will contain the semaphore set. */ /* this variable will contain the semaphore set. */
int sem_set_id; int sem_set_id;
...@@ -138,6 +138,9 @@ int createShm(unsigned numBytes, int *shmKey) ...@@ -138,6 +138,9 @@ int createShm(unsigned numBytes, int *shmKey)
*shmKey = key; *shmKey = key;
shm_id = shmget(key, numBytes, 0644 | IPC_CREAT); shm_id = shmget(key, numBytes, 0644 | IPC_CREAT);
if (shm_id == -1)
perror("shmget");
return shm_id; return shm_id;
} }
...@@ -288,7 +291,7 @@ void VideoReceiveThread::setup() ...@@ -288,7 +291,7 @@ void VideoReceiveThread::setup()
// create shared memory segment and attach to it // create shared memory segment and attach to it
shmID_ = createShm(videoBufferSize_, &shmKey_); shmID_ = createShm(videoBufferSize_, &shmKey_);
shmBuffer_ = attachShm(shmID_); shmBuffer_ = attachShm(shmID_);
semSetID_ = createSemSet(shmID_, shmKey_, &semKey_); semSetID_ = createSemSet(shmKey_, &semKey_);
shmReady_.signal(); shmReady_.signal();
// allocate video frame // allocate video frame
......
...@@ -30,14 +30,24 @@ ...@@ -30,14 +30,24 @@
#include "video_rtp_factory.h" #include "video_rtp_factory.h"
#include "video_rtp_session.h" #include "video_rtp_session.h"
#include <map>
#include <string>
namespace sfl_video namespace sfl_video
{ {
VideoRtpFactory::VideoRtpFactory() : VideoRtpFactory::VideoRtpFactory()
session_(new VideoRtpSession("/dev/video0", "mpeg4", 1000000,
"rtp://127.0.0.1:5000"))
{ {
std::map<std::string, std::string> args;
args["input"] = "/dev/video0";
args["codec"] = "mpeg4";
args["bitrate"] = "1000000";
args["destination"] = "rtp://127.0.0.1:5000";
args["format"] = "rgb24";
args["width"] = "640";
args["height"] = "480";
session_ = std::tr1::shared_ptr<VideoRtpSession>(new VideoRtpSession(args));
} }
void VideoRtpFactory::start() void VideoRtpFactory::start()
......
...@@ -57,4 +57,4 @@ class VideoRtpFactory { ...@@ -57,4 +57,4 @@ class VideoRtpFactory {
}; };
} }
#endif // __VIDEO_RTP_SESSION_H__ #endif // __VIDEO_RTP_FACTORY_H__
...@@ -39,12 +39,8 @@ ...@@ -39,12 +39,8 @@
namespace sfl_video { namespace sfl_video {
VideoRtpSession::VideoRtpSession(const std::string &input, VideoRtpSession::VideoRtpSession(std::map<std::string,std::string> args) :
const std::string &codec, args_(args)
int bitrate,
const std::string &destinationURI) :
input_(input), codec_(codec), bitrate_(bitrate),
destinationURI_(destinationURI)
{ {
} }
...@@ -52,19 +48,8 @@ void VideoRtpSession::test() ...@@ -52,19 +48,8 @@ void VideoRtpSession::test()
{ {
assert(sendThread_.get() == 0); assert(sendThread_.get() == 0);
assert(receiveThread_.get() == 0); assert(receiveThread_.get() == 0);
std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ <<
" at " << bitrate_ << " bps, sending to " << destinationURI_ << sendThread_.reset(new VideoSendThread(args_));
std::endl;
std::map<std::string, std::string> args;
args["input"] = input_;
args["codec"] = codec_;
std::stringstream bitstr;
bitstr << bitrate_;
args["bitrate"] = bitstr.str();
args["destination"] = destinationURI_;
sendThread_.reset(new VideoSendThread(args));
sendThread_->start(); sendThread_->start();
/* block until SDP is ready */ /* block until SDP is ready */
...@@ -75,25 +60,14 @@ void VideoRtpSession::test() ...@@ -75,25 +60,14 @@ void VideoRtpSession::test()
void VideoRtpSession::test_loopback() void VideoRtpSession::test_loopback()
{ {
assert(sendThread_.get() == 0); assert(sendThread_.get() == 0);
std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ <<
" at " << bitrate_ << " bps, sending to " << destinationURI_ << sendThread_.reset(new VideoSendThread(args_));
std::endl;
std::map<std::string, std::string> args;
args["input"] = input_;
args["codec"] = codec_;
std::stringstream bitstr;
bitstr << bitrate_;
args["bitrate"] = bitstr.str();
args["destination"] = destinationURI_;
sendThread_.reset(new VideoSendThread(args));
sendThread_->start(); sendThread_->start();
sendThread_->waitForSDP(); sendThread_->waitForSDP();
std::map<std::string, std::string> args(args_);
args["input"] = "test.sdp"; args["input"] = "test.sdp";
std::cerr << "Receiving at " << destinationURI_ <<
", writing to shared memory" << std::endl;
receiveThread_.reset(new VideoReceiveThread(args)); receiveThread_.reset(new VideoReceiveThread(args));
receiveThread_->start(); receiveThread_->start();
} }
...@@ -102,21 +76,12 @@ void VideoRtpSession::start() ...@@ -102,21 +76,12 @@ void VideoRtpSession::start()
{ {
assert(sendThread_.get() == 0); assert(sendThread_.get() == 0);
assert(receiveThread_.get() == 0); assert(receiveThread_.get() == 0);
std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ <<
" at " << bitrate_ << " bps, sending to " << destinationURI_ << sendThread_.reset(new VideoSendThread(args_));
std::endl;
std::map<std::string, std::string> args;
args["input"] = input_;
args["codec"] = codec_;
std::stringstream bitstr;
bitstr << bitrate_;
args["bitrate"] = bitstr.str();
args["destination"] = destinationURI_;
sendThread_.reset(new VideoSendThread(args));
sendThread_->start(); sendThread_->start();
sendThread_->waitForSDP();
std::map<std::string, std::string> args(args_);
args["input"] = "test.sdp"; args["input"] = "test.sdp";
receiveThread_.reset(new VideoReceiveThread(args)); receiveThread_.reset(new VideoReceiveThread(args));
receiveThread_->start(); receiveThread_->start();
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define __VIDEO_RTP_SESSION_H__ #define __VIDEO_RTP_SESSION_H__
#include <string> #include <string>
#include <map>
#include <tr1/memory> #include <tr1/memory>
namespace sfl_video { namespace sfl_video {
...@@ -41,20 +42,16 @@ class VideoReceiveThread; ...@@ -41,20 +42,16 @@ class VideoReceiveThread;
class VideoRtpSession { class VideoRtpSession {
public: public:
VideoRtpSession(const std::string &input, const std::string &codec, VideoRtpSession(std::map<std::string,std::string> args);
int bitrate, const std::string &destinationURI);
void start(); void start();
void test(); void test();
void test_loopback(); void test_loopback();
void stop(); void stop();
private: private:
const std::string input_;
const std::string codec_;
const int bitrate_;
const std::string destinationURI_;
std::tr1::shared_ptr<VideoSendThread> sendThread_; std::tr1::shared_ptr<VideoSendThread> sendThread_;
std::tr1::shared_ptr<VideoReceiveThread> receiveThread_; std::tr1::shared_ptr<VideoReceiveThread> receiveThread_;
std::map<std::string,std::string> args_;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment