Commit 46d8dad0 authored by Damien Lucas's avatar Damien Lucas

. First version of a tcpinput/tcpreader

  . reads a stream directly over tcp
  . no options available right now
parent 8f629f93
......@@ -101,6 +101,17 @@ V4LINPUT_CCFLAGS = @V4LINPUT_CCFLAGS@
V4LINPUT_DCFLAGS = @V4LINPUT_DCFLAGS@
V4LINPUT_LCFLAGS = @V4LINPUT_LCFLAGS@
TCPINPUT_LIB = @TCPINPUT_LIB@
TCPINPUT_CCFLAGS = @TCPINPUT_CCFLAGS@
TCPINPUT_DCFLAGS = @TCPINPUT_DCFLAGS@
TCPINPUT_LCFLAGS = @TCPINPUT_LCFLAGS@
TCPREADER_LIB = @TCPREADER_LIB@
TCPREADER_CCFLAGS = @TCPREADER_CCFLAGS@
TCPREADER_DCFLAGS = @TCPREADER_DCFLAGS@
TCPREADER_LCFLAGS = @TCPREADER_LCFLAGS@
BUILTINS_LIB = $(patsubst %,$$%_LIB,$(shell echo ${BUILTINS} | tr '[a-z]' '[A-Z]'))
VLS_LIB += $(BUILTINS_LIB)
......
......@@ -242,7 +242,7 @@ ARCH=${target_cpu}
dnl
dnl default modules
dnl
BUILTINS="${BUILTINS} filechannel netchannel filereader ts2ts ps2ts localinput videoinput dummyinterface telnetinterface nativeinterface normaltrickplay"
BUILTINS="${BUILTINS} filechannel netchannel filereader ts2ts ps2ts localinput videoinput dummyinterface telnetinterface nativeinterface normaltrickplay tcpinput tcpreader"
dnl
dnl Debugging mode
......@@ -550,6 +550,16 @@ AC_SUBST(V4LINPUT_CCFLAGS)
AC_SUBST(V4LINPUT_DCFLAGS)
AC_SUBST(V4LINPUT_LCFLAGS)
AC_SUBST(TCPINPUT_LIB)
AC_SUBST(TCPINPUT_CCFLAGS)
AC_SUBST(TCPINPUT_DCFLAGS)
AC_SUBST(TCPINPUT_LCFLAGS)
AC_SUBST(TCPREADER_LIB)
AC_SUBST(TCPREADER_CCFLAGS)
AC_SUBST(TCPREADER_DCFLAGS)
AC_SUBST(TCPREADER_LCFLAGS)
AC_SUBST(MANAGER_EXTRA_FLAG)
AC_SUBST(VLS_LCFLAGS)
AC_SUBST(VLS_LIB)
......
################################################################################
# "tcp" input Makefile
#-------------------------------------------------------------------------------
# (c)1999-2003 VideoLAN
# $Id: Makefile,v 1.1 2003/08/25 12:45:59 nitrox Exp $
################################################################################
################################################################################
# Common options
################################################################################
ifeq ($(shell [ ! -r ../../../Makefile.opts ] && echo 1),)
include ../../../Makefile.opts
endif
################################################################################
# Files description
################################################################################
#
# Input name
#
MODULE=tcpinput
#
# Source files
#
MODULE_SRC=tcpinput.cpp \
MODULE_LIB+=$(TCPINPUT_LIB)
MODULE_DCFLAGS+=$(TCPINPUT_DCFLAGS)
MODULE_LCFLAGS+=$(TCPINPUT_LCFLAGS)
MODULE_CCFLAGS+=$(TCPINPUT_CCFLAGS)
################################################################################
# Makefile skeleton
################################################################################
include ../../../Makefile.module
################################################################################
# Notes
################################################################################
# Look at the Makefile.module file for more information.
/*******************************************************************************
* tcpinput.cpp: Input for spawning a tcp reader
*-------------------------------------------------------------------------------
* (c)2003 Anevia
* $Id: tcpinput.cpp,v 1.1 2003/08/25 12:45:59 nitrox Exp $
*
* Authors: Damien Lucas <damien.lucas@anevia.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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*----------------------------------------------------------------------------
*
*******************************************************************************/
//------------------------------------------------------------------------------
// Preamble
//------------------------------------------------------------------------------
#include "../../core/defs.h"
#include "../../core/core.h"
#include "../../mpeg/mpeg.h"
#include "../../mpeg/ts.h"
#include "../../mpeg/rtp.h"
#include "../../server/program.h"
#include "../../server/buffer.h"
#include "../../server/output.h"
#include "../../server/channel.h"
#include "../../server/broadcast.h"
#include "../../server/request.h"
#include "../../server/input.h"
#include "../../server/tsstreamer.h"
#include "../../mpeg/reader.h"
#include "../../mpeg/trickplay.h"
#include "../../mpeg/converter.h"
#include "tcpinput.h"
//------------------------------------------------------------------------------
// Library declaration
//------------------------------------------------------------------------------
#ifdef __PLUGIN__
GENERATE_LIB_ARGS(C_TcpInputModule, handle);
#endif
//------------------------------------------------------------------------------
// Builtin declaration
//------------------------------------------------------------------------------
#ifdef __BUILTIN__
C_Module* NewBuiltin_tcpinput(handle hLog)
{
return new C_TcpInputModule(hLog);
}
#endif
/*******************************************************************************
* C_TcpInput class
********************************************************************************
*
*******************************************************************************/
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
C_TcpInput::C_TcpInput(C_Module* pModule, const C_String& strName)
: C_Input(pModule, strName)
{
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
C_TcpInput::~C_TcpInput()
{
}
//------------------------------------------------------------------------------
// Initialization
//------------------------------------------------------------------------------
void C_TcpInput::OnInit()
{
C_String* pStr = new C_String("tcp1");
m_vProgramNames.Add(pStr);
Log(m_hLog, LOG_NOTE, "Added program '" + *pStr+"'");
return;
}
//------------------------------------------------------------------------------
// Destruction
//------------------------------------------------------------------------------
void C_TcpInput::OnDestroy()
{
return;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
C_List<C_Program> C_TcpInput::OnGetAvailablePgrms()
{
C_List<C_Program> cPgrmList;
for(unsigned int ui = 0; ui < m_vProgramNames.Size(); ui++)
{
C_Program* pProgram = new C_Program(m_vProgramNames[ui]);
ASSERT(pProgram);
cPgrmList.PushEnd(pProgram);
}
return cPgrmList;
}
//------------------------------------------------------------------------------
// Start the reception of the given program
//------------------------------------------------------------------------------
void C_TcpInput::OnStartStreaming(C_Broadcast* pBroadcast)
{
C_String strReaderType = "tcp";
C_String strConverterType = "ts2ts";
C_String strTrickPlayType = "normal";
// Create the netlist and the fifo
const C_Channel* pChannel = pBroadcast->GetChannel();
C_NetList* pTsProvider = new C_NetList(3*3*797);
uint16_t uiSize = pTsProvider->Capacity() -pChannel->GetBuffCapacity()-2;
C_SyncFifo* pBuffer = new C_SyncFifo(uiSize);
// Create the reader
C_MpegReader* pReader;
C_MpegReaderModule* pReaderModule = (C_MpegReaderModule*)
C_Application::GetModuleManager()
->GetModule("mpegreader",
strReaderType);
if(pReaderModule)
{
pReader = pReaderModule->NewMpegReader(pBroadcast);
}
else
{
throw E_Exception(GEN_ERR, "Module mpegreader:" + strConverterType +
" not present");
}
// Create the converter
C_MpegConverter* pConverter;
C_MpegConverterModule* pConverterModule = (C_MpegConverterModule*)
C_Application::GetModuleManager()
->GetModule("mpegconverter",
strConverterType);
if(pConverterModule)
{
C_MpegConverterConfig cConfig;
cConfig.m_hLog = m_hLog;
cConfig.m_pBroadcast = pBroadcast;
cConfig.m_pReader = pReader;
cConfig.m_pTsProvider = pTsProvider;
cConfig.m_pEventHandler = m_pEventHandler;
pConverter = pConverterModule->NewMpegConverter(cConfig);
ASSERT(pConverter);
}
else
{
throw E_Exception(GEN_ERR, "Module mpegconverter:" +
strConverterType + " not present");
}
pReader->SetConverter(pConverter);
// Create the trickplay
C_TrickPlay* pTrickPlay;
C_TrickPlayModule* pTrickPlayModule = (C_TrickPlayModule*)
C_Application::GetModuleManager()
->GetModule("trickplay",
strTrickPlayType);
if (pTrickPlayModule)
{
C_TrickPlayConfig cTrickPlayConfig;
cTrickPlayConfig.m_hLog = m_hLog;
cTrickPlayConfig.m_pBroadcast = pBroadcast;
cTrickPlayConfig.m_pReader = pReader;
cTrickPlayConfig.m_pHandler = pBuffer;
cTrickPlayConfig.m_iInitFill = pBuffer->Capacity();
cTrickPlayConfig.m_pEventHandler = m_pEventHandler;
cTrickPlayConfig.m_pTsProvider = pTsProvider;
cTrickPlayConfig.m_pConverter = pConverter;
pTrickPlay = pTrickPlayModule->NewTrickPlay(cTrickPlayConfig);
ASSERT(pTrickPlay);
}
else
{
throw E_Exception(GEN_ERR,
"Module TrickPlay:" + strTrickPlayType +
" not present");
}
// Create the streamer
C_TsStreamer* pStreamer = new C_TsStreamer(m_hLog, pBroadcast,
pTsProvider, pBuffer,
m_pEventHandler, true, false);
ASSERT(pStreamer);
m_cTrickPlay.Add(pBroadcast, pTrickPlay);
m_cStreamers.Add(pBroadcast, pStreamer);
m_cConverters.Add(pBroadcast, pConverter);
try
{
pTrickPlay->Create();
pStreamer->Create();
fprintf(stderr, "nitrox -- Right\n");
}
catch(E_Exception e)
{
pStreamer->Stop();
pTrickPlay->Stop();
//Unregister the 2 thread and delete them
m_cTrickPlay.Delete(pBroadcast);
m_cStreamers.Delete(pBroadcast);
throw E_Exception(GEN_ERR, "unable to start streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
// Resume the reception of the given program
//------------------------------------------------------------------------------
void C_TcpInput::OnResumeStreaming(C_Broadcast* pBroadcast)
{
ASSERT(pBroadcast);
// Find the converter that receive the pgrm
C_TrickPlay* pTrickPlay = m_cTrickPlay.Get(pBroadcast);
ASSERT(pTrickPlay);
// Resume the thread
try
{
pTrickPlay->Resume();
}
catch(E_Exception e)
{
throw E_Exception(GEN_ERR, "Unable to resume streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
// Suspend the reception of the given program
//------------------------------------------------------------------------------
void C_TcpInput::OnSuspendStreaming(C_Broadcast* pBroadcast)
{
ASSERT(pBroadcast);
// Find the converter that receive the pgrm
C_TrickPlay* pTrickPlay = m_cTrickPlay.Get(pBroadcast);
ASSERT(pTrickPlay);
C_String strPgrmName = pBroadcast->GetProgram()->GetName();
// Suspend the thread
try
{
pTrickPlay->Suspend();
}
catch (E_Exception e)
{
throw E_Exception(GEN_ERR, "Unable to resume streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
// Forward the reception of the given program with specified speed
//------------------------------------------------------------------------------
void C_TcpInput::OnForwardStreaming(C_Broadcast* pBroadcast, int speed)
{
ASSERT(pBroadcast);
// Find the reader and the streamer that receive the pgrm
C_TrickPlay* pTrickPlay = m_cTrickPlay.Get(pBroadcast);
ASSERT(pTrickPlay);
// Call forward to the threads
try
{
pTrickPlay->Forward(speed);
}
catch(E_Exception e)
{
throw E_Exception(GEN_ERR,
"Unable to forward into the streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
// Rewind the reception of the given program with specified speed
//------------------------------------------------------------------------------
void C_TcpInput::OnRewindStreaming(C_Broadcast* pBroadcast, int speed)
{
ASSERT(pBroadcast);
// Find the reader and the streamer that receive the pgrm
C_TrickPlay* pTrickPlay = m_cTrickPlay.Get(pBroadcast);
ASSERT(pTrickPlay);
// Call rewind to the threads
try
{
pTrickPlay->Rewind(speed);
}
catch(E_Exception e)
{
throw E_Exception(GEN_ERR,
"Unable to rewind into the streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
// Stop the reception of the given program
//------------------------------------------------------------------------------
void C_TcpInput::OnStopStreaming(C_Broadcast* pBroadcast)
{
ASSERT(pBroadcast);
// Find the reader and the streamer that receive the pgrm
C_TrickPlay* pTrickPlay = m_cTrickPlay.Remove(pBroadcast);
ASSERT(pTrickPlay);
C_TsStreamer* pStreamer = m_cStreamers.Remove(pBroadcast);
ASSERT(pStreamer);
C_MpegConverter* pConverter = m_cConverters.Remove(pBroadcast);
ASSERT(pConverter);
// Stop the threads
try
{
pStreamer->Stop();
pTrickPlay->Stop();
delete pTrickPlay;
delete pConverter;
delete pStreamer; // streamer MUST be deleted last
}
catch(E_Exception e)
{
throw E_Exception(GEN_ERR, "Unable to stop streaming of program "+
pBroadcast->GetProgram()->GetName(), e);
}
return;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_TcpInput::OnUpdateProgram(C_String strProgram,
C_String strFileName, C_String strType)
{
throw E_Exception(GEN_ERR, "Updating program not implemented");
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_TcpInput::OnDeleteProgram(C_String strProgram)
{
throw E_Exception(GEN_ERR, "Deleting program not implemented");
}
/*******************************************************************************
* tcpinput.h: TCP Input class definition
*-------------------------------------------------------------------------------
* (c)2003 Anevia
* $Id: tcpinput.h,v 1.1 2003/08/25 12:45:59 nitrox Exp $
*
* Authors: Damien Lucas <damien.lucas@anevia.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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*-------------------------------------------------------------------------------
*
*******************************************************************************/
#ifndef _TCP_INPUT_H_
#define _TCP_INPUT_H_
//------------------------------------------------------------------------------
// C_XXXInput class
//------------------------------------------------------------------------------
class C_TcpInput : public C_Input
{
public:
C_TcpInput(C_Module* pModule, const C_String& strName);
~C_TcpInput();
protected:
// Init/termination methods
virtual void OnInit();
virtual void OnDestroy();
// Selection of the pgrms to broadcast
virtual void OnStartStreaming(C_Broadcast* pBroadcast);
virtual void OnResumeStreaming(C_Broadcast* pBroadcast);
virtual void OnSuspendStreaming(C_Broadcast* pBroadcast);
virtual void OnForwardStreaming(C_Broadcast* pBroadcast, int speed);
virtual void OnRewindStreaming(C_Broadcast* pBroadcast, int speed);
virtual void OnStopStreaming(C_Broadcast* pBroadcast);
virtual void OnUpdateProgram(C_String strProgram,C_String strFileName, C_String strType);
virtual void OnDeleteProgram(C_String strProgram);
virtual C_List<C_Program> OnGetAvailablePgrms();
private:
// Programs names
// the program ID is m_vProgramNames.Find(strName) + 1
C_Vector<C_String> m_vProgramNames;
// List of currently running trickplay, streamers and converters
C_HashTable<handle, C_TsStreamer> m_cStreamers;
C_HashTable<handle, C_TrickPlay> m_cTrickPlay;
C_HashTable<handle, C_MpegConverter> m_cConverters;
};
// Declaration and implementation of C_XXXInputModule
DECLARE_MODULE(Tcp, Input, "tcp", const C_String&);
#else
#error "Multiple inclusins of tcpinput.h"
#endif
################################################################################
# "tcp" reader Makefile
#-------------------------------------------------------------------------------
# (c)1999-2003 VideoLAN
# $Id: Makefile,v 1.1 2003/08/25 12:45:59 nitrox Exp $
################################################################################
################################################################################
# Common options
################################################################################
ifeq ($(shell [ ! -r ../../../Makefile.opts ] && echo 1),)
include ../../../Makefile.opts
endif
################################################################################
# Files description
################################################################################
#
# Input name
#
MODULE=tcpreader
#
# Source files
#
MODULE_SRC=tcpreader.cpp \
MODULE_LIB+=$(TCPREADER_LIB)
MODULE_DCFLAGS+=$(TCPREADER_DCFLAGS)
MODULE_LCFLAGS+=$(TCPREADER_LCFLAGS)
MODULE_CCFLAGS+=$(TCPREADER_CCFLAGS)
################################################################################
# Makefile skeleton
################################################################################
include ../../../Makefile.module
################################################################################
# Notes
################################################################################
# Look at the Makefile.module file for more information.
/*******************************************************************************
* TCP reader.cpp: TCP reader
*-------------------------------------------------------------------------------
* (c)2003 Anevia
* $Id: tcpreader.cpp,v 1.1 2003/08/25 12:45:59 nitrox Exp $
*
* Authors: Damien Lucas <damien.lucas@anevia.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 2
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*-------------------------------------------------------------------------------
*
*******************************************************************************/
//------------------------------------------------------------------------------
// Preamble
//------------------------------------------------------------------------------
#include "../../core/defs.h"
#include "../../core/core.h"
#include "../../mpeg/mpeg.h"
#include "../../mpeg/ts.h"
#include "../../server/buffer.h"
#include "../../server/broadcast.h"
#include "../../server/request.h"
#include "../../mpeg/reader.h"
#include "../../mpeg/converter.h"
#include "tcpreader.h"
//------------------------------------------------------------------------------
// Library declaration
//------------------------------------------------------------------------------
#ifdef __PLUGIN__
GENERATE_LIB_ARGS(C_TcpMpegReaderModule, handle);
#endif
//------------------------------------------------------------------------------
// Builtin declaration
//------------------------------------------------------------------------------
#ifdef __BUILTIN__
C_Module* NewBuiltin_tcpreader(handle hLog)
{
return new C_TcpMpegReaderModule(hLog);
}
#endif
/*******************************************************************************
* C_XXXMpegReader
********************************************************************************
*
*******************************************************************************/
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
C_TcpMpegReader::C_TcpMpegReader(C_Module* pModule,
C_Broadcast* pBroadcast) :
C_MpegReader(pModule, pBroadcast)
{
}
//------------------------------------------------------------------------------
// Initialization
//------------------------------------------------------------------------------
void C_TcpMpegReader::Init()
{
// We need to create the socket and connect it
m_cSocket.Open(AF_INET, SOCK_STREAM);
// TODO
m_cSocket.Connect("127.0.0.1", "4212");
return;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
void C_TcpMpegReader::Close()
{
try
{
m_cSocket.Close();
}
catch(E_Exception e)
{
throw E_Exception(GEN_ERR, "Reader termination failed to close socket");
}
return;
}
//------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------
s64 C_TcpMpegReader::Read(byte* pBuff, s64 iSize)
{
unsigned int iRc = m_cSocket.Read((char*)pBuff,iSize);
return iRc;
}