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.

180 lines
5.1KB

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