vc1test.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_MAX/2;
  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 -1;
  48. /* init video codec */
  49. st = avformat_new_stream(s, NULL);
  50. if (!st)
  51. return -1;
  52. st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
  53. st->codec->codec_id = AV_CODEC_ID_WMV3;
  54. st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
  55. st->codec->extradata_size = VC1_EXTRADATA_SIZE;
  56. avio_read(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
  57. st->codec->height = avio_rl32(pb);
  58. st->codec->width = avio_rl32(pb);
  59. if(avio_rl32(pb) != 0xC)
  60. return -1;
  61. avio_skip(pb, 8);
  62. fps = avio_rl32(pb);
  63. if(fps == 0xFFFFFFFF)
  64. avpriv_set_pts_info(st, 32, 1, 1000);
  65. else{
  66. if (!fps) {
  67. av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n");
  68. fps = 1;
  69. }
  70. avpriv_set_pts_info(st, 24, 1, fps);
  71. st->duration = frames;
  72. }
  73. return 0;
  74. }
  75. static int vc1t_read_packet(AVFormatContext *s,
  76. AVPacket *pkt)
  77. {
  78. AVIOContext *pb = s->pb;
  79. int frame_size;
  80. int keyframe = 0;
  81. uint32_t pts;
  82. if(url_feof(pb))
  83. return AVERROR(EIO);
  84. frame_size = avio_rl24(pb);
  85. if(avio_r8(pb) & 0x80)
  86. keyframe = 1;
  87. pts = avio_rl32(pb);
  88. if(av_get_packet(pb, pkt, frame_size) < 0)
  89. return AVERROR(EIO);
  90. if(s->streams[0]->time_base.den == 1000)
  91. pkt->pts = pts;
  92. pkt->flags |= keyframe ? AV_PKT_FLAG_KEY : 0;
  93. pkt->pos -= 8;
  94. return pkt->size;
  95. }
  96. AVInputFormat ff_vc1t_demuxer = {
  97. .name = "vc1test",
  98. .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"),
  99. .read_probe = vc1t_probe,
  100. .read_header = vc1t_read_header,
  101. .read_packet = vc1t_read_packet,
  102. .flags = AVFMT_GENERIC_INDEX,
  103. };