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.

122 lines
3.3KB

  1. /*
  2. * VC1 Test Bitstreams Format Demuxer
  3. * Copyright (c) 2006, 2008 Konstantin Shishkov
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav 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. * Libav 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 Libav; 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->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
  53. st->codecpar->codec_id = AV_CODEC_ID_WMV3;
  54. st->codecpar->extradata = av_malloc(VC1_EXTRADATA_SIZE);
  55. if (!st->codecpar->extradata)
  56. return AVERROR(ENOMEM);
  57. st->codecpar->extradata_size = VC1_EXTRADATA_SIZE;
  58. avio_read(pb, st->codecpar->extradata, VC1_EXTRADATA_SIZE);
  59. st->codecpar->height = avio_rl32(pb);
  60. st->codecpar->width = avio_rl32(pb);
  61. if(avio_rl32(pb) != 0xC)
  62. return AVERROR_INVALIDDATA;
  63. avio_skip(pb, 8);
  64. fps = avio_rl32(pb);
  65. if(fps == 0xFFFFFFFF)
  66. avpriv_set_pts_info(st, 32, 1, 1000);
  67. else{
  68. if (!fps) {
  69. av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n");
  70. fps = 1;
  71. }
  72. avpriv_set_pts_info(st, 24, 1, fps);
  73. st->duration = frames;
  74. }
  75. return 0;
  76. }
  77. static int vc1t_read_packet(AVFormatContext *s,
  78. AVPacket *pkt)
  79. {
  80. AVIOContext *pb = s->pb;
  81. int frame_size;
  82. int keyframe = 0;
  83. uint32_t pts;
  84. if(pb->eof_reached)
  85. return AVERROR(EIO);
  86. frame_size = avio_rl24(pb);
  87. if(avio_r8(pb) & 0x80)
  88. keyframe = 1;
  89. pts = avio_rl32(pb);
  90. if(av_get_packet(pb, pkt, frame_size) < 0)
  91. return AVERROR(EIO);
  92. if(s->streams[0]->time_base.den == 1000)
  93. pkt->pts = pts;
  94. pkt->flags |= keyframe ? AV_PKT_FLAG_KEY : 0;
  95. pkt->pos -= 8;
  96. return pkt->size;
  97. }
  98. AVInputFormat ff_vc1t_demuxer = {
  99. .name = "vc1test",
  100. .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
  101. .read_probe = vc1t_probe,
  102. .read_header = vc1t_read_header,
  103. .read_packet = vc1t_read_packet,
  104. .flags = AVFMT_GENERIC_INDEX,
  105. };