• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /**
19  *  @file pvmf_format_type.h
20  *  @brief This file defines known format types and MIME strings,
21  *    and some utilities for converting between them.
22  *
23  */
24 
25 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED
26 #define PVMF_FORMAT_TYPE_H_INCLUDED
27 
28 #ifndef OSCL_BASE_H_INCLUDED
29 #include "oscl_base.h"
30 #endif
31 
32 #ifdef __cplusplus
33 #ifndef OSCL_STRING_H_INCLUDED
34 #include "oscl_string.h"
35 #endif
36 
37 #ifndef OSCL_STR_PTR_LEN_H_INCLUDED
38 #include "oscl_str_ptr_len.h"
39 #endif
40 
41 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
42 #include "oscl_string_containers.h"
43 #endif
44 
45 /** PvmfMimeString is used in several PVMF APIs */
46 typedef OSCL_String PvmfMimeString;
47 #endif
48 
49 // MIME string for unknown format
50 #define PVMF_MIME_FORMAT_UNKNOWN    "FORMATUNKNOWN"
51 
52 /**
53 ** Note on format MIME strings:
54 ** The MIME strings that start with "X" were made up by PV.
55 ** The others came from:
56 ** http://www.iana.org/assignments/media-types/index.html.
57 ** The names were chosen to match the names of the PV format
58 ** index values.
59 **/
60 
61 /* Following are the recognized formats  */
62 
63 // MIME strings for uncompressed audio formats
64 #define PVMF_MIME_PCM       "X-PCM-GEN"
65 #define PVMF_MIME_PCM8      "audio/L8"
66 #define PVMF_MIME_PCM16     "audio/L16"
67 #define PVMF_MIME_PCM16_BE  "X-PCM16-BE"
68 #define PVMF_MIME_ULAW      "audio/PCMU"
69 #define PVMF_MIME_ALAW      "audio/PCMA"
70 
71 // MIME strings for uncompressed video formats
72 #define PVMF_MIME_YUV420    "X-YUV-420"
73 #define PVMF_MIME_YUV422    "X-YUV-422"
74 #define PVMF_MIME_RGB8      "X-RGB-8"
75 #define PVMF_MIME_RGB12     "X-RGB-12"
76 #define PVMF_MIME_RGB16     "X-RGB-16"
77 #define PVMF_MIME_RGB24     "X-RGB-24"
78 
79 // MIME strings for uncompressed sub-video formats
80 #define PVMF_MIME_YUV420_PLANAR             "X-YUV-420-PLANAR"
81 #define PVMF_MIME_YUV420_PACKEDPLANAR       "X-YUV-420-PACKEDPLANAR"
82 #define PVMF_MIME_YUV420_SEMIPLANAR         "X-YUV-420-SEMIPLANAR"
83 #define PVMF_MIME_YUV420_PACKEDSEMIPLANAR   "X-YUV-420-PACKEDSEMIPLANAR"
84 #define PVMF_MIME_YUV422_PLANAR             "X-YUV-422-PLANAR"
85 #define PVMF_MIME_YUV422_PACKEDPLANAR       "X-YUV-422-PACKEDPLANAR"
86 #define PVMF_MIME_YUV422_SEMIPLANAR         "X-YUV-422-SEMIPLANAR"
87 #define PVMF_MIME_YUV422_PACKEDSEMIPLANAR   "X-YUV-422-PACKEDSEMIPLANAR"
88 #define PVMF_MIME_YUV420_SEMIPLANAR_YVU     "X-YUV-420-SEMIPLANAR-YUV"
89 
90 // MIME strings for compressed audio formats
91 #define PVMF_MIME_AMR           "audio/AMR" // Streaming AMR format, aka IETF_COMBINED_TOC
92 #define PVMF_MIME_AMRWB         "audio/AMR-WB" // AMR Wide Band
93 #define PVMF_MIME_AMR_IETF      "X-AMR-IETF-SEPARATE" // Today's IETF
94 #define PVMF_MIME_AMRWB_IETF    "X-AMRWB-IETF-SEPARATE" // Today's IETF
95 #define PVMF_MIME_AMR_IF2       "X-AMR-IF2"
96 #define PVMF_MIME_EVRC          "audio/EVRC" // Streaming EVRC format
97 #define PVMF_MIME_MP3           "audio/MPEG"
98 #define PVMF_MIME_ADIF          "X-AAC-ADIF" //.aac file format
99 #define PVMF_MIME_ADTS          "X-AAC-ADTS" //.aac file format
100 #define PVMF_MIME_AAC_SIZEHDR   "X-AAC-SIZEHDR"
101 #define PVMF_MIME_LATM          "audio/MP4A-LATM" // Streaming AAC format
102 #define PVMF_MIME_MPEG4_AUDIO   "X-MPEG4-AUDIO"// MPEG4 Audio (AAC) as stored in MPEG4 File
103 #define PVMF_MIME_G723          "audio/G723"
104 #define PVMF_MIME_G726          "x-pvmf/audio/g726"
105 //WMA Audio
106 #define PVMF_MIME_WMA           "audio/x-ms-wma"
107 // AMR Audio from a asf file
108 #define PVMF_MIME_ASF_AMR       "x-pvmf/audio/asf-amr"
109 // real audio
110 #define PVMF_MIME_REAL_AUDIO    "audio/vnd.rn-realaudio"
111 // MPEG4 Audio from a asf file
112 #define PVMF_MIME_ASF_MPEG4_AUDIO   "x-pvmf/audio/asf-mpeg4-audio"
113 #define PVMF_MIME_3640       "audio/mpeg4-generic" // Streaming AAC format
114 
115 // MIME strings for Compressed video formats
116 #define PVMF_MIME_M4V       "video/MP4V-ES"// MPEG4 Video
117 #define PVMF_MIME_H2631998  "video/H263-1998"
118 #define PVMF_MIME_H2632000  "video/H263-2000"
119 //Raw 264 files (.264 - stored as per byte stream format)
120 #define PVMF_MIME_H264_VIDEO_RAW "X-H264-BYTE-STREAM"
121 //H264 tracks as stored in MP4/3GP files
122 #define PVMF_MIME_H264_VIDEO_MP4  "X-H264-VIDEO"
123 //H263 streamed as per RFC 3984
124 #define PVMF_MIME_H264_VIDEO "video/H264"
125 // WMV7, WMV8, WMV9
126 #define PVMF_MIME_WMV         "video/x-ms-wmv"
127 // RV8, RV0
128 #define PVMF_MIME_REAL_VIDEO          "video/vnd.rn-realvideo"
129 
130 // MIME strings for still image formats
131 #define PVMF_MIME_M4V_IMAGE "X-M4V-IMAGE" // PV Proprietary Still Image
132 #define PVMF_MIME_IMAGE_FORMAT "image"
133 
134 // MIME strings for Multiplexed formats and single-media file formats.
135 #define PVMF_MIME_MPEG4FF       "video/MP4"
136 #define PVMF_MIME_H223          "X-H223"
137 #define PVMF_MIME_RTP           "X-RTP"
138 #define PVMF_MIME_AMRFF         "X-AMR-FF"
139 #define PVMF_MIME_AACFF         "X-AAC-FF"
140 #define PVMF_MIME_MP3FF         "X-MP3-FF"
141 #define PVMF_MIME_WAVFF         "X-WAV-FF"
142 #define PVMF_MIME_ASFFF         "x-pvmf/mux/asf"
143 #define PVMF_MIME_RMFF          "x-pvmf/mux/rm"
144 #define PVMF_MIME_DIVXFF        "x-pvmf/mux/divx"
145 #define PVMF_MIME_MIDIFF        "application/x-midi"
146 #define PVMF_MIME_AVIFF         "x-pvmf/mux/avi"
147 #define PVMF_MIME_DATA_PVRFF    "video/x-pvmf-pvr "
148 
149 // MIME strings for RAW data formats
150 #define PVMF_MIME_8BIT_RAW   "X-RAW-8"
151 
152 // MIME strings for PVMF data source types
153 #define PVMF_MIME_DATA_SOURCE_RTSP_URL  "X-PVMF-DATA-SRC-RTSP-URL"
154 #define PVMF_MIME_DATA_SOURCE_RTSP_PVR_FCS_URL "X-PVMF-DATA-SRC-RTSP-PVR-FCS-URL"
155 #define PVMF_MIME_DATA_SOURCE_HTTP_URL  "X-PVMF-DATA-SRC-HTTP-URL"
156 #define PVMF_MIME_DATA_SOURCE_SDP_FILE  "X-PVMF-DATA-SRC-SDP-FILE"
157 #define PVMF_MIME_DATA_SOURCE_SDP_PVR_FCS_FILE "X-PVMF-DATA-SRC-SDP-PVR-FCS-FILE"
158 #define PVMF_MIME_DATA_SOURCE_SDP_BROADCAST "X-PVMF-DATA-SRC-SDP-BROADCAST"
159 #define PVMF_MIME_DATA_SOURCE_PVX_FILE  "X-PVMF-DATA-SRC-PVX-FILE"
160 #define PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL "X-PVMF-DATA-SRC-MS-HTTP-STREAMING-URL"
161 #define PVMF_MIME_DATA_SOURCE_REAL_HTTP_CLOAKING_URL "X-PVMF-DATA-SRC-REAL-HTTP-CLOAKING-URL"
162 #define PVMF_MIME_DATA_SOURCE_RTP_PACKET_SOURCE "X-PVMF-DATA-SRC-RTP-PACKET"
163 #define PVMF_MIME_DATA_SOURCE_SHOUTCAST_URL "X-PVMF-DATA-SRC-SHOUTCAST-URL"
164 #define PVMF_MIME_DATA_SOURCE_UNKNOWN_URL "X-PVMF-DATA-SRC-UNKNOWN-URL"
165 
166 
167 // MIME string for miscellaneous media data formats
168 #define PVMF_MIME_3GPP_TIMEDTEXT        "video/3gpp-tt"
169 
170 // MIME string for protocol formats
171 #define PVMF_MIME_INET_UDP              "X-PVMF-NET-INET-UDP"
172 #define PVMF_MIME_INET_TCP              "X-PVMF-NET-INET-TCP"
173 #define PVMF_MIME_RTSP                  "X-PVMF-NET-INET-RTSP"
174 #define PVMF_MIME_RTCP                  "X-PVMF-NET-INET-RTCP"
175 
176 // reserved for 2way
177 #define PVMF_MIME_USERINPUT_BASIC_STRING    "x-pvmf/userinput/basic-string"
178 #define PVMF_MIME_USERINPUT_IA5_STRING      "x-pvmf/userinput/ia5-string"
179 #define PVMF_MIME_USERINPUT_GENERAL_STRING  "x-pvmf/userinput/general-string"
180 #define PVMF_MIME_USERINPUT_DTMF            "x-pvmf/userinput/dtmf"
181 
182 
183 class PVMFFormatType
184 {
185     public:
186         // default constructor
PVMFFormatType()187         PVMFFormatType() : iCompressed(false), iMimeStr(PVMF_MIME_FORMAT_UNKNOWN)
188         {}
189 
190         PVMFFormatType(const char* mimeStrPtr, bool compressed = false)
191         {
192             iStr = OSCL_HeapString<OsclMemAllocator> (mimeStrPtr);
193             iMimeStr = iStr.get_cstr();
194             iCompressed = compressed;
195         }
196 
197         PVMFFormatType(const char* mimeStrPtr, int32 mimeStrLen, bool compressed = false)
198         {
199             iStr = OSCL_HeapString<OsclMemAllocator> (mimeStrPtr, mimeStrLen);
200             iMimeStr.setPtrLen(iStr.get_cstr(), iStr.get_size());
201             iCompressed = compressed;
202         }
203 
204         PVMFFormatType& operator=(const PVMFFormatType& rhs)
205         {
206             iStr = OSCL_HeapString<OsclMemAllocator> (rhs.getMIMEStrPtr(), rhs.getMIMEStrLen());
207             iMimeStr.setPtrLen(iStr.get_cstr(), iStr.get_size());
208             iCompressed = rhs.isCompressed();
209             return *this;
210         }
211 
212         PVMFFormatType& operator=(const char* mimeStrPtr)
213         {
214             iStr = OSCL_HeapString<OsclMemAllocator> (mimeStrPtr);
215             iMimeStr = iStr.get_cstr();
216             return *this;
217         }
218 
~PVMFFormatType()219         virtual ~PVMFFormatType() {};
220 
221         // case insensitive comparision
222         c_bool operator==(const PVMFFormatType& rhs) const
223         {
224             return iMimeStr.isCIEquivalentTo(rhs.getStrCSumPtr());
225         }
226 
227         bool operator!=(const PVMFFormatType& rhs) const
228         {
229             return !(*this == rhs);
230         }
231 
232         void setCompressed(bool compressed = false)
233         {
234             iCompressed = compressed;
235         }
236 
getMIMEStrPtr()237         const char* getMIMEStrPtr() const
238         {
239             return iMimeStr.c_str();
240         }
241 
getMIMEStrLen()242         int32 getMIMEStrLen() const
243         {
244             return iMimeStr.length();
245         }
246 
getStrCSumPtr()247         const StrCSumPtrLen& getStrCSumPtr() const
248         {
249             return iMimeStr;
250         }
251 
252         //return true if it is a compressed Media
253         OSCL_IMPORT_REF bool isCompressed() const;
254 
255         //return true if a media type is IANA audio format or PV internal audio format.
256         OSCL_IMPORT_REF bool isAudio() const;
257 
258         //return true if a media type is IANA video format or PV internal video format.
259         OSCL_IMPORT_REF bool isVideo() const;
260 
261         //return true if a media type is image format or PV internal image format.
262         OSCL_IMPORT_REF bool isImage() const;
263 
264         //return true if a media type is IANA text format.
265         OSCL_IMPORT_REF bool isText() const;
266 
267         //return true if a media type is PV internal file format.
268         OSCL_IMPORT_REF bool isFile() const;
269 
270         //return true if a media type is PV internal raw format.
271         OSCL_IMPORT_REF bool isRaw() const;
272 
273         //return true if a media type is PV internal data source.
274         OSCL_IMPORT_REF bool isDataSource() const;
275 
276         //return true if a media type is PV internal data source.
277         OSCL_IMPORT_REF bool isUserInput() const;
278 
279         // a flag to indicate if a media type described by the MIME is compressed
280         // this value should be passed in because this class does not have the
281         // ability to determine if a given media type, especially a format from
282         // the third party???
283         bool                                iCompressed;
284 
285     protected:
286         // a local storage for MIME string
287         OSCL_HeapString<OsclMemAllocator>   iStr;
288         StrCSumPtrLen                       iMimeStr;
289 
290 };
291 
292 #endif
293