fragmentcollector_mpd.cpp
/**
 * @brief Push encrypted headers if available
 */
@brief Push encrypted headers if available
@brief Push encrypted headers if available
void PrivateStreamAbstractionMPD::PushEncryptedHeaders()
{
	size_t numPeriods = mpd->GetPeriods().size();
	int headerCount = 0;
	for(int i = mNumberOfTracks - 1; i >= 0; i--)
	{
		bool encryptionFound = false;
		unsigned iPeriod = 0;
		while(iPeriod < numPeriods && !encryptionFound)
		{
			IPeriod *period = mpd->GetPeriods().at(iPeriod);
			size_t numAdaptationSets = period->GetAdaptationSets().size();
			for(unsigned iAdaptationSet = 0; iAdaptationSet < numAdaptationSets && !encryptionFound; iAdaptationSet++)
			{
				IAdaptationSet *adaptationSet = period->GetAdaptationSets().at(iAdaptationSet);
				if (IsContentType(adaptationSet, (MediaType)i ))
				{
					vector<IDescriptor*> contentProt;
					contentProt = adaptationSet->GetContentProtection();
					if(0 == contentProt.size())
					{
						continue;
					}
					else
					{
						ISegmentTemplate *segmentTemplate = adaptationSet->GetSegmentTemplate();
						if (segmentTemplate)
						{
							std::string initialization = segmentTemplate->Getinitialization();
							if (!initialization.empty())
							{
								char fragmentUrl[MAX_URI_LENGTH];
								struct FragmentDescriptor * fragmentDescriptor = (struct FragmentDescriptor *) malloc(sizeof(struct FragmentDescriptor));
								memset(fragmentDescriptor, 0, sizeof(FragmentDescriptor));
								fragmentDescriptor->manifestUrl = mMediaStreamContext[eMEDIATYPE_VIDEO]->fragmentDescriptor.manifestUrl;
								IRepresentation *representation = NULL;
								size_t representionIndex = 0;
								if(MediaType(i) == eMEDIATYPE_VIDEO)
								{
									size_t representationCount = adaptationSet->GetRepresentation().size();
									if(adaptationSet->GetRepresentation().at(representionIndex)->GetBandwidth() > adaptationSet->GetRepresentation().at(representationCount - 1)->GetBandwidth())
									{
										representionIndex = representationCount - 1;
									}
								}
								else if (mAudioType != eAUDIO_UNKNOWN)
								{
									AudioType selectedAudioType = eAUDIO_UNKNOWN;
									representionIndex = GetDesiredCodecIndex(adaptationSet, selectedAudioType);
									if(selectedAudioType != mAudioType)
									{
										continue;
									}
									logprintf("%s %d Audio type %d\n", __FUNCTION__, __LINE__, selectedAudioType);
								}
								else
								{
									logprintf("%s %d Audio type eAUDIO_UNKNOWN\n", __FUNCTION__, __LINE__);
								}
								ProcessContentProtection(adaptationSet, (MediaType)i);
								representation = adaptationSet->GetRepresentation().at(representionIndex);
								fragmentDescriptor->Bandwidth = representation->GetBandwidth();
								fragmentDescriptor->baseUrls = &representation->GetBaseURLs();
								if (fragmentDescriptor->baseUrls->size() == 0)
								{
									fragmentDescriptor->baseUrls = &adaptationSet->GetBaseURLs();
									if (fragmentDescriptor->baseUrls->size() == 0)
									{
										fragmentDescriptor->baseUrls = &period->GetBaseURLs();
										if (fragmentDescriptor->baseUrls->size() == 0)
										{
											fragmentDescriptor->baseUrls = &mpd->GetBaseUrls();
										}
									}
								}
								strcpy(fragmentDescriptor->RepresentationID, representation->GetId().c_str());
								GetFragmentUrl(fragmentUrl,fragmentDescriptor , initialization);
								if (mMediaStreamContext[i]->WaitForFreeFragmentAvailable())
								{
									logprintf("%s %d Pushing encrypted header for %s\n", __FUNCTION__, __LINE__, mMediaTypeName[i]);
									mMediaStreamContext[i]->CacheFragment(fragmentUrl, i, mMediaStreamContext[i]->fragmentTime, 0.0, NULL, true);
								}
								free(fragmentDescriptor);
								encryptionFound = true;
							}
						}
					}
				}
			}
			iPeriod++;
		}
	}
}
void PrivateStreamAbstractionMPD :: PushEncryptedHeaders ( ) { size_t numPeriods = mpd -> GetPeriods ( ) . size ( ) ; int headerCount = 0 ; for ( int i = mNumberOfTracks - 1 ; i >= 0 ; i -- ) { bool encryptionFound = false ; unsigned iPeriod = 0 ; while ( iPeriod < numPeriods && ! encryptionFound ) { IPeriod * period = mpd -> GetPeriods ( ) . at ( iPeriod ) ; size_t numAdaptationSets = period -> GetAdaptationSets ( ) . size ( ) ; for ( unsigned iAdaptationSet = 0 ; iAdaptationSet < numAdaptationSets && ! encryptionFound ; iAdaptationSet ++ ) { IAdaptationSet * adaptationSet = period -> GetAdaptationSets ( ) . at ( iAdaptationSet ) ; if ( IsContentType ( adaptationSet , ( MediaType ) i ) ) { vector < IDescriptor * > contentProt ; contentProt = adaptationSet -> GetContentProtection ( ) ; if ( 0 == contentProt . size ( ) ) { continue ; } else { ISegmentTemplate * segmentTemplate = adaptationSet -> GetSegmentTemplate ( ) ; if ( segmentTemplate ) { std :: string initialization = segmentTemplate -> Getinitialization ( ) ; if ( ! initialization . empty ( ) ) { char fragmentUrl [ MAX_URI_LENGTH ] ; struct FragmentDescriptor * fragmentDescriptor = ( struct FragmentDescriptor * ) malloc ( sizeof ( struct FragmentDescriptor ) ) ; memset ( fragmentDescriptor , 0 , sizeof ( FragmentDescriptor ) ) ; fragmentDescriptor -> manifestUrl = mMediaStreamContext [ eMEDIATYPE_VIDEO ] -> fragmentDescriptor . manifestUrl ; IRepresentation * representation = NULL ; size_t representionIndex = 0 ; if ( MediaType ( i ) == eMEDIATYPE_VIDEO ) { size_t representationCount = adaptationSet -> GetRepresentation ( ) . size ( ) ; if ( adaptationSet -> GetRepresentation ( ) . at ( representionIndex ) -> GetBandwidth ( ) > adaptationSet -> GetRepresentation ( ) . at ( representationCount - 1 ) -> GetBandwidth ( ) ) { representionIndex = representationCount - 1 ; } } else if ( mAudioType != eAUDIO_UNKNOWN ) { AudioType selectedAudioType = eAUDIO_UNKNOWN ; representionIndex = GetDesiredCodecIndex ( adaptationSet , selectedAudioType ) ; if ( selectedAudioType != mAudioType ) { continue ; } logprintf ( " \n " , __FUNCTION__ , __LINE__ , selectedAudioType ) ; } else { logprintf ( " \n " , __FUNCTION__ , __LINE__ ) ; } ProcessContentProtection ( adaptationSet , ( MediaType ) i ) ; representation = adaptationSet -> GetRepresentation ( ) . at ( representionIndex ) ; fragmentDescriptor -> Bandwidth = representation -> GetBandwidth ( ) ; fragmentDescriptor -> baseUrls = & representation -> GetBaseURLs ( ) ; if ( fragmentDescriptor -> baseUrls -> size ( ) == 0 ) { fragmentDescriptor -> baseUrls = & adaptationSet -> GetBaseURLs ( ) ; if ( fragmentDescriptor -> baseUrls -> size ( ) == 0 ) { fragmentDescriptor -> baseUrls = & period -> GetBaseURLs ( ) ; if ( fragmentDescriptor -> baseUrls -> size ( ) == 0 ) { fragmentDescriptor -> baseUrls = & mpd -> GetBaseUrls ( ) ; } } } strcpy ( fragmentDescriptor -> RepresentationID , representation -> GetId ( ) . c_str ( ) ) ; GetFragmentUrl ( fragmentUrl , fragmentDescriptor , initialization ) ; if ( mMediaStreamContext [ i ] -> WaitForFreeFragmentAvailable ( ) ) { logprintf ( " \n " , __FUNCTION__ , __LINE__ , mMediaTypeName [ i ] ) ; mMediaStreamContext [ i ] -> CacheFragment ( fragmentUrl , i , mMediaStreamContext [ i ] -> fragmentTime , 0.0 , NULL , true ) ; } free ( fragmentDescriptor ) ; encryptionFound = true ; } } } } } iPeriod ++ ; } } }
@brief Push encrypted headers if available
@brief Push encrypted headers if available
//Find the first period with contentProtection