diff --git a/sflphone-common/src/video/test/Makefile.am b/sflphone-common/src/video/test/Makefile.am index 16163bf9f2904ffd77dc166850f45c6d6635212b..8c685e8cc7a564090a57ab1031b1628f2d60bec8 100644 --- a/sflphone-common/src/video/test/Makefile.am +++ b/sflphone-common/src/video/test/Makefile.am @@ -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_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_preview_SOURCES=test_video_preview.cpp test_video_preview.h diff --git a/sflphone-common/src/video/test/test_video_rtp.cpp b/sflphone-common/src/video/test/test_video_rtp.cpp index ed8fa5c0ff57af00746dc7e02a70aaf88c0c32c1..d96092ec3c0b90f39ec9073afbb4a10fa650a57b 100644 --- a/sflphone-common/src/video/test/test_video_rtp.cpp +++ b/sflphone-common/src/video/test/test_video_rtp.cpp @@ -31,20 +31,26 @@ #include <iostream> #include <cassert> #include <unistd.h> // for sleep -#include "test_video_rtp.h" -#include "video_rtp_factory.h" +#include <map> +#include <string> +#include "video_rtp_session.h" -void VideoRtpTest::testRTPSession() +int main (int argc, char* argv[]) { - sfl_video::VideoRtpFactory videortp; - videortp.start(); + 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"; + + 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); - videortp.stop(); -} + videosend.stop(); -int main (int argc, char* argv[]) -{ - VideoRtpTest test; - test.testRTPSession(); return 0; } diff --git a/sflphone-common/src/video/test/test_video_rtp.h b/sflphone-common/src/video/test/test_video_rtp.h deleted file mode 100644 index 2c87a3cf54cf4b86fe7a589b1d1d524056a7d556..0000000000000000000000000000000000000000 --- a/sflphone-common/src/video/test/test_video_rtp.h +++ /dev/null @@ -1,39 +0,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_ diff --git a/sflphone-common/src/video/video_receive_thread.cpp b/sflphone-common/src/video/video_receive_thread.cpp index 819dfbdbf7f94bfa8a685eb6ca4a89f69e05d5c7..a65b323932116963ffc4a79ab81d5318507d2b18 100644 --- a/sflphone-common/src/video/video_receive_thread.cpp +++ b/sflphone-common/src/video/video_receive_thread.cpp @@ -72,7 +72,7 @@ union semun }; #endif -int createSemSet(int shm_id, int shmKey, int *semKey) +int createSemSet(int shmKey, int *semKey) { /* this variable will contain the semaphore set. */ int sem_set_id; @@ -138,6 +138,9 @@ int createShm(unsigned numBytes, int *shmKey) *shmKey = key; shm_id = shmget(key, numBytes, 0644 | IPC_CREAT); + if (shm_id == -1) + perror("shmget"); + return shm_id; } @@ -288,7 +291,7 @@ void VideoReceiveThread::setup() // create shared memory segment and attach to it shmID_ = createShm(videoBufferSize_, &shmKey_); shmBuffer_ = attachShm(shmID_); - semSetID_ = createSemSet(shmID_, shmKey_, &semKey_); + semSetID_ = createSemSet(shmKey_, &semKey_); shmReady_.signal(); // allocate video frame diff --git a/sflphone-common/src/video/video_rtp_factory.cpp b/sflphone-common/src/video/video_rtp_factory.cpp index d1d9296398ae98cc0cc90f9cd5853fccb12edf51..72d6ade6e97c693257b072958d5f676617e95eaa 100644 --- a/sflphone-common/src/video/video_rtp_factory.cpp +++ b/sflphone-common/src/video/video_rtp_factory.cpp @@ -30,14 +30,24 @@ #include "video_rtp_factory.h" #include "video_rtp_session.h" +#include <map> +#include <string> namespace sfl_video { -VideoRtpFactory::VideoRtpFactory() : - session_(new VideoRtpSession("/dev/video0", "mpeg4", 1000000, - "rtp://127.0.0.1:5000")) +VideoRtpFactory::VideoRtpFactory() { + 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() diff --git a/sflphone-common/src/video/video_rtp_factory.h b/sflphone-common/src/video/video_rtp_factory.h index e3ae2ef481730de482679ebb5b9d447b5b8ac85b..6fa3d92ea5d352a6358b449466564583a0bfc38f 100644 --- a/sflphone-common/src/video/video_rtp_factory.h +++ b/sflphone-common/src/video/video_rtp_factory.h @@ -57,4 +57,4 @@ class VideoRtpFactory { }; } -#endif // __VIDEO_RTP_SESSION_H__ +#endif // __VIDEO_RTP_FACTORY_H__ diff --git a/sflphone-common/src/video/video_rtp_session.cpp b/sflphone-common/src/video/video_rtp_session.cpp index 207978b1d211fb0c384c2e11091186647cd989a0..a58944628aa9713377452dc1f4bae60c7a508468 100644 --- a/sflphone-common/src/video/video_rtp_session.cpp +++ b/sflphone-common/src/video/video_rtp_session.cpp @@ -39,12 +39,8 @@ namespace sfl_video { -VideoRtpSession::VideoRtpSession(const std::string &input, - const std::string &codec, - int bitrate, - const std::string &destinationURI) : - input_(input), codec_(codec), bitrate_(bitrate), - destinationURI_(destinationURI) +VideoRtpSession::VideoRtpSession(std::map<std::string,std::string> args) : + args_(args) { } @@ -52,19 +48,8 @@ void VideoRtpSession::test() { assert(sendThread_.get() == 0); assert(receiveThread_.get() == 0); - std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ << - " at " << bitrate_ << " bps, sending to " << destinationURI_ << - 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_.reset(new VideoSendThread(args_)); sendThread_->start(); /* block until SDP is ready */ @@ -75,25 +60,14 @@ void VideoRtpSession::test() void VideoRtpSession::test_loopback() { assert(sendThread_.get() == 0); - std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ << - " at " << bitrate_ << " bps, sending to " << destinationURI_ << - 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_.reset(new VideoSendThread(args_)); sendThread_->start(); sendThread_->waitForSDP(); + std::map<std::string, std::string> args(args_); args["input"] = "test.sdp"; - std::cerr << "Receiving at " << destinationURI_ << - ", writing to shared memory" << std::endl; + receiveThread_.reset(new VideoReceiveThread(args)); receiveThread_->start(); } @@ -102,21 +76,12 @@ void VideoRtpSession::start() { assert(sendThread_.get() == 0); assert(receiveThread_.get() == 0); - std::cerr << "Capturing from " << input_ << ", encoding to " << codec_ << - " at " << bitrate_ << " bps, sending to " << destinationURI_ << - 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_.reset(new VideoSendThread(args_)); sendThread_->start(); + sendThread_->waitForSDP(); + std::map<std::string, std::string> args(args_); args["input"] = "test.sdp"; receiveThread_.reset(new VideoReceiveThread(args)); receiveThread_->start(); diff --git a/sflphone-common/src/video/video_rtp_session.h b/sflphone-common/src/video/video_rtp_session.h index 6d353071d1663899d3160ad333c7fa5ba61ff049..703c5b9abe81787bb808c14bf2f060d2e726b2ec 100644 --- a/sflphone-common/src/video/video_rtp_session.h +++ b/sflphone-common/src/video/video_rtp_session.h @@ -32,6 +32,7 @@ #define __VIDEO_RTP_SESSION_H__ #include <string> +#include <map> #include <tr1/memory> namespace sfl_video { @@ -41,20 +42,16 @@ class VideoReceiveThread; class VideoRtpSession { public: - VideoRtpSession(const std::string &input, const std::string &codec, - int bitrate, const std::string &destinationURI); + VideoRtpSession(std::map<std::string,std::string> args); void start(); void test(); void test_loopback(); void stop(); 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<VideoReceiveThread> receiveThread_; + std::map<std::string,std::string> args_; }; }