vc1test.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 libavformat/vc1test.c
  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. #define VC1_EXTRADATA_SIZE 4
  30. static int vc1t_probe(AVProbeData *p)
  31. {
  32. if (p->buf[3] != 0xC5 && AV_RL32(&p->buf[4]) != 4)
  33. return 0;
  34. return AVPROBE_SCORE_MAX/2;
  35. }
  36. static int vc1t_read_header(AVFormatContext *s,
  37. AVFormatParameters *ap)
  38. {
  39. ByteIOContext *pb = s->pb;
  40. AVStream *st;
  41. int fps, frames;
  42. frames = get_le24(pb);
  43. if(get_byte(pb) != 0xC5 || get_le32(pb) != 4)
  44. return -1;
  45. /* init video codec */
  46. st = av_new_stream(s, 0);
  47. if (!st)
  48. return -1;
  49. st->codec->codec_type = CODEC_TYPE_VIDEO;
  50. st->codec->codec_id = CODEC_ID_WMV3;
  51. st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE);
  52. st->codec->extradata_size = VC1_EXTRADATA_SIZE;
  53. get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE);
  54. st->codec->height = get_le32(pb);
  55. st->codec->width = get_le32(pb);
  56. if(get_le32(pb) != 0xC)
  57. return -1;
  58. url_fskip(pb, 8);
  59. fps = get_le32(pb);
  60. if(fps == -1)
  61. av_set_pts_info(st, 32, 1, 1000);
  62. else{
  63. av_set_pts_info(st, 24, 1, fps);
  64. st->duration = frames;
  65. }
  66. return 0;
  67. }
  68. static int vc1t_read_packet(AVFormatContext *s,
  69. AVPacket *pkt)
  70. {
  71. ByteIOContext *pb = s->pb;
  72. int frame_size;
  73. int keyframe = 0;
  74. uint32_t pts;
  75. if(url_feof(pb))
  76. return AVERROR(EIO);
  77. frame_size = get_le24(pb);
  78. if(get_byte(pb) & 0x80)
  79. keyframe = 1;
  80. pts = get_le32(pb);
  81. if(av_get_packet(pb, pkt, frame_size) < 0)
  82. return AVERROR(EIO);
  83. if(s->streams[0]->time_base.den == 1000)
  84. pkt->pts = pts;
  85. pkt->flags |= keyframe ? PKT_FLAG_KEY : 0;
  86. pkt->pos -= 8;
  87. return pkt->size;
  88. }
  89. AVInputFormat vc1t_demuxer = {
  90. "vc1test",
  91. NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"),
  92. 0,
  93. vc1t_probe,
  94. vc1t_read_header,
  95. vc1t_read_packet,
  96. .flags = AVFMT_GENERIC_INDEX,
  97. };