1 /* 2 * Copyright (C) 2008 iptego GmbH 3 * 4 * This file is part of SEMS, a free SIP media server. 5 * 6 * SEMS is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. This program is released under 10 * the GPL with the additional exemption that compiling, linking, 11 * and/or using OpenSSL is allowed. 12 * 13 * For a license to use the SEMS software under conditions 14 * other than those described here, or to purchase support for this 15 * software, please contact iptel.org by e-mail at the following addresses: 16 * info@iptel.org 17 * 18 * SEMS is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU General Public License for more details. 22 * 23 * You should have received a copy of the GNU General Public License 24 * along with this program; if not, write to the Free Software 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 */ 27 28 #ifndef _AmPrecodedFile_H 29 #define _AmPrecodedFile_H 30 31 #include "AmPlugIn.h" 32 #include "AmSdp.h" 33 #include "amci/amci.h" 34 #include "AmAudioFile.h" 35 #include "AmAudio.h" 36 #include "AmRtpAudio.h" 37 38 #include <string> 39 #include <map> 40 41 #define PRECODED_CODEC_ID 100 // could go into amci/codecs.h 42 43 struct precoded_payload_t : public amci_payload_t { 44 public: 45 string c_name; 46 string format_parameters; 47 unsigned int frame_ms; 48 unsigned int frame_bytes; 49 string filename; 50 precoded_payload_tprecoded_payload_t51 precoded_payload_t() {codec_id = PRECODED_CODEC_ID;} 52 }; 53 54 class AmPrecodedFileFormat : public AmAudioFileFormat { 55 56 precoded_payload_t& precoded_payload; 57 amci_subtype_t subtype; 58 59 /* encoded frame size in bytes */ 60 int frame_encoded_size; 61 62 public: 63 AmPrecodedFileFormat(precoded_payload_t& precoded_payload); 64 ~AmPrecodedFileFormat(); getSubtype()65 amci_subtype_t* getSubtype() { return &subtype; } getFrameEncodedSize()66 int getFrameEncodedSize() { return frame_encoded_size; } 67 }; 68 69 class AmPrecodedRtpFormat : public AmAudioRtpFormat 70 { 71 precoded_payload_t& precoded_payload; 72 73 /* encoded frame size in bytes */ 74 int frame_encoded_size; 75 76 public: 77 AmPrecodedRtpFormat(precoded_payload_t& precoded_payload); 78 ~AmPrecodedRtpFormat(); 79 getFrameEncodedSize()80 int getFrameEncodedSize() { return frame_encoded_size; } 81 }; 82 83 class AmPrecodedFileInstance 84 : public AmAudioFile { 85 86 precoded_payload_t& precoded_payload; 87 amci_inoutfmt_t m_iofmt; 88 89 public: 90 AmPrecodedFileInstance(precoded_payload_t& precoded_payload); 91 ~AmPrecodedFileInstance(); 92 93 AmPrecodedRtpFormat* getRtpFormat(); 94 95 int open(); 96 97 protected: 98 AmAudioFileFormat* fileName2Fmt(const string& name, const string& subtype); 99 }; 100 101 class AmPrecodedFile 102 : public AmPayloadProvider { 103 104 std::map<int,precoded_payload_t> payloads; 105 106 public: 107 AmPrecodedFile(); 108 ~AmPrecodedFile(); 109 110 /** Open the file */ 111 int open(const std::string& filename); 112 113 /** need to call after open() */ 114 void initPlugin(); 115 116 AmPrecodedFileInstance* getFileInstance(int payload_id); 117 118 /** from @AmPayloadProvider */ 119 amci_payload_t* payload(int payload_id) const; 120 int getDynPayload(const string& name, int rate, int encoding_param) const; 121 void getPayloads(vector<SdpPayload>& pl_vec) const; 122 }; 123 124 #endif 125