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.

178 lines
5.0KB

  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 "internal.h"
  24. #include "avio_internal.h"
  25. #include "rawdec.h"
  26. #include "libavutil/opt.h"
  27. #include "libavutil/parseutils.h"
  28. #include "libavutil/pixdesc.h"
  29. #include "libavutil/avassert.h"
  30. #define RAW_PACKET_SIZE 1024
  31. int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
  32. {
  33. int ret, size;
  34. size = RAW_PACKET_SIZE;
  35. if (av_new_packet(pkt, size) < 0)
  36. return AVERROR(ENOMEM);
  37. pkt->pos= avio_tell(s->pb);
  38. pkt->stream_index = 0;
  39. ret = ffio_read_partial(s->pb, pkt->data, size);
  40. if (ret < 0) {
  41. av_free_packet(pkt);
  42. return ret;
  43. }
  44. av_shrink_packet(pkt, ret);
  45. return ret;
  46. }
  47. int ff_raw_audio_read_header(AVFormatContext *s)
  48. {
  49. AVStream *st = avformat_new_stream(s, NULL);
  50. if (!st)
  51. return AVERROR(ENOMEM);
  52. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  53. st->codec->codec_id = s->iformat->raw_codec_id;
  54. st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
  55. st->start_time = 0;
  56. /* the parameters will be extracted from the compressed bitstream */
  57. return 0;
  58. }
  59. /* MPEG-1/H.263 input */
  60. int ff_raw_video_read_header(AVFormatContext *s)
  61. {
  62. AVStream *st;
  63. FFRawVideoDemuxerContext *s1 = s->priv_data;
  64. int ret = 0;
  65. st = avformat_new_stream(s, NULL);
  66. if (!st) {
  67. ret = AVERROR(ENOMEM);
  68. goto fail;
  69. }
  70. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  71. st->codec->codec_id = s->iformat->raw_codec_id;
  72. st->need_parsing = AVSTREAM_PARSE_FULL_RAW;
  73. st->codec->time_base = av_inv_q(s1->framerate);
  74. avpriv_set_pts_info(st, 64, 1, 1200000);
  75. fail:
  76. return ret;
  77. }
  78. static int ff_raw_data_read_header(AVFormatContext *s)
  79. {
  80. AVStream *st = avformat_new_stream(s, NULL);
  81. if (!st)
  82. return AVERROR(ENOMEM);
  83. st->codec->codec_type = AVMEDIA_TYPE_DATA;
  84. st->codec->codec_id = s->iformat->raw_codec_id;
  85. st->start_time = 0;
  86. return 0;
  87. }
  88. /* Note: Do not forget to add new entries to the Makefile as well. */
  89. #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
  90. #define DEC AV_OPT_FLAG_DECODING_PARAM
  91. const AVOption ff_rawvideo_options[] = {
  92. { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, 0, DEC},
  93. { NULL },
  94. };
  95. #if CONFIG_DATA_DEMUXER
  96. AVInputFormat ff_data_demuxer = {
  97. .name = "data",
  98. .long_name = NULL_IF_CONFIG_SMALL("raw data"),
  99. .read_header = ff_raw_data_read_header,
  100. .read_packet = ff_raw_read_partial_packet,
  101. .raw_codec_id = AV_CODEC_ID_NONE,
  102. };
  103. #endif
  104. #if CONFIG_LATM_DEMUXER
  105. AVInputFormat ff_latm_demuxer = {
  106. .name = "latm",
  107. .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
  108. .read_header = ff_raw_audio_read_header,
  109. .read_packet = ff_raw_read_partial_packet,
  110. .flags = AVFMT_GENERIC_INDEX,
  111. .extensions = "latm",
  112. .raw_codec_id = AV_CODEC_ID_AAC_LATM,
  113. };
  114. #endif
  115. #if CONFIG_MJPEG_DEMUXER
  116. FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
  117. #endif
  118. #if CONFIG_MLP_DEMUXER
  119. AVInputFormat ff_mlp_demuxer = {
  120. .name = "mlp",
  121. .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
  122. .read_header = ff_raw_audio_read_header,
  123. .read_packet = ff_raw_read_partial_packet,
  124. .flags = AVFMT_GENERIC_INDEX,
  125. .extensions = "mlp",
  126. .raw_codec_id = AV_CODEC_ID_MLP,
  127. };
  128. #endif
  129. #if CONFIG_TRUEHD_DEMUXER
  130. AVInputFormat ff_truehd_demuxer = {
  131. .name = "truehd",
  132. .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
  133. .read_header = ff_raw_audio_read_header,
  134. .read_packet = ff_raw_read_partial_packet,
  135. .flags = AVFMT_GENERIC_INDEX,
  136. .extensions = "thd",
  137. .raw_codec_id = AV_CODEC_ID_TRUEHD,
  138. };
  139. #endif
  140. #if CONFIG_SHORTEN_DEMUXER
  141. AVInputFormat ff_shorten_demuxer = {
  142. .name = "shn",
  143. .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
  144. .read_header = ff_raw_audio_read_header,
  145. .read_packet = ff_raw_read_partial_packet,
  146. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
  147. .extensions = "shn",
  148. .raw_codec_id = AV_CODEC_ID_SHORTEN,
  149. };
  150. #endif
  151. #if CONFIG_VC1_DEMUXER
  152. FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
  153. #endif