服务器live555
客户端(Qt) vlc api
不是直播,是点播
关于live555配置http://www.cnblogs.com/azraelly/articles/2445477.html
关于 vlc 调用 http://blog.chinaunix.net/uid-26611383-id-3789962.html
只是live555 testOnDemandRTSPServer.cpp
服务器端
#include "stdafx.h"
#include "liveMedia.hh"
#include "BasicUsageEnvironment.hh"
UsageEnvironment* env;
// To make the second and subsequent client for each stream reuse the same
// input stream as the first client (rather than playing the file from the
// start for each client), change the following "False" to "True":
Boolean reuseFirstSource = False;
// To stream *only* MPEG-1 or 2 video "I" frames
// (e.g., to reduce network bandwidth),
// change the following "False" to "True":
Boolean iFramesOnly = False;
static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
char const* streamName, char const* inputFileName); // fwd
static char newDemuxWatchVariable;
static MatroskaFileServerDemux* matroskaDemux;
static void onMatroskaDemuxCreation(MatroskaFileServerDemux* newDemux, void* /*clientData*/) {
matroskaDemux = newDemux;
newDemuxWatchVariable = 1;
}
static OggFileServerDemux* oggDemux;
static void onOggDemuxCreation(OggFileServerDemux* newDemux, void* /*clientData*/) {
oggDemux = newDemux;
newDemuxWatchVariable = 1;
}
int main(int argc, char** argv) {
// Begin by setting up our usage environment:
TaskScheduler* scheduler = BasicTaskScheduler::createNew();
env = BasicUsageEnvironment::createNew(*scheduler);
UserAuthenticationDatabase* authDB = NULL;
// Create the RTSP server:
RTSPServer* rtspServer = RTSPServer::createNew(*env, 8554, authDB);
if (rtspServer == NULL) {
*env << "Failed to create RTSP server: " << env->getResultMsg() << "\n";
exit(1);
}
char const* descriptionString
= "Session streamed by \"testOnDemandRTSPServer\"";
// A MP3 audio stream (actually, any MPEG-1 or 2 audio file will work):
// To stream using 'ADUs' rather than raw MP3 frames, uncomment the following:
//#define STREAM_USING_ADUS 1
// To also reorder ADUs before streaming, uncomment the following:
//#define INTERLEAVE_ADUS 1
// (For more information about ADUs and interleaving,
// see <http://www.live555.com/rtp-mp3/>)
{
char const* streamName = "mp3AudioTest";
char const* inputFileName = "test.mp3";
ServerMediaSession* sms
= ServerMediaSession::createNew(*env, streamName, streamName,
descriptionString);
Boolean useADUs = False;
Interleaving* interleaving = NULL;
sms->addSubsession(MP3AudioFileServerMediaSubsession
::createNew(*env, inputFileName, reuseFirstSource,
useADUs, interleaving));
rtspServer->addServerMediaSession(sms);
announceStream(rtspServer, sms, streamName, inputFileName);
}
// Also, attempt to create a HTTP server for RTSP-over-HTTP tunneling.
// Try first with the default HTTP port (80), and then with the alternative HTTP
// port numbers (8000 and 8080).
if (rtspServer->setUpTunnelingOverHTTP(80) || rtspServer->setUpTunnelingOverHTTP(8000) || rtspServer->setUpTunnelingOverHTTP(8080)) {
*env << "\n(We use port " << rtspServer->httpServerPortNum() << " for optional RTSP-over-HTTP tunneling.)\n";
} else {
*env << "\n(RTSP-over-HTTP tunneling is not available.)\n";
}
env->taskScheduler().doEventLoop(); // does not return
return 0; // only to prevent compiler warning
}
static void announceStream(RTSPServer* rtspServer, ServerMediaSession* sms,
char const* streamName, char const* inputFileName) {
char* url = rtspServer->rtspURL(sms);
UsageEnvironment& env = rtspServer->envir();
env << "\n\"" << streamName << "\" stream, from the file \""
<< inputFileName << "\"\n";
env << "Play this stream using the URL \"" << url << "\"\n";
delete[] url;
}
Qt 播放
#include "vlcpaler.h"
#include <QMessageBox>
vlcpaler::vlcpaler(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
vlcPlayer = NULL;
/* Init libVLC */
if((vlcObject = libvlc_new(0,NULL)) == NULL) {
printf("Could not init libVLC");
exit(1);
}
b_state = false;
connect(ui.pushButton,SIGNAL(clicked()),this,SLOT(StartPlay()));
}
vlcpaler::~vlcpaler()
{
if(vlcObject)
libvlc_release(vlcObject);
}
void vlcpaler::StartPlay()
{
if( vlcPlayer && libvlc_media_player_is_playing(vlcPlayer) )
Stop();
// New Media
libvlc_media_t *vlcMedia = libvlc_media_new_location(vlcObject,"rtsp://192.168.126.1:8554/mp3AudioTest");
if( !vlcMedia )
return;
vlcPlayer = libvlc_media_player_new_from_media (vlcMedia);
libvlc_media_release(vlcMedia);
/* And play */
libvlc_media_player_play (vlcPlayer);
if(!b_state){
ui.pushButton->setText(tr("pause"));
}else{
ui.pushButton->setText(tr("paly"));
}
b_state = !b_state;
}
void vlcpaler::Stop() {
if(vlcPlayer) {
libvlc_media_player_stop(vlcPlayer);
libvlc_media_player_release(vlcPlayer);
ui.pushButton->setText(tr("paly"));
}
vlcPlayer = NULL;
}
ok.