mp4live_config.h
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:12k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /*
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is MPEG4IP.
  13.  * 
  14.  * The Initial Developer of the Original Code is Cisco Systems Inc.
  15.  * Portions created by Cisco Systems Inc. are
  16.  * Copyright (C) Cisco Systems Inc. 2000, 2001.  All Rights Reserved.
  17.  * 
  18.  * Contributor(s): 
  19.  * Dave Mackie dmackie@cisco.com
  20.  * Bill May  wmay@cisco.com
  21.  */
  22. #ifndef __LIVE_CONFIG_H__
  23. #define __LIVE_CONFIG_H__
  24. #include <sys/types.h>
  25. #include <linux/videodev.h>
  26. #define CONFIG_SAFETY 0 // go fast, live dangerously
  27. #include "config_set.h"
  28. #include "media_time.h"
  29. #include "video_util_tv.h"
  30. #define NUM_FILE_HISTORY 8
  31. #define FILE_SOURCE "FILE"
  32. #define URL_SOURCE "URL"
  33. #define AUDIO_SOURCE_OSS "OSS"
  34. #define AUDIO_ENCODER_FAAC "faac"
  35. #define AUDIO_ENCODER_LAME "lame"
  36. #define AUDIO_ENCODING_NONE "None"
  37. #define AUDIO_ENCODING_PCM16 "PCM16"
  38. #define AUDIO_ENCODING_MP3 "MP3"
  39. #define AUDIO_ENCODING_AAC "AAC"
  40. #define AUDIO_ENCODING_AC3 "AC3"
  41. #define AUDIO_ENCODING_VORBIS "VORBIS"
  42. #define VIDEO_SOURCE_V4L "V4L"
  43. #define VIDEO_ENCODER_FFMPEG "ffmpeg"
  44. #define VIDEO_ENCODER_DIVX "divx"
  45. #define VIDEO_ENCODER_H26L "h26l"
  46. #define VIDEO_ENCODER_XVID "xvid"
  47. #define VIDEO_ENCODING_NONE "None"
  48. #define VIDEO_ENCODING_YUV12 "YUV12"
  49. #define VIDEO_ENCODING_MPEG2 "MPEG2"
  50. #define VIDEO_ENCODING_MPEG4 "MPEG4"
  51. #define VIDEO_ENCODING_H26L "H26L"
  52. #define VIDEO_NTSC_FRAME_RATE ((float)29.97)
  53. #define VIDEO_PAL_FRAME_RATE ((float)25.00)
  54. #define VIDEO_STD_ASPECT_RATIO  ((float)1.33) // standard 4:3
  55. #define VIDEO_LB1_ASPECT_RATIO  ((float)2.35) // typical "widescreen" format
  56. #define VIDEO_LB2_ASPECT_RATIO  ((float)1.85) // alternate widescreen format
  57. #define VIDEO_LB3_ASPECT_RATIO  ((float)1.78) // hdtv 16:9
  58. #define MP3_MPEG1_SAMPLES_PER_FRAME 1152 // for MPEG-1 bitrates
  59. #define MP3_MPEG2_SAMPLES_PER_FRAME 576 // for MPEG-2 bitrates
  60. // forward declarations
  61. class CVideoCapabilities;
  62. class CAudioCapabilities;
  63. class CLiveConfig;
  64. // some configuration utility routines
  65. void CalculateVideoFrameSize(CLiveConfig* pConfig);
  66. void GenerateMpeg4VideoConfig(CLiveConfig* pConfig);
  67. bool GenerateSdpFile(CLiveConfig* pConfig);
  68. enum {
  69. CONFIG_APP_REAL_TIME,
  70. CONFIG_APP_REAL_TIME_SCHEDULER,
  71. CONFIG_APP_DURATION,
  72. CONFIG_APP_DURATION_UNITS,
  73. CONFIG_APP_FILE_0,
  74. CONFIG_APP_FILE_1,
  75. CONFIG_APP_FILE_2,
  76. CONFIG_APP_FILE_3,
  77. CONFIG_APP_FILE_4,
  78. CONFIG_APP_FILE_5,
  79. CONFIG_APP_FILE_6,
  80. CONFIG_APP_FILE_7,
  81. CONFIG_APP_DEBUG,
  82. CONFIG_APP_LOGLEVEL,
  83. CONFIG_AUDIO_ENABLE,
  84. CONFIG_AUDIO_SOURCE_TYPE,
  85. CONFIG_AUDIO_SOURCE_NAME,
  86. CONFIG_AUDIO_MIXER_NAME,
  87. CONFIG_AUDIO_INPUT_NAME,
  88. CONFIG_AUDIO_SOURCE_TRACK,
  89. CONFIG_AUDIO_CHANNELS,
  90. CONFIG_AUDIO_SAMPLE_RATE,
  91. CONFIG_AUDIO_BIT_RATE,
  92. CONFIG_AUDIO_ENCODING,
  93. CONFIG_AUDIO_ENCODER,
  94. CONFIG_VIDEO_ENABLE,
  95. CONFIG_VIDEO_SOURCE_TYPE,
  96. CONFIG_VIDEO_SOURCE_NAME,
  97. CONFIG_VIDEO_INPUT,
  98. CONFIG_VIDEO_SIGNAL,
  99. CONFIG_VIDEO_TUNER,
  100. CONFIG_VIDEO_CHANNEL_LIST_INDEX,
  101. CONFIG_VIDEO_CHANNEL_INDEX,
  102. CONFIG_VIDEO_SOURCE_TRACK,
  103. CONFIG_VIDEO_PREVIEW,
  104. CONFIG_VIDEO_RAW_PREVIEW,
  105. CONFIG_VIDEO_ENCODED_PREVIEW,
  106. CONFIG_VIDEO_ENCODER,
  107. CONFIG_VIDEO_RAW_WIDTH,
  108. CONFIG_VIDEO_RAW_HEIGHT,
  109. CONFIG_VIDEO_ASPECT_RATIO,
  110. CONFIG_VIDEO_FRAME_RATE,
  111. CONFIG_VIDEO_KEY_FRAME_INTERVAL,
  112. CONFIG_VIDEO_BIT_RATE,
  113. CONFIG_VIDEO_PROFILE_ID,
  114. CONFIG_VIDEO_PROFILE_LEVEL_ID,
  115. CONFIG_RECORD_ENABLE,
  116. CONFIG_RECORD_RAW_AUDIO,
  117. CONFIG_RECORD_RAW_VIDEO,
  118. CONFIG_RECORD_ENCODED_AUDIO,
  119. CONFIG_RECORD_ENCODED_VIDEO,
  120. CONFIG_RECORD_MP4_FILE_NAME,
  121. CONFIG_RECORD_MP4_HINT_TRACKS,
  122. CONFIG_RECORD_MP4_OVERWRITE,
  123. CONFIG_RECORD_MP4_OPTIMIZE,
  124. CONFIG_RTP_ENABLE,
  125. CONFIG_RTP_DEST_ADDRESS,
  126. CONFIG_RTP_AUDIO_DEST_PORT,
  127. CONFIG_RTP_VIDEO_DEST_PORT,
  128. CONFIG_RTP_OVER_RTSP,
  129. CONFIG_RTP_RECV_BUFFER_TIME,
  130. CONFIG_RTP_PAYLOAD_SIZE,
  131. CONFIG_RTP_MCAST_TTL,
  132. CONFIG_RTP_DISABLE_TS_OFFSET,
  133. CONFIG_RTP_USE_SSM,
  134. CONFIG_SDP_FILE_NAME,
  135. CONFIG_RAW_ENABLE,
  136. CONFIG_RAW_PCM_FILE_NAME,
  137. CONFIG_RAW_PCM_FIFO,
  138. CONFIG_RAW_YUV_FILE_NAME,
  139. CONFIG_RAW_YUV_FIFO,
  140. };
  141. // normally this would be in a .cpp file
  142. // but we have it here to make it easier to keep
  143. // the enumerator list and the variables in sync
  144. #ifdef DECLARE_CONFIG_VARIABLES
  145. static SConfigVariable MyConfigVariables[] = {
  146. // APP
  147. { CONFIG_APP_REAL_TIME, "isRealTime", 
  148. CONFIG_TYPE_BOOL, true, },
  149. { CONFIG_APP_REAL_TIME_SCHEDULER, "useRealTimeScheduler", 
  150. CONFIG_TYPE_BOOL, true, },
  151. { CONFIG_APP_DURATION, "duration", 
  152. CONFIG_TYPE_INTEGER, (config_integer_t)1, },
  153. { CONFIG_APP_DURATION_UNITS, "durationUnits", 
  154. CONFIG_TYPE_INTEGER, (config_integer_t)60, },
  155. { CONFIG_APP_FILE_0, "file0", 
  156. CONFIG_TYPE_STRING, "", },
  157. { CONFIG_APP_FILE_1, "file1", 
  158. CONFIG_TYPE_STRING, "", },
  159. { CONFIG_APP_FILE_2, "file2", 
  160. CONFIG_TYPE_STRING, "", },
  161. { CONFIG_APP_FILE_3, "file3", 
  162. CONFIG_TYPE_STRING, "", },
  163. { CONFIG_APP_FILE_4, "file4", 
  164. CONFIG_TYPE_STRING, "", },
  165. { CONFIG_APP_FILE_5, "file5", 
  166. CONFIG_TYPE_STRING, "", },
  167. { CONFIG_APP_FILE_6, "file6", 
  168. CONFIG_TYPE_STRING, "", },
  169. { CONFIG_APP_FILE_7, "file7", 
  170. CONFIG_TYPE_STRING, "", },
  171. { CONFIG_APP_DEBUG, "debug", 
  172. CONFIG_TYPE_BOOL, false, },
  173. { CONFIG_APP_LOGLEVEL, "logLevel", 
  174. CONFIG_TYPE_INTEGER, (config_integer_t)0, },
  175. // AUDIO
  176. { CONFIG_AUDIO_ENABLE, "audioEnable", 
  177. CONFIG_TYPE_BOOL, true, },
  178. { CONFIG_AUDIO_SOURCE_TYPE, "audioSourceType", 
  179. CONFIG_TYPE_STRING, AUDIO_SOURCE_OSS, },
  180. { CONFIG_AUDIO_SOURCE_NAME, "audioDevice", 
  181. CONFIG_TYPE_STRING, "/dev/dsp", },
  182. { CONFIG_AUDIO_MIXER_NAME, "audioMixer", 
  183. CONFIG_TYPE_STRING, "/dev/mixer", },
  184. { CONFIG_AUDIO_INPUT_NAME, "audioInput", 
  185. CONFIG_TYPE_STRING, "mix", },
  186. { CONFIG_AUDIO_SOURCE_TRACK, "audioSourceTrack", 
  187. CONFIG_TYPE_INTEGER, (config_integer_t)0, },
  188. { CONFIG_AUDIO_CHANNELS, "audioChannels", 
  189. CONFIG_TYPE_INTEGER, (config_integer_t)2, },
  190. { CONFIG_AUDIO_SAMPLE_RATE, "audioSampleRate", 
  191. CONFIG_TYPE_INTEGER, (config_integer_t)44100, },
  192. { CONFIG_AUDIO_BIT_RATE, "audioBitRate", 
  193. CONFIG_TYPE_INTEGER, (config_integer_t)128, },
  194. { CONFIG_AUDIO_ENCODING, "audioEncoding",
  195. CONFIG_TYPE_STRING, AUDIO_ENCODING_MP3, },
  196. { CONFIG_AUDIO_ENCODER, "audioEncoder",
  197. CONFIG_TYPE_STRING, AUDIO_ENCODER_LAME, },
  198. // VIDEO
  199. { CONFIG_VIDEO_ENABLE, "videoEnable", 
  200. CONFIG_TYPE_BOOL, true, },
  201. { CONFIG_VIDEO_SOURCE_TYPE, "videoSourceType", 
  202. CONFIG_TYPE_STRING, VIDEO_SOURCE_V4L, },
  203. { CONFIG_VIDEO_SOURCE_NAME, "videoDevice", 
  204. CONFIG_TYPE_STRING, "/dev/video0", },
  205. { CONFIG_VIDEO_INPUT, "videoInput",
  206. CONFIG_TYPE_INTEGER, (config_integer_t)1, },
  207. { CONFIG_VIDEO_SIGNAL, "videoSignal",
  208. CONFIG_TYPE_INTEGER, (config_integer_t)VIDEO_MODE_NTSC, },
  209. { CONFIG_VIDEO_TUNER, "videoTuner",
  210. CONFIG_TYPE_INTEGER, (config_integer_t)-1, },
  211. { CONFIG_VIDEO_CHANNEL_LIST_INDEX, "videoChannelListIndex",
  212. CONFIG_TYPE_INTEGER, (config_integer_t)0, },
  213. { CONFIG_VIDEO_CHANNEL_INDEX, "videoChannelIndex",
  214. CONFIG_TYPE_INTEGER, (config_integer_t)1, },
  215. { CONFIG_VIDEO_SOURCE_TRACK, "videoSourceTrack", 
  216. CONFIG_TYPE_INTEGER, (config_integer_t)0, },
  217. { CONFIG_VIDEO_PREVIEW, "videoPreview",
  218. CONFIG_TYPE_BOOL, true, },
  219. { CONFIG_VIDEO_RAW_PREVIEW, "videoRawPreview",
  220. CONFIG_TYPE_BOOL, false, },
  221. { CONFIG_VIDEO_ENCODED_PREVIEW, "videoEncodedPreview",
  222. CONFIG_TYPE_BOOL, true, },
  223. { CONFIG_VIDEO_ENCODER, "videoEncoder",
  224. CONFIG_TYPE_STRING, VIDEO_ENCODER_XVID, },
  225. { CONFIG_VIDEO_RAW_WIDTH, "videoRawWidth",
  226. CONFIG_TYPE_INTEGER, (config_integer_t)320, },
  227. { CONFIG_VIDEO_RAW_HEIGHT, "videoRawHeight",
  228. CONFIG_TYPE_INTEGER, (config_integer_t)240, },
  229. { CONFIG_VIDEO_ASPECT_RATIO, "videoAspectRatio",
  230. CONFIG_TYPE_FLOAT, VIDEO_STD_ASPECT_RATIO },
  231. { CONFIG_VIDEO_FRAME_RATE, "videoFrameRate", 
  232. CONFIG_TYPE_FLOAT, VIDEO_NTSC_FRAME_RATE, },
  233. { CONFIG_VIDEO_KEY_FRAME_INTERVAL, "videoKeyFrameInterval", 
  234. CONFIG_TYPE_FLOAT, (float)2.0, },
  235. { CONFIG_VIDEO_BIT_RATE, "videoBitRate",
  236. CONFIG_TYPE_INTEGER, (config_integer_t)500, },
  237. { CONFIG_VIDEO_PROFILE_ID, "videoProfileId",
  238. CONFIG_TYPE_INTEGER, (config_integer_t)1, },
  239. { CONFIG_VIDEO_PROFILE_LEVEL_ID, "videoProfileLevelId",
  240. CONFIG_TYPE_INTEGER, (config_integer_t)3, },
  241. // RECORD
  242. { CONFIG_RECORD_ENABLE, "recordEnable", 
  243. CONFIG_TYPE_BOOL, true, },
  244. { CONFIG_RECORD_RAW_AUDIO, "recordRawAudio", 
  245. CONFIG_TYPE_BOOL, false, },
  246. { CONFIG_RECORD_RAW_VIDEO, "recordRawVideo", 
  247. CONFIG_TYPE_BOOL, false, },
  248. { CONFIG_RECORD_ENCODED_AUDIO, "recordEncodedAudio", 
  249. CONFIG_TYPE_BOOL, true, },
  250. { CONFIG_RECORD_ENCODED_VIDEO, "recordEncodedVideo", 
  251. CONFIG_TYPE_BOOL, true, },
  252. { CONFIG_RECORD_MP4_FILE_NAME, "recordMp4File", 
  253. CONFIG_TYPE_STRING, "capture.mp4", },
  254. { CONFIG_RECORD_MP4_HINT_TRACKS, "recordMp4HintTracks", 
  255. CONFIG_TYPE_BOOL, true, },
  256. { CONFIG_RECORD_MP4_OVERWRITE, "recordMp4Overwrite", 
  257. CONFIG_TYPE_BOOL, true, },
  258. { CONFIG_RECORD_MP4_OPTIMIZE, "recordMp4Optimize", 
  259. CONFIG_TYPE_BOOL, false, },
  260. // RTP
  261. { CONFIG_RTP_ENABLE, "rtpEnable", 
  262. CONFIG_TYPE_BOOL, false, },
  263. { CONFIG_RTP_DEST_ADDRESS, "rtpDestAddress",
  264. CONFIG_TYPE_STRING, "224.1.2.3", },
  265. { CONFIG_RTP_AUDIO_DEST_PORT, "rtpAudioDestPort",
  266. CONFIG_TYPE_INTEGER, (config_integer_t)20002, },
  267. { CONFIG_RTP_VIDEO_DEST_PORT, "rtpVideoDestPort",
  268. CONFIG_TYPE_INTEGER, (config_integer_t)20000, },
  269. { CONFIG_RTP_OVER_RTSP, "rtpOverRtsp",
  270. CONFIG_TYPE_BOOL, false, },
  271. { CONFIG_RTP_RECV_BUFFER_TIME, "rtpRecvBufferTime",
  272. CONFIG_TYPE_INTEGER, (config_integer_t)2, },
  273. { CONFIG_RTP_PAYLOAD_SIZE, "rtpPayloadSize",
  274. CONFIG_TYPE_INTEGER, (config_integer_t)1460, },
  275. { CONFIG_RTP_MCAST_TTL, "rtpMulticastTtl",
  276. CONFIG_TYPE_INTEGER, (config_integer_t)15, },
  277. { CONFIG_RTP_DISABLE_TS_OFFSET, "rtpDisableTimestampOffset", 
  278. CONFIG_TYPE_BOOL, false, },
  279. { CONFIG_RTP_USE_SSM, "rtpUseSingleSourceMulticast", 
  280. CONFIG_TYPE_BOOL, false, },
  281. { CONFIG_SDP_FILE_NAME, "sdpFile", 
  282. CONFIG_TYPE_STRING, "capture.sdp", },
  283. // RAW sink
  284. { CONFIG_RAW_ENABLE, "rawEnable", 
  285. CONFIG_TYPE_BOOL, false, },
  286. { CONFIG_RAW_PCM_FILE_NAME, "rawAudioFile", 
  287. CONFIG_TYPE_STRING, "capture.pcm", },
  288. { CONFIG_RAW_PCM_FIFO, "rawAudioUseFifo", 
  289. CONFIG_TYPE_BOOL, false, },
  290. { CONFIG_RAW_YUV_FILE_NAME, "rawVideoFile", 
  291. CONFIG_TYPE_STRING, "capture.yuv", },
  292. { CONFIG_RAW_YUV_FIFO, "rawVideoUseFifo", 
  293. CONFIG_TYPE_BOOL, false, },
  294. };
  295. #endif /* DECLARE_CONFIG_VARIABLES */
  296. class CLiveConfig : public CConfigSet {
  297. public:
  298. CLiveConfig(SConfigVariable* variables, 
  299. config_index_t numVariables, const char* defaultFileName);
  300. ~CLiveConfig();
  301. // recalculate derived values
  302. void Update();
  303. void UpdateFileHistory(char* fileName);
  304. void UpdateVideo();
  305. void UpdateAudio();
  306. void UpdateRecord();
  307. bool IsOneSource();
  308. bool IsCaptureVideoSource();
  309. bool IsCaptureAudioSource();
  310. bool SourceRawVideo() {
  311. return (GetBoolValue(CONFIG_VIDEO_RAW_PREVIEW)
  312. || (GetBoolValue(CONFIG_RECORD_ENABLE)
  313. && GetBoolValue(CONFIG_RECORD_RAW_VIDEO))
  314. || GetBoolValue(CONFIG_RAW_ENABLE));
  315. }
  316. bool SourceRawAudio() {
  317. return (GetBoolValue(CONFIG_RECORD_ENABLE)
  318. && GetBoolValue(CONFIG_RECORD_RAW_AUDIO))
  319. || GetBoolValue(CONFIG_RAW_ENABLE);
  320. }
  321. public:
  322. // command line configuration
  323. bool m_appAutomatic;
  324. // derived, shared video configuration
  325. CVideoCapabilities* m_videoCapabilities;
  326. bool m_videoEncode;
  327. u_int32_t m_videoPreviewWindowId;
  328. u_int16_t m_videoWidth;
  329. u_int16_t m_videoHeight;
  330. u_int16_t m_videoMaxWidth;
  331. u_int16_t m_videoMaxHeight;
  332. u_int32_t m_ySize;
  333. u_int32_t m_uvSize;
  334. u_int32_t m_yuvSize;
  335. bool m_videoNeedRgbToYuv;
  336. u_int16_t m_videoMpeg4ConfigLength;
  337. u_int8_t* m_videoMpeg4Config;
  338. u_int32_t m_videoMaxVopSize;
  339. u_int8_t m_videoTimeIncrBits;
  340. // derived, shared audio configuration
  341. CAudioCapabilities* m_audioCapabilities;
  342. bool m_audioEncode;
  343. // derived, shared file configuration
  344. u_int64_t m_recordEstFileSize;
  345. };
  346. #endif /* __LIVE_CONFIG_H__ */