@ -9,6 +9,11 @@
# include "CvText.h"
# include "PositionHelper.h"
# include "DngCreator.h"
# include "media/Streaming.h"
# include "netcamera/VendorCtrl.h"
# include "netcamera/YuShiCtrl.h"
# include "netcamera/HangYuCtrl.h"
# include "media/RTSPRecorder.h"
@ -1711,8 +1716,8 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
}
XYLOG ( XYLOG_SEVERITY_DEBUG , " Ethernet Power ON " ) ;
// std::shared_ptr<PowerControl> ethernetPowerCtrl = std::make_shared<EthernetPowerCtrl>(1);
std : : shared_ptr < PowerControl > ethernetPowerCtrl ;
std : : shared_ptr < PowerControl > ethernetPowerCtrl = std : : make_shared < EthernetPowerCtrl > ( 1 ) ;
// std::shared_ptr<PowerControl> ethernetPowerCtrl;
net_handle_t netHandle = GetEthnetHandle ( ) ;
if ( netHandle = = 0 )
@ -1747,64 +1752,37 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
// SetStaticIp();
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 256 ) ) ;
NET_PHOTO_INFO netPhotoInfo = { netHandle , 0 } ;
if ( localPhotoInfo . vendor = = 1 )
{
// Hai Kang
netPhotoInfo . authType = HTTP_AUTH_TYPE_DIGEST ;
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /ISAPI/Streaming/channels/1/picture? " ) ;
}
else if ( localPhotoInfo . vendor = = 2 )
{
// Hang Yu
strcpy ( netPhotoInfo . url , " /cgi-bin/snapshot.cgi " ) ;
}
else if ( localPhotoInfo . vendor = = 3 )
{
// Yu Shi
netPhotoInfo . authType = HTTP_AUTH_TYPE_DIGEST ;
int streamSid = 0 ; // should put into config
// rtsp://192.168.0.13:554/media/video1
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /media/video%u " , ( uint32_t ) localPhotoInfo . cameraId ) ;
// strcpy(netPhotoInfo.url, "rtsp://192.168.50.224/live/0");
}
else if ( localPhotoInfo . vendor = = 5 )
{
// Hang Yu - New
netPhotoInfo . authType = HTTP_AUTH_TYPE_BASIC ;
// http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080
// http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg
// http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg " , ( uint32_t ) localPhotoInfo . cameraId ) ;
}
else
struct in_addr addr ;
char ip [ 32 ] = { 0 } ;
addr . s_addr = localPhotoInfo . ip ;
strcpy ( ip , inet_ntoa ( addr ) ) ;
// strcpy(netPhotoInfo.outputPath, path.c_str());
VendorCtrl * vendorCtrl = MakeVendorCtrl ( localPhotoInfo . vendor , localPhotoInfo . channel , ip , localPhotoInfo . userName , localPhotoInfo . password , netHandle ) ;
if ( vendorCtrl = = NULL )
{
XYLOG ( XYLOG_SEVERITY_ERROR , " Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u " , ( uint32_t ) localPhotoInfo . vendor , ( uint32_t ) localPhotoInfo . channel , ( unsigned int ) localPhotoInfo . preset , localPhotoInfo . photoId ) ;
TakePhotoCb ( 0 , localPhotoInfo , " " , 0 ) ;
return false ;
}
struct in_addr addr ;
addr . s_addr = localPhotoInfo . ip ;
strcpy ( netPhotoInfo . ip , inet_ntoa ( addr ) ) ;
strcpy ( netPhotoInfo . outputPath , path . c_str ( ) ) ;
if ( ! localPhotoInfo . userName . empty ( ) )
{
size_t len = std : : min < size_t > ( sizeof ( netPhotoInfo . userName ) - 1 , localPhotoInfo . userName . size ( ) ) ;
strncpy ( netPhotoInfo . userName , localPhotoInfo . userName . c_str ( ) , len ) ;
}
if ( ! localPhotoInfo . password . empty ( ) )
std : : string streamingUrl = vendorCtrl - > GetStreamingUrl ( localPhotoInfo . cameraId ) ;
if ( streamingUrl . empty ( ) )
{
size_t len = std : : min < size_t > ( sizeof ( netPhotoInfo . password ) - 1 , localPhotoInfo . password . size ( ) ) ;
strncpy ( netPhotoInfo . password , localPhotoInfo . password . c_str ( ) , len ) ;
XYLOG ( XYLOG_SEVERITY_ERROR , " Invalid Streaming URL CH=%u PR=%X PHOTOID=%u " , ( uint32_t ) localPhotoInfo . channel , ( unsigned int ) localPhotoInfo . preset , localPhotoInfo . photoId ) ;
TakePhotoCb ( 0 , localPhotoInfo , " " , 0 ) ;
return false ;
}
// strcpy(netPhotoInfo.outputPath, path.c_str());
// strcpy(netPhotoInfo.interface, "eth0");
localPhotoInfo . photoTime = time ( NULL ) ;
std : : string tmpFile = m_appPath + ( APP_PATH_TMP DIR_SEP_STR ) + std : : to_string ( localPhotoInfo . photoId ) + " .mp4 " ;
// RTSPToMP4 dumper(netPhotoInfo.url, tmpFile.c_str(), localPhotoInfo.duration * 1000);
// dumper.start();
dumpRtspToMp4 ( netPhotoInfo. url , tmpFile . c_str ( ) , localPhotoInfo . duration * 1000 ) ;
dumpRtspToMp4 ( streamingUrl . c_str ( ) , tmpFile . c_str ( ) , localPhotoInfo . duration * 1000 , GetEthnetHandle ( ) ) ;
ethernetPowerCtrl . reset ( ) ;
XYLOG ( XYLOG_SEVERITY_DEBUG , " Ethernet Power OFF " ) ;
@ -1820,7 +1798,7 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
{
TakePhotoCb ( 0 , localPhotoInfo , " " , 0 ) ;
XYLOG ( XYLOG_SEVERITY_ERROR , " Failed to TP on NET Camera CH=%u PR=%X PHOTOID=%u URL=http://%s%s " , ( uint32_t ) localPhotoInfo . channel , ( uint32_t ) localPhotoInfo . preset ,
localPhotoInfo . photoId , netPhotoInfo. ip , netPhotoInfo . url ) ;
localPhotoInfo . photoId , ip, streamingUrl . c_str ( ) ) ;
}
// Notify to take next photo
// TakePhotoCb(1, localPhotoInfo, "", takingTime);
@ -1832,8 +1810,92 @@ bool CPhoneDevice::TakeVideoWithNetCamera(IDevice::PHOTO_INFO& localPhotoInfo, c
return true ;
}
bool CPhoneDevice : : StartPushStreaming ( IDevice : : PHOTO_INFO & localPhotoInfo , const std : : string & url , std : : vector < IDevice : : OSD_INFO > & osds , std : : shared_ptr < PowerControl > powerCtrlPtr )
bool CPhoneDevice : : StartPushStreaming ( IDevice : : PHOTO_INFO & photoInfo , const std : : string & url , std : : vector < IDevice : : OSD_INFO > & osds , std : : shared_ptr < PowerControl > powerCtrlPtr )
{
#if 0
if ( photoInfo . mediaType = = XY_MEDIA_TYPE_STREAM )
{
std : : map < uint8_t , std : : shared_ptr < Streaming > > : : iterator it = m_streamings . find ( photoInfo . channel ) ;
if ( it ! = m_streamings . end ( ) )
{
it - > second - > stop ( ) ;
it - > second . reset ( ) ;
m_streamings . erase ( it ) ;
}
NET_PHOTO_INFO netPhotoInfo = { 0 , 0 } ;
if ( photoInfo . vendor = = 1 )
{
// Hai Kang
netPhotoInfo . authType = HTTP_AUTH_TYPE_DIGEST ;
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /ISAPI/Streaming/channels/1/picture? " ) ;
}
else if ( photoInfo . vendor = = 2 )
{
// Hang Yu
strcpy ( netPhotoInfo . url , " /cgi-bin/snapshot.cgi " ) ;
}
else if ( photoInfo . vendor = = 3 )
{
// Yu Shi
netPhotoInfo . authType = HTTP_AUTH_TYPE_DIGEST ;
int streamSid = 0 ; // should put into config
// rtsp://192.168.0.13:554/media/video1
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /media/video%u " , ( uint32_t ) photoInfo . cameraId ) ;
// strcpy(netPhotoInfo.url, "rtsp://192.168.50.224/live/0");
}
else if ( photoInfo . vendor = = 5 )
{
// Hang Yu - New
netPhotoInfo . authType = HTTP_AUTH_TYPE_BASIC ;
// http://192.168.1.46/Snapshot/%u/RemoteImageCapture?ImageFormat=2&HorizontalPixel=1920&VerticalPixel=1080
// http://192.168.1.101/Snapshot/1/2/RemoteImageCaptureV2?ImageFormat=jpg
// http://192.168.1.101/Snapshot/1/1/RemoteImageCaptureV2?ImageFormat=jpg
snprintf ( netPhotoInfo . url , sizeof ( netPhotoInfo . url ) , " /Snapshot/%u/1/RemoteImageCaptureV2?ImageFormat=jpg " , ( uint32_t ) photoInfo . cameraId ) ;
}
else
{
XYLOG ( XYLOG_SEVERITY_ERROR , " Vendor(%u) not Supported CH=%u PR=%X PHOTOID=%u " , ( uint32_t ) photoInfo . vendor , ( uint32_t ) photoInfo . channel , ( unsigned int ) photoInfo . preset , photoInfo . photoId ) ;
TakePhotoCb ( 0 , photoInfo , " " , 0 ) ;
return false ;
}
StreamForwarder * forwarder = new StreamForwarder ( ) ;
m_streamings [ photoInfo . channel ] = std : : shared_ptr < Streaming > ( ( Streaming * ) forwarder ) ;
// Initialize with RTSP input and RTMP output
if ( ! forwarder - > initialize ( std : : string ( netPhotoInfo . url ) , url ) ) {
std : : cerr < < " Failed to initialize stream forwarder " < < std : : endl ;
return - 1 ;
}
// Optional: Set callback to process video frames
#if 0
forwarder - > setFrameCallback ( [ ] ( uint8_t * data , int linesize , int width , int height ) {
// Process frame data here
// Example: Add OSD overlay
} ) ;
# endif
// Start forwarding
forwarder - > start ( ) ;
// Wait for user input to stop
// std::cout << "Press Enter to stop streaming..." << std::endl;
// std::cin.get();
// forwarder.stop();
}
else if ( photoInfo . mediaType = = XY_MEDIA_TYPE_STREAM_OFF )
{
auto it = m_streamings . find ( photoInfo . channel ) ;
if ( it ! = m_streamings . end ( ) )
{
it - > second - > stop ( ) ;
it - > second . reset ( ) ;
m_streamings . erase ( it ) ;
}
}
# endif
return true ;
}
@ -2037,7 +2099,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
std : : this_thread : : sleep_for ( std : : chrono : : seconds ( 5 ) ) ;
}
CameraPhotoCmd ( ts , localPhotoInfo . channel , 0 , localPhotoInfo . resolution , localPhotoInfo . preset , param . serfile , param . baud , param . addr ) ;
CameraPhotoCmd ( ts , localPhotoInfo . channel , TAKE_PHOTO , localPhotoInfo . resolution , localPhotoInfo . preset , param . serfile , param . baud , param . addr ) ;
XYLOG ( XYLOG_SEVERITY_INFO , " Taking photo over " ) ;
if ( localPhotoInfo . scheduleTime = = 0 ) {
@ -4958,3 +5020,24 @@ void CPhoneDevice::SetStaticIp()
XYLOG ( XYLOG_SEVERITY_WARNING , " No Static IP Confg " ) ;
}
}
VendorCtrl * CPhoneDevice : : MakeVendorCtrl ( int vendor , uint8_t channel , const std : : string & ip , const std : : string & userName , const std : : string & password , net_handle_t netHandle )
{
VendorCtrl * vendorCtrl = NULL ;
switch ( vendor )
{
case 1 :
// Hai Kang
break ;
case 2 :
break ;
case 3 :
// Yu Shi
vendorCtrl = new YuShiCtrl ( ip , userName , password , channel , netHandle ) ;
break ;
case 5 :
// Hang Yu - New
vendorCtrl = new HangYuCtrl ( ip , userName , password , channel , netHandle ) ;
}
return vendorCtrl ;
}