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.

119 lines
3.2KB

  1. /*
  2. * VC1 Test Bitstreams Format Demuxer
  3. * Copyright (c) 2006, 2008 Konstantin Shishkov
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * VC1 test bitstream file demuxer
  24. * by Konstantin Shishkov
  25. * Format specified in SMPTE standard 421 Annex L
  26. */
  27. #include "libavutil/intreadwrite.h"
  28. #include "avformat.h"
  29. #include "internal.h"
  30. #define VC1_EXTRADATA_SIZE 4
  31. static int vc1t_probe(AVProbeData *p)
  32. {
  33. if (p->buf_size < 24)
  34. return 0;
  35. if (p->buf[3] != 0xC5 || AV_RL32(&p->buf[4]) != 4 || AV_RL32(&p->buf[20]) != 0xC)
  36. return 0;
  37. return AVPROBE_SCORE_EXTENSION;
  38. }
  39. static int vc1t_read_header(AVFormatContext *s)
  40. {
  41. AVIOContext *pb = s->pb;
  42. AVStream *st;
  43. int frames;
  44. uint32_t fps;
  45. frames = avio_rl24(pb);
  46. if(avio_r8(pb) != 0xC5 || avio_rl32(pb) != 4)
  47. return AVERROR_INVALIDDATA;
  48. /* init video codec */
  49. st = avformat_new_stream(s, NULL);
  50. if (!st)
  51. return AVERROR(ENOMEM);
  52. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  53. st->codec->codec_id = AV_CODEC_ID_WMV3;
  54. if (ff_get_extradata(st->codec, pb, VC1_EXTRADATA_SIZE) < 0)
  55. return AVERROR(ENOMEM);
  56. st->codec->height = avio_rl32(pb);
  57. st->codec->width = avio_rl32(pb);
  58. if(avio_rl32(pb) != 0xC)
  59. return AVERROR_INVALIDDATA;
  60. avio_skip(pb, 8);
  61. fps = avio_rl32(pb);
  62. if(fps == 0xFFFFFFFF)
  63. avpriv_set_pts_info(st, 32, 1, 1000);
  64. else{
  65. if (!fps) {
  66. av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n");
  67. fps = 1;
  68. }
  69. avpriv_set_pts_info(st, 24, 1, fps);
  70. st->duration = frames;
  71. }
  72. return 0;
  73. }
  74. static int vc1t_read_packet(AVFormatContext *s,
  75. AVPacket *pkt)
  76. {
  77. AVIOContext *pb = s->pb;
  78. int frame_size;
  79. int keyframe = 0;
  80. uint32_t pts;
  81. if(url_feof(pb))
  82. return AVERROR(EIO);
  83. frame_size = avio_rl24(pb);
  84. if(avio_r8(pb) & 0x80)
  85. keyframe = 1;
  86. pts = avio_rl32(pb);
  87. if(av_get_packet(pb, pkt, frame_size) < 0)
  88. return AVERROR(EIO);
  89. if(s->streams[0]->time_base.den == 1000)
  90. pkt->pts = pts;
  91. pkt->flags |= keyframe ? AV_PKT_FLAG_KEY : 0;
  92. pkt->pos -= 8;
  93. return pkt->size;
  94. }
  95. AVInputFormat ff_vc1t_demuxer = {
  96. .name = "vc1test",
  97. .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
  98. .read_probe = vc1t_probe,
  99. .read_header = vc1t_read_header,
  100. .read_packet = vc1t_read_packet,
  101. .flags = AVFMT_GENERIC_INDEX,
  102. };