1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #include "pvmf_file_data_sink.h" 19 #include "pvmf_media_msg_format_ids.h" 20 21 OSCL_EXPORT_REF PVMFFileDataSink::PVMFFileDataSink(int32 aPortTag) 22 : PVMFBufferDataSink(aPortTag) 23 { 24 } 25 26 OSCL_EXPORT_REF PVMFFileDataSink::~PVMFFileDataSink() 27 { 28 fclose(iWriteFile); 29 } 30 31 // PVMFPortInterface virtuals 32 33 PVMFStatus PVMFFileDataSink::PutData(PVMFSharedMediaMsgPtr aMsg) 34 { 35 iNumPktsReceived++; 36 PVUid32 msgFormatID = aMsg->getFormatID(); 37 if (msgFormatID < PVMF_MEDIA_CMD_FORMAT_IDS_START) 38 { 39 //this code should be run for media data 40 // object only 41 PVMFSharedMediaDataPtr mediaData; 42 convertToPVMFMediaData(mediaData, aMsg); 43 iNumBytesReceived += mediaData->getFilledSize(); 44 45 if (mediaData->getErrorsFlag()) 46 iNumPktErrorsReceived++; 47 OsclSharedPtr<PVMFMediaDataImpl> mediaDataImpl; 48 mediaData->getMediaDataImpl(mediaDataImpl); 49 for (uint i = 0; i < mediaDataImpl->getNumFragments() ; i++) 50 { 51 OsclRefCounterMemFrag copy_frag; 52 mediaDataImpl->getMediaFragment(i, copy_frag); 53 fwrite(copy_frag.getMemFragPtr(), 1, copy_frag.getMemFragSize(), iWriteFile); 54 } 55 } 56 return PVMFSuccess; 57 } 58