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.

169 lines
4.9KB

  1. /*
  2. * RAW demuxers
  3. * Copyright (c) 2001 Fabrice Bellard
  4. * Copyright (c) 2005 Alex Beregszaszi
  5. *
  6. * This file is part of Libav.
  7. *
  8. * Libav 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. * Libav 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 Libav; 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. #define RAW_PACKET_SIZE 1024
  30. int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
  31. {
  32. int ret, size;
  33. size = RAW_PACKET_SIZE;
  34. if (av_new_packet(pkt, size) < 0)
  35. return AVERROR(ENOMEM);
  36. pkt->pos= avio_tell(s->pb);
  37. pkt->stream_index = 0;
  38. ret = ffio_read_partial(s->pb, pkt->data, size);
  39. if (ret < 0) {
  40. av_free_packet(pkt);
  41. return ret;
  42. } else if (ret < size) {
  43. /* initialize end of packet for partial reads to avoid reading
  44. * uninitialized data on allowed overreads */
  45. memset(pkt->data + ret, 0, FF_INPUT_BUFFER_PADDING_SIZE);
  46. }
  47. pkt->size = ret;
  48. return ret;
  49. }
  50. int ff_raw_audio_read_header(AVFormatContext *s)
  51. {
  52. AVStream *st = avformat_new_stream(s, NULL);
  53. if (!st)
  54. return AVERROR(ENOMEM);
  55. st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
  56. st->codec->codec_id = s->iformat->raw_codec_id;
  57. st->need_parsing = AVSTREAM_PARSE_FULL;
  58. st->start_time = 0;
  59. /* the parameters will be extracted from the compressed bitstream */
  60. return 0;
  61. }
  62. /* MPEG-1/H.263 input */
  63. int ff_raw_video_read_header(AVFormatContext *s)
  64. {
  65. AVStream *st;
  66. FFRawVideoDemuxerContext *s1 = s->priv_data;
  67. AVRational framerate;
  68. int ret = 0;
  69. st = avformat_new_stream(s, NULL);
  70. if (!st) {
  71. ret = AVERROR(ENOMEM);
  72. goto fail;
  73. }
  74. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  75. st->codec->codec_id = s->iformat->raw_codec_id;
  76. st->need_parsing = AVSTREAM_PARSE_FULL;
  77. if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
  78. av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
  79. goto fail;
  80. }
  81. #if FF_API_R_FRAME_RATE
  82. st->r_frame_rate =
  83. #endif
  84. st->avg_frame_rate = framerate;
  85. avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
  86. fail:
  87. return ret;
  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_STRING, {.str = "25"}, 0, 0, DEC},
  94. { NULL },
  95. };
  96. #if CONFIG_LATM_DEMUXER
  97. AVInputFormat ff_latm_demuxer = {
  98. .name = "latm",
  99. .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
  100. .read_header = ff_raw_audio_read_header,
  101. .read_packet = ff_raw_read_partial_packet,
  102. .flags = AVFMT_GENERIC_INDEX,
  103. .extensions = "latm",
  104. .raw_codec_id = AV_CODEC_ID_AAC_LATM,
  105. };
  106. #endif
  107. #if CONFIG_MJPEG_DEMUXER
  108. FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", AV_CODEC_ID_MJPEG)
  109. #endif
  110. #if CONFIG_MLP_DEMUXER
  111. AVInputFormat ff_mlp_demuxer = {
  112. .name = "mlp",
  113. .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
  114. .read_header = ff_raw_audio_read_header,
  115. .read_packet = ff_raw_read_partial_packet,
  116. .flags = AVFMT_GENERIC_INDEX,
  117. .extensions = "mlp",
  118. .raw_codec_id = AV_CODEC_ID_MLP,
  119. };
  120. #endif
  121. #if CONFIG_TRUEHD_DEMUXER
  122. AVInputFormat ff_truehd_demuxer = {
  123. .name = "truehd",
  124. .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
  125. .read_header = ff_raw_audio_read_header,
  126. .read_packet = ff_raw_read_partial_packet,
  127. .flags = AVFMT_GENERIC_INDEX,
  128. .extensions = "thd",
  129. .raw_codec_id = AV_CODEC_ID_TRUEHD,
  130. };
  131. #endif
  132. #if CONFIG_SHORTEN_DEMUXER
  133. AVInputFormat ff_shorten_demuxer = {
  134. .name = "shn",
  135. .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"),
  136. .read_header = ff_raw_audio_read_header,
  137. .read_packet = ff_raw_read_partial_packet,
  138. .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
  139. .extensions = "shn",
  140. .raw_codec_id = AV_CODEC_ID_SHORTEN,
  141. };
  142. #endif
  143. #if CONFIG_VC1_DEMUXER
  144. FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", AV_CODEC_ID_VC1)
  145. #endif