You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
6.3KB

  1. /*
  2. * RAW demuxers
  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 "avformat.h"
  23. #include "avio_internal.h"
  24. #include "rawdec.h"
  25. /* raw input */
  26. int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
  27. {
  28. AVStream *st;
  29. enum CodecID id;
  30. st = av_new_stream(s, 0);
  31. if (!st)
  32. return AVERROR(ENOMEM);
  33. id = s->iformat->value;
  34. if (id == CODEC_ID_RAWVIDEO) {
  35. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  36. } else {
  37. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  38. }
  39. st->codec->codec_id = id;
  40. switch(st->codec->codec_type) {
  41. case AVMEDIA_TYPE_AUDIO:
  42. st->codec->sample_rate = ap->sample_rate;
  43. if(ap->channels) st->codec->channels = ap->channels;
  44. else st->codec->channels = 1;
  45. st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
  46. assert(st->codec->bits_per_coded_sample > 0);
  47. st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
  48. av_set_pts_info(st, 64, 1, st->codec->sample_rate);
  49. break;
  50. case AVMEDIA_TYPE_VIDEO:
  51. if(ap->time_base.num)
  52. av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
  53. else
  54. av_set_pts_info(st, 64, 1, 25);
  55. st->codec->width = ap->width;
  56. st->codec->height = ap->height;
  57. st->codec->pix_fmt = ap->pix_fmt;
  58. if(st->codec->pix_fmt == PIX_FMT_NONE)
  59. st->codec->pix_fmt= PIX_FMT_YUV420P;
  60. break;
  61. default:
  62. return -1;
  63. }
  64. return 0;
  65. }
  66. #define RAW_PACKET_SIZE 1024
  67. int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
  68. {
  69. int ret, size;
  70. size = RAW_PACKET_SIZE;
  71. if (av_new_packet(pkt, size) < 0)
  72. return AVERROR(ENOMEM);
  73. pkt->pos= avio_tell(s->pb);
  74. pkt->stream_index = 0;
  75. ret = ffio_read_partial(s->pb, pkt->data, size);
  76. if (ret < 0) {
  77. av_free_packet(pkt);
  78. return ret;
  79. }
  80. pkt->size = ret;
  81. return ret;
  82. }
  83. int ff_raw_audio_read_header(AVFormatContext *s,
  84. AVFormatParameters *ap)
  85. {
  86. AVStream *st = av_new_stream(s, 0);
  87. if (!st)
  88. return AVERROR(ENOMEM);
  89. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  90. st->codec->codec_id = s->iformat->value;
  91. st->need_parsing = AVSTREAM_PARSE_FULL;
  92. st->start_time = 0;
  93. /* the parameters will be extracted from the compressed bitstream */
  94. return 0;
  95. }
  96. /* MPEG-1/H.263 input */
  97. int ff_raw_video_read_header(AVFormatContext *s,
  98. AVFormatParameters *ap)
  99. {
  100. AVStream *st;
  101. st = av_new_stream(s, 0);
  102. if (!st)
  103. return AVERROR(ENOMEM);
  104. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  105. st->codec->codec_id = s->iformat->value;
  106. st->need_parsing = AVSTREAM_PARSE_FULL;
  107. /* for MJPEG, specify frame rate */
  108. /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
  109. if (ap->time_base.num) {
  110. st->codec->time_base= ap->time_base;
  111. } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
  112. st->codec->codec_id == CODEC_ID_MPEG4 ||
  113. st->codec->codec_id == CODEC_ID_DIRAC ||
  114. st->codec->codec_id == CODEC_ID_DNXHD ||
  115. st->codec->codec_id == CODEC_ID_VC1 ||
  116. st->codec->codec_id == CODEC_ID_H264) {
  117. st->codec->time_base= (AVRational){1,25};
  118. }
  119. av_set_pts_info(st, 64, 1, 1200000);
  120. return 0;
  121. }
  122. /* Note: Do not forget to add new entries to the Makefile as well. */
  123. #if CONFIG_G722_DEMUXER
  124. AVInputFormat ff_g722_demuxer = {
  125. "g722",
  126. NULL_IF_CONFIG_SMALL("raw G.722"),
  127. 0,
  128. NULL,
  129. ff_raw_read_header,
  130. ff_raw_read_partial_packet,
  131. .flags= AVFMT_GENERIC_INDEX,
  132. .extensions = "g722,722",
  133. .value = CODEC_ID_ADPCM_G722,
  134. };
  135. #endif
  136. #if CONFIG_GSM_DEMUXER
  137. AVInputFormat ff_gsm_demuxer = {
  138. "gsm",
  139. NULL_IF_CONFIG_SMALL("raw GSM"),
  140. 0,
  141. NULL,
  142. ff_raw_audio_read_header,
  143. ff_raw_read_partial_packet,
  144. .flags= AVFMT_GENERIC_INDEX,
  145. .extensions = "gsm",
  146. .value = CODEC_ID_GSM,
  147. };
  148. #endif
  149. #if CONFIG_MJPEG_DEMUXER
  150. AVInputFormat ff_mjpeg_demuxer = {
  151. "mjpeg",
  152. NULL_IF_CONFIG_SMALL("raw MJPEG video"),
  153. 0,
  154. NULL,
  155. ff_raw_video_read_header,
  156. ff_raw_read_partial_packet,
  157. .flags= AVFMT_GENERIC_INDEX,
  158. .extensions = "mjpg,mjpeg",
  159. .value = CODEC_ID_MJPEG,
  160. };
  161. #endif
  162. #if CONFIG_MLP_DEMUXER
  163. AVInputFormat ff_mlp_demuxer = {
  164. "mlp",
  165. NULL_IF_CONFIG_SMALL("raw MLP"),
  166. 0,
  167. NULL,
  168. ff_raw_audio_read_header,
  169. ff_raw_read_partial_packet,
  170. .flags= AVFMT_GENERIC_INDEX,
  171. .extensions = "mlp",
  172. .value = CODEC_ID_MLP,
  173. };
  174. #endif
  175. #if CONFIG_TRUEHD_DEMUXER
  176. AVInputFormat ff_truehd_demuxer = {
  177. "truehd",
  178. NULL_IF_CONFIG_SMALL("raw TrueHD"),
  179. 0,
  180. NULL,
  181. ff_raw_audio_read_header,
  182. ff_raw_read_partial_packet,
  183. .flags= AVFMT_GENERIC_INDEX,
  184. .extensions = "thd",
  185. .value = CODEC_ID_TRUEHD,
  186. };
  187. #endif
  188. #if CONFIG_SHORTEN_DEMUXER
  189. AVInputFormat ff_shorten_demuxer = {
  190. "shn",
  191. NULL_IF_CONFIG_SMALL("raw Shorten"),
  192. 0,
  193. NULL,
  194. ff_raw_audio_read_header,
  195. ff_raw_read_partial_packet,
  196. .flags= AVFMT_GENERIC_INDEX,
  197. .extensions = "shn",
  198. .value = CODEC_ID_SHORTEN,
  199. };
  200. #endif
  201. #if CONFIG_VC1_DEMUXER
  202. AVInputFormat ff_vc1_demuxer = {
  203. "vc1",
  204. NULL_IF_CONFIG_SMALL("raw VC-1"),
  205. 0,
  206. NULL /* vc1_probe */,
  207. ff_raw_video_read_header,
  208. ff_raw_read_partial_packet,
  209. .extensions = "vc1",
  210. .value = CODEC_ID_VC1,
  211. };
  212. #endif