You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
219 lines
6.4 KiB
219 lines
6.4 KiB
#include "mediaVideoSourceManager.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "mediaVideoSourceManager", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "mediaVideoSourceManager", this, _LOG_ERROR, X )
|
|
|
|
mediaVideoSourceManager* mediaVideoSourceManager::_instance = 0;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
mediaVideoSourceManager* mediaVideoSourceManager::getInstance() {
|
|
// check if the instance has been created yet
|
|
if (0 == _instance) {
|
|
// if not, then create it
|
|
_instance = new mediaVideoSourceManager;
|
|
}
|
|
// return the single instance
|
|
return _instance;
|
|
};
|
|
|
|
// Constructor implementation
|
|
mediaVideoSourceManager::mediaVideoSourceManager(){
|
|
m_pLog = basicLogCollection::getInstance();
|
|
m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, "VIDEO_SOURCE_MANAGER");
|
|
#ifdef __linux__
|
|
enumerateDevices(&m_vLocalDevices, "video");
|
|
#else
|
|
enumerateDevices(&m_vLocalDevices, CLSID_VideoInputDeviceCategory);//CLSID_AudioInputDeviceCategory
|
|
#endif
|
|
loadAssignedSources();
|
|
};
|
|
|
|
// Destructor implementation
|
|
mediaVideoSourceManager::~mediaVideoSourceManager(){
|
|
shutdownAllVideoSources();
|
|
};
|
|
|
|
void mediaVideoSourceManager::shutdownAllVideoSources(void){
|
|
if (m_vCameras.size()){
|
|
for (vectorCamerasInterator index = m_vCameras.begin(); index < m_vCameras.end(); index++){
|
|
(*index)->stop();
|
|
switch ((*index)->getType()){
|
|
case 0:
|
|
delete ((objectStaticCamera *)*index);
|
|
break;
|
|
#ifndef NO_PTZ_CAMERAS
|
|
case 3:
|
|
delete ((objectCameraPTZ *)*index);
|
|
break;
|
|
#endif
|
|
default:
|
|
break;
|
|
};
|
|
};
|
|
m_vCameras.clear();
|
|
};
|
|
};
|
|
|
|
|
|
|
|
bool mediaVideoSourceManager::isUsed(int id){
|
|
for( sourcePool::iterator index = m_vUsedDevices.begin(); index < m_vUsedDevices.end(); index++ ){
|
|
if (id == (*index)->deviceId) return true;
|
|
};
|
|
return false;
|
|
};
|
|
|
|
bool mediaVideoSourceManager::loadAssignedSources(void){
|
|
int index, count, tType, tSType;
|
|
config_setting_t *tRec;
|
|
config_setting_t *ttRec;
|
|
count = config_setting_length(m_pSettings);
|
|
if (count){
|
|
for (index = 0; index < count; index++){
|
|
tRec = config_setting_get_elem(m_pSettings, index);
|
|
if (tRec != NULL){
|
|
ttRec = config_setting_get_elem(tRec, 0);
|
|
if (!config_setting_lookup_int(ttRec, BCI_TAG_CAMERA_TYPE, &tType)) continue;
|
|
if (!config_setting_lookup_int(ttRec, BCI_TAG_SOURCE_TYPE, &tSType)) continue;
|
|
switch (tType){
|
|
case 0: {
|
|
objectStaticCamera *tCamera;
|
|
tCamera = new objectStaticCamera(ttRec);
|
|
if (tCamera->create()) m_vCameras.push_back((basicCamera *)tCamera);
|
|
break;
|
|
};
|
|
#ifndef NO_PTZ_CAMERAS
|
|
case 1:
|
|
case 2:
|
|
case 3:{
|
|
objectCameraPTZ *tCamera = NULL;
|
|
tCamera = new objectCameraPTZ(ttRec);
|
|
if( tCamera!= NULL ){
|
|
if (tCamera->create()){
|
|
m_vCameras.push_back((basicCamera *)tCamera);
|
|
} else {
|
|
LOG_ERROR("LOADING CAMERA FAILURE!");
|
|
delete(tCamera);
|
|
};
|
|
} else {
|
|
LOG_ERROR("CREATING CAMERA FAILURE!");
|
|
}
|
|
break;
|
|
};
|
|
#endif
|
|
};
|
|
};
|
|
};
|
|
};
|
|
return true;
|
|
};
|
|
|
|
basicCamera *mediaVideoSourceManager::addSource(SOURCE_INFO *SRC){
|
|
basicCamera *RetVal = NULL;
|
|
if( SRC != NULL ){
|
|
char Buffer[64];
|
|
config_setting_t *tSettingsNode;
|
|
basicCamera *ttCamera = NULL;
|
|
sprintf(Buffer, "VIDEO_SOURCE_%d", m_vCameras.size());
|
|
tSettingsNode = basicSettingsProvider::getInstance()->getSubNode(m_pSettings, Buffer);
|
|
switch ( SRC->type ){
|
|
case 0:{
|
|
objectStaticCamera *tCamera;
|
|
tCamera = new objectStaticCamera(basicSettingsProvider::getInstance()->getSubNode(tSettingsNode, "CAMERA"));
|
|
if(tCamera->create(SRC)){
|
|
if(tCamera->create()){
|
|
ttCamera = (basicCamera*)tCamera;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
case 1:{
|
|
|
|
break;
|
|
};
|
|
case 2:{
|
|
|
|
break;
|
|
};
|
|
#ifndef NO_PTZ_CAMERAS
|
|
case 3:{
|
|
objectCameraPTZ *tCamera;
|
|
tCamera = new objectCameraPTZ(basicSettingsProvider::getInstance()->getSubNode(tSettingsNode, "CAMERA"));
|
|
if(tCamera->create(SRC)){
|
|
if( tCamera->create() ){
|
|
ttCamera = (basicCamera*)tCamera;
|
|
};
|
|
};
|
|
break;
|
|
};
|
|
#endif
|
|
};
|
|
if (ttCamera != NULL){
|
|
m_vCameras.push_back(ttCamera);
|
|
RetVal = ttCamera;
|
|
//ToDo: Make Metod to abadon added config node in case camera failure
|
|
basicSettingsProvider::getInstance()->compromise();
|
|
};
|
|
};
|
|
basicSettingsProvider::getInstance()->validate();
|
|
return RetVal;
|
|
};
|
|
|
|
bool mediaVideoSourceManager::removeSource(basicCamera *ptr){
|
|
for (vectorCameras::iterator index = m_vCameras.begin(); index < m_vCameras.end(); index++){
|
|
if ((*index) == ptr){
|
|
(*index)->stop();
|
|
};
|
|
};
|
|
return false;
|
|
};
|
|
|
|
size_t mediaVideoSourceManager::getLocalSourceCount( void ){
|
|
return m_vLocalDevices.size();
|
|
};
|
|
|
|
DeviceInfo *mediaVideoSourceManager::getLocalSourceInfo( size_t sourceId ){
|
|
if( sourceId < m_vLocalDevices.size() ) {
|
|
return m_vLocalDevices[sourceId];
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
basicMediaSource *mediaVideoSourceManager::getVideoSource( int sourceId ){
|
|
if( sourceId < m_vSourceCollection.size() ) {
|
|
return m_vSourceCollection[sourceId];
|
|
};
|
|
return NULL;
|
|
};
|
|
|
|
const char *mediaVideoSourceManager::getStandardSize(bool wide, int id){
|
|
if( wide ){
|
|
return g_aFrameSizeStandardNames_16_9[id%g_iStandardFrameSizesCount];
|
|
} else {
|
|
return g_aFrameSizeStandardNames_4_3[id%g_iStandardFrameSizesCount];
|
|
};
|
|
};
|
|
|
|
const int mediaVideoSourceManager::getStandardWidth(bool wide, int id){
|
|
if (wide){
|
|
return g_aFrameWidthStandard_16_9[id%g_iStandardFrameSizesCount];
|
|
}
|
|
else {
|
|
return g_aFrameWidthStandard_4_3[id%g_iStandardFrameSizesCount];
|
|
};
|
|
};
|
|
|
|
const int mediaVideoSourceManager::getStandardHeight(bool wide, int id){
|
|
if (wide){
|
|
return g_aFrameHeightStandard_16_9[id % g_iStandardFrameSizesCount];
|
|
}
|
|
else {
|
|
return g_aFrameHeightStandard_4_3[id % g_iStandardFrameSizesCount];
|
|
};
|
|
};
|
|
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|