vc1test.c 3.2 KB

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