00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "freMediaDrainController.h"
00024 #include "freStoreableMediaControllerBase.h"
00025 #include "freExceptions.h"
00026
00027 namespace FREE
00028 {
00029
00033 DefineParameterMacro(MediaDrainController,SaveAllMedia,"SaveAllMedia","Request this parameter to save all linked media that have changed. In the returning parameter every layer is associated to one stored media. Values are media ID and IDPath of the source.");
00034
00035
00036 void
00037 MediaDrainController::
00038 SetMediaCasted(const MediaID& mediaID, GenericMediaType* pMedia, ComponentType* pComponent,
00039 SessionComponentCache* pComponentCache,
00040 SessionInfo* pSessionInfo) const
00041 {
00042 if (!pComponentCache) throwCtrlExceptionMacro("","Passed component cache is NULL.");
00043 if (!pSessionInfo) throwCtrlExceptionMacro("","Passed session info is NULL.");
00044
00045 SessionComponentCache::Pointer smpMediaCache = pComponentCache->SubCaches().GetElement(mediaID);
00046 if (smpMediaCache.IsNotNull())
00047 {
00048 if (!smpMediaCache->IsActive()) throwCtrlExceptionMacro("","Cannot save media via drain. Responsible subcomponent is inactive. (ComponentID: "<<mediaID<<")");
00049
00050 StatisticEntry* pMediaEntry = AddStatisticEntry(smpMediaCache,pSessionInfo,"MediaSave","Saving of a Media");
00051
00052 try
00053 {
00054 DirectSessionComponentAccessor::SetComponent(pMedia, smpMediaCache);
00055 const GenericStoreableMediaController* pStorableInterface = dynamic_cast<const GenericStoreableMediaController*>(smpMediaCache->Controller());
00056
00057 if (!pStorableInterface) throwCtrlExceptionMacro("","Cannot save media via drain. Media seems to be no descendant of StoreableMediaControllerInterface. ControllerID: "<<smpMediaCache->GetControllerID());
00058
00059 pStorableInterface->SaveMedia(smpMediaCache);
00060
00061 if (pMediaEntry)
00062 {
00063 smpMediaCache->Controller()->SetStatisticEntry(*pMediaEntry, smpMediaCache, pSessionInfo);
00064 pMediaEntry->CloseEntry();
00065 }
00066
00067
00068
00069 GenericMediaType::Pointer smpDummyMedia = GenericMediaType::New();
00070 DirectSessionComponentAccessor::SetComponent(smpDummyMedia, smpMediaCache);
00071 }
00072 catchAllNPassMacro("Error while setting and saving media. Media ID: "<<mediaID);
00073
00074 this->ActualizeMediaValidityTag(mediaID,pComponentCache);
00075
00076 this->NotifyProgress(2,"Media stored. MediaID: "+mediaID,pComponentCache);
00077 }
00078 else
00079 {
00080 Superclass::SetMediaCasted(mediaID, pMedia, pComponent, pComponentCache, pSessionInfo);
00081 }
00082 };
00083
00084 MediaDrainController::
00085 MediaDrainController()
00086 {
00087 this->UpdateControllerID(ControllerID::MediaDrainController);
00088 this->m_Description = "Media drain is a special version of the media bridge that is able to store media via their subcomponents.";
00089 };
00090
00091
00092 Parameter::Pointer
00093 MediaDrainController::
00094 GetParameter(const SessionComponentCache* pComponentCache,
00095 const std::string& sParameterName) const
00096 {
00097 if (sParameterName == cParam_SaveAllMedia)
00098 {
00099 Parameter::Pointer smpParameter = Parameter::New(cParam_SaveAllMedia,3);
00100
00101
00102
00103
00104
00105
00106 return smpParameter;
00107 }
00108
00109 return Superclass::GetParameter(pComponentCache, sParameterName);
00110 };
00111
00112 bool
00113 MediaDrainController::
00114 SaveMedia(const MediaID& mediaID, SessionComponentCache* pComponentCache,
00115 SessionInfo* pSessionInfo) const
00116 {
00117 bool result = false;
00118
00119 if (!pComponentCache) throwCtrlExceptionMacro("","Error; cannot save media. Passed component cache is NULL.");
00120 if (!pSessionInfo) throwCtrlExceptionMacro("","Error; cannot save media. Passed session info is NULL.");
00121
00122 ComponentMediaLink::Pointer pLink = pComponentCache->Setup()->MediaLinks().GetElement(mediaID);
00123
00124 if (pLink.IsNull())
00125 {
00126 this->NotifyProgress(0,"No media linked; skip saving. MediaID: "+mediaID,pComponentCache);
00127 }
00128 else
00129 {
00130 ValidityTag::Pointer smpVal = this->GetMediaValidityTag(mediaID,pComponentCache);
00131 ValidityTag::Pointer smpValReq = this->GetMediaValidityTagRequirement(mediaID,pComponentCache);
00132
00133 if (smpVal->IsOutdated(smpValReq))
00134 {
00135 this->NotifyProgress(1,"Generating media. MediaID: "+mediaID,pComponentCache);
00136
00137 IDPath mediaPath = pLink->GetSourceIDPath().TransformIDPath(pComponentCache->GetIDPath());
00138 GenericMediaType::Pointer smpMedia = SessionAccessor::GetMedia(mediaPath,pSessionInfo);
00139
00140 this->SetMedia(mediaID,smpMedia,pComponentCache,pSessionInfo);
00141
00142 result = true;
00143 }
00144 else
00145 {
00146 this->NotifyProgress(0,"Media is up to date. MediaID: "+mediaID,pComponentCache);
00147 }
00148 }
00149
00150 return result;
00151 };
00152
00153
00154 STLStringVector
00155 MediaDrainController::
00156 SaveAllMedia(SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo) const
00157 {
00158 if (!pComponentCache) throwCtrlExceptionMacro("","Error; cannot save media. Passed component cache is NULL.");
00159 if (!pSessionInfo) throwCtrlExceptionMacro("","Error; cannot save media. Passed session info is NULL.");
00160
00161 STLStringVector savedMedia;
00162
00163 for (unsigned int i=0; i < pComponentCache->Setup()->MediaLinks().Size(); i++)
00164 {
00165 ComponentMediaLink::Pointer pLink = pComponentCache->Setup()->MediaLinks().GetElement(i);
00166
00167 if (this->SaveMedia(pLink->GetMediaID(),pComponentCache,pSessionInfo))
00168 {
00169 savedMedia.push_back(pLink->GetMediaID());
00170 }
00171 }
00172
00173 return savedMedia;
00174 };
00175
00176 void
00177 MediaDrainController::
00178 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00179 const SessionComponentCache* pComponentCache,
00180 bool bRegardOldSetup) const
00181 {
00182
00183 profile.Parameters().AddParameter(cParam_SaveAllMedia,Parameter::PVTIDPath,cParamDsc_SaveAllMedia,3,"",-1,false,0,DAGet);
00184
00185
00186 CtrlProfile::SubComponent* pSub = profile.SubComponents().AddSubComponent("MediaWriter",0);
00187 pSub->SetIsTemplate(true);
00188
00189
00190 CtrlProfile::ProfileOption* pOption;
00191 pOption = profile.Requirements().AddRequirement("MediaWriter")->AddProfileOption();
00192 pOption->Inheritance().AddAncestor(ControllerID::StoreableMediaControllerBase);
00193 pOption->CheckForInheritance();
00194
00195 if (bRegardOldSetup)
00196 {
00197
00198
00199 for ( unsigned int i = 0; i < pComponentCache->Setup()->Components().Size(); i++)
00200 {
00201 ComponentSetup* pComponent = pComponentCache->Setup()->Components().GetElement(i);
00202 if ((!pComponent->IsTemplateBased())&&(pComponent->ControllerIsAssigned()))
00203 {
00204 profile.MediaMap().AddMedia(pComponent->GetComponentID(),pComponent->GetControllerID(),DASet);
00205 }
00206 }
00207 }
00208 };
00209
00210 ValidityTag::Pointer
00211 MediaDrainController::
00212 GetMediaValidityTag(const MediaID& mediaID, SessionComponentCache* pComponentCache) const
00213 {
00214 return Superclass::Superclass::GetMediaValidityTag(mediaID, pComponentCache);
00215 };
00216
00217 }