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.

163 lines
4.6KB

  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. AVRational framerate;
  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. if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
  75. av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
  76. goto fail;
  77. }
  78. st->codec->time_base = av_inv_q(framerate);
  79. avpriv_set_pts_info(st, 64, 1, 1200000);
  80. fail:
  81. return ret;
  82. }
  83. /* Note: Do not forget to add new entries to the Makefile as well. */
  84. #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
  85. #define DEC AV_OPT_FLAG_DECODING_PARAM
  86. const AVOption ff_rawvideo_options[] = {
  87. { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
  88. { NULL },
  89. };
  90. #if CONFIG_LATM_DEMUXER
  91. AVInputFormat ff_latm_demuxer = {
  92. .name = "latm",
  93. .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
  94. .read_header = ff_raw_audio_read_header,
  95. .read_packet = ff_raw_read_partial_packet,
  96. .flags = AVFMT_GENERIC_INDEX,
  97. .extensions = "latm",
  98. .raw_codec_id = AV_CODEC_ID_AAC_LATM,
  99. };
  100. #endif
  101. #if CONFIG_MJPEG_DEMUXER
  102. FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", AV_CODEC_ID_MJPEG)
  103. #endif
  104. #if CONFIG_MLP_DEMUXER
  105. AVInputFormat ff_mlp_demuxer = {
  106. .name = "mlp",
  107. .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
  108. .read_header = ff_raw_audio_read_header,
  109. .read_packet = ff_raw_read_partial_packet,
  110. .flags = AVFMT_GENERIC_INDEX,
  111. .extensions = "mlp",
  112. .raw_codec_id = AV_CODEC_ID_MLP,
  113. };
  114. #endif
  115. #if CONFIG_TRUEHD_DEMUXER
  116. AVInputFormat ff_truehd_demuxer = {
  117. .name = "truehd",
  118. .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
  119. .read_header = ff_raw_audio_read_header,
  120. .read_packet = ff_raw_read_partial_packet,
  121. .flags = AVFMT_GENERIC_INDEX,
  122. .extensions = "thd",
  123. .raw_codec_id = AV_CODEC_ID_TRUEHD,
  124. };
  125. #endif
  126. #if CONFIG_SHORTEN_DEMUXER
  127. AVInputFormat ff_shorten_demuxer = {
  128. .name = "shn",
  129. .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
  130. .read_header = ff_raw_audio_read_header,
  131. .read_packet = ff_raw_read_partial_packet,
  132. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
  133. .extensions = "shn",
  134. .raw_codec_id = AV_CODEC_ID_SHORTEN,
  135. };
  136. #endif
  137. #if CONFIG_VC1_DEMUXER
  138. FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
  139. #endif