raw.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229
  1. /*
  2. * RAW muxer and demuxer
  3. * Copyright (c) 2001 Fabrice Bellard
  4. * Copyright (c) 2005 Alex Beregszaszi
  5. *
  6. * This file is part of FFmpeg.
  7. *
  8. * FFmpeg is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * FFmpeg is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with FFmpeg; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include "libavutil/crc.h"
  23. #include "libavcodec/ac3_parser.h"
  24. #include "libavcodec/bitstream.h"
  25. #include "libavcodec/bytestream.h"
  26. #include "avformat.h"
  27. #include "raw.h"
  28. #include "id3v2.h"
  29. /* simple formats */
  30. #if CONFIG_ROQ_MUXER
  31. static int roq_write_header(struct AVFormatContext *s)
  32. {
  33. static const uint8_t header[] = {
  34. 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00
  35. };
  36. put_buffer(s->pb, header, 8);
  37. put_flush_packet(s->pb);
  38. return 0;
  39. }
  40. #endif
  41. #if CONFIG_NULL_MUXER
  42. static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  43. {
  44. return 0;
  45. }
  46. #endif
  47. #if CONFIG_MUXERS
  48. static int raw_write_packet(struct AVFormatContext *s, AVPacket *pkt)
  49. {
  50. put_buffer(s->pb, pkt->data, pkt->size);
  51. put_flush_packet(s->pb);
  52. return 0;
  53. }
  54. #endif
  55. #if CONFIG_DEMUXERS
  56. /* raw input */
  57. static int raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
  58. {
  59. AVStream *st;
  60. int id;
  61. st = av_new_stream(s, 0);
  62. if (!st)
  63. return AVERROR(ENOMEM);
  64. id = s->iformat->value;
  65. if (id == CODEC_ID_RAWVIDEO) {
  66. st->codec->codec_type = CODEC_TYPE_VIDEO;
  67. } else {
  68. st->codec->codec_type = CODEC_TYPE_AUDIO;
  69. }
  70. st->codec->codec_id = id;
  71. switch(st->codec->codec_type) {
  72. case CODEC_TYPE_AUDIO:
  73. st->codec->sample_rate = ap->sample_rate;
  74. if(ap->channels) st->codec->channels = ap->channels;
  75. else st->codec->channels = 1;
  76. av_set_pts_info(st, 64, 1, st->codec->sample_rate);
  77. break;
  78. case CODEC_TYPE_VIDEO:
  79. if(ap->time_base.num)
  80. av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
  81. else
  82. av_set_pts_info(st, 64, 1, 25);
  83. st->codec->width = ap->width;
  84. st->codec->height = ap->height;
  85. st->codec->pix_fmt = ap->pix_fmt;
  86. if(st->codec->pix_fmt == PIX_FMT_NONE)
  87. st->codec->pix_fmt= PIX_FMT_YUV420P;
  88. break;
  89. default:
  90. return -1;
  91. }
  92. return 0;
  93. }
  94. #define RAW_PACKET_SIZE 1024
  95. static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
  96. {
  97. int ret, size, bps;
  98. // AVStream *st = s->streams[0];
  99. size= RAW_PACKET_SIZE;
  100. ret= av_get_packet(s->pb, pkt, size);
  101. pkt->stream_index = 0;
  102. if (ret <= 0) {
  103. return AVERROR(EIO);
  104. }
  105. /* note: we need to modify the packet size here to handle the last
  106. packet */
  107. pkt->size = ret;
  108. bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
  109. assert(bps); // if false there IS a bug elsewhere (NOT in this function)
  110. pkt->dts=
  111. pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
  112. return ret;
  113. }
  114. int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
  115. {
  116. int ret, size;
  117. size = RAW_PACKET_SIZE;
  118. if (av_new_packet(pkt, size) < 0)
  119. return AVERROR(EIO);
  120. pkt->pos= url_ftell(s->pb);
  121. pkt->stream_index = 0;
  122. ret = get_partial_buffer(s->pb, pkt->data, size);
  123. if (ret <= 0) {
  124. av_free_packet(pkt);
  125. return AVERROR(EIO);
  126. }
  127. pkt->size = ret;
  128. return ret;
  129. }
  130. #endif
  131. #if CONFIG_RAWVIDEO_DEMUXER
  132. static int rawvideo_read_packet(AVFormatContext *s, AVPacket *pkt)
  133. {
  134. int packet_size, ret, width, height;
  135. AVStream *st = s->streams[0];
  136. width = st->codec->width;
  137. height = st->codec->height;
  138. packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
  139. if (packet_size < 0)
  140. return -1;
  141. ret= av_get_packet(s->pb, pkt, packet_size);
  142. pkt->pts=
  143. pkt->dts= pkt->pos / packet_size;
  144. pkt->stream_index = 0;
  145. if (ret != packet_size) {
  146. return AVERROR(EIO);
  147. } else {
  148. return 0;
  149. }
  150. }
  151. #endif
  152. #if CONFIG_INGENIENT_DEMUXER
  153. // http://www.artificis.hu/files/texts/ingenient.txt
  154. static int ingenient_read_packet(AVFormatContext *s, AVPacket *pkt)
  155. {
  156. int ret, size, w, h, unk1, unk2;
  157. if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G'))
  158. return AVERROR(EIO); // FIXME
  159. size = get_le32(s->pb);
  160. w = get_le16(s->pb);
  161. h = get_le16(s->pb);
  162. url_fskip(s->pb, 8); // zero + size (padded?)
  163. url_fskip(s->pb, 2);
  164. unk1 = get_le16(s->pb);
  165. unk2 = get_le16(s->pb);
  166. url_fskip(s->pb, 22); // ASCII timestamp
  167. av_log(s, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n",
  168. size, w, h, unk1, unk2);
  169. if (av_new_packet(pkt, size) < 0)
  170. return AVERROR(EIO);
  171. pkt->pos = url_ftell(s->pb);
  172. pkt->stream_index = 0;
  173. ret = get_buffer(s->pb, pkt->data, size);
  174. if (ret <= 0) {
  175. av_free_packet(pkt);
  176. return AVERROR(EIO);
  177. }
  178. pkt->size = ret;
  179. return ret;
  180. }
  181. #endif
  182. #if CONFIG_DEMUXERS
  183. int pcm_read_seek(AVFormatContext *s,
  184. int stream_index, int64_t timestamp, int flags)
  185. {
  186. AVStream *st;
  187. int block_align, byte_rate, ret;
  188. int64_t pos;
  189. st = s->streams[0];
  190. block_align = st->codec->block_align ? st->codec->block_align :
  191. (av_get_bits_per_sample(st->codec->codec_id) * st->codec->channels) >> 3;
  192. byte_rate = st->codec->bit_rate ? st->codec->bit_rate >> 3 :
  193. block_align * st->codec->sample_rate;
  194. if (block_align <= 0 || byte_rate <= 0)
  195. return -1;
  196. /* compute the position by aligning it to block_align */
  197. pos = av_rescale_rnd(timestamp * byte_rate,
  198. st->time_base.num,
  199. st->time_base.den * (int64_t)block_align,
  200. (flags & AVSEEK_FLAG_BACKWARD) ? AV_ROUND_DOWN : AV_ROUND_UP);
  201. pos *= block_align;
  202. /* recompute exact position */
  203. st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num);
  204. if ((ret = url_fseek(s->pb, pos + s->data_offset, SEEK_SET)) < 0)
  205. return ret;
  206. return 0;
  207. }
  208. static int audio_read_header(AVFormatContext *s,
  209. AVFormatParameters *ap)
  210. {
  211. AVStream *st = av_new_stream(s, 0);
  212. if (!st)
  213. return AVERROR(ENOMEM);
  214. st->codec->codec_type = CODEC_TYPE_AUDIO;
  215. st->codec->codec_id = s->iformat->value;
  216. st->need_parsing = AVSTREAM_PARSE_FULL;
  217. /* the parameters will be extracted from the compressed bitstream */
  218. return 0;
  219. }
  220. /* MPEG-1/H.263 input */
  221. static int video_read_header(AVFormatContext *s,
  222. AVFormatParameters *ap)
  223. {
  224. AVStream *st;
  225. st = av_new_stream(s, 0);
  226. if (!st)
  227. return AVERROR(ENOMEM);
  228. st->codec->codec_type = CODEC_TYPE_VIDEO;
  229. st->codec->codec_id = s->iformat->value;
  230. st->need_parsing = AVSTREAM_PARSE_FULL;
  231. /* for MJPEG, specify frame rate */
  232. /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
  233. if (ap->time_base.num) {
  234. st->codec->time_base= ap->time_base;
  235. } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
  236. st->codec->codec_id == CODEC_ID_MPEG4 ||
  237. st->codec->codec_id == CODEC_ID_DIRAC ||
  238. st->codec->codec_id == CODEC_ID_H264) {
  239. st->codec->time_base= (AVRational){1,25};
  240. }
  241. av_set_pts_info(st, 64, 1, 1200000);
  242. return 0;
  243. }
  244. #endif
  245. #if CONFIG_MPEGVIDEO_DEMUXER
  246. #define SEQ_START_CODE 0x000001b3
  247. #define GOP_START_CODE 0x000001b8
  248. #define PICTURE_START_CODE 0x00000100
  249. #define SLICE_START_CODE 0x00000101
  250. #define PACK_START_CODE 0x000001ba
  251. #define VIDEO_ID 0x000001e0
  252. #define AUDIO_ID 0x000001c0
  253. static int mpegvideo_probe(AVProbeData *p)
  254. {
  255. uint32_t code= -1;
  256. int pic=0, seq=0, slice=0, pspack=0, pes=0;
  257. int i;
  258. for(i=0; i<p->buf_size; i++){
  259. code = (code<<8) + p->buf[i];
  260. if ((code & 0xffffff00) == 0x100) {
  261. switch(code){
  262. case SEQ_START_CODE: seq++; break;
  263. case PICTURE_START_CODE: pic++; break;
  264. case SLICE_START_CODE: slice++; break;
  265. case PACK_START_CODE: pspack++; break;
  266. }
  267. if ((code & 0x1f0) == VIDEO_ID) pes++;
  268. else if((code & 0x1e0) == AUDIO_ID) pes++;
  269. }
  270. }
  271. if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes)
  272. return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
  273. return 0;
  274. }
  275. #define CAVS_SEQ_START_CODE 0x000001b0
  276. #define CAVS_PIC_I_START_CODE 0x000001b3
  277. #define CAVS_UNDEF_START_CODE 0x000001b4
  278. #define CAVS_PIC_PB_START_CODE 0x000001b6
  279. #define CAVS_VIDEO_EDIT_CODE 0x000001b7
  280. #define CAVS_PROFILE_JIZHUN 0x20
  281. static int cavsvideo_probe(AVProbeData *p)
  282. {
  283. uint32_t code= -1;
  284. int pic=0, seq=0, slice_pos = 0;
  285. int i;
  286. for(i=0; i<p->buf_size; i++){
  287. code = (code<<8) + p->buf[i];
  288. if ((code & 0xffffff00) == 0x100) {
  289. if(code < CAVS_SEQ_START_CODE) {
  290. /* slices have to be consecutive */
  291. if(code < slice_pos)
  292. return 0;
  293. slice_pos = code;
  294. } else {
  295. slice_pos = 0;
  296. }
  297. if (code == CAVS_SEQ_START_CODE) {
  298. seq++;
  299. /* check for the only currently supported profile */
  300. if(p->buf[i+1] != CAVS_PROFILE_JIZHUN)
  301. return 0;
  302. } else if ((code == CAVS_PIC_I_START_CODE) ||
  303. (code == CAVS_PIC_PB_START_CODE)) {
  304. pic++;
  305. } else if ((code == CAVS_UNDEF_START_CODE) ||
  306. (code > CAVS_VIDEO_EDIT_CODE)) {
  307. return 0;
  308. }
  309. }
  310. }
  311. if(seq && seq*9<=pic*10)
  312. return AVPROBE_SCORE_MAX/2;
  313. return 0;
  314. }
  315. #endif
  316. #if CONFIG_M4V_DEMUXER
  317. #define VISUAL_OBJECT_START_CODE 0x000001b5
  318. #define VOP_START_CODE 0x000001b6
  319. static int mpeg4video_probe(AVProbeData *probe_packet)
  320. {
  321. uint32_t temp_buffer= -1;
  322. int VO=0, VOL=0, VOP = 0, VISO = 0, res=0;
  323. int i;
  324. for(i=0; i<probe_packet->buf_size; i++){
  325. temp_buffer = (temp_buffer<<8) + probe_packet->buf[i];
  326. if ((temp_buffer & 0xffffff00) != 0x100)
  327. continue;
  328. if (temp_buffer == VOP_START_CODE) VOP++;
  329. else if (temp_buffer == VISUAL_OBJECT_START_CODE) VISO++;
  330. else if (temp_buffer < 0x120) VO++;
  331. else if (temp_buffer < 0x130) VOL++;
  332. else if ( !(0x1AF < temp_buffer && temp_buffer < 0x1B7)
  333. && !(0x1B9 < temp_buffer && temp_buffer < 0x1C4)) res++;
  334. }
  335. if ( VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0)
  336. return AVPROBE_SCORE_MAX/2;
  337. return 0;
  338. }
  339. #endif
  340. #if CONFIG_H264_DEMUXER
  341. static int h264_probe(AVProbeData *p)
  342. {
  343. uint32_t code= -1;
  344. int sps=0, pps=0, idr=0, res=0, sli=0;
  345. int i;
  346. for(i=0; i<p->buf_size; i++){
  347. code = (code<<8) + p->buf[i];
  348. if ((code & 0xffffff00) == 0x100) {
  349. int ref_idc= (code>>5)&3;
  350. int type = code & 0x1F;
  351. static const int8_t ref_zero[32]={
  352. 2, 0, 0, 0, 0,-1, 1,-1,
  353. -1, 1, 1, 1, 1,-1, 2, 2,
  354. 2, 2, 2, 0, 2, 2, 2, 2,
  355. 2, 2, 2, 2, 2, 2, 2, 2
  356. };
  357. if(code & 0x80) //forbidden bit
  358. return 0;
  359. if(ref_zero[type] == 1 && ref_idc)
  360. return 0;
  361. if(ref_zero[type] ==-1 && !ref_idc)
  362. return 0;
  363. if(ref_zero[type] == 2)
  364. res++;
  365. switch(type){
  366. case 1: sli++; break;
  367. case 5: idr++; break;
  368. case 7:
  369. if(p->buf[i+2]&0x0F)
  370. return 0;
  371. sps++;
  372. break;
  373. case 8: pps++; break;
  374. }
  375. }
  376. }
  377. if(sps && pps && (idr||sli>3) && res<(sps+pps+idr))
  378. return AVPROBE_SCORE_MAX/2+1; // +1 for .mpg
  379. return 0;
  380. }
  381. #endif
  382. #if CONFIG_H263_DEMUXER
  383. static int h263_probe(AVProbeData *p)
  384. {
  385. int code;
  386. const uint8_t *d;
  387. d = p->buf;
  388. code = (d[0] << 14) | (d[1] << 6) | (d[2] >> 2);
  389. if (code == 0x20) {
  390. return 50;
  391. }
  392. return 0;
  393. }
  394. #endif
  395. #if CONFIG_H261_DEMUXER
  396. static int h261_probe(AVProbeData *p)
  397. {
  398. int code;
  399. const uint8_t *d;
  400. d = p->buf;
  401. code = (d[0] << 12) | (d[1] << 4) | (d[2] >> 4);
  402. if (code == 0x10) {
  403. return 50;
  404. }
  405. return 0;
  406. }
  407. #endif
  408. #if CONFIG_DTS_DEMUXER
  409. #define DCA_MARKER_14B_BE 0x1FFFE800
  410. #define DCA_MARKER_14B_LE 0xFF1F00E8
  411. #define DCA_MARKER_RAW_BE 0x7FFE8001
  412. #define DCA_MARKER_RAW_LE 0xFE7F0180
  413. static int dts_probe(AVProbeData *p)
  414. {
  415. const uint8_t *buf, *bufp;
  416. uint32_t state = -1;
  417. buf = p->buf;
  418. for(; buf < (p->buf+p->buf_size)-2; buf+=2) {
  419. bufp = buf;
  420. state = (state << 16) | bytestream_get_be16(&bufp);
  421. /* regular bitstream */
  422. if (state == DCA_MARKER_RAW_BE || state == DCA_MARKER_RAW_LE)
  423. return AVPROBE_SCORE_MAX/2+1;
  424. /* 14 bits big-endian bitstream */
  425. if (state == DCA_MARKER_14B_BE)
  426. if ((bytestream_get_be16(&bufp) & 0xFFF0) == 0x07F0)
  427. return AVPROBE_SCORE_MAX/2+1;
  428. /* 14 bits little-endian bitstream */
  429. if (state == DCA_MARKER_14B_LE)
  430. if ((bytestream_get_be16(&bufp) & 0xF0FF) == 0xF007)
  431. return AVPROBE_SCORE_MAX/2+1;
  432. }
  433. return 0;
  434. }
  435. #endif
  436. #if CONFIG_DIRAC_DEMUXER
  437. static int dirac_probe(AVProbeData *p)
  438. {
  439. if (AV_RL32(p->buf) == MKTAG('B', 'B', 'C', 'D'))
  440. return AVPROBE_SCORE_MAX;
  441. else
  442. return 0;
  443. }
  444. #endif
  445. #if CONFIG_DNXHD_DEMUXER
  446. static int dnxhd_probe(AVProbeData *p)
  447. {
  448. static const uint8_t header[] = {0x00,0x00,0x02,0x80,0x01};
  449. if (!memcmp(p->buf, header, 5))
  450. return AVPROBE_SCORE_MAX;
  451. else
  452. return 0;
  453. }
  454. #endif
  455. #if CONFIG_AC3_DEMUXER || CONFIG_EAC3_DEMUXER
  456. static int ac3_eac3_probe(AVProbeData *p, enum CodecID expected_codec_id)
  457. {
  458. int max_frames, first_frames = 0, frames;
  459. uint8_t *buf, *buf2, *end;
  460. AC3HeaderInfo hdr;
  461. GetBitContext gbc;
  462. enum CodecID codec_id = CODEC_ID_AC3;
  463. max_frames = 0;
  464. buf = p->buf;
  465. end = buf + p->buf_size;
  466. for(; buf < end; buf++) {
  467. buf2 = buf;
  468. for(frames = 0; buf2 < end; frames++) {
  469. init_get_bits(&gbc, buf2, 54);
  470. if(ff_ac3_parse_header(&gbc, &hdr) < 0)
  471. break;
  472. if(buf2 + hdr.frame_size > end ||
  473. av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
  474. break;
  475. if (hdr.bitstream_id > 10)
  476. codec_id = CODEC_ID_EAC3;
  477. buf2 += hdr.frame_size;
  478. }
  479. max_frames = FFMAX(max_frames, frames);
  480. if(buf == p->buf)
  481. first_frames = frames;
  482. }
  483. if(codec_id != expected_codec_id) return 0;
  484. if (first_frames>=3) return AVPROBE_SCORE_MAX * 3 / 4;
  485. else if(max_frames>=3) return AVPROBE_SCORE_MAX / 2;
  486. else if(max_frames>=1) return 1;
  487. else return 0;
  488. }
  489. #endif
  490. #if CONFIG_AC3_DEMUXER
  491. static int ac3_probe(AVProbeData *p)
  492. {
  493. return ac3_eac3_probe(p, CODEC_ID_AC3);
  494. }
  495. #endif
  496. #if CONFIG_EAC3_DEMUXER
  497. static int eac3_probe(AVProbeData *p)
  498. {
  499. return ac3_eac3_probe(p, CODEC_ID_EAC3);
  500. }
  501. #endif
  502. #if CONFIG_AAC_DEMUXER
  503. static int adts_aac_probe(AVProbeData *p)
  504. {
  505. int max_frames = 0, first_frames = 0;
  506. int fsize, frames;
  507. uint8_t *buf0 = p->buf;
  508. uint8_t *buf2;
  509. uint8_t *buf;
  510. uint8_t *end = buf0 + p->buf_size - 7;
  511. if (ff_id3v2_match(buf0)) {
  512. buf0 += ff_id3v2_tag_len(buf0);
  513. }
  514. buf = buf0;
  515. for(; buf < end; buf= buf2+1) {
  516. buf2 = buf;
  517. for(frames = 0; buf2 < end; frames++) {
  518. uint32_t header = AV_RB16(buf2);
  519. if((header&0xFFF6) != 0xFFF0)
  520. break;
  521. fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF;
  522. if(fsize < 7)
  523. break;
  524. buf2 += fsize;
  525. }
  526. max_frames = FFMAX(max_frames, frames);
  527. if(buf == buf0)
  528. first_frames= frames;
  529. }
  530. if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
  531. else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
  532. else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
  533. else if(max_frames>=1) return 1;
  534. else return 0;
  535. }
  536. #endif
  537. /* Note: Do not forget to add new entries to the Makefile as well. */
  538. #if CONFIG_AAC_DEMUXER
  539. AVInputFormat aac_demuxer = {
  540. "aac",
  541. NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
  542. 0,
  543. adts_aac_probe,
  544. audio_read_header,
  545. ff_raw_read_partial_packet,
  546. .flags= AVFMT_GENERIC_INDEX,
  547. .extensions = "aac",
  548. .value = CODEC_ID_AAC,
  549. };
  550. #endif
  551. #if CONFIG_AC3_DEMUXER
  552. AVInputFormat ac3_demuxer = {
  553. "ac3",
  554. NULL_IF_CONFIG_SMALL("raw AC-3"),
  555. 0,
  556. ac3_probe,
  557. audio_read_header,
  558. ff_raw_read_partial_packet,
  559. .flags= AVFMT_GENERIC_INDEX,
  560. .extensions = "ac3",
  561. .value = CODEC_ID_AC3,
  562. };
  563. #endif
  564. #if CONFIG_AC3_MUXER
  565. AVOutputFormat ac3_muxer = {
  566. "ac3",
  567. NULL_IF_CONFIG_SMALL("raw AC-3"),
  568. "audio/x-ac3",
  569. "ac3",
  570. 0,
  571. CODEC_ID_AC3,
  572. CODEC_ID_NONE,
  573. NULL,
  574. raw_write_packet,
  575. .flags= AVFMT_NOTIMESTAMPS,
  576. };
  577. #endif
  578. #if CONFIG_DIRAC_DEMUXER
  579. AVInputFormat dirac_demuxer = {
  580. "dirac",
  581. NULL_IF_CONFIG_SMALL("raw Dirac"),
  582. 0,
  583. dirac_probe,
  584. video_read_header,
  585. ff_raw_read_partial_packet,
  586. .flags= AVFMT_GENERIC_INDEX,
  587. .value = CODEC_ID_DIRAC,
  588. };
  589. #endif
  590. #if CONFIG_DIRAC_MUXER
  591. AVOutputFormat dirac_muxer = {
  592. "dirac",
  593. NULL_IF_CONFIG_SMALL("raw Dirac"),
  594. NULL,
  595. "drc",
  596. 0,
  597. CODEC_ID_NONE,
  598. CODEC_ID_DIRAC,
  599. NULL,
  600. raw_write_packet,
  601. .flags= AVFMT_NOTIMESTAMPS,
  602. };
  603. #endif
  604. #if CONFIG_DNXHD_DEMUXER
  605. AVInputFormat dnxhd_demuxer = {
  606. "dnxhd",
  607. NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
  608. 0,
  609. dnxhd_probe,
  610. video_read_header,
  611. ff_raw_read_partial_packet,
  612. .flags= AVFMT_GENERIC_INDEX,
  613. .value = CODEC_ID_DNXHD,
  614. };
  615. #endif
  616. #if CONFIG_DNXHD_MUXER
  617. AVOutputFormat dnxhd_muxer = {
  618. "dnxhd",
  619. NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
  620. NULL,
  621. "dnxhd",
  622. 0,
  623. CODEC_ID_NONE,
  624. CODEC_ID_DNXHD,
  625. NULL,
  626. raw_write_packet,
  627. .flags= AVFMT_NOTIMESTAMPS,
  628. };
  629. #endif
  630. #if CONFIG_DTS_DEMUXER
  631. AVInputFormat dts_demuxer = {
  632. "dts",
  633. NULL_IF_CONFIG_SMALL("raw DTS"),
  634. 0,
  635. dts_probe,
  636. audio_read_header,
  637. ff_raw_read_partial_packet,
  638. .flags= AVFMT_GENERIC_INDEX,
  639. .extensions = "dts",
  640. .value = CODEC_ID_DTS,
  641. };
  642. #endif
  643. #if CONFIG_DTS_MUXER
  644. AVOutputFormat dts_muxer = {
  645. "dts",
  646. NULL_IF_CONFIG_SMALL("raw DTS"),
  647. "audio/x-dca",
  648. "dts",
  649. 0,
  650. CODEC_ID_DTS,
  651. CODEC_ID_NONE,
  652. NULL,
  653. raw_write_packet,
  654. .flags= AVFMT_NOTIMESTAMPS,
  655. };
  656. #endif
  657. #if CONFIG_EAC3_DEMUXER
  658. AVInputFormat eac3_demuxer = {
  659. "eac3",
  660. NULL_IF_CONFIG_SMALL("raw E-AC-3"),
  661. 0,
  662. eac3_probe,
  663. audio_read_header,
  664. ff_raw_read_partial_packet,
  665. .flags= AVFMT_GENERIC_INDEX,
  666. .extensions = "eac3",
  667. .value = CODEC_ID_EAC3,
  668. };
  669. #endif
  670. #if CONFIG_EAC3_MUXER
  671. AVOutputFormat eac3_muxer = {
  672. "eac3",
  673. NULL_IF_CONFIG_SMALL("raw E-AC-3"),
  674. "audio/x-eac3",
  675. "eac3",
  676. 0,
  677. CODEC_ID_EAC3,
  678. CODEC_ID_NONE,
  679. NULL,
  680. raw_write_packet,
  681. .flags= AVFMT_NOTIMESTAMPS,
  682. };
  683. #endif
  684. #if CONFIG_GSM_DEMUXER
  685. AVInputFormat gsm_demuxer = {
  686. "gsm",
  687. NULL_IF_CONFIG_SMALL("raw GSM"),
  688. 0,
  689. NULL,
  690. audio_read_header,
  691. ff_raw_read_partial_packet,
  692. .flags= AVFMT_GENERIC_INDEX,
  693. .extensions = "gsm",
  694. .value = CODEC_ID_GSM,
  695. };
  696. #endif
  697. #if CONFIG_H261_DEMUXER
  698. AVInputFormat h261_demuxer = {
  699. "h261",
  700. NULL_IF_CONFIG_SMALL("raw H.261"),
  701. 0,
  702. h261_probe,
  703. video_read_header,
  704. ff_raw_read_partial_packet,
  705. .flags= AVFMT_GENERIC_INDEX,
  706. .extensions = "h261",
  707. .value = CODEC_ID_H261,
  708. };
  709. #endif
  710. #if CONFIG_H261_MUXER
  711. AVOutputFormat h261_muxer = {
  712. "h261",
  713. NULL_IF_CONFIG_SMALL("raw H.261"),
  714. "video/x-h261",
  715. "h261",
  716. 0,
  717. CODEC_ID_NONE,
  718. CODEC_ID_H261,
  719. NULL,
  720. raw_write_packet,
  721. .flags= AVFMT_NOTIMESTAMPS,
  722. };
  723. #endif
  724. #if CONFIG_H263_DEMUXER
  725. AVInputFormat h263_demuxer = {
  726. "h263",
  727. NULL_IF_CONFIG_SMALL("raw H.263"),
  728. 0,
  729. h263_probe,
  730. video_read_header,
  731. ff_raw_read_partial_packet,
  732. .flags= AVFMT_GENERIC_INDEX,
  733. // .extensions = "h263", //FIXME remove after writing mpeg4_probe
  734. .value = CODEC_ID_H263,
  735. };
  736. #endif
  737. #if CONFIG_H263_MUXER
  738. AVOutputFormat h263_muxer = {
  739. "h263",
  740. NULL_IF_CONFIG_SMALL("raw H.263"),
  741. "video/x-h263",
  742. "h263",
  743. 0,
  744. CODEC_ID_NONE,
  745. CODEC_ID_H263,
  746. NULL,
  747. raw_write_packet,
  748. .flags= AVFMT_NOTIMESTAMPS,
  749. };
  750. #endif
  751. #if CONFIG_H264_DEMUXER
  752. AVInputFormat h264_demuxer = {
  753. "h264",
  754. NULL_IF_CONFIG_SMALL("raw H.264 video format"),
  755. 0,
  756. h264_probe,
  757. video_read_header,
  758. ff_raw_read_partial_packet,
  759. .flags= AVFMT_GENERIC_INDEX,
  760. .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe
  761. .value = CODEC_ID_H264,
  762. };
  763. #endif
  764. #if CONFIG_H264_MUXER
  765. AVOutputFormat h264_muxer = {
  766. "h264",
  767. NULL_IF_CONFIG_SMALL("raw H.264 video format"),
  768. NULL,
  769. "h264",
  770. 0,
  771. CODEC_ID_NONE,
  772. CODEC_ID_H264,
  773. NULL,
  774. raw_write_packet,
  775. .flags= AVFMT_NOTIMESTAMPS,
  776. };
  777. #endif
  778. #if CONFIG_INGENIENT_DEMUXER
  779. AVInputFormat ingenient_demuxer = {
  780. "ingenient",
  781. NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"),
  782. 0,
  783. NULL,
  784. video_read_header,
  785. ingenient_read_packet,
  786. .flags= AVFMT_GENERIC_INDEX,
  787. .extensions = "cgi", // FIXME
  788. .value = CODEC_ID_MJPEG,
  789. };
  790. #endif
  791. #if CONFIG_M4V_DEMUXER
  792. AVInputFormat m4v_demuxer = {
  793. "m4v",
  794. NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
  795. 0,
  796. mpeg4video_probe, /** probing for MPEG-4 data */
  797. video_read_header,
  798. ff_raw_read_partial_packet,
  799. .flags= AVFMT_GENERIC_INDEX,
  800. .extensions = "m4v",
  801. .value = CODEC_ID_MPEG4,
  802. };
  803. #endif
  804. #if CONFIG_M4V_MUXER
  805. AVOutputFormat m4v_muxer = {
  806. "m4v",
  807. NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"),
  808. NULL,
  809. "m4v",
  810. 0,
  811. CODEC_ID_NONE,
  812. CODEC_ID_MPEG4,
  813. NULL,
  814. raw_write_packet,
  815. .flags= AVFMT_NOTIMESTAMPS,
  816. };
  817. #endif
  818. #if CONFIG_MJPEG_DEMUXER
  819. AVInputFormat mjpeg_demuxer = {
  820. "mjpeg",
  821. NULL_IF_CONFIG_SMALL("raw MJPEG video"),
  822. 0,
  823. NULL,
  824. video_read_header,
  825. ff_raw_read_partial_packet,
  826. .flags= AVFMT_GENERIC_INDEX,
  827. .extensions = "mjpg,mjpeg",
  828. .value = CODEC_ID_MJPEG,
  829. };
  830. #endif
  831. #if CONFIG_MJPEG_MUXER
  832. AVOutputFormat mjpeg_muxer = {
  833. "mjpeg",
  834. NULL_IF_CONFIG_SMALL("raw MJPEG video"),
  835. "video/x-mjpeg",
  836. "mjpg,mjpeg",
  837. 0,
  838. CODEC_ID_NONE,
  839. CODEC_ID_MJPEG,
  840. NULL,
  841. raw_write_packet,
  842. .flags= AVFMT_NOTIMESTAMPS,
  843. };
  844. #endif
  845. #if CONFIG_MLP_DEMUXER
  846. AVInputFormat mlp_demuxer = {
  847. "mlp",
  848. NULL_IF_CONFIG_SMALL("raw MLP"),
  849. 0,
  850. NULL,
  851. audio_read_header,
  852. ff_raw_read_partial_packet,
  853. .flags= AVFMT_GENERIC_INDEX,
  854. .extensions = "mlp",
  855. .value = CODEC_ID_MLP,
  856. };
  857. #endif
  858. #if CONFIG_MPEG1VIDEO_MUXER
  859. AVOutputFormat mpeg1video_muxer = {
  860. "mpeg1video",
  861. NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
  862. "video/x-mpeg",
  863. "mpg,mpeg,m1v",
  864. 0,
  865. CODEC_ID_NONE,
  866. CODEC_ID_MPEG1VIDEO,
  867. NULL,
  868. raw_write_packet,
  869. .flags= AVFMT_NOTIMESTAMPS,
  870. };
  871. #endif
  872. #if CONFIG_MPEG2VIDEO_MUXER
  873. AVOutputFormat mpeg2video_muxer = {
  874. "mpeg2video",
  875. NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
  876. NULL,
  877. "m2v",
  878. 0,
  879. CODEC_ID_NONE,
  880. CODEC_ID_MPEG2VIDEO,
  881. NULL,
  882. raw_write_packet,
  883. .flags= AVFMT_NOTIMESTAMPS,
  884. };
  885. #endif
  886. #if CONFIG_MPEGVIDEO_DEMUXER
  887. AVInputFormat mpegvideo_demuxer = {
  888. "mpegvideo",
  889. NULL_IF_CONFIG_SMALL("raw MPEG video"),
  890. 0,
  891. mpegvideo_probe,
  892. video_read_header,
  893. ff_raw_read_partial_packet,
  894. .flags= AVFMT_GENERIC_INDEX,
  895. .value = CODEC_ID_MPEG1VIDEO,
  896. };
  897. #endif
  898. #if CONFIG_CAVSVIDEO_DEMUXER
  899. AVInputFormat cavsvideo_demuxer = {
  900. "cavsvideo",
  901. NULL_IF_CONFIG_SMALL("raw Chinese AVS video"),
  902. 0,
  903. cavsvideo_probe,
  904. video_read_header,
  905. ff_raw_read_partial_packet,
  906. .flags= AVFMT_GENERIC_INDEX,
  907. .value = CODEC_ID_CAVS,
  908. };
  909. #endif
  910. #if CONFIG_NULL_MUXER
  911. AVOutputFormat null_muxer = {
  912. "null",
  913. NULL_IF_CONFIG_SMALL("raw null video format"),
  914. NULL,
  915. NULL,
  916. 0,
  917. #ifdef WORDS_BIGENDIAN
  918. CODEC_ID_PCM_S16BE,
  919. #else
  920. CODEC_ID_PCM_S16LE,
  921. #endif
  922. CODEC_ID_RAWVIDEO,
  923. NULL,
  924. null_write_packet,
  925. .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS,
  926. };
  927. #endif
  928. #if CONFIG_RAWVIDEO_DEMUXER
  929. AVInputFormat rawvideo_demuxer = {
  930. "rawvideo",
  931. NULL_IF_CONFIG_SMALL("raw video format"),
  932. 0,
  933. NULL,
  934. raw_read_header,
  935. rawvideo_read_packet,
  936. .flags= AVFMT_GENERIC_INDEX,
  937. .extensions = "yuv,cif,qcif,rgb",
  938. .value = CODEC_ID_RAWVIDEO,
  939. };
  940. #endif
  941. #if CONFIG_RAWVIDEO_MUXER
  942. AVOutputFormat rawvideo_muxer = {
  943. "rawvideo",
  944. NULL_IF_CONFIG_SMALL("raw video format"),
  945. NULL,
  946. "yuv,rgb",
  947. 0,
  948. CODEC_ID_NONE,
  949. CODEC_ID_RAWVIDEO,
  950. NULL,
  951. raw_write_packet,
  952. .flags= AVFMT_NOTIMESTAMPS,
  953. };
  954. #endif
  955. #if CONFIG_ROQ_MUXER
  956. AVOutputFormat roq_muxer =
  957. {
  958. "RoQ",
  959. NULL_IF_CONFIG_SMALL("raw id RoQ format"),
  960. NULL,
  961. "roq",
  962. 0,
  963. CODEC_ID_ROQ_DPCM,
  964. CODEC_ID_ROQ,
  965. roq_write_header,
  966. raw_write_packet,
  967. };
  968. #endif
  969. #if CONFIG_SHORTEN_DEMUXER
  970. AVInputFormat shorten_demuxer = {
  971. "shn",
  972. NULL_IF_CONFIG_SMALL("raw Shorten"),
  973. 0,
  974. NULL,
  975. audio_read_header,
  976. ff_raw_read_partial_packet,
  977. .flags= AVFMT_GENERIC_INDEX,
  978. .extensions = "shn",
  979. .value = CODEC_ID_SHORTEN,
  980. };
  981. #endif
  982. #if CONFIG_VC1_DEMUXER
  983. AVInputFormat vc1_demuxer = {
  984. "vc1",
  985. NULL_IF_CONFIG_SMALL("raw VC-1"),
  986. 0,
  987. NULL /* vc1_probe */,
  988. video_read_header,
  989. ff_raw_read_partial_packet,
  990. .extensions = "vc1",
  991. .value = CODEC_ID_VC1,
  992. };
  993. #endif
  994. /* PCM formats */
  995. #define PCMINPUTDEF(name, long_name, ext, codec) \
  996. AVInputFormat pcm_ ## name ## _demuxer = {\
  997. #name,\
  998. NULL_IF_CONFIG_SMALL(long_name),\
  999. 0,\
  1000. NULL,\
  1001. raw_read_header,\
  1002. raw_read_packet,\
  1003. NULL,\
  1004. pcm_read_seek,\
  1005. .flags= AVFMT_GENERIC_INDEX,\
  1006. .extensions = ext,\
  1007. .value = codec,\
  1008. };
  1009. #define PCMOUTPUTDEF(name, long_name, ext, codec) \
  1010. AVOutputFormat pcm_ ## name ## _muxer = {\
  1011. #name,\
  1012. NULL_IF_CONFIG_SMALL(long_name),\
  1013. NULL,\
  1014. ext,\
  1015. 0,\
  1016. codec,\
  1017. CODEC_ID_NONE,\
  1018. NULL,\
  1019. raw_write_packet,\
  1020. .flags= AVFMT_NOTIMESTAMPS,\
  1021. };
  1022. #if !CONFIG_MUXERS && CONFIG_DEMUXERS
  1023. #define PCMDEF(name, long_name, ext, codec) \
  1024. PCMINPUTDEF(name, long_name, ext, codec)
  1025. #elif CONFIG_MUXERS && !CONFIG_DEMUXERS
  1026. #define PCMDEF(name, long_name, ext, codec) \
  1027. PCMOUTPUTDEF(name, long_name, ext, codec)
  1028. #elif CONFIG_MUXERS && CONFIG_DEMUXERS
  1029. #define PCMDEF(name, long_name, ext, codec) \
  1030. PCMINPUTDEF(name, long_name, ext, codec)\
  1031. PCMOUTPUTDEF(name, long_name, ext, codec)
  1032. #else
  1033. #define PCMDEF(name, long_name, ext, codec)
  1034. #endif
  1035. #ifdef WORDS_BIGENDIAN
  1036. #define BE_DEF(s) s
  1037. #define LE_DEF(s) NULL
  1038. #else
  1039. #define BE_DEF(s) NULL
  1040. #define LE_DEF(s) s
  1041. #endif
  1042. PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
  1043. NULL, CODEC_ID_PCM_F64BE)
  1044. PCMDEF(f64le, "PCM 64 bit floating-point little-endian format",
  1045. NULL, CODEC_ID_PCM_F64LE)
  1046. PCMDEF(f32be, "PCM 32 bit floating-point big-endian format",
  1047. NULL, CODEC_ID_PCM_F32BE)
  1048. PCMDEF(f32le, "PCM 32 bit floating-point little-endian format",
  1049. NULL, CODEC_ID_PCM_F32LE)
  1050. PCMDEF(s32be, "PCM signed 32 bit big-endian format",
  1051. NULL, CODEC_ID_PCM_S32BE)
  1052. PCMDEF(s32le, "PCM signed 32 bit little-endian format",
  1053. NULL, CODEC_ID_PCM_S32LE)
  1054. PCMDEF(s24be, "PCM signed 24 bit big-endian format",
  1055. NULL, CODEC_ID_PCM_S24BE)
  1056. PCMDEF(s24le, "PCM signed 24 bit little-endian format",
  1057. NULL, CODEC_ID_PCM_S24LE)
  1058. PCMDEF(s16be, "PCM signed 16 bit big-endian format",
  1059. BE_DEF("sw"), CODEC_ID_PCM_S16BE)
  1060. PCMDEF(s16le, "PCM signed 16 bit little-endian format",
  1061. LE_DEF("sw"), CODEC_ID_PCM_S16LE)
  1062. PCMDEF(s8, "PCM signed 8 bit format",
  1063. "sb", CODEC_ID_PCM_S8)
  1064. PCMDEF(u32be, "PCM unsigned 32 bit big-endian format",
  1065. NULL, CODEC_ID_PCM_U32BE)
  1066. PCMDEF(u32le, "PCM unsigned 32 bit little-endian format",
  1067. NULL, CODEC_ID_PCM_U32LE)
  1068. PCMDEF(u24be, "PCM unsigned 24 bit big-endian format",
  1069. NULL, CODEC_ID_PCM_U24BE)
  1070. PCMDEF(u24le, "PCM unsigned 24 bit little-endian format",
  1071. NULL, CODEC_ID_PCM_U24LE)
  1072. PCMDEF(u16be, "PCM unsigned 16 bit big-endian format",
  1073. BE_DEF("uw"), CODEC_ID_PCM_U16BE)
  1074. PCMDEF(u16le, "PCM unsigned 16 bit little-endian format",
  1075. LE_DEF("uw"), CODEC_ID_PCM_U16LE)
  1076. PCMDEF(u8, "PCM unsigned 8 bit format",
  1077. "ub", CODEC_ID_PCM_U8)
  1078. PCMDEF(alaw, "PCM A-law format",
  1079. "al", CODEC_ID_PCM_ALAW)
  1080. PCMDEF(mulaw, "PCM mu-law format",
  1081. "ul", CODEC_ID_PCM_MULAW)