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 // -*- c++ -*- 19 #ifndef MEDIA_PACKET_H 20 #define MEDIA_PACKET_H 21 22 #include "oscl_media_data.h" 23 #include "oscl_media_status.h" 24 #include "oscl_time.h" 25 26 #include "media_fragment.h" 27 #include "packet.h" 28 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 29 #include "pvmf_media_data.h" 30 #endif 31 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED 32 #include "pvmf_simple_media_buffer.h" 33 #endif 34 // Constants controlling the size of the RTP packet container 35 36 class MediaPacket : public Packet 37 { 38 public: 39 virtual ~MediaPacket() {}; 40 41 OSCL_IMPORT_REF BufFragStatusClass::status_t AddMediaFragment(MediaFragment* fragment, int32 location_offset = APPEND_MEDIA_AT_END); 42 43 OSCL_IMPORT_REF MediaFragment* GetMediaFragment(int32 idx, MediaFragment& fragment); 44 45 OSCL_IMPORT_REF void Reset(); 46 OSCL_IMPORT_REF void SetTimeval(TimeValue& val) 47 { 48 time_val = val; 49 } 50 OSCL_IMPORT_REF TimeValue* GetTimeval() 51 { 52 return &time_val; 53 } 54 55 uint8* cur_pos; 56 uint8* end_pos; 57 int cur_frag_num; 58 59 protected: 60 MediaPacket() : cur_pos(NULL), end_pos(NULL), cur_frag_num(0)/*, next(NULL)*/ {}; 61 private: 62 // MediaPacket *next; 63 TimeValue time_val; 64 friend class MediaPacketAllocator; 65 friend class MediaPacketPoolAllocator; 66 }; 67 68 class MediaPacketAllocator 69 { 70 public: 71 MediaPacketAllocator() {}; 72 73 virtual ~MediaPacketAllocator() 74 { 75 //printf("here\n"); 76 } 77 /* This should change to allocate memory from a memory pool */ 78 OSCL_IMPORT_REF virtual MediaPacket* allocate_packet(EPacketType type = EPacketDefault); 79 /* Change to return to pool */ 80 OSCL_IMPORT_REF virtual void deallocate_packet(MediaPacket* pack); 81 }; 82 83 class MediaPacketPoolAllocator : public MediaPacketAllocator 84 { 85 public: 86 OSCL_IMPORT_REF MediaPacketPoolAllocator(int packets); 87 virtual ~MediaPacketPoolAllocator(); 88 89 OSCL_IMPORT_REF MediaPacket *allocate_packet(EPacketType type = EPacketDefault); 90 91 OSCL_IMPORT_REF void deallocate_packet(MediaPacket *pack); 92 93 private: 94 int num_packets; 95 MediaPacket *free_list; 96 MediaPacket *entire_list; 97 }; 98 99 OSCL_IMPORT_REF PVMFSharedMediaMsgPtr MediaPacketToPVMFMediaMsg(MediaPacket* packet, PVMFSimpleMediaBufferCombinedAlloc& alloc); 100 OSCL_IMPORT_REF MediaPacket* PVMFMediaMsgToMediaPacket(PVMFSharedMediaMsgPtr aMsg, 101 MediaPacketAllocator& aMediaPacketAlloc, FragmentAllocator& aFragmentAlloc); 102 #endif 103